Add employee presence with kiosk sign-in, QR badges, and mobile step-out.
Deploy Ladill Frontdesk / deploy (push) Failing after 26s
Deploy Ladill Frontdesk / deploy (push) Failing after 26s
Enables staff roster, PIN/code kiosk flow, attendance reports, evacuation staff roll call, webhooks, branch mismatch warnings, and a linked-user My presence portal. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,206 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Http\Middleware\EnsurePlatformSession;
|
||||
use App\Models\Branch;
|
||||
use App\Models\Device;
|
||||
use App\Models\Employee;
|
||||
use App\Models\Member;
|
||||
use App\Models\Organization;
|
||||
use App\Models\User;
|
||||
use App\Models\WebhookEndpoint;
|
||||
use App\Services\Frontdesk\EmployeePresenceService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Tests\TestCase;
|
||||
|
||||
class FrontdeskEmployeePhase23Test extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected User $user;
|
||||
|
||||
protected Organization $organization;
|
||||
|
||||
protected Branch $homeBranch;
|
||||
|
||||
protected Branch $otherBranch;
|
||||
|
||||
protected string $deviceToken;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->withoutMiddleware(EnsurePlatformSession::class);
|
||||
|
||||
$this->user = User::create([
|
||||
'public_id' => 'phase23-user',
|
||||
'name' => 'Phase 23 User',
|
||||
'email' => 'phase23@example.com',
|
||||
]);
|
||||
|
||||
$this->organization = Organization::create([
|
||||
'owner_ref' => $this->user->public_id,
|
||||
'name' => 'Phase 23 Org',
|
||||
'slug' => 'phase23-org',
|
||||
'settings' => ['onboarded' => true, 'employee_kiosk_enabled' => true],
|
||||
]);
|
||||
|
||||
Member::create([
|
||||
'owner_ref' => $this->user->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'user_ref' => $this->user->public_id,
|
||||
'role' => 'org_admin',
|
||||
]);
|
||||
|
||||
$this->homeBranch = Branch::create([
|
||||
'owner_ref' => $this->user->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'name' => 'HQ',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$this->otherBranch = Branch::create([
|
||||
'owner_ref' => $this->user->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'name' => 'Annex',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$this->deviceToken = 'kiosk-phase23-'.str_repeat('z', 32);
|
||||
|
||||
Device::create([
|
||||
'owner_ref' => $this->user->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'branch_id' => $this->otherBranch->id,
|
||||
'name' => 'Annex Kiosk',
|
||||
'type' => 'kiosk',
|
||||
'status' => 'offline',
|
||||
'device_token' => $this->deviceToken,
|
||||
]);
|
||||
}
|
||||
|
||||
protected function createEmployee(array $overrides = []): Employee
|
||||
{
|
||||
$service = app(EmployeePresenceService::class);
|
||||
|
||||
$employee = Employee::create([
|
||||
'owner_ref' => $this->user->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'branch_id' => $this->homeBranch->id,
|
||||
'employee_code' => 'P23001',
|
||||
'full_name' => 'Alex Staff',
|
||||
'pin_hash' => $service->hashPin('5678'),
|
||||
'active' => true,
|
||||
...$overrides,
|
||||
]);
|
||||
|
||||
$service->presenceFor($employee);
|
||||
|
||||
return $employee->fresh();
|
||||
}
|
||||
|
||||
public function test_kiosk_identifies_employee_by_qr_token(): void
|
||||
{
|
||||
$employee = $this->createEmployee();
|
||||
|
||||
$this->postJson(route('frontdesk.kiosk.device.staff.action', $this->deviceToken), [
|
||||
'qr_token' => $employee->qr_token,
|
||||
'pin' => '5678',
|
||||
'action' => 'identify',
|
||||
])->assertOk()
|
||||
->assertJsonPath('employee.full_name', 'Alex Staff');
|
||||
}
|
||||
|
||||
public function test_branch_mismatch_requires_confirmation(): void
|
||||
{
|
||||
$this->createEmployee();
|
||||
|
||||
$this->postJson(route('frontdesk.kiosk.device.staff.action', $this->deviceToken), [
|
||||
'employee_code' => 'P23001',
|
||||
'pin' => '5678',
|
||||
'action' => 'sign_in',
|
||||
])->assertUnprocessable()
|
||||
->assertJsonValidationErrors(['branch_mismatch']);
|
||||
|
||||
$this->postJson(route('frontdesk.kiosk.device.staff.action', $this->deviceToken), [
|
||||
'employee_code' => 'P23001',
|
||||
'pin' => '5678',
|
||||
'action' => 'sign_in',
|
||||
'confirm_branch_mismatch' => true,
|
||||
])->assertOk()
|
||||
->assertJsonPath('employee.status', 'on_site');
|
||||
}
|
||||
|
||||
public function test_employee_portal_step_out_without_kiosk(): void
|
||||
{
|
||||
$employee = $this->createEmployee(['user_ref' => $this->user->public_id]);
|
||||
app(EmployeePresenceService::class)->signIn($employee)['presence'];
|
||||
|
||||
$this->actingAs($this->user)
|
||||
->post(route('frontdesk.employee.portal.action'), [
|
||||
'action' => 'step_out',
|
||||
'step_out_reason' => 'lunch',
|
||||
'destination' => 'Cafeteria',
|
||||
])
|
||||
->assertRedirect(route('frontdesk.employee.portal'));
|
||||
|
||||
$this->assertDatabaseHas('frontdesk_employee_presence', [
|
||||
'employee_id' => $employee->id,
|
||||
'status' => 'stepped_out',
|
||||
'destination' => 'Cafeteria',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_evacuation_report_includes_staff(): void
|
||||
{
|
||||
$employee = $this->createEmployee();
|
||||
app(EmployeePresenceService::class)->signIn($employee, null, true)['presence'];
|
||||
|
||||
$this->actingAs($this->user)
|
||||
->get(route('frontdesk.security.evacuation'))
|
||||
->assertOk()
|
||||
->assertSee('Alex Staff', false)
|
||||
->assertSee('Staff', false);
|
||||
}
|
||||
|
||||
public function test_employee_webhook_dispatched_on_sign_in(): void
|
||||
{
|
||||
Http::fake();
|
||||
|
||||
WebhookEndpoint::create([
|
||||
'owner_ref' => $this->user->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'url' => 'https://example.com/hooks/frontdesk',
|
||||
'secret' => 'secret',
|
||||
'events' => ['employee.signed_in'],
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$employee = $this->createEmployee(['branch_id' => $this->otherBranch->id]);
|
||||
|
||||
$this->postJson(route('frontdesk.kiosk.device.staff.action', $this->deviceToken), [
|
||||
'employee_code' => 'P23001',
|
||||
'pin' => '5678',
|
||||
'action' => 'sign_in',
|
||||
])->assertOk();
|
||||
|
||||
Http::assertSent(fn ($request) => $request->url() === 'https://example.com/hooks/frontdesk'
|
||||
&& $request['event'] === 'employee.signed_in'
|
||||
&& $request['employee']['employee_code'] === 'P23001');
|
||||
}
|
||||
|
||||
public function test_hr_attendance_export(): void
|
||||
{
|
||||
$employee = $this->createEmployee();
|
||||
app(EmployeePresenceService::class)->signIn($employee, null, true);
|
||||
|
||||
$response = $this->actingAs($this->user)
|
||||
->get(route('frontdesk.employees.export.attendance'));
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertStringContainsString('Alex Staff', $response->streamedContent());
|
||||
$this->assertStringContainsString('Sign in', $response->streamedContent());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Http\Middleware\EnsurePlatformSession;
|
||||
use App\Models\Device;
|
||||
use App\Models\Employee;
|
||||
use App\Models\Member;
|
||||
use App\Models\Organization;
|
||||
use App\Models\User;
|
||||
use App\Services\Frontdesk\EmployeePresenceService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class FrontdeskEmployeePresenceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected User $user;
|
||||
|
||||
protected Organization $organization;
|
||||
|
||||
protected string $deviceToken;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->withoutMiddleware(EnsurePlatformSession::class);
|
||||
|
||||
$this->user = User::create([
|
||||
'public_id' => 'emp-user-001',
|
||||
'name' => 'Employee Test User',
|
||||
'email' => 'employee-test@example.com',
|
||||
]);
|
||||
|
||||
$this->organization = Organization::create([
|
||||
'owner_ref' => $this->user->public_id,
|
||||
'name' => 'Employee Org',
|
||||
'slug' => 'employee-org',
|
||||
'settings' => ['onboarded' => true, 'employee_kiosk_enabled' => true],
|
||||
]);
|
||||
|
||||
Member::create([
|
||||
'owner_ref' => $this->user->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'user_ref' => $this->user->public_id,
|
||||
'role' => 'org_admin',
|
||||
]);
|
||||
|
||||
$this->deviceToken = 'kiosk-employee-'.str_repeat('y', 32);
|
||||
|
||||
Device::create([
|
||||
'owner_ref' => $this->user->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'name' => 'Lobby Kiosk',
|
||||
'type' => 'kiosk',
|
||||
'status' => 'offline',
|
||||
'device_token' => $this->deviceToken,
|
||||
]);
|
||||
}
|
||||
|
||||
protected function createEmployee(string $code = 'EMP001', string $pin = '1234'): Employee
|
||||
{
|
||||
$service = app(EmployeePresenceService::class);
|
||||
|
||||
$employee = Employee::create([
|
||||
'owner_ref' => $this->user->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'employee_code' => $code,
|
||||
'full_name' => 'Jane Staff',
|
||||
'department' => 'Operations',
|
||||
'pin_hash' => $service->hashPin($pin),
|
||||
'active' => true,
|
||||
]);
|
||||
|
||||
$service->presenceFor($employee);
|
||||
|
||||
return $employee;
|
||||
}
|
||||
|
||||
public function test_admin_can_create_employee(): void
|
||||
{
|
||||
$this->actingAs($this->user)
|
||||
->post(route('frontdesk.employees.store'), [
|
||||
'employee_code' => 'EMP100',
|
||||
'full_name' => 'Kwame Ops',
|
||||
'pin' => '4321',
|
||||
'department' => 'Ops',
|
||||
])
|
||||
->assertRedirect(route('frontdesk.employees.index'));
|
||||
|
||||
$this->assertDatabaseHas('frontdesk_employees', [
|
||||
'employee_code' => 'EMP100',
|
||||
'full_name' => 'Kwame Ops',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_kiosk_staff_sign_in_and_step_out_flow(): void
|
||||
{
|
||||
$this->createEmployee();
|
||||
|
||||
$this->postJson(route('frontdesk.kiosk.device.staff.action', $this->deviceToken), [
|
||||
'employee_code' => 'EMP001',
|
||||
'pin' => '1234',
|
||||
'action' => 'sign_in',
|
||||
])->assertOk()
|
||||
->assertJsonPath('employee.status', 'on_site');
|
||||
|
||||
$this->postJson(route('frontdesk.kiosk.device.staff.action', $this->deviceToken), [
|
||||
'employee_code' => 'EMP001',
|
||||
'pin' => '1234',
|
||||
'action' => 'step_out',
|
||||
'step_out_reason' => 'client_visit',
|
||||
'destination' => 'Client office',
|
||||
])->assertOk()
|
||||
->assertJsonPath('employee.status', 'stepped_out')
|
||||
->assertJsonPath('employee.destination', 'Client office');
|
||||
|
||||
$this->postJson(route('frontdesk.kiosk.device.staff.action', $this->deviceToken), [
|
||||
'employee_code' => 'EMP001',
|
||||
'pin' => '1234',
|
||||
'action' => 'step_in',
|
||||
])->assertOk()
|
||||
->assertJsonPath('employee.status', 'on_site');
|
||||
|
||||
$this->postJson(route('frontdesk.kiosk.device.staff.action', $this->deviceToken), [
|
||||
'employee_code' => 'EMP001',
|
||||
'pin' => '1234',
|
||||
'action' => 'sign_out',
|
||||
])->assertOk()
|
||||
->assertJsonPath('employee.status', 'off_site');
|
||||
|
||||
$this->assertDatabaseCount('frontdesk_employee_presence_events', 4);
|
||||
}
|
||||
|
||||
public function test_kiosk_rejects_invalid_pin(): void
|
||||
{
|
||||
$this->createEmployee();
|
||||
|
||||
$this->postJson(route('frontdesk.kiosk.device.staff.action', $this->deviceToken), [
|
||||
'employee_code' => 'EMP001',
|
||||
'pin' => '9999',
|
||||
'action' => 'sign_in',
|
||||
])->assertUnprocessable();
|
||||
}
|
||||
|
||||
public function test_security_dashboard_lists_staff_on_site(): void
|
||||
{
|
||||
$employee = $this->createEmployee();
|
||||
app(EmployeePresenceService::class)->signIn($employee)['presence'];
|
||||
|
||||
$this->actingAs($this->user)
|
||||
->get(route('frontdesk.security.index'))
|
||||
->assertOk()
|
||||
->assertSee('Jane Staff', false)
|
||||
->assertSee('Staff on premises', false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user