withoutMiddleware(EnsurePlatformSession::class); $this->user = User::create([ 'public_id' => 'phase11-user-001', 'name' => 'Phase11 User', 'email' => 'phase11@example.com', ]); $this->organization = Organization::create([ 'owner_ref' => $this->user->public_id, 'name' => 'Phase11 Org', 'slug' => 'phase11-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_dashboard_stats_are_cached(): void { Cache::flush(); $this->actingAs($this->user)->get(route('frontdesk.dashboard'))->assertOk(); $this->assertTrue(Cache::has('fd:dashboard:'.$this->user->public_id.':'.$this->organization->id.':all')); } public function test_kiosk_device_route_is_rate_limited(): void { RateLimiter::clear('kiosk-device'); $device = Device::create([ 'owner_ref' => $this->user->public_id, 'organization_id' => $this->organization->id, 'name' => 'Limited Kiosk', 'type' => 'kiosk', 'device_token' => 'rate-limit-token', 'status' => 'offline', ]); for ($i = 0; $i < 31; $i++) { $response = $this->postJson(route('frontdesk.kiosk.device.check-in', $device->device_token), [ 'full_name' => 'Guest '.$i, 'visitor_type' => 'visitor', 'policies_accepted' => 1, ]); } $response->assertStatus(429); } public function test_offline_sync_replays_queued_check_in(): void { $device = Device::create([ 'owner_ref' => $this->user->public_id, 'organization_id' => $this->organization->id, 'branch_id' => Branch::first()->id, 'name' => 'Offline Kiosk', 'type' => 'kiosk', 'device_token' => 'offline-sync-token', 'status' => 'online', ]); $clientId = '550e8400-e29b-41d4-a716-446655440000'; $this->postJson('/api/kiosk/offline-sync', [ 'client_id' => $clientId, 'payload' => [ 'full_name' => 'Offline Guest', 'visitor_type' => 'visitor', 'policies_accepted' => true, ], ], ['X-Device-Token' => $device->device_token]) ->assertCreated() ->assertJsonPath('status', 'synced'); $this->postJson('/api/kiosk/offline-sync', [ 'client_id' => $clientId, 'payload' => [ 'full_name' => 'Offline Guest', 'visitor_type' => 'visitor', 'policies_accepted' => true, ], ], ['X-Device-Token' => $device->device_token]) ->assertOk() ->assertJsonPath('status', 'already_synced'); } public function test_kiosk_device_can_check_out_visitor_by_badge_code(): void { $device = Device::create([ 'owner_ref' => $this->user->public_id, 'organization_id' => $this->organization->id, 'name' => 'Checkout Kiosk', 'type' => 'kiosk', 'device_token' => 'checkout-kiosk-token', 'status' => 'online', ]); $visitor = Visitor::create([ 'owner_ref' => $this->user->public_id, 'organization_id' => $this->organization->id, 'full_name' => 'Leaving Guest', ]); $visit = Visit::create([ 'owner_ref' => $this->user->public_id, 'organization_id' => $this->organization->id, 'visitor_id' => $visitor->id, 'visitor_type' => 'visitor', 'status' => Visit::STATUS_CHECKED_IN, 'checked_in_at' => now(), 'badge_code' => 'LEAVE123', 'qr_token' => 'qr-checkout-token-32chars-long-ok', ]); $this->postJson(route('frontdesk.kiosk.device.check-out', $device->device_token), [ 'badge_code' => 'leave123', ]) ->assertOk() ->assertJsonPath('visit.visitor_name', 'Leaving Guest') ->assertJsonPath('visit.badge_code', 'LEAVE123'); $this->assertSame(Visit::STATUS_CHECKED_OUT, $visit->fresh()->status); } public function test_kiosk_device_check_out_rejects_unknown_badge(): void { $device = Device::create([ 'owner_ref' => $this->user->public_id, 'organization_id' => $this->organization->id, 'name' => 'Checkout Kiosk', 'type' => 'kiosk', 'device_token' => 'checkout-kiosk-token-2', 'status' => 'online', ]); $this->postJson(route('frontdesk.kiosk.device.check-out', $device->device_token), [ 'badge_code' => 'UNKNOWN1', ]) ->assertStatus(422) ->assertJsonValidationErrors('credentials'); } }