Files
speedBB/tests/Unit/UpdateUserPasswordTest.php
tracer 88e4a70f88
Some checks failed
CI/CD Pipeline / test (push) Successful in 3s
CI/CD Pipeline / deploy (push) Failing after 15s
Add comprehensive test coverage and update notes
2026-02-08 19:04:12 +01:00

45 lines
1.2 KiB
PHP

<?php
use App\Actions\Fortify\UpdateUserPassword;
use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\ValidationException;
it('updates password when current password matches', function (): void {
$user = User::factory()->create([
'password' => Hash::make('OldPass123!'),
]);
$this->actingAs($user);
$action = new UpdateUserPassword();
$action->update($user, [
'current_password' => 'OldPass123!',
'password' => 'NewPass123!',
'password_confirmation' => 'NewPass123!',
]);
$user->refresh();
expect(Hash::check('NewPass123!', $user->password))->toBeTrue();
});
it('rejects wrong current password', function (): void {
$user = User::factory()->create([
'password' => Hash::make('OldPass123!'),
]);
$this->actingAs($user);
$action = new UpdateUserPassword();
try {
$action->update($user, [
'current_password' => 'WrongPass',
'password' => 'NewPass123!',
'password_confirmation' => 'NewPass123!',
]);
$this->fail('Expected ValidationException not thrown.');
} catch (ValidationException $e) {
expect($e->errors())->toHaveKey('current_password');
}
});