22
33namespace  Tests \Feature \Auth ;
44
5+ use  App \Livewire \Auth \ForgotPassword ;
6+ use  App \Livewire \Auth \ResetPassword ;
57use  App \Models \User ;
6- use  Illuminate \Auth \Notifications \ResetPassword ;
8+ use  Illuminate \Auth \Notifications \ResetPassword   as   ResetPasswordNotification ;
79use  Illuminate \Foundation \Testing \RefreshDatabase ;
810use  Illuminate \Support \Facades \Notification ;
11+ use  Livewire \Livewire ;
912use  Tests \TestCase ;
1013
1114class  PasswordResetTest extends  TestCase
@@ -25,9 +28,11 @@ public function test_reset_password_link_can_be_requested(): void
2528
2629        $ userfactory ()->create ();
2730
28-         $ this post ('/forgot-password ' , ['email '  => $ useremail ]);
31+         Livewire::test (ForgotPassword::class)
32+             ->set ('email ' , $ useremail )
33+             ->call ('sendPasswordResetLink ' );
2934
30-         Notification::assertSentTo ($ userResetPassword ::class);
35+         Notification::assertSentTo ($ userResetPasswordNotification ::class);
3136    }
3237
3338    public  function  test_reset_password_screen_can_be_rendered (): void 
@@ -36,10 +41,12 @@ public function test_reset_password_screen_can_be_rendered(): void
3641
3742        $ userfactory ()->create ();
3843
39-         $ this post ('/forgot-password ' , ['email '  => $ useremail ]);
44+         Livewire::test (ForgotPassword::class)
45+             ->set ('email ' , $ useremail )
46+             ->call ('sendPasswordResetLink ' );
4047
41-         Notification::assertSentTo ($ userResetPassword ::class, function  ($ notification
42-             $ response$ this get ('/reset-password/ ' . $ notificationtoken );
48+         Notification::assertSentTo ($ userResetPasswordNotification ::class, function  ($ notification
49+             $ response$ this get ('/reset-password/ '  .  $ notificationtoken );
4350
4451            $ responseassertStatus (200 );
4552
@@ -53,19 +60,20 @@ public function test_password_can_be_reset_with_valid_token(): void
5360
5461        $ userfactory ()->create ();
5562
56-         $ this post ('/forgot-password ' , ['email '  => $ useremail ]);
63+         Livewire::test (ForgotPassword::class)
64+             ->set ('email ' , $ useremail )
65+             ->call ('sendPasswordResetLink ' );
5766
58-         Notification::assertSentTo ($ userfunction  ($ notificationuse  ($ user
59-             $ response$ this post ('/reset-password ' , [
60-                 'token '  => $ notificationtoken ,
61-                 'email '  => $ useremail ,
62-                 'password '  => 'password ' ,
63-                 'password_confirmation '  => 'password ' ,
64-             ]);
67+         Notification::assertSentTo ($ userfunction  ($ notificationuse  ($ user
68+             $ responsetest (ResetPassword::class, ['token '  => $ notificationtoken ])
69+                 ->set ('email ' , $ useremail )
70+                 ->set ('password ' , 'password ' )
71+                 ->set ('password_confirmation ' , 'password ' )
72+                 ->call ('resetPassword ' );
6573
6674            $ response
67-                 ->assertSessionHasNoErrors ()
68-                 ->assertRedirect (route ('login ' ));
75+                 ->assertHasNoErrors ()
76+                 ->assertRedirect (route ('login ' , absolute:  false ));
6977
7078            return  true ;
7179        });
0 commit comments