Files
ladill-care/tests/Feature/CareWebTest.php
T
isaaccladandCursor 2f1ebd5387
Deploy Ladill Care / deploy (push) Successful in 25s
Show patients in queue on the doctor dashboard.
Clinical staff without admin KPIs get waiting and in-consultation lists in the empty space.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-15 00:54:28 +00:00

153 lines
4.6 KiB
PHP

<?php
namespace Tests\Feature;
use App\Http\Middleware\EnsurePlatformSession;
use App\Models\Branch;
use App\Models\Department;
use App\Models\Member;
use App\Models\Organization;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class CareWebTest 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 Clinic',
'slug' => 'test-clinic',
'timezone' => 'UTC',
'settings' => ['onboarded' => true, 'facility_type' => 'clinic'],
]);
Member::create([
'owner_ref' => $this->user->public_id,
'organization_id' => $this->organization->id,
'user_ref' => $this->user->public_id,
'role' => 'hospital_admin',
]);
$branch = Branch::create([
'owner_ref' => $this->user->public_id,
'organization_id' => $this->organization->id,
'name' => 'Main Branch',
'is_active' => true,
]);
Department::create([
'owner_ref' => $this->user->public_id,
'branch_id' => $branch->id,
'name' => 'General Outpatient',
'type' => 'outpatient',
'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('care.dashboard'))
->assertRedirect(route('care.onboarding.show'));
}
public function test_dashboard_loads_for_authenticated_user(): void
{
$this->actingAs($this->user)
->get(route('care.dashboard'))
->assertOk()
->assertSee('Test Clinic')
->assertSee('Revenue today')
->assertSee('Open bills');
}
public function test_doctor_dashboard_hides_finance_metrics(): void
{
Member::where('user_ref', $this->user->public_id)->update(['role' => 'doctor']);
$this->actingAs($this->user)
->get(route('care.dashboard'))
->assertOk()
->assertSee('Patients today')
->assertSee('Appointments today')
->assertSee('Patients in queue')
->assertSee('No patients waiting right now.')
->assertDontSee('Revenue today')
->assertDontSee('Open bills')
->assertDontSee('Team members')
->assertDontSee('Active branches');
}
public function test_onboarding_creates_organization(): void
{
Organization::query()->delete();
Member::query()->delete();
Branch::query()->delete();
Department::query()->delete();
$this->actingAs($this->user)
->post(route('care.onboarding.store'), [
'organization_name' => 'Accra Medical Centre',
'facility_type' => 'hospital',
'branch_name' => 'Head Office',
'branch_address' => '123 Main St',
'branch_phone' => '+233201234567',
'timezone' => 'Africa/Accra',
])
->assertRedirect(route('care.dashboard'));
$this->assertDatabaseHas('care_organizations', ['name' => 'Accra Medical Centre']);
$this->assertDatabaseHas('care_branches', ['name' => 'Head Office']);
$this->assertDatabaseHas('care_departments', ['name' => 'General Outpatient']);
}
public function test_branches_index_loads(): void
{
$this->actingAs($this->user)
->get(route('care.branches.index'))
->assertOk()
->assertSee('Main Branch');
}
public function test_members_index_loads(): void
{
$this->actingAs($this->user)
->get(route('care.members.index'))
->assertOk()
->assertSee('test-user-001');
}
public function test_audit_log_index_loads(): void
{
$this->actingAs($this->user)
->get(route('care.audit.index'))
->assertOk()
->assertSee('Audit log');
}
}