Seed org structure, rooms, and participant history with plan-based volume only. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Branch;
|
||||
use App\Models\Member;
|
||||
use App\Models\Organization;
|
||||
use App\Models\Participant;
|
||||
use App\Models\Room;
|
||||
use App\Models\Session;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DemoSeedCommandTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Http::fake();
|
||||
}
|
||||
|
||||
public function test_seeds_org_member_branch_rooms_sessions_and_participants(): void
|
||||
{
|
||||
$user = User::create([
|
||||
'public_id' => 'meet-demo-free-001',
|
||||
'name' => 'Meet Demo Free',
|
||||
'email' => 'demo-free@ladill.com',
|
||||
]);
|
||||
|
||||
$this->artisan('demo:seed', ['identity' => $user->email, '--plan' => 'free'])
|
||||
->assertSuccessful();
|
||||
|
||||
$org = Organization::query()->where('owner_ref', $user->public_id)->first();
|
||||
$this->assertNotNull($org);
|
||||
$this->assertTrue((bool) data_get($org->settings, 'demo'));
|
||||
$this->assertTrue((bool) data_get($org->settings, 'onboarded'));
|
||||
|
||||
$this->assertDatabaseHas('meet_members', [
|
||||
'organization_id' => $org->id,
|
||||
'user_ref' => $user->public_id,
|
||||
'role' => 'owner',
|
||||
]);
|
||||
$this->assertSame(1, Branch::query()->where('organization_id', $org->id)->count());
|
||||
$this->assertSame(2, Room::query()->where('owner_ref', $user->public_id)->count());
|
||||
$this->assertGreaterThan(0, Session::query()->where('owner_ref', $user->public_id)->count());
|
||||
$this->assertGreaterThan(0, Participant::query()->where('owner_ref', $user->public_id)->count());
|
||||
$this->assertTrue(
|
||||
Room::query()->where('owner_ref', $user->public_id)->where('status', 'scheduled')->exists()
|
||||
);
|
||||
$this->assertTrue(
|
||||
Room::query()->where('owner_ref', $user->public_id)->where('status', 'ended')->exists()
|
||||
);
|
||||
}
|
||||
|
||||
public function test_plan_only_varies_volume_and_makes_no_http_calls(): void
|
||||
{
|
||||
$user = User::create([
|
||||
'public_id' => 'meet-demo-ent-001',
|
||||
'name' => 'Meet Demo Ent',
|
||||
'email' => 'demo-enterprise@ladill.com',
|
||||
]);
|
||||
|
||||
Http::fake();
|
||||
|
||||
$this->artisan('demo:seed', ['identity' => $user->public_id, '--plan' => 'enterprise'])
|
||||
->assertSuccessful();
|
||||
|
||||
Http::assertNothingSent();
|
||||
|
||||
$this->assertSame(3, Branch::query()->where('owner_ref', $user->public_id)->count());
|
||||
$this->assertSame(6, Room::query()->where('owner_ref', $user->public_id)->count());
|
||||
}
|
||||
|
||||
public function test_idempotent_and_reset_is_tenant_scoped(): void
|
||||
{
|
||||
$user = User::create([
|
||||
'public_id' => 'meet-demo-pro-001',
|
||||
'name' => 'Meet Demo Pro',
|
||||
'email' => 'demo-pro@ladill.com',
|
||||
]);
|
||||
$other = User::create([
|
||||
'public_id' => 'meet-other-001',
|
||||
'name' => 'Other User',
|
||||
'email' => 'other@example.com',
|
||||
]);
|
||||
|
||||
Organization::create([
|
||||
'owner_ref' => $other->public_id,
|
||||
'name' => 'Other Org',
|
||||
'slug' => 'other-org',
|
||||
'timezone' => 'UTC',
|
||||
'settings' => ['onboarded' => true],
|
||||
]);
|
||||
|
||||
$this->artisan('demo:seed', ['identity' => $user->email, '--plan' => 'pro'])
|
||||
->assertSuccessful();
|
||||
$rooms = Room::query()->where('owner_ref', $user->public_id)->count();
|
||||
$this->assertSame(4, $rooms);
|
||||
|
||||
$this->artisan('demo:seed', ['identity' => $user->email, '--plan' => 'pro'])
|
||||
->assertSuccessful();
|
||||
$this->assertSame(4, Room::query()->where('owner_ref', $user->public_id)->count());
|
||||
|
||||
$this->artisan('demo:seed', [
|
||||
'identity' => $user->email,
|
||||
'--plan' => 'free',
|
||||
'--reset' => true,
|
||||
])->assertSuccessful();
|
||||
|
||||
$this->assertSame(2, Room::query()->where('owner_ref', $user->public_id)->count());
|
||||
$this->assertSame(1, Member::query()->where('owner_ref', $user->public_id)->count());
|
||||
$this->assertDatabaseHas('meet_organizations', [
|
||||
'owner_ref' => $other->public_id,
|
||||
'slug' => 'other-org',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user