Files
ladill-frontdesk/tests/Feature/FrontdeskApiTest.php
T
isaaccladandCursor 9e2d79936c
Deploy Ladill Frontdesk / deploy (push) Failing after 35s
Test / test (push) Failing after 2m45s
Initial Ladill Frontdesk release with deploy pipeline.
Visitor management app with SSO, kiosk, badges, reports, and Gitea CI deploy to frontdesk.ladill.com.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-27 20:37:15 +00:00

118 lines
3.5 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Organization;
use App\Models\User;
use App\Models\Visit;
use App\Models\Visitor;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class FrontdeskApiTest extends TestCase
{
use RefreshDatabase;
protected string $apiKey = 'test-frontdesk-api-key';
protected User $user;
protected Organization $organization;
protected function setUp(): void
{
parent::setUp();
config(['frontdesk.service_api_keys' => ['care' => $this->apiKey]]);
$this->user = User::create([
'public_id' => 'api-user-001',
'name' => 'API User',
'email' => 'api@example.com',
]);
$this->organization = Organization::create([
'owner_ref' => $this->user->public_id,
'name' => 'API Org',
'slug' => 'api-org',
'settings' => ['onboarded' => true],
]);
}
public function test_api_requires_service_key(): void
{
$this->getJson('/api/visits?owner='.$this->user->public_id)
->assertUnauthorized();
}
public function test_api_can_create_visit(): void
{
$response = $this->withHeaders(['Authorization' => 'Bearer '.$this->apiKey])
->postJson('/api/visits', [
'owner' => $this->user->public_id,
'organization_id' => $this->organization->id,
'full_name' => 'API Visitor',
'visitor_type' => 'visitor',
]);
$response->assertCreated();
$this->assertDatabaseHas('frontdesk_visits', ['visitor_type' => 'visitor']);
}
public function test_api_can_list_visits(): void
{
$visitor = Visitor::create([
'owner_ref' => $this->user->public_id,
'organization_id' => $this->organization->id,
'full_name' => 'Listed Visitor',
]);
Visit::create([
'owner_ref' => $this->user->public_id,
'organization_id' => $this->organization->id,
'visitor_id' => $visitor->id,
'visitor_type' => 'visitor',
'status' => Visit::STATUS_CHECKED_IN,
'checked_in_at' => now(),
]);
$this->withHeaders(['Authorization' => 'Bearer '.$this->apiKey])
->getJson('/api/visits?owner='.$this->user->public_id)
->assertOk()
->assertJsonPath('total', 1);
}
public function test_api_scopes_to_owner(): void
{
$other = User::create([
'public_id' => 'other-user',
'name' => 'Other',
'email' => 'other@example.com',
]);
$visitor = Visitor::create([
'owner_ref' => $other->public_id,
'organization_id' => Organization::create([
'owner_ref' => $other->public_id,
'name' => 'Other Org',
'slug' => 'other',
])->id,
'full_name' => 'Secret Visitor',
]);
Visit::create([
'owner_ref' => $other->public_id,
'organization_id' => $visitor->organization_id,
'visitor_id' => $visitor->id,
'visitor_type' => 'visitor',
'status' => Visit::STATUS_CHECKED_IN,
'checked_in_at' => now(),
]);
$this->withHeaders(['Authorization' => 'Bearer '.$this->apiKey])
->getJson('/api/visits?owner='.$this->user->public_id)
->assertOk()
->assertJsonPath('total', 0);
}
}