Require package reinstall after industry change and wipe old queues.
Deploy Ladill Queue / deploy (push) Successful in 1m5s
Deploy Ladill Queue / deploy (push) Successful in 1m5s
Changing industry now flags a pending reinstall with an app banner; reinstall clears queues, tickets, and service points before applying the new template. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -206,4 +206,96 @@ class IndustryPackageTest extends TestCase
|
||||
$this->assertSame($before, ServiceQueue::where('organization_id', $org->id)->count());
|
||||
$this->assertSame('patient', data_get($org->fresh()->settings, 'industry_package.ticket_entity'));
|
||||
}
|
||||
|
||||
public function test_replace_install_clears_previous_queues_and_tickets(): void
|
||||
{
|
||||
$user = User::create([
|
||||
'public_id' => 'pkg-replace-owner',
|
||||
'name' => 'Replace Owner',
|
||||
'email' => 'replace-owner@example.com',
|
||||
'password' => bcrypt('password'),
|
||||
]);
|
||||
|
||||
$org = app(OrganizationResolver::class)->completeOnboarding($user, [
|
||||
'organization_name' => 'Cafe',
|
||||
'industry' => 'restaurant',
|
||||
'appointment_mode' => 'hybrid',
|
||||
'branch_name' => 'Main',
|
||||
'timezone' => 'UTC',
|
||||
]);
|
||||
$org->update([
|
||||
'settings' => array_merge($org->settings ?? [], [
|
||||
'plan' => 'pro',
|
||||
'plan_expires_at' => now()->addMonth()->toIso8601String(),
|
||||
]),
|
||||
]);
|
||||
|
||||
$branch = Branch::where('organization_id', $org->id)->first();
|
||||
$oldQueue = ServiceQueue::where('organization_id', $org->id)->first();
|
||||
$this->assertNotNull($oldQueue);
|
||||
|
||||
app(QueueEngine::class)->issueTicket($oldQueue, $user->public_id, [
|
||||
'customer_name' => 'Old Ticket',
|
||||
'source' => 'reception',
|
||||
]);
|
||||
$this->assertGreaterThan(0, \App\Models\Ticket::where('organization_id', $org->id)->count());
|
||||
|
||||
$result = app(IndustryPackageInstaller::class)->install($org->fresh(), $branch, 'banking', [
|
||||
'replace' => true,
|
||||
'include_optional' => true,
|
||||
]);
|
||||
|
||||
$this->assertTrue($result['replaced']);
|
||||
$this->assertSame(0, \App\Models\Ticket::where('organization_id', $org->id)->count());
|
||||
$this->assertFalse(
|
||||
ServiceQueue::where('organization_id', $org->id)->where('id', $oldQueue->id)->exists()
|
||||
);
|
||||
$this->assertSame('banking', data_get($org->fresh()->settings, 'industry_package.key'));
|
||||
$this->assertNull(data_get($org->fresh()->settings, 'industry_package_needs_reinstall'));
|
||||
$this->assertGreaterThanOrEqual(3, ServiceQueue::where('organization_id', $org->id)->count());
|
||||
}
|
||||
|
||||
public function test_changing_industry_requires_reinstall_without_auto_provision(): void
|
||||
{
|
||||
$this->withoutMiddleware(\App\Http\Middleware\EnsurePlatformSession::class);
|
||||
|
||||
$user = User::create([
|
||||
'public_id' => 'pkg-settings-owner',
|
||||
'name' => 'Settings Owner',
|
||||
'email' => 'settings-pkg@example.com',
|
||||
'password' => bcrypt('password'),
|
||||
]);
|
||||
|
||||
$org = app(OrganizationResolver::class)->completeOnboarding($user, [
|
||||
'organization_name' => 'Shop',
|
||||
'industry' => 'restaurant',
|
||||
'appointment_mode' => 'hybrid',
|
||||
'branch_name' => 'Main',
|
||||
'timezone' => 'UTC',
|
||||
]);
|
||||
|
||||
$beforeQueues = ServiceQueue::where('organization_id', $org->id)->count();
|
||||
|
||||
$this->actingAs($user)
|
||||
->put(route('qms.settings.update'), [
|
||||
'name' => $org->name,
|
||||
'timezone' => $org->timezone,
|
||||
'appointment_mode' => 'hybrid',
|
||||
'industry' => 'banking',
|
||||
'notifications_enabled' => '1',
|
||||
])
|
||||
->assertRedirect();
|
||||
|
||||
$org->refresh();
|
||||
$this->assertSame('banking', data_get($org->settings, 'industry'));
|
||||
$this->assertSame('restaurant', data_get($org->settings, 'industry_package.key'));
|
||||
$this->assertTrue((bool) data_get($org->settings, 'industry_package_needs_reinstall'));
|
||||
$this->assertTrue(IndustryPackageInstaller::needsReinstall($org));
|
||||
$this->assertSame($beforeQueues, ServiceQueue::where('organization_id', $org->id)->count());
|
||||
|
||||
$this->actingAs($user)
|
||||
->get(route('qms.dashboard'))
|
||||
->assertOk()
|
||||
->assertSee('Reinstall industry package required');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user