Deploy Ladill Frontdesk / deploy (push) Successful in 23s
Show Ladill Frontdesk or uploaded logo top-left on kiosk; allow logo upload in onboarding and organization settings. Co-authored-by: Cursor <cursoragent@cursor.com>
208 lines
6.8 KiB
PHP
208 lines
6.8 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 Illuminate\Http\UploadedFile;
|
|
use Illuminate\Support\Facades\Storage;
|
|
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']);
|
|
}
|
|
|
|
public function test_org_admin_can_upload_organization_logo(): void
|
|
{
|
|
Storage::fake('public');
|
|
|
|
$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'],
|
|
'logo' => UploadedFile::fake()->image('company-logo.png', 400, 120),
|
|
])
|
|
->assertRedirect();
|
|
|
|
$this->organization->refresh();
|
|
$this->assertNotNull($this->organization->logo_path);
|
|
Storage::disk('public')->assertExists($this->organization->logo_path);
|
|
}
|
|
|
|
public function test_org_admin_can_remove_organization_logo(): void
|
|
{
|
|
Storage::fake('public');
|
|
$path = UploadedFile::fake()->image('company-logo.png')->store('frontdesk/organizations/'.$this->organization->id, 'public');
|
|
$this->organization->update(['logo_path' => $path]);
|
|
|
|
$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'],
|
|
'remove_logo' => '1',
|
|
])
|
|
->assertRedirect();
|
|
|
|
$this->organization->refresh();
|
|
$this->assertNull($this->organization->logo_path);
|
|
Storage::disk('public')->assertMissing($path);
|
|
}
|
|
}
|