diff --git a/app/Actions/Fortify/UpdateUserProfileInformation.php b/app/Actions/Fortify/UpdateUserProfileInformation.php index 2a56ab6..7a0a4ba 100644 --- a/app/Actions/Fortify/UpdateUserProfileInformation.php +++ b/app/Actions/Fortify/UpdateUserProfileInformation.php @@ -44,17 +44,18 @@ class UpdateUserProfileInformation implements UpdatesUserProfileInformation 'cell_phone' => $input['cell_phone'], 'email' => $input['email'], ])->save(); + $message = 'Updated user #'.$user->id.' - '.$user->email + .'
Name: '.$user->full_name() + .'
Judging Pref: '.$user->judging_preference + .'
Cell Phone: '.$user->cell_phone; + AuditLogEntry::create([ + 'user' => auth()->user()->email, + 'ip_address' => request()->ip(), + 'message' => $message, + 'affected' => ['users' => [$user->id]], + ]); } - $message = 'Updated user #'.$user->id.' - '.$user->email - .'
Name: '.$user->full_name() - .'
Judging Pref: '.$user->judging_preference - .'
Cell Phone: '.$user->cell_phone; - AuditLogEntry::create([ - 'user' => auth()->user()->email, - 'ip_address' => request()->ip(), - 'message' => $message, - 'affected' => ['users' => [$user->id]], - ]); + } /** diff --git a/tests/Feature/app/Actions/Fortify/UpdateUserProfileInformationTest.php b/tests/Feature/app/Actions/Fortify/UpdateUserProfileInformationTest.php new file mode 100644 index 0000000..8f5e0b5 --- /dev/null +++ b/tests/Feature/app/Actions/Fortify/UpdateUserProfileInformationTest.php @@ -0,0 +1,76 @@ +user = $creator->create([ + 'registration_code' => auditionSetting('registrationCode'), + 'first_name' => 'Old', + 'last_name' => 'Name', + 'judging_preference' => 'oldPreference', + 'cell_phone' => '0123456789', + 'email' => 'old@email.com', + 'password' => 'password', + 'password_confirmation' => 'password', + ]); + $this->changer = app(UpdateUserProfileInformation::class); + $this->user->email_verified_at = Carbon::now(); + $this->user->save(); + $this->user->refresh(); + $this->actingAs($this->user); +}); + +it('updates a user profile, maintains verification when retaining email', function () { + $newdata = [ + 'first_name' => 'New', + 'last_name' => 'Named', + 'judging_preference' => 'newPreference', + 'cell_phone' => '0987654321', + 'email' => 'old@email.com', + ]; + $this->changer->update($this->user, $newdata); + expect($this->user->first_name)->toEqual('New') + ->and($this->user->last_name)->toEqual('Named') + ->and($this->user->judging_preference)->toEqual('newPreference') + ->and($this->user->cell_phone)->toEqual('0987654321') + ->and($this->user->email)->toEqual('old@email.com') + ->and($this->user->email_verified_at)->not()->toBeNull(); +}); + +it('updates a user profile, clears verification when changing email', function () { + $newdata = [ + 'first_name' => 'New', + 'last_name' => 'Named', + 'judging_preference' => 'newPreference', + 'cell_phone' => '0987654321', + 'email' => 'new@email.com', + ]; + $this->changer->update($this->user, $newdata); + $this->user->refresh(); + expect($this->user->first_name)->toEqual('New') + ->and($this->user->last_name)->toEqual('Named') + ->and($this->user->judging_preference)->toEqual('newPreference') + ->and($this->user->cell_phone)->toEqual('0987654321') + ->and($this->user->email)->toEqual('new@email.com') + ->and($this->user->email_verified_at)->toBeNull(); +}); + +it('logs changes in use profile', function () { + $newdata = [ + 'first_name' => 'New', + 'last_name' => 'Named', + 'judging_preference' => 'newPreference', + 'cell_phone' => '0987654321', + 'email' => 'new@email.com', + ]; + $this->changer->update($this->user, $newdata); + $this->user->refresh(); + expect(AuditLogEntry::where('message', 'like', 'Updated user %')->count())->toEqual(1); +});