Create tests for app/actions/fortify/ResetUserPassword
This commit is contained in:
parent
a5928350a7
commit
373ad8b869
|
|
@ -29,7 +29,7 @@ class ResetUserPassword implements ResetsUserPasswords
|
|||
AuditLogEntry::create([
|
||||
'user' => $user->email,
|
||||
'ip_address' => request()->ip(),
|
||||
'message' => 'Reset Password',
|
||||
'message' => 'Changed password for '.$user->email.' ('.$user->full_name().')',
|
||||
'affected' => ['users' => [$user->id]],
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
use App\Actions\Fortify\ResetUserPassword;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->user = User::factory()->create();
|
||||
});
|
||||
|
||||
it('resets a user password', function () {
|
||||
$changer = app(ResetUserPassword::class);
|
||||
$changer->reset($this->user, ['password' => 'password123', 'password_confirmation' => 'password123']);
|
||||
$this->user->refresh();
|
||||
expect(\Illuminate\Support\Facades\Hash::check('password123', $this->user->password))->toBeTrue();
|
||||
});
|
||||
|
||||
it('logs password change', function () {
|
||||
$changer = app(ResetUserPassword::class);
|
||||
$changer->reset($this->user, ['password' => 'password123', 'password_confirmation' => 'password123']);
|
||||
$logEntry = \App\Models\AuditLogEntry::first();
|
||||
expect($logEntry->message)->toEqual('Changed password for '.$this->user->email.' ('.$this->user->full_name().')');
|
||||
});
|
||||
Loading…
Reference in New Issue