Trying to Test Password Change Functionality
Hi all - I would love some help figuring out how to write a pest test to test and simulate the flow of a user updating their password after forgetting. Here is the test I have so far, but it's always failling at the assertion of the hash result at the end (suggesting that the password change is not actually being saved to the database). I appreciate any help available. Code is below:
1 Reply
it('can reset a password ', function () {
Notification::fake();
$user = User::factory()->create();
$token = app(PasswordBroker::class)->createToken($user);
$url = Filament::getResetPasswordUrl($token, $user);
$user->notify(new ResetPasswordNotification($token));
Notification::assertSentTo($user, ResetPasswordNotification::class);
$this->get($url)->assertOk();
$password = 'password&TEST123!';
livewire(ResetPassword::class, [
'token' => $token,
'email' => $user->email,
])
->assertSuccessful()
->set('password', $password)
->set('passwordConfirmation', $password)
->call('resetPassword');
$this->assertTrue(Hash::check($password, $user->fresh()->password));
});
Hey i experienced the same problem and managed to fix it by loading the token and email into the ResetPassword component.
livewire(ResetPassword::class, [ 'token' => $token, 'email' => $user->email, ])...