Keep Care org onboarded during demo login reseed.
Deploy Ladill Care / deploy (push) Successful in 1m19s

Avoid the onboarding flash when reset-on-login deletes the tenant before the afterResponse() reseed finishes.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-17 19:29:09 +00:00
co-authored by Cursor
parent a3521247e0
commit 2c2cc1e938
2 changed files with 41 additions and 2 deletions
+16 -2
View File
@@ -249,14 +249,28 @@ class DemoTenantSeeder
DB::table('care_practitioner_schedules')->where('owner_ref', $ownerRef)->delete();
DB::table('care_practitioners')->where('owner_ref', $ownerRef)->delete();
DB::table('care_members')->where('owner_ref', $ownerRef)->delete();
// Keep the owner member + organization so SSO redirects never see
// "not onboarded" while afterResponse() reseeding is still running.
DB::table('care_members')
->where('owner_ref', $ownerRef)
->where('user_ref', '!=', $ownerRef)
->delete();
DB::table('care_departments')->where('owner_ref', $ownerRef)->delete();
DB::table('care_branches')->where('owner_ref', $ownerRef)->delete();
DB::table('care_messaging_credentials')->where('owner_ref', $ownerRef)->delete();
DB::table('care_payment_gateway_settings')->where('owner_ref', $ownerRef)->delete();
DB::table('care_audit_logs')->where('owner_ref', $ownerRef)->delete();
DB::table('care_organizations')->where('owner_ref', $ownerRef)->delete();
$organization = Organization::withTrashed()->where('owner_ref', $ownerRef)->first();
if ($organization) {
if ($organization->trashed()) {
$organization->restore();
}
$settings = $organization->settings ?? [];
$settings['onboarded'] = true;
$organization->forceFill(['settings' => $settings])->save();
}
}
/**
+25
View File
@@ -188,6 +188,31 @@ class DemoSeedCommandTest extends TestCase
$this->assertSame(1, Branch::query()->where('owner_ref', $keep->public_id)->count());
}
public function test_reset_keeps_organization_onboarded_mid_wipe(): void
{
$user = User::create([
'public_id' => 'demo-mid-reset-id',
'name' => 'Mid Reset Demo',
'email' => 'demo-mid-reset@ladill.com',
]);
$this->artisan('demo:seed', [
'identity' => 'demo-mid-reset@ladill.com',
'--plan' => 'free',
])->assertSuccessful();
$orgId = (int) Organization::query()->where('owner_ref', $user->public_id)->value('id');
$this->assertGreaterThan(0, $orgId);
app(DemoTenantSeeder::class)->resetTenant($user->public_id);
$org = Organization::query()->find($orgId);
$this->assertNotNull($org);
$this->assertTrue((bool) data_get($org->settings, 'onboarded'));
$this->assertTrue(app(\App\Services\Care\OrganizationResolver::class)->isOnboarded($user));
$this->assertSame(0, Branch::query()->where('owner_ref', $user->public_id)->count());
}
public function test_creates_local_mirror_when_public_id_and_email_provided(): void
{
$this->assertDatabaseMissing('users', ['email' => 'new-demo@ladill.com']);