Visitor management app with SSO, kiosk, badges, reports, and Gitea CI deploy to frontdesk.ladill.com. Co-authored-by: Cursor <cursoragent@cursor.com>
141 lines
4.2 KiB
PHP
141 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Http\Middleware\EnsurePlatformSession;
|
|
use App\Models\Branch;
|
|
use App\Models\Member;
|
|
use App\Models\Organization;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class FrontdeskPhase2Test extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected User $admin;
|
|
|
|
protected Organization $organization;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->withoutMiddleware(EnsurePlatformSession::class);
|
|
|
|
$this->admin = User::create([
|
|
'public_id' => 'admin-001',
|
|
'name' => 'Admin User',
|
|
'email' => 'admin@example.com',
|
|
]);
|
|
|
|
$this->organization = Organization::create([
|
|
'owner_ref' => $this->admin->public_id,
|
|
'name' => 'Phase2 Org',
|
|
'slug' => 'phase2-org',
|
|
'settings' => ['onboarded' => true],
|
|
]);
|
|
|
|
Member::create([
|
|
'owner_ref' => $this->admin->public_id,
|
|
'organization_id' => $this->organization->id,
|
|
'user_ref' => $this->admin->public_id,
|
|
'role' => 'org_admin',
|
|
]);
|
|
}
|
|
|
|
public function test_onboarding_creates_organization_and_branch(): void
|
|
{
|
|
Organization::query()->delete();
|
|
Member::query()->delete();
|
|
|
|
$this->actingAs($this->admin)
|
|
->post(route('frontdesk.onboarding.store'), [
|
|
'organization_name' => 'New Corp',
|
|
'branch_name' => 'HQ',
|
|
'timezone' => 'UTC',
|
|
'badge_expiry_hours' => 8,
|
|
])
|
|
->assertRedirect(route('frontdesk.dashboard'));
|
|
|
|
$this->assertDatabaseHas('frontdesk_organizations', ['name' => 'New Corp']);
|
|
$this->assertDatabaseHas('frontdesk_branches', ['name' => 'HQ']);
|
|
$this->assertDatabaseHas('frontdesk_members', ['role' => 'org_admin']);
|
|
}
|
|
|
|
public function test_org_admin_can_create_branch(): void
|
|
{
|
|
$this->actingAs($this->admin)
|
|
->post(route('frontdesk.branches.store'), [
|
|
'name' => 'East Wing',
|
|
'address' => '123 Main St',
|
|
])
|
|
->assertRedirect(route('frontdesk.branches.index'));
|
|
|
|
$this->assertDatabaseHas('frontdesk_branches', ['name' => 'East Wing']);
|
|
}
|
|
|
|
public function test_org_admin_can_add_team_member(): void
|
|
{
|
|
$branch = Branch::create([
|
|
'owner_ref' => $this->admin->public_id,
|
|
'organization_id' => $this->organization->id,
|
|
'name' => 'Main',
|
|
'is_active' => true,
|
|
]);
|
|
|
|
$this->actingAs($this->admin)
|
|
->post(route('frontdesk.members.store'), [
|
|
'user_ref' => 'receptionist-001',
|
|
'role' => 'receptionist',
|
|
'branch_id' => $branch->id,
|
|
])
|
|
->assertRedirect(route('frontdesk.members.index'));
|
|
|
|
$this->assertDatabaseHas('frontdesk_members', [
|
|
'user_ref' => 'receptionist-001',
|
|
'role' => 'receptionist',
|
|
]);
|
|
}
|
|
|
|
public function test_receptionist_cannot_manage_branches(): void
|
|
{
|
|
$receptionist = User::create([
|
|
'public_id' => 'receptionist-001',
|
|
'name' => 'Receptionist',
|
|
'email' => 'rec@example.com',
|
|
]);
|
|
|
|
Member::create([
|
|
'owner_ref' => $this->admin->public_id,
|
|
'organization_id' => $this->organization->id,
|
|
'user_ref' => $receptionist->public_id,
|
|
'role' => 'receptionist',
|
|
]);
|
|
|
|
$this->actingAs($receptionist)
|
|
->get(route('frontdesk.branches.create'))
|
|
->assertForbidden();
|
|
}
|
|
|
|
public function test_receptionist_can_access_check_in(): void
|
|
{
|
|
$receptionist = User::create([
|
|
'public_id' => 'receptionist-002',
|
|
'name' => 'Receptionist Two',
|
|
'email' => 'rec2@example.com',
|
|
]);
|
|
|
|
Member::create([
|
|
'owner_ref' => $this->admin->public_id,
|
|
'organization_id' => $this->organization->id,
|
|
'user_ref' => $receptionist->public_id,
|
|
'role' => 'receptionist',
|
|
]);
|
|
|
|
$this->actingAs($receptionist)
|
|
->get(route('frontdesk.visits.create'))
|
|
->assertOk();
|
|
}
|
|
}
|