Files
ladill-frontdesk/tests/Feature/FrontdeskAfiaTest.php
T
isaaccladandCursor 5a42759886
Deploy Ladill Frontdesk / deploy (push) Successful in 34s
Wire Afia into Frontdesk and sync the app launcher catalog.
Add the AI assistant button, chat endpoint, and Frontdesk-specific prompts, and include Frontdesk in the shared launcher config used by the app switcher.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-28 01:40:32 +00:00

87 lines
2.5 KiB
PHP

<?php
namespace Tests\Feature;
use App\Http\Middleware\EnsurePlatformSession;
use App\Models\Member;
use App\Models\Organization;
use App\Models\User;
use App\Services\Afia\AfiaService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class FrontdeskAfiaTest extends TestCase
{
use RefreshDatabase;
protected User $user;
protected function setUp(): void
{
parent::setUp();
$this->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' => '']);
$this->actingAs($this->user)
->postJson(route('frontdesk.ai.chat'), [
'message' => 'Hello',
])
->assertStatus(503);
}
}