Reseed demo tenants after each SSO login.
Deploy Ladill Events / deploy (push) Successful in 2m18s

Demo Free/Pro/Enterprise accounts wipe and reload sample data on
authorization-code SSO callbacks so every sales walkthrough starts clean.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-17 11:19:04 +00:00
co-authored by Cursor
parent 66e6e117de
commit da5fc51262
5 changed files with 190 additions and 0 deletions
+80
View File
@@ -0,0 +1,80 @@
<?php
namespace Tests\Feature;
use App\Models\User;
use App\Services\Events\DemoLoginReseeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;
use Tests\TestCase;
class DemoLoginReseederTest extends TestCase
{
use RefreshDatabase;
public function test_reseeds_demo_free_account_via_artisan_after_login(): void
{
config([
'demo_accounts.enabled' => true,
'demo_accounts.reset_on_login' => true,
]);
$user = User::factory()->create([
'public_id' => (string) Str::uuid(),
'email' => 'demo-free@ladill.com',
]);
Artisan::shouldReceive('call')
->once()
->withArgs(function (string $command, array $params): bool {
return $command === 'demo:seed'
&& $params['identity'] === 'demo-free@ladill.com'
&& $params['--plan'] === 'free'
&& $params['--reset'] === true;
})
->andReturn(0);
app(DemoLoginReseeder::class)->maybeResetAfterLogin($user);
$this->app->terminate();
$this->assertFalse(Cache::has('demo-reseed:events:'.$user->public_id));
}
public function test_skips_when_demo_accounts_disabled(): void
{
config([
'demo_accounts.enabled' => false,
'demo_accounts.reset_on_login' => true,
]);
$user = User::factory()->create([
'public_id' => (string) Str::uuid(),
'email' => 'demo-free@ladill.com',
]);
Artisan::shouldReceive('call')->never();
app(DemoLoginReseeder::class)->maybeResetAfterLogin($user);
$this->app->terminate();
}
public function test_skips_non_demo_emails(): void
{
config([
'demo_accounts.enabled' => true,
'demo_accounts.reset_on_login' => true,
]);
$user = User::factory()->create([
'public_id' => (string) Str::uuid(),
'email' => 'regular@example.com',
]);
Artisan::shouldReceive('call')->never();
app(DemoLoginReseeder::class)->maybeResetAfterLogin($user);
$this->app->terminate();
}
}