Files
ladill-frontdesk/tests/Feature/FrontdeskPhase10Test.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

140 lines
4.5 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Organization;
use App\Models\User;
use App\Models\Visit;
use App\Models\Visitor;
use App\Models\WebhookEndpoint;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
class FrontdeskPhase10Test extends TestCase
{
use RefreshDatabase;
protected string $careKey = 'test-care-api-key';
protected User $user;
protected Organization $organization;
protected function setUp(): void
{
parent::setUp();
config(['frontdesk.service_api_keys' => ['care' => $this->careKey, 'lab' => 'test-lab-key']]);
$this->user = User::create([
'public_id' => 'phase10-user-001',
'name' => 'Phase10 User',
'email' => 'phase10@example.com',
]);
$this->organization = Organization::create([
'owner_ref' => $this->user->public_id,
'name' => 'Phase10 Org',
'slug' => 'phase10-org',
'settings' => ['onboarded' => true],
]);
}
public function test_care_api_can_create_visit_with_external_ref(): void
{
$response = $this->withHeaders(['Authorization' => 'Bearer '.$this->careKey])
->postJson('/api/visits', [
'owner' => $this->user->public_id,
'organization_id' => $this->organization->id,
'external_ref' => 'care-appt-001',
'full_name' => 'Care Patient',
'visitor_type' => 'visitor',
'integration_metadata' => ['appointment_id' => 'A-100'],
]);
$response->assertCreated();
$this->assertDatabaseHas('frontdesk_visits', [
'external_ref' => 'care-appt-001',
'source' => 'care',
]);
}
public function test_external_ref_is_idempotent_for_same_source(): void
{
$payload = [
'owner' => $this->user->public_id,
'organization_id' => $this->organization->id,
'external_ref' => 'lab-specimen-42',
'full_name' => 'Lab Walk-in',
'visitor_type' => 'visitor',
];
config(['frontdesk.service_api_keys' => ['lab' => 'test-lab-key']]);
$this->withHeaders(['Authorization' => 'Bearer test-lab-key'])
->postJson('/api/visits', $payload)
->assertCreated();
$this->withHeaders(['Authorization' => 'Bearer test-lab-key'])
->postJson('/api/visits', $payload)
->assertOk();
$this->assertSame(1, Visit::where('external_ref', 'lab-specimen-42')->count());
}
public function test_webhook_dispatched_on_check_in(): void
{
Http::fake();
WebhookEndpoint::create([
'owner_ref' => $this->user->public_id,
'organization_id' => $this->organization->id,
'url' => 'https://example.com/webhooks/frontdesk',
'secret' => 'secret123',
'events' => ['visit.checked_in'],
'is_active' => true,
]);
$this->withHeaders(['Authorization' => 'Bearer '.$this->careKey])
->postJson('/api/visits', [
'owner' => $this->user->public_id,
'organization_id' => $this->organization->id,
'full_name' => 'Webhook Guest',
'visitor_type' => 'visitor',
])
->assertCreated();
Http::assertSent(fn ($request) => $request->url() === 'https://example.com/webhooks/frontdesk');
}
public function test_ical_feed_returns_calendar_data(): void
{
$visitor = Visitor::create([
'owner_ref' => $this->user->public_id,
'organization_id' => $this->organization->id,
'full_name' => 'Scheduled Guest',
]);
Visit::create([
'owner_ref' => $this->user->public_id,
'organization_id' => $this->organization->id,
'visitor_id' => $visitor->id,
'visitor_type' => 'visitor',
'status' => Visit::STATUS_EXPECTED,
'scheduled_at' => now()->addHours(2),
]);
$token = hash_hmac('sha256', "{$this->organization->id}:{$this->user->public_id}", (string) config('app.key'));
$this->get(route('frontdesk.integrations.ical', [
'organization' => $this->organization->id,
'owner' => $this->user->public_id,
'token' => $token,
]))
->assertOk()
->assertHeader('content-type', 'text/calendar; charset=utf-8')
->assertSee('BEGIN:VCALENDAR');
}
}