withoutMiddleware(EnsurePlatformSession::class); $this->user = User::create([ 'public_id' => 'afia-user-001', 'name' => 'Afia User', 'email' => 'afia@example.com', ]); Organization::create([ 'owner_ref' => $this->user->public_id, 'name' => 'Afia Org', 'slug' => 'afia-org', 'settings' => ['onboarded' => true], ]); Member::create([ 'owner_ref' => $this->user->public_id, 'organization_id' => 1, 'user_ref' => $this->user->public_id, 'role' => 'org_admin', ]); } public function test_dashboard_includes_afia_button_and_panel(): void { $response = $this->actingAs($this->user)->get(route('frontdesk.dashboard')); $response->assertOk(); $response->assertSee('Open Afia AI assistant', false); $response->assertSee('Frontdesk assistant', false); $response->assertSee(route('frontdesk.ai.chat'), false); $response->assertSee('How do I set up a visitor kiosk?', false); } public function test_afia_chat_returns_reply_when_enabled(): void { config([ 'afia.enabled' => true, 'afia.api_key' => 'test-key', ]); $this->mock(AfiaService::class, function ($mock) { $mock->shouldReceive('enabled')->andReturn(true); $mock->shouldReceive('chat')->once()->andReturn('Register a Visitor Kiosk under Devices.'); }); $this->actingAs($this->user) ->postJson(route('frontdesk.ai.chat'), [ 'message' => 'How do I set up a kiosk?', ]) ->assertOk() ->assertJsonPath('reply', 'Register a Visitor Kiosk under Devices.'); } public function test_afia_chat_returns_service_unavailable_when_disabled(): void { config([ 'afia.enabled' => false, 'afia.api_key' => '', 'afia.platform_api_key' => '', ]); $this->actingAs($this->user) ->postJson(route('frontdesk.ai.chat'), [ 'message' => 'Hello', ]) ->assertStatus(503); } public function test_afia_chat_uses_platform_relay_when_local_key_missing(): void { config([ 'afia.enabled' => true, 'afia.api_key' => '', 'afia.platform_api_url' => 'https://platform.test/api', 'afia.platform_api_key' => 'frontdesk-relay-key', ]); Http::fake([ 'platform.test/api/afia/chat' => Http::response([ 'reply' => 'Open Devices and register a Visitor Kiosk.', ]), ]); $this->actingAs($this->user) ->postJson(route('frontdesk.ai.chat'), [ 'message' => 'How do I set up a kiosk?', ]) ->assertOk() ->assertJsonPath('reply', 'Open Devices and register a Visitor Kiosk.'); } }