Files
ladill-frontdesk/tests/Feature/FrontdeskPhase8Test.php
T
isaacclad b6f229ab9a
Deploy Ladill Frontdesk / deploy (push) Has been cancelled
Tighten Pro alert caps and move custom badges to Enterprise.
Pro includes 5,000 email and 5,000 SMS host alerts per month with hard
monthly caps; Enterprise is unlimited. Custom badge templates are
Enterprise-only, and plan benefit copy matches the new limits.
2026-07-16 08:37:06 +00:00

185 lines
5.9 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 App\Models\Visit;
use App\Models\Visitor;
use App\Services\Frontdesk\VisitorTypeService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class FrontdeskPhase8Test extends TestCase
{
use RefreshDatabase;
protected User $user;
protected Organization $organization;
protected function setUp(): void
{
parent::setUp();
Storage::fake('public');
$this->withoutMiddleware(EnsurePlatformSession::class);
$this->user = User::create([
'public_id' => 'phase8-user-001',
'name' => 'Phase8 User',
'email' => 'phase8@example.com',
]);
$this->organization = Organization::create([
'owner_ref' => $this->user->public_id,
'name' => 'Phase8 Org',
'slug' => 'phase8-org',
'settings' => [
'onboarded' => true,
'badge_expiry_hours' => 8,
'badge_template' => ['show_qr' => true, 'show_photo' => true],
],
]);
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' => 'HQ',
'is_active' => true,
]);
}
public function test_badge_template_settings_can_be_updated_on_enterprise(): void
{
$this->organization->update([
'settings' => array_merge($this->organization->settings ?? [], [
'plan' => 'enterprise',
'plan_expires_at' => now()->addYear()->toIso8601String(),
]),
]);
$this->actingAs($this->user)
->put(route('frontdesk.settings.badge.update'), [
'show_photo' => '1',
'show_qr' => '1',
'show_host' => '1',
'show_company' => '0',
'show_type' => '1',
'primary_color' => '#ff0000',
'footer_text' => 'Property of Phase8 Org',
])
->assertRedirect();
$settings = $this->organization->fresh()->settings;
$this->assertSame('#ff0000', $settings['badge_template']['primary_color']);
$this->assertFalse($settings['badge_template']['show_company']);
}
public function test_badge_template_requires_enterprise(): void
{
$this->organization->update([
'settings' => array_merge($this->organization->settings ?? [], [
'plan' => 'pro',
'plan_expires_at' => now()->addMonth()->toIso8601String(),
]),
]);
$this->actingAs($this->user)
->get(route('frontdesk.settings.badge'))
->assertOk()
->assertSee('Upgrade your plan');
$this->actingAs($this->user)
->put(route('frontdesk.settings.badge.update'), [
'show_photo' => '1',
'show_qr' => '1',
'primary_color' => '#00ff00',
])
->assertRedirect(route('frontdesk.pro.index'))
->assertSessionHas('error');
}
public function test_check_in_stores_photo_from_base64(): void
{
$png = 'data:image/png;base64,'.base64_encode(UploadedFile::fake()->image('photo.png')->getContent());
$this->actingAs($this->user)
->post(route('frontdesk.visits.store'), [
'full_name' => 'Photo Guest',
'visitor_type' => 'visitor',
'policies_accepted' => '1',
'photo_data' => $png,
])
->assertRedirect();
$visit = Visit::first();
$this->assertNotNull($visit->photo_path);
Storage::disk('public')->assertExists($visit->photo_path);
}
public function test_badge_preview_renders_for_checked_in_visit(): void
{
$visitor = Visitor::create([
'owner_ref' => $this->user->public_id,
'organization_id' => $this->organization->id,
'full_name' => 'Badge Guest',
]);
$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(),
'badge_code' => 'ABC123',
'qr_token' => 'qr-token-123',
'badge_expires_at' => now()->addHours(8),
]);
$this->actingAs($this->user)
->get(route('frontdesk.visits.badge.preview', $visit))
->assertOk()
->assertSee('Badge Guest')
->assertSee('ABC123');
}
public function test_evacuation_badges_page_lists_current_visitors(): void
{
$visitor = Visitor::create([
'owner_ref' => $this->user->public_id,
'organization_id' => $this->organization->id,
'full_name' => 'Inside Guest',
]);
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(),
'badge_code' => 'EVAC1',
'qr_token' => 'evac-token',
'badge_expires_at' => now()->addHours(8),
]);
$this->actingAs($this->user)
->get(route('frontdesk.security.evacuation.badges'))
->assertOk()
->assertSee('Inside Guest');
}
}