2
2
3
3
namespace Tests \Feature \Auth ;
4
4
5
+ use App \Livewire \Auth \ForgotPassword ;
6
+ use App \Livewire \Auth \ResetPassword ;
5
7
use App \Models \User ;
6
- use Illuminate \Auth \Notifications \ResetPassword ;
8
+ use Illuminate \Auth \Notifications \ResetPassword as ResetPasswordNotification ;
7
9
use Illuminate \Foundation \Testing \RefreshDatabase ;
8
10
use Illuminate \Support \Facades \Notification ;
11
+ use Livewire \Livewire ;
9
12
use Tests \TestCase ;
10
13
11
14
class PasswordResetTest extends TestCase
@@ -25,9 +28,11 @@ public function test_reset_password_link_can_be_requested(): void
25
28
26
29
$ user = User::factory ()->create ();
27
30
28
- $ this ->post ('/forgot-password ' , ['email ' => $ user ->email ]);
31
+ Livewire::test (ForgotPassword::class)
32
+ ->set ('email ' , $ user ->email )
33
+ ->call ('sendPasswordResetLink ' );
29
34
30
- Notification::assertSentTo ($ user , ResetPassword ::class);
35
+ Notification::assertSentTo ($ user , ResetPasswordNotification ::class);
31
36
}
32
37
33
38
public function test_reset_password_screen_can_be_rendered (): void
@@ -36,10 +41,12 @@ public function test_reset_password_screen_can_be_rendered(): void
36
41
37
42
$ user = User::factory ()->create ();
38
43
39
- $ this ->post ('/forgot-password ' , ['email ' => $ user ->email ]);
44
+ Livewire::test (ForgotPassword::class)
45
+ ->set ('email ' , $ user ->email )
46
+ ->call ('sendPasswordResetLink ' );
40
47
41
- Notification::assertSentTo ($ user , ResetPassword ::class, function ($ notification ) {
42
- $ response = $ this ->get ('/reset-password/ ' . $ notification ->token );
48
+ Notification::assertSentTo ($ user , ResetPasswordNotification ::class, function ($ notification ) {
49
+ $ response = $ this ->get ('/reset-password/ ' . $ notification ->token );
43
50
44
51
$ response ->assertStatus (200 );
45
52
@@ -53,19 +60,20 @@ public function test_password_can_be_reset_with_valid_token(): void
53
60
54
61
$ user = User::factory ()->create ();
55
62
56
- $ this ->post ('/forgot-password ' , ['email ' => $ user ->email ]);
63
+ Livewire::test (ForgotPassword::class)
64
+ ->set ('email ' , $ user ->email )
65
+ ->call ('sendPasswordResetLink ' );
57
66
58
- Notification::assertSentTo ($ user , ResetPassword::class, function ($ notification ) use ($ user ) {
59
- $ response = $ this ->post ('/reset-password ' , [
60
- 'token ' => $ notification ->token ,
61
- 'email ' => $ user ->email ,
62
- 'password ' => 'password ' ,
63
- 'password_confirmation ' => 'password ' ,
64
- ]);
67
+ Notification::assertSentTo ($ user , ResetPasswordNotification::class, function ($ notification ) use ($ user ) {
68
+ $ response = Livewire::test (ResetPassword::class, ['token ' => $ notification ->token ])
69
+ ->set ('email ' , $ user ->email )
70
+ ->set ('password ' , 'password ' )
71
+ ->set ('password_confirmation ' , 'password ' )
72
+ ->call ('resetPassword ' );
65
73
66
74
$ response
67
- ->assertSessionHasNoErrors ()
68
- ->assertRedirect (route ('login ' ));
75
+ ->assertHasNoErrors ()
76
+ ->assertRedirect (route ('login ' , absolute: false ));
69
77
70
78
return true ;
71
79
});
0 commit comments