diff --git a/app/Actions/Fortify/CreateNewUser.php b/app/Actions/Fortify/CreateNewUser.php index 6adb624..c60dadb 100644 --- a/app/Actions/Fortify/CreateNewUser.php +++ b/app/Actions/Fortify/CreateNewUser.php @@ -61,7 +61,7 @@ class CreateNewUser implements CreatesNewUsers 'user' => $input['email'], 'ip_address' => request()->ip(), 'message' => $message, - 'affected' => ['users' => $user->id], + 'affected' => ['users' => [$user->id]], ]); return $user; diff --git a/tests/Feature/app/Actions/Fortify/CreateNewUserTest.php b/tests/Feature/app/Actions/Fortify/CreateNewUserTest.php new file mode 100644 index 0000000..9b1e7df --- /dev/null +++ b/tests/Feature/app/Actions/Fortify/CreateNewUserTest.php @@ -0,0 +1,42 @@ +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_confirmation' => '', + ]; +}); + +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('New User Registered') + ->and($logEntry->affected['users'])->toEqual([$newUser->id]); +});