diff --git a/app/Http/Controllers/Api/IntegrationController.php b/app/Http/Controllers/Api/IntegrationController.php index a7e800e..c979457 100644 --- a/app/Http/Controllers/Api/IntegrationController.php +++ b/app/Http/Controllers/Api/IntegrationController.php @@ -96,6 +96,10 @@ class IntegrationController extends Controller AuditLogger::record($owner, 'organization.created', $organization->id, $owner, Organization::class, $organization->id); } + if (in_array($caller, ['care', 'frontdesk'], true)) { + $this->syncIntegrationFlag($organization->fresh(), $caller, true); + } + return response()->json([ 'data' => [ 'provisioned' => true, diff --git a/tests/Feature/CareIntegrationTest.php b/tests/Feature/CareIntegrationTest.php new file mode 100644 index 0000000..f380178 --- /dev/null +++ b/tests/Feature/CareIntegrationTest.php @@ -0,0 +1,52 @@ + 'test-care-key']); + + return [ + 'Authorization' => 'Bearer test-care-key', + 'Accept' => 'application/json', + ]; + } + + public function test_provision_enables_care_integration(): void + { + $owner = 'care-owner-uuid'; + + $this->postJson('/api/v1/integrations/provision', [ + 'owner' => $owner, + 'organization_name' => 'Care Clinic', + 'branch_name' => 'Main', + ], $this->careHeaders($owner)) + ->assertCreated() + ->assertJsonPath('data.integrations.care', true); + + $organization = Organization::owned($owner)->first(); + $this->assertTrue((bool) data_get($organization->settings, 'integrations.care_enabled')); + } + + public function test_counters_allowed_after_care_provision(): void + { + $owner = 'care-owner-uuid'; + $headers = $this->careHeaders($owner); + + $this->postJson('/api/v1/integrations/provision', [ + 'owner' => $owner, + 'organization_name' => 'Care Clinic', + ], $headers)->assertSuccessful(); + + $this->getJson('/api/v1/counters?owner='.$owner, $headers) + ->assertOk(); + } +}