Create tests for app/actions/fortify/ResetUserPassword

This commit is contained in:
Matt Young 2025-07-01 21:26:40 -05:00
parent a5928350a7
commit 373ad8b869
2 changed files with 26 additions and 1 deletions

View File

@ -29,7 +29,7 @@ class ResetUserPassword implements ResetsUserPasswords
AuditLogEntry::create([ AuditLogEntry::create([
'user' => $user->email, 'user' => $user->email,
'ip_address' => request()->ip(), 'ip_address' => request()->ip(),
'message' => 'Reset Password', 'message' => 'Changed password for '.$user->email.' ('.$user->full_name().')',
'affected' => ['users' => [$user->id]], 'affected' => ['users' => [$user->id]],
]); ]);
} }

View File

@ -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().')');
});