'test-owner-uuid', 'name' => 'Test User', 'email' => 'test@example.com', 'password' => bcrypt('password'), ]); $resolver = app(OrganizationResolver::class); $org = $resolver->completeOnboarding($user, [ 'organization_name' => 'Test Org', 'industry' => 'custom', 'appointment_mode' => 'hybrid', 'branch_name' => 'Main', 'timezone' => 'UTC', ]); $branch = Branch::first(); $queue = ServiceQueue::query() ->where('organization_id', $org->id) ->where('branch_id', $branch->id) ->orderBy('id') ->first(); if (! $queue) { $queue = ServiceQueue::create([ 'owner_ref' => $user->public_id, 'organization_id' => $org->id, 'branch_id' => $branch->id, 'name' => 'Reception', 'prefix' => 'A', 'strategy' => 'fifo', 'is_active' => true, ]); } else { $queue->update(['name' => 'Reception', 'prefix' => 'A']); $queue = $queue->fresh(); } return [$user, $org, $branch, $queue]; } public function test_display_data_includes_pending_announcement_after_call(): void { [$user, , $branch, $queue] = $this->setUpOrg(); $counter = Counter::create([ 'owner_ref' => $user->public_id, 'organization_id' => $queue->organization_id, 'branch_id' => $queue->branch_id, 'name' => 'Counter 1', 'status' => 'available', 'is_active' => true, ]); $screen = DisplayScreen::create([ 'owner_ref' => $user->public_id, 'organization_id' => $queue->organization_id, 'branch_id' => $branch->id, 'name' => 'Lobby', 'layout' => 'standard', 'service_queue_ids' => [$queue->id], 'is_active' => true, ]); $engine = app(QueueEngine::class); $ticket = $engine->issueTicket($queue, $user->public_id); $engine->callTicket($ticket, $counter, $user->public_id); $response = $this->getJson(route('qms.display.data', $screen->access_token)); $response->assertOk() ->assertJsonPath('announcements.0.message', 'Ticket A001, please proceed to Counter 1.') ->assertJsonPath('waiting_count', 0) ->assertJsonPath('now_serving.0.ticket_number', 'A001') ->assertJsonPath('now_serving.0.queue_name', 'Reception') ->assertJsonPath('now_serving.0.counter', 'Counter 1'); $this->get(route('qms.display.public', $screen->access_token)) ->assertOk() ->assertDontSee('qms-display__ticket--newest') ->assertSee('Please proceed to') ->assertSee('A001') ->assertSee('Reception') ->assertSee('Counter 1'); } public function test_display_shows_only_latest_ticket_per_counter(): void { [$user, , $branch, $queue] = $this->setUpOrg(); $room12 = Counter::create([ 'owner_ref' => $user->public_id, 'organization_id' => $queue->organization_id, 'branch_id' => $queue->branch_id, 'name' => 'Room 12', 'status' => 'available', 'is_active' => true, ]); $room14 = Counter::create([ 'owner_ref' => $user->public_id, 'organization_id' => $queue->organization_id, 'branch_id' => $queue->branch_id, 'name' => 'Room 14', 'status' => 'available', 'is_active' => true, ]); $screen = DisplayScreen::create([ 'owner_ref' => $user->public_id, 'organization_id' => $queue->organization_id, 'branch_id' => $branch->id, 'name' => 'Busy Lobby', 'layout' => 'standard', 'service_queue_ids' => [$queue->id], 'is_active' => true, ]); foreach ([ ['A001', $room12->id, 6], ['A002', $room12->id, 5], ['A003', $room12->id, 2], ['A004', $room14->id, 4], ['A005', $room14->id, 1], ] as [$number, $counterId, $minutesAgo]) { Ticket::create([ 'owner_ref' => $user->public_id, 'organization_id' => $queue->organization_id, 'branch_id' => $branch->id, 'service_queue_id' => $queue->id, 'counter_id' => $counterId, 'ticket_number' => $number, 'status' => 'called', 'issued_at' => now()->subMinutes(20), 'called_at' => now()->subMinutes($minutesAgo), ]); } $payload = $this->getJson(route('qms.display.data', $screen->access_token)) ->assertOk() ->assertJsonCount(2, 'now_serving') ->json('now_serving'); $byCounter = collect($payload)->keyBy('counter'); $this->assertSame('A003', $byCounter['Room 12']['ticket_number']); $this->assertSame('A005', $byCounter['Room 14']['ticket_number']); // Stable alphabetical order by destination — equal presentation, no newest-first primacy. $this->assertSame(['Room 12', 'Room 14'], collect($payload)->pluck('counter')->all()); } public function test_display_falls_back_to_branch_queues_when_none_assigned(): void { [$user, , $branch, $queue] = $this->setUpOrg(); $screen = DisplayScreen::create([ 'owner_ref' => $user->public_id, 'organization_id' => $queue->organization_id, 'branch_id' => $branch->id, 'name' => 'Lobby', 'layout' => 'standard', 'service_queue_ids' => [], 'is_active' => true, ]); app(QueueEngine::class)->issueTicket($queue, $user->public_id); $this->getJson(route('qms.display.data', $screen->access_token)) ->assertOk() ->assertJsonPath('waiting_count', 1) ->assertJsonPath('queues.0.name', 'Reception'); } public function test_display_marks_announcement_played(): void { [$user, , $branch, $queue] = $this->setUpOrg(); $screen = DisplayScreen::create([ 'owner_ref' => $user->public_id, 'organization_id' => $queue->organization_id, 'branch_id' => $branch->id, 'name' => 'Lobby', 'layout' => 'standard', 'service_queue_ids' => [$queue->id], 'is_active' => true, ]); $announcement = VoiceAnnouncement::create([ 'owner_ref' => $user->public_id, 'organization_id' => $queue->organization_id, 'branch_id' => $branch->id, 'locale' => 'en', 'message' => 'Ticket A001, please proceed to Counter 1.', 'status' => 'pending', ]); $this->postJson(route('qms.display.announcement.played', [ 'token' => $screen->access_token, 'announcement' => $announcement->id, ]))->assertOk(); $this->assertSame('played', $announcement->fresh()->status); } }