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:
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user