54 lines
1.6 KiB
PHP
54 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Integration\WithApp\App\Cqs\Actions\Users;
|
|
|
|
use App\Contracts\ActionInput;
|
|
use App\Cqs\Actions\Users\CreateUser;
|
|
use App\Cqs\Actions\Users\CreateUserInput;
|
|
use App\Models\User;
|
|
use Domain\Enums\UserRole;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
describe('CreateUser action', function (): void {
|
|
it('creates and persists a verified admin user with hashed password', function (): void {
|
|
// GIVEN
|
|
$action = new CreateUser();
|
|
$input = new CreateUserInput(
|
|
firstname: 'Jean',
|
|
lastname: 'Dupont',
|
|
email: 'jean.dupont@ldc.fr',
|
|
password: 'SecretPassword123!',
|
|
role: UserRole::Admin,
|
|
);
|
|
|
|
// WHEN
|
|
$user = $action($input);
|
|
|
|
// THEN
|
|
expect($user->firstname)->toBe('Jean')
|
|
->and($user->lastname)->toBe('Dupont')
|
|
->and($user->email)->toBe('jean.dupont@ldc.fr')
|
|
->and($user->role)->toBe(UserRole::Admin)
|
|
->and($user->email_verified_at)->not->toBeNull()
|
|
->and(Hash::check('SecretPassword123!', $user->password))->toBeTrue()
|
|
->and(User::query()->find($user->id))->not->toBeNull();
|
|
});
|
|
|
|
it('throws when an invalid input is passed', function (): void {
|
|
// GIVEN
|
|
$action = new CreateUser();
|
|
$invalidInput = new class () implements ActionInput
|
|
{
|
|
};
|
|
|
|
// WHEN
|
|
expect(
|
|
/** @phpstan-ignore argument.type */
|
|
fn () => $action($invalidInput)
|
|
)
|
|
// THEN
|
|
->toThrow(\InvalidArgumentException::class);
|
|
});
|
|
});
|