mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-11-13 09:38:48 +01:00
136 lines
3.5 KiB
PHP
136 lines
3.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Actions\Fortify\CreateNewUser;
|
|
use App\Models\Auth\User;
|
|
use Illuminate\Foundation\Testing\WithFaker;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Validation\ValidationException;
|
|
use Mockery\MockInterface;
|
|
use Propaganistas\LaravelDisposableEmail\Validation\Indisposable;
|
|
|
|
pest()->use(WithFaker::class);
|
|
|
|
test('required', function (): void {
|
|
$this->expectException(ValidationException::class);
|
|
|
|
$action = new CreateNewUser();
|
|
|
|
$action->create([]);
|
|
});
|
|
|
|
test('username alpha dash', function (): void {
|
|
$this->expectException(ValidationException::class);
|
|
|
|
$action = new CreateNewUser();
|
|
|
|
$password = Str::password(20);
|
|
|
|
$action->create([
|
|
User::ATTRIBUTE_NAME => fake()->password(20),
|
|
User::ATTRIBUTE_EMAIL => fake()->companyEmail(),
|
|
User::ATTRIBUTE_PASSWORD => $password,
|
|
'password_confirmation' => $password,
|
|
'terms' => 'terms',
|
|
]);
|
|
});
|
|
|
|
test('username unique', function (): void {
|
|
$this->expectException(ValidationException::class);
|
|
|
|
$name = fake()->word();
|
|
|
|
User::factory()->createOne([
|
|
User::ATTRIBUTE_NAME => $name,
|
|
]);
|
|
|
|
$action = new CreateNewUser();
|
|
|
|
$password = Str::password(20);
|
|
|
|
$action->create([
|
|
User::ATTRIBUTE_NAME => $name,
|
|
User::ATTRIBUTE_EMAIL => fake()->companyEmail(),
|
|
User::ATTRIBUTE_PASSWORD => $password,
|
|
'password_confirmation' => $password,
|
|
'terms' => 'terms',
|
|
]);
|
|
});
|
|
|
|
test('created', function (): void {
|
|
$action = new CreateNewUser();
|
|
|
|
$password = Str::password(20);
|
|
|
|
$action->create([
|
|
User::ATTRIBUTE_NAME => fake()->word(),
|
|
User::ATTRIBUTE_EMAIL => fake()->companyEmail(),
|
|
User::ATTRIBUTE_PASSWORD => $password,
|
|
'password_confirmation' => $password,
|
|
'terms' => 'terms',
|
|
]);
|
|
|
|
$this->assertDatabaseCount(User::class, 1);
|
|
});
|
|
|
|
test('disposable email', function (): void {
|
|
$this->mock(Indisposable::class, function (MockInterface $mock): void {
|
|
$mock->shouldReceive('validate')->once()->andReturn(false);
|
|
});
|
|
|
|
$action = new CreateNewUser();
|
|
|
|
$password = Str::password(20);
|
|
|
|
$action->create([
|
|
User::ATTRIBUTE_NAME => fake()->word(),
|
|
User::ATTRIBUTE_EMAIL => fake()->companyEmail(),
|
|
User::ATTRIBUTE_PASSWORD => $password,
|
|
'password_confirmation' => $password,
|
|
'terms' => 'terms',
|
|
]);
|
|
})->throws(ValidationException::class);
|
|
|
|
test('indisposable email', function (): void {
|
|
$this->mock(Indisposable::class, function (MockInterface $mock): void {
|
|
$mock->shouldReceive('validate')->once()->andReturn(true);
|
|
});
|
|
|
|
$action = new CreateNewUser();
|
|
|
|
$password = Str::password(20);
|
|
|
|
$action->create([
|
|
User::ATTRIBUTE_NAME => fake()->word(),
|
|
User::ATTRIBUTE_EMAIL => fake()->companyEmail(),
|
|
User::ATTRIBUTE_PASSWORD => $password,
|
|
'password_confirmation' => $password,
|
|
'terms' => 'terms',
|
|
]);
|
|
|
|
$this->assertDatabaseCount(User::class, 1);
|
|
});
|
|
|
|
test('email unique', function (): void {
|
|
$this->expectException(ValidationException::class);
|
|
|
|
$email = fake()->companyEmail();
|
|
|
|
User::factory()->createOne([
|
|
User::ATTRIBUTE_EMAIL => $email,
|
|
]);
|
|
|
|
$action = new CreateNewUser();
|
|
|
|
$password = Str::password(20);
|
|
|
|
$action->create([
|
|
User::ATTRIBUTE_NAME => fake()->word(),
|
|
User::ATTRIBUTE_EMAIL => $email,
|
|
User::ATTRIBUTE_PASSWORD => $password,
|
|
'password_confirmation' => $password,
|
|
'terms' => 'terms',
|
|
]);
|
|
});
|