- CreateUser now provisions a default "{name}'s Workspace" for non-invite
signups (email, Google, GitHub, seeder), with the owner as Admin and
current_workspace_id set. Invite signups still skip it (they join the
inviter's workspace on acceptance).
- UserSeeder drops its now-redundant explicit CreateWorkspace call.
- After Stripe checkout, billing/processing lands the user on the social
accounts screen with the connect dialog open (was: calendar), so onboarding
flows straight into connecting an account.
Quantity stays correct (1 workspace → checkout quantity 1). The first workspace
is created without brand details; brand setup remains available in Settings and
on the create-workspace screen for additional workspaces.
79 lines
2.4 KiB
PHP
79 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Actions\User\CreateUser;
|
|
use App\Jobs\PostHog\SyncUser;
|
|
use App\Models\Account;
|
|
use App\Models\Workspace;
|
|
use Illuminate\Support\Facades\Bus;
|
|
|
|
test('CreateUser creates the owner a default workspace and sets it as current', function () {
|
|
$user = CreateUser::execute([
|
|
'name' => 'Jane Doe',
|
|
'email' => 'jane@example.com',
|
|
'password' => 'secret123',
|
|
]);
|
|
|
|
expect($user->name)->toBe('Jane Doe');
|
|
expect($user->email)->toBe('jane@example.com');
|
|
expect($user->account_id)->not->toBeNull();
|
|
expect(Account::find($user->account_id))->not->toBeNull();
|
|
|
|
$workspace = $user->workspaces()->first();
|
|
expect($user->workspaces()->count())->toBe(1);
|
|
expect($workspace->name)->toBe("Jane Doe's Workspace");
|
|
expect($workspace->account_id)->toBe($user->account_id);
|
|
expect($user->fresh()->current_workspace_id)->toBe($workspace->id);
|
|
});
|
|
|
|
test('CreateUser sets account owner_id to the new user', function () {
|
|
$user = CreateUser::execute([
|
|
'name' => 'Jane Doe',
|
|
'email' => 'jane2@example.com',
|
|
'password' => 'secret123',
|
|
]);
|
|
|
|
expect($user->account->owner_id)->toBe($user->id);
|
|
});
|
|
|
|
test('CreateUser invite-style still creates user without workspace (workspace assignment happens via invite acceptance)', function () {
|
|
$user = CreateUser::execute([
|
|
'name' => 'Invited',
|
|
'email' => 'invited@example.com',
|
|
'password' => 'secret123',
|
|
'is_invite' => true,
|
|
]);
|
|
|
|
expect($user->email_verified_at)->not->toBeNull();
|
|
expect(Workspace::count())->toBe(0);
|
|
});
|
|
|
|
test('CreateUser dispatches SyncUser with the new user id when PostHog is enabled', function () {
|
|
config(['services.posthog.enabled' => true, 'services.posthog.api_key' => 'phc_test_key']);
|
|
Bus::fake([SyncUser::class]);
|
|
|
|
$user = CreateUser::execute([
|
|
'name' => 'Jane Doe',
|
|
'email' => 'jane.posthog@example.com',
|
|
'password' => 'secret123',
|
|
]);
|
|
|
|
Bus::assertDispatched(
|
|
SyncUser::class,
|
|
fn ($job) => $job->userId === (string) $user->id,
|
|
);
|
|
});
|
|
|
|
test('CreateUser does not dispatch SyncUser when PostHog is disabled', function () {
|
|
config(['services.posthog.enabled' => false]);
|
|
Bus::fake([SyncUser::class]);
|
|
|
|
CreateUser::execute([
|
|
'name' => 'Jane Doe',
|
|
'email' => 'jane.posthog.disabled@example.com',
|
|
'password' => 'secret123',
|
|
]);
|
|
|
|
Bus::assertNotDispatched(SyncUser::class);
|
|
});
|