Visitor management app with SSO, kiosk, badges, reports, and Gitea CI deploy to frontdesk.ladill.com. Co-authored-by: Cursor <cursoragent@cursor.com>
178 lines
6.1 KiB
PHP
178 lines
6.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Http\Middleware\EnsurePlatformSession;
|
|
use App\Models\Branch;
|
|
use App\Models\Member;
|
|
use App\Models\Organization;
|
|
use App\Models\User;
|
|
use App\Models\Visit;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class FrontdeskPhase4Test extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected User $user;
|
|
|
|
protected Organization $organization;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->withoutMiddleware(EnsurePlatformSession::class);
|
|
|
|
$this->user = User::create([
|
|
'public_id' => 'phase4-user-001',
|
|
'name' => 'Phase4 User',
|
|
'email' => 'phase4@example.com',
|
|
]);
|
|
|
|
$this->organization = Organization::create([
|
|
'owner_ref' => $this->user->public_id,
|
|
'name' => 'Phase4 Org',
|
|
'slug' => 'phase4-org',
|
|
'settings' => ['onboarded' => true, 'badge_expiry_hours' => 8],
|
|
]);
|
|
|
|
Member::create([
|
|
'owner_ref' => $this->user->public_id,
|
|
'organization_id' => $this->organization->id,
|
|
'user_ref' => $this->user->public_id,
|
|
'role' => 'org_admin',
|
|
]);
|
|
|
|
Branch::create([
|
|
'owner_ref' => $this->user->public_id,
|
|
'organization_id' => $this->organization->id,
|
|
'name' => 'HQ',
|
|
'is_active' => true,
|
|
]);
|
|
}
|
|
|
|
public function test_contractor_check_in_stores_details_and_extended_badge(): void
|
|
{
|
|
$this->actingAs($this->user)
|
|
->post(route('frontdesk.visits.store'), [
|
|
'full_name' => 'Site Worker',
|
|
'visitor_type' => 'contractor',
|
|
'policies_accepted' => '1',
|
|
'type_fields' => [
|
|
'contract_company' => 'BuildCo',
|
|
'supervisor' => 'Jane Smith',
|
|
'safety_induction_completed' => '1',
|
|
'permit_number' => 'PERMIT-99',
|
|
],
|
|
])
|
|
->assertRedirect();
|
|
|
|
$visit = Visit::first();
|
|
$this->assertSame(Visit::STATUS_CHECKED_IN, $visit->status);
|
|
$this->assertSame('BuildCo', $visit->contractor_details['contract_company']);
|
|
$this->assertSame('PERMIT-99', $visit->contractor_details['permit_number']);
|
|
$this->assertTrue($visit->badge_expires_at->greaterThan(now()->addHours(11)));
|
|
}
|
|
|
|
public function test_delivery_check_in_records_received_time(): void
|
|
{
|
|
$this->actingAs($this->user)
|
|
->post(route('frontdesk.visits.store'), [
|
|
'full_name' => 'Courier',
|
|
'visitor_type' => 'delivery',
|
|
'policies_accepted' => '1',
|
|
'type_fields' => [
|
|
'courier_company' => 'FastPost',
|
|
'recipient' => 'Finance Dept',
|
|
'tracking_number' => 'TRK123',
|
|
],
|
|
])
|
|
->assertRedirect();
|
|
|
|
$visit = Visit::first();
|
|
$this->assertSame('FastPost', $visit->delivery_details['courier_company']);
|
|
$this->assertArrayHasKey('received_at', $visit->delivery_details);
|
|
$this->assertTrue($visit->badge_expires_at->lessThanOrEqualTo(now()->addHours(2)->addMinute()));
|
|
}
|
|
|
|
public function test_vendor_check_in_requires_approval(): void
|
|
{
|
|
$this->actingAs($this->user)
|
|
->post(route('frontdesk.visits.store'), [
|
|
'full_name' => 'Vendor Rep',
|
|
'visitor_type' => 'vendor',
|
|
'policies_accepted' => '1',
|
|
'type_fields' => [
|
|
'vendor_company' => 'Supply Ltd',
|
|
'service_type' => 'Office supplies',
|
|
],
|
|
])
|
|
->assertRedirect()
|
|
->assertSessionHas('success', 'Visit submitted for approval.');
|
|
|
|
$visit = Visit::first();
|
|
$this->assertSame(Visit::STATUS_WAITING, $visit->status);
|
|
$this->assertNull($visit->checked_in_at);
|
|
$this->assertTrue($visit->awaitingApproval());
|
|
|
|
$this->actingAs($this->user)
|
|
->post(route('frontdesk.visits.approve', $visit))
|
|
->assertRedirect();
|
|
|
|
$visit->refresh();
|
|
$this->assertSame(Visit::STATUS_CHECKED_IN, $visit->status);
|
|
$this->assertNotNull($visit->checked_in_at);
|
|
}
|
|
|
|
public function test_kiosk_contractor_check_in_via_json(): void
|
|
{
|
|
$this->actingAs($this->user)
|
|
->postJson(route('frontdesk.kiosk.check-in'), [
|
|
'full_name' => 'Kiosk Contractor',
|
|
'visitor_type' => 'contractor',
|
|
'policies_accepted' => true,
|
|
'type_fields' => [
|
|
'contract_company' => 'Kiosk Build',
|
|
'supervisor' => 'Supervisor',
|
|
'safety_induction_completed' => true,
|
|
],
|
|
])
|
|
->assertOk()
|
|
->assertJsonPath('visit.status', Visit::STATUS_CHECKED_IN);
|
|
|
|
$this->assertDatabaseHas('frontdesk_visits', [
|
|
'visitor_type' => 'contractor',
|
|
'status' => Visit::STATUS_CHECKED_IN,
|
|
]);
|
|
}
|
|
|
|
public function test_org_can_override_contractor_badge_expiry(): void
|
|
{
|
|
$this->actingAs($this->user)
|
|
->put(route('frontdesk.settings.update'), [
|
|
'name' => 'Phase4 Org',
|
|
'timezone' => 'UTC',
|
|
'badge_expiry_hours' => 8,
|
|
'kiosk_reset_seconds' => 120,
|
|
'contractor_badge_expiry_hours' => 16,
|
|
])
|
|
->assertRedirect();
|
|
|
|
$this->actingAs($this->user)
|
|
->post(route('frontdesk.visits.store'), [
|
|
'full_name' => 'Long Shift Worker',
|
|
'visitor_type' => 'contractor',
|
|
'policies_accepted' => '1',
|
|
'type_fields' => [
|
|
'contract_company' => 'BuildCo',
|
|
'supervisor' => 'Jane Smith',
|
|
'safety_induction_completed' => '1',
|
|
],
|
|
]);
|
|
|
|
$visit = Visit::latest()->first();
|
|
$this->assertTrue($visit->badge_expires_at->greaterThan(now()->addHours(15)));
|
|
}
|
|
}
|