Deploy Ladill Care / deploy (push) Successful in 53s
Remove the standalone Service Queues nav so call-next/now-serving lives on clinical queue, appointments, pharmacy, lab, and specialty surfaces; Pro orgs can activate dentistry and related modules with branch departments and queue stubs. Co-authored-by: Cursor <cursoragent@cursor.com>
144 lines
4.7 KiB
PHP
144 lines
4.7 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 App\Services\Care\SpecialtyModuleService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Tests\TestCase;
|
|
|
|
class CareSpecialtyModulesTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected User $owner;
|
|
|
|
protected Organization $organization;
|
|
|
|
protected Branch $branch;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->withoutMiddleware(EnsurePlatformSession::class);
|
|
|
|
$this->owner = User::create([
|
|
'public_id' => 'care-modules-owner',
|
|
'name' => 'Owner',
|
|
'email' => 'modules-owner@example.com',
|
|
]);
|
|
|
|
$this->organization = Organization::create([
|
|
'owner_ref' => $this->owner->public_id,
|
|
'name' => 'Modules Clinic',
|
|
'slug' => 'modules-clinic',
|
|
'settings' => [
|
|
'onboarded' => true,
|
|
'facility_type' => 'clinic',
|
|
'plan' => 'pro',
|
|
'plan_expires_at' => now()->addMonth()->toIso8601String(),
|
|
],
|
|
]);
|
|
|
|
Member::create([
|
|
'owner_ref' => $this->owner->public_id,
|
|
'organization_id' => $this->organization->id,
|
|
'user_ref' => $this->owner->public_id,
|
|
'role' => 'hospital_admin',
|
|
]);
|
|
|
|
$this->branch = Branch::create([
|
|
'owner_ref' => $this->owner->public_id,
|
|
'organization_id' => $this->organization->id,
|
|
'name' => 'Main',
|
|
'is_active' => true,
|
|
]);
|
|
}
|
|
|
|
public function test_activating_dentistry_creates_department_and_queue_stubs(): void
|
|
{
|
|
Http::fake();
|
|
|
|
$service = app(SpecialtyModuleService::class);
|
|
$service->activate($this->organization, $this->owner->public_id, 'dentistry');
|
|
|
|
$this->organization->refresh();
|
|
$this->assertTrue((bool) data_get($this->organization->settings, 'specialty_modules.dentistry'));
|
|
|
|
$this->assertDatabaseHas('care_departments', [
|
|
'branch_id' => $this->branch->id,
|
|
'type' => 'dental',
|
|
'name' => 'Dentistry',
|
|
'is_active' => true,
|
|
]);
|
|
|
|
$stubs = data_get($this->organization->settings, 'specialty_module_provisioning.dentistry.queues');
|
|
$this->assertIsArray($stubs);
|
|
$this->assertNotEmpty($stubs);
|
|
$this->assertSame('Dentistry', $stubs[0]['name']);
|
|
$this->assertSame($this->branch->id, $stubs[0]['branch_id']);
|
|
}
|
|
|
|
public function test_deactivating_hides_department_without_deleting(): void
|
|
{
|
|
Http::fake();
|
|
$service = app(SpecialtyModuleService::class);
|
|
$service->activate($this->organization, $this->owner->public_id, 'dentistry');
|
|
$department = Department::query()->where('type', 'dental')->firstOrFail();
|
|
|
|
$service->deactivate($this->organization->fresh(), $this->owner->public_id, 'dentistry');
|
|
|
|
$this->organization->refresh();
|
|
$this->assertFalse((bool) data_get($this->organization->settings, 'specialty_modules.dentistry'));
|
|
$this->assertFalse($department->fresh()->is_active);
|
|
$this->assertDatabaseHas('care_departments', ['id' => $department->id]);
|
|
}
|
|
|
|
public function test_free_plan_cannot_activate_modules_via_settings(): void
|
|
{
|
|
$this->organization->update([
|
|
'settings' => array_merge($this->organization->settings ?? [], [
|
|
'plan' => 'free',
|
|
'plan_expires_at' => null,
|
|
]),
|
|
]);
|
|
|
|
$this->actingAs($this->owner)
|
|
->put(route('care.settings.modules.update'), [
|
|
'modules' => ['dentistry' => '1'],
|
|
])
|
|
->assertRedirect(route('care.pro.index'))
|
|
->assertSessionHas('upsell');
|
|
}
|
|
|
|
public function test_modules_settings_page_lists_catalog(): void
|
|
{
|
|
$this->actingAs($this->owner)
|
|
->get(route('care.settings.modules'))
|
|
->assertOk()
|
|
->assertSee('Dentistry')
|
|
->assertSee('Eye care')
|
|
->assertSee('Physiotherapy')
|
|
->assertSee('Maternity')
|
|
->assertSee('Radiology');
|
|
}
|
|
|
|
public function test_specialty_page_visible_when_module_enabled(): void
|
|
{
|
|
Http::fake();
|
|
app(SpecialtyModuleService::class)->activate($this->organization, $this->owner->public_id, 'dentistry');
|
|
|
|
$this->actingAs($this->owner)
|
|
->get(route('care.specialty.show', 'dentistry'))
|
|
->assertOk()
|
|
->assertSee('Dentistry')
|
|
->assertSee('Departments');
|
|
}
|
|
}
|