- Refactor WorkspacePolicy to use pivot role instead of workspace.user_id - Add manageBilling policy (owner only) to BillingController - Fix ApiKeyController authorization (view → manageTeam for store/destroy) - Fix WorkspaceInviteController using workspace.user_id for owner checks - Fix WorkspaceController settings is_owner using workspace.user_id - Create PostAction enum for UpdatePost/PostController action strings - Create ApiToken\Status enum - Add User::SUBSCRIPTION_NAME constant, replace all hardcoded 'default' - Convert wantsEmailFor to accept NotificationType enum - Convert all $data[] to data_get() across publishers, controllers, jobs - Fix SocialLoginController callback missing try/catch - Fix SocialController::toggleActive missing workspace null check - Fix UpdatePost NPE on meta merge when postPlatform not found - Remove HTML5 required attributes from form inputs - Convert function declarations to arrow functions in Vue components - Replace hardcoded URLs with Wayfinder route helpers - Replace new Date() with dayjs - Add 16 new test files covering policies, authorization, publishing
96 lines
2.7 KiB
PHP
96 lines
2.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Actions\User\CreateUser;
|
|
use App\Enums\User\Setup;
|
|
use App\Enums\UserWorkspace\Role;
|
|
|
|
test('creates user with correct attributes', function () {
|
|
$user = CreateUser::execute([
|
|
'name' => 'John Doe',
|
|
'email' => 'john@example.com',
|
|
'password' => 'password123',
|
|
]);
|
|
|
|
expect($user->name)->toBe('John Doe');
|
|
expect($user->email)->toBe('john@example.com');
|
|
expect($user->setup)->toBe(Setup::Role);
|
|
expect($user->email_verified_at)->toBeNull();
|
|
});
|
|
|
|
test('creates default workspace for new user', function () {
|
|
$user = CreateUser::execute([
|
|
'name' => 'Jane Doe',
|
|
'email' => 'jane@example.com',
|
|
'password' => 'password123',
|
|
]);
|
|
|
|
expect($user->workspaces)->toHaveCount(1);
|
|
expect($user->workspaces->first()->name)->toBe("Jane Doe's Workspace");
|
|
});
|
|
|
|
test('attaches user as workspace owner', function () {
|
|
$user = CreateUser::execute([
|
|
'name' => 'Test User',
|
|
'email' => 'test@example.com',
|
|
'password' => 'password123',
|
|
]);
|
|
|
|
$pivot = $user->workspaces->first()->pivot;
|
|
expect($pivot->role)->toBe(Role::Owner->value);
|
|
});
|
|
|
|
test('sets current workspace on user', function () {
|
|
$user = CreateUser::execute([
|
|
'name' => 'Test User',
|
|
'email' => 'test@example.com',
|
|
'password' => 'password123',
|
|
]);
|
|
|
|
expect($user->current_workspace_id)->toBe($user->workspaces->first()->id);
|
|
});
|
|
|
|
test('uses provided timezone for workspace', function () {
|
|
$user = CreateUser::execute([
|
|
'name' => 'Test User',
|
|
'email' => 'test@example.com',
|
|
'password' => 'password123',
|
|
'timezone' => 'America/Sao_Paulo',
|
|
]);
|
|
|
|
expect($user->workspaces->first()->timezone)->toBe('America/Sao_Paulo');
|
|
});
|
|
|
|
test('defaults timezone to UTC', function () {
|
|
$user = CreateUser::execute([
|
|
'name' => 'Test User',
|
|
'email' => 'test@example.com',
|
|
'password' => 'password123',
|
|
]);
|
|
|
|
expect($user->workspaces->first()->timezone)->toBe('UTC');
|
|
});
|
|
|
|
test('invite registration sets setup to completed and verifies email', function () {
|
|
$user = CreateUser::execute([
|
|
'name' => 'Invited User',
|
|
'email' => 'invited@example.com',
|
|
'password' => 'password123',
|
|
'is_invite' => true,
|
|
]);
|
|
|
|
expect($user->setup)->toBe(Setup::Completed);
|
|
expect($user->email_verified_at)->not->toBeNull();
|
|
});
|
|
|
|
test('creates user without password for social login', function () {
|
|
$user = CreateUser::execute([
|
|
'name' => 'Social User',
|
|
'email' => 'social@example.com',
|
|
'email_verified_at' => now(),
|
|
]);
|
|
|
|
expect($user->password)->toBeNull();
|
|
expect($user->email_verified_at)->not->toBeNull();
|
|
});
|