43 lines
1.5 KiB
PHP
43 lines
1.5 KiB
PHP
<?php
|
|
|
|
use App\Actions\Fortify\CreateNewUser;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
$this->createArray = [
|
|
'registration_code' => auditionSetting('registrationCode'),
|
|
'first_name' => fake()->firstName(),
|
|
'last_name' => fake()->lastName(),
|
|
'judging_preference' => 'Sarrousaphone',
|
|
'cell_phone' => fake()->phoneNumber(),
|
|
'email' => fake()->safeEmail(),
|
|
'password' => '<PASSWORD>',
|
|
'password_confirmation' => '<PASSWORD>',
|
|
];
|
|
});
|
|
|
|
it('creates a new user', function () {
|
|
$creator = app(CreateNewUser::class);
|
|
$newUser = $creator->create($this->createArray);
|
|
expect(User::where('email', $this->createArray['email'])->exists())->toBeTrue();
|
|
});
|
|
|
|
it('fails when an invalid registration code is used', function () {
|
|
$creator = app(CreateNewUser::class);
|
|
$this->createArray['registration_code'] = 'invalid';
|
|
$newUser = $creator->create($this->createArray);
|
|
|
|
})->throws(ValidationException::class, 'Incorrect registration code provided');
|
|
|
|
it('logs user creation', function () {
|
|
$creator = app(CreateNewUser::class);
|
|
$newUser = $creator->create($this->createArray);
|
|
$logEntry = \App\Models\AuditLogEntry::first();
|
|
expect($logEntry->message)->toStartWith('Added User '.$newUser->full_name())
|
|
->and($logEntry->affected['users'])->toEqual([$newUser->id]);
|
|
});
|