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

164 lines
5.1 KiB
PHP

<?php
namespace Tests\Feature;
use App\Http\Middleware\EnsurePlatformSession;
use App\Models\Branch;
use App\Models\Host;
use App\Models\Member;
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 FrontdeskWebTest extends TestCase
{
use RefreshDatabase;
protected User $user;
protected Organization $organization;
protected function setUp(): void
{
parent::setUp();
$this->withoutMiddleware(EnsurePlatformSession::class);
$this->user = User::create([
'public_id' => 'test-user-001',
'name' => 'Test User',
'email' => 'test@example.com',
]);
$this->organization = Organization::create([
'owner_ref' => $this->user->public_id,
'name' => 'Test Org',
'slug' => 'test-org',
'timezone' => 'UTC',
'settings' => ['onboarded' => true, 'badge_expiry_hours' => 8, 'kiosk_reset_seconds' => 120],
]);
Member::create([
'owner_ref' => $this->user->public_id,
'organization_id' => $this->organization->id,
'user_ref' => $this->user->public_id,
'role' => 'org_admin',
]);
Branch::create([
'owner_ref' => $this->user->public_id,
'organization_id' => $this->organization->id,
'name' => 'Main Office',
'is_active' => true,
]);
}
public function test_guest_is_redirected_to_sso(): void
{
$this->get('/dashboard')->assertRedirect();
}
public function test_unonboarded_user_is_redirected_to_onboarding(): void
{
Organization::query()->delete();
Member::query()->delete();
$this->actingAs($this->user)
->get(route('frontdesk.dashboard'))
->assertRedirect(route('frontdesk.onboarding.show'));
}
public function test_dashboard_loads_for_authenticated_user(): void
{
$this->actingAs($this->user)
->get(route('frontdesk.dashboard'))
->assertOk()
->assertSee('Reception dashboard');
}
public function test_receptionist_can_check_in_visitor(): void
{
$host = Host::create([
'owner_ref' => $this->user->public_id,
'organization_id' => $this->organization->id,
'name' => 'Jane Host',
'email' => 'jane@example.com',
]);
$response = $this->actingAs($this->user)->post(route('frontdesk.visits.store'), [
'full_name' => 'John Visitor',
'company' => 'Acme Corp',
'phone' => '+233201234567',
'email' => 'john@example.com',
'host_id' => $host->id,
'visitor_type' => 'visitor',
'purpose' => 'Meeting',
'policies_accepted' => '1',
]);
$response->assertRedirect();
$this->assertDatabaseHas('frontdesk_visitors', ['full_name' => 'John Visitor']);
$this->assertDatabaseHas('frontdesk_visits', ['status' => Visit::STATUS_CHECKED_IN]);
}
public function test_receptionist_can_check_out_visitor(): void
{
$visitor = Visitor::create([
'owner_ref' => $this->user->public_id,
'organization_id' => $this->organization->id,
'full_name' => 'John Visitor',
]);
$visit = 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->actingAs($this->user)
->post(route('frontdesk.visits.checkout', $visit))
->assertRedirect();
$this->assertEquals(Visit::STATUS_CHECKED_OUT, $visit->fresh()->status);
}
public function test_blacklisted_visitor_cannot_check_in(): void
{
$visitor = Visitor::create([
'owner_ref' => $this->user->public_id,
'organization_id' => $this->organization->id,
'full_name' => 'Blocked Person',
'watchlist_status' => Visitor::WATCHLIST_BLACKLISTED,
]);
$this->actingAs($this->user)->post(route('frontdesk.visits.store'), [
'visitor_id' => $visitor->id,
'full_name' => 'Blocked Person',
'visitor_type' => 'visitor',
'policies_accepted' => '1',
])->assertStatus(403);
}
public function test_org_admin_can_update_settings(): void
{
$this->actingAs($this->user)
->put(route('frontdesk.settings.update'), [
'name' => 'Updated Org',
'timezone' => 'Africa/Accra',
'badge_expiry_hours' => 6,
'kiosk_reset_seconds' => 90,
'notification_channels' => ['email'],
])
->assertRedirect();
$this->organization->refresh();
$this->assertEquals('Updated Org', $this->organization->name);
$this->assertEquals(6, $this->organization->settings['badge_expiry_hours']);
}
}