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'); } }