Deploy Ladill Frontdesk / deploy (push) Successful in 45s
Frontdesk now calls ladill.com/api/afia/chat using IDENTITY_API_KEY_FRONTDESK so production does not need a separate OpenAI key in the frontdesk .env. Co-authored-by: Cursor <cursoragent@cursor.com>
115 lines
3.4 KiB
PHP
115 lines
3.4 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 Illuminate\Support\Facades\Http;
|
|
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' => '',
|
|
'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.');
|
|
}
|
|
}
|