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', ]); });