create(); $this->actingAs($user); Livewire::test(NoAccess::class) ->mountAction('createWorkspace') ->set('mountedActions.0.data.name', 'Acme') ->set('mountedActions.0.data.slug', 'acme') ->callMountedAction() ->assertHasNoActionErrors(); $workspace = Workspace::query()->where('slug', 'acme')->firstOrFail(); expect(WorkspaceMembership::query() ->where('workspace_id', $workspace->getKey()) ->where('user_id', $user->getKey()) ->where('role', 'owner') ->exists())->toBeTrue(); expect(session()->get(WorkspaceContext::SESSION_KEY))->toBe($workspace->getKey()); expect($user->fresh()->last_workspace_id)->toBe($workspace->getKey()); }); it('allows creating a new workspace from the choose-workspace page', function () { $user = User::factory()->create(); $workspaceA = Workspace::factory()->create(); $workspaceB = Workspace::factory()->create(); WorkspaceMembership::factory()->for($workspaceA)->for($user)->create(['role' => 'owner']); WorkspaceMembership::factory()->for($workspaceB)->for($user)->create(['role' => 'owner']); $this->actingAs($user); Livewire::test(ChooseWorkspace::class) ->mountAction('createWorkspace') ->set('mountedActions.0.data.name', 'New Workspace') ->set('mountedActions.0.data.slug', 'new-workspace') ->callMountedAction() ->assertHasNoActionErrors(); $workspace = Workspace::query()->where('slug', 'new-workspace')->firstOrFail(); expect(WorkspaceMembership::query() ->where('workspace_id', $workspace->getKey()) ->where('user_id', $user->getKey()) ->where('role', 'owner') ->exists())->toBeTrue(); expect(session()->get(WorkspaceContext::SESSION_KEY))->toBe($workspace->getKey()); expect($user->fresh()->last_workspace_id)->toBe($workspace->getKey()); });