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,81 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Http\Middleware\EnsurePlatformSession;
|
||||
use App\Models\User;
|
||||
use App\Services\Qms\DemoLoginReseeder;
|
||||
use App\Services\Qms\DemoSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DemoLoginReseederTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->withoutMiddleware(EnsurePlatformSession::class);
|
||||
config([
|
||||
'demo_accounts.enabled' => true,
|
||||
'demo_accounts.reset_on_login' => true,
|
||||
]);
|
||||
Cache::flush();
|
||||
}
|
||||
|
||||
public function test_it_reseeds_demo_free_user_after_login(): void
|
||||
{
|
||||
$user = User::create([
|
||||
'public_id' => 'demo-free-pid',
|
||||
'name' => 'Ladill Demo (Free)',
|
||||
'email' => 'demo-free@ladill.com',
|
||||
'password' => bcrypt('password'),
|
||||
]);
|
||||
|
||||
$seeder = $this->mock(DemoSeeder::class);
|
||||
$seeder->shouldReceive('seed')
|
||||
->once()
|
||||
->withArgs(fn (string $identity, string $plan, bool $reset) => $identity === $user->email && $plan === 'free' && $reset === true)
|
||||
->andReturn(['user' => $user, 'plan' => 'free', 'counts' => []]);
|
||||
|
||||
app(DemoLoginReseeder::class)->maybeResetAfterLogin($user);
|
||||
|
||||
$this->app->terminate();
|
||||
}
|
||||
|
||||
public function test_it_skips_non_demo_users(): void
|
||||
{
|
||||
$user = User::create([
|
||||
'public_id' => 'regular-pid',
|
||||
'name' => 'Regular',
|
||||
'email' => 'regular@example.com',
|
||||
'password' => bcrypt('password'),
|
||||
]);
|
||||
|
||||
$seeder = $this->mock(DemoSeeder::class);
|
||||
$seeder->shouldReceive('seed')->never();
|
||||
|
||||
app(DemoLoginReseeder::class)->maybeResetAfterLogin($user);
|
||||
$this->app->terminate();
|
||||
}
|
||||
|
||||
public function test_it_skips_when_disabled(): void
|
||||
{
|
||||
config(['demo_accounts.enabled' => false]);
|
||||
|
||||
$user = User::create([
|
||||
'public_id' => 'demo-free-pid',
|
||||
'name' => 'Ladill Demo (Free)',
|
||||
'email' => 'demo-free@ladill.com',
|
||||
'password' => bcrypt('password'),
|
||||
]);
|
||||
|
||||
$seeder = $this->mock(DemoSeeder::class);
|
||||
$seeder->shouldReceive('seed')->never();
|
||||
|
||||
app(DemoLoginReseeder::class)->maybeResetAfterLogin($user);
|
||||
$this->app->terminate();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user