Files
ladill-care/tests/Feature/CareWebTest.php
T
isaaccladandCursor 86bfce1e17
Deploy Ladill Care / deploy (push) Failing after 45s
Add workflow-centric patient journey with financial gates.
Introduces a facility workflow engine as Care's primary configuration
object: onboarding now leads with a facility category (which modules to
enable) and a workflow template (how patients move + where money is
collected), including standard herbal hospital/clinic templates.

Templates materialize into care_facility_workflows/care_workflow_stages.
The engine tracks a visit's position via care_visit_stage_advances and,
with FinancialGateService, gates a stage's queue behind a cleared
FinancialObligation (paid/authorized/waived/deferred) for "before"
payment timing while leaving "after" (pay-at-exit) flows unblocked.
Gated behavior is opt-in behind the workflow_engine/financial_gates
rollout flags; legacy orgs keep current behavior.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-17 20:47:33 +00:00

161 lines
5.1 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_category' => 'hospital',
'workflow_template' => 'public_hospital_gh',
'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']);
$this->assertDatabaseHas('care_facility_workflows', ['template_key' => 'public_hospital_gh']);
$this->assertDatabaseHas('care_workflow_stages', ['code' => 'consultation', 'requires_payment' => true]);
}
public function test_branches_index_loads(): void
{
// Free plan: multi-branch management is Pro-gated (setup branch still exists).
$this->actingAs($this->user)
->get(route('care.branches.index'))
->assertOk()
->assertSee('Upgrade your plan')
->assertSee('View plans')
->assertDontSee('Main Branch');
}
public function test_members_index_loads(): void
{
$this->actingAs($this->user)
->get(route('care.members.index'))
->assertOk()
->assertSee('Team members')
->assertSee('test@example.com')
->assertSee('Settings');
}
public function test_audit_log_index_loads(): void
{
$this->actingAs($this->user)
->get(route('care.audit.index'))
->assertOk()
->assertSee('Audit log');
}
}