|
4 | 4 | use Illuminate\Auth\Notifications\ResetPassword;
|
5 | 5 | use Illuminate\Support\Facades\Notification;
|
6 | 6 |
|
| 7 | +use function Pest\Laravel\post; |
| 8 | + |
7 | 9 | test('reset password link screen can be rendered', function () {
|
8 | 10 | visit(route('password.request'))
|
9 | 11 | ->assertSee('Forgot password')
|
|
12 | 14 | ->assertNoJavaScriptErrors();
|
13 | 15 | });
|
14 | 16 |
|
15 |
| -test('test_reset_password_link_can_be_requested', function () { |
16 |
| - Notification::fake(); |
17 |
| - |
| 17 | +test('test reset password link can be requested', function () { |
18 | 18 | $user = User::factory()->create();
|
19 | 19 |
|
| 20 | + Notification::fake(); |
| 21 | + |
20 | 22 | visit(route('password.request'))
|
21 | 23 | ->fill('email', $user->email)
|
22 | 24 | ->press('Email password reset link')
|
23 |
| - ->assertSee('A reset link will be sent if the account exists.'); |
| 25 | + ->assertSee('A reset link will be sent if the account exists.') |
| 26 | + ->assertNoConsoleLogs() |
| 27 | + ->assertNoJavaScriptErrors(); |
24 | 28 |
|
25 | 29 | Notification::assertSentTo($user, ResetPassword::class);
|
26 | 30 | });
|
27 | 31 |
|
28 |
| - // public function test_reset_password_screen_can_be_rendered() |
29 |
| - // { |
30 |
| - // Notification::fake(); |
31 |
| - |
32 |
| - // $user = User::factory()->create(); |
33 |
| - |
34 |
| - // $this->post(route('password.email'), ['email' => $user->email]); |
35 |
| - |
36 |
| - // Notification::assertSentTo($user, ResetPassword::class, function ($notification) { |
37 |
| - // $response = $this->get(route('password.request', $notification->token)); |
38 |
| - |
39 |
| - // $response->assertStatus(200); |
| 32 | +test('reset password screen can be rendered', function () { |
| 33 | + $user = User::factory()->create(); |
40 | 34 |
|
41 |
| - // return true; |
42 |
| - // }); |
43 |
| - // } |
| 35 | + Notification::fake(); |
44 | 36 |
|
45 |
| - // public function test_password_can_be_reset_with_valid_token() |
46 |
| - // { |
47 |
| - // Notification::fake(); |
| 37 | + post(route('password.email'), ['email' => $user->email]); |
48 | 38 |
|
49 |
| - // $user = User::factory()->create(); |
| 39 | + Notification::assertSentTo($user, ResetPassword::class, function ($notification) { |
| 40 | + visit(route('password.reset', $notification->token)) |
| 41 | + ->assertNoConsoleLogs() |
| 42 | + ->assertNoJavaScriptErrors(); |
50 | 43 |
|
51 |
| - // $this->post(route('password.email'), ['email' => $user->email]); |
| 44 | + return true; |
| 45 | + }); |
| 46 | +}); |
52 | 47 |
|
53 |
| - // Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) { |
54 |
| - // $response = $this->post(route('password.store'), [ |
55 |
| - // 'token' => $notification->token, |
56 |
| - // 'email' => $user->email, |
57 |
| - // 'password' => 'password', |
58 |
| - // 'password_confirmation' => 'password', |
59 |
| - // ]); |
| 48 | +test('password can be reset with valid token', function () { |
| 49 | + $user = User::factory()->create(); |
60 | 50 |
|
61 |
| - // $response |
62 |
| - // ->assertSessionHasNoErrors() |
63 |
| - // ->assertRedirect(route('login')); |
| 51 | + Notification::fake(); |
64 | 52 |
|
65 |
| - // return true; |
66 |
| - // }); |
67 |
| - // } |
| 53 | + post(route('password.email'), ['email' => $user->email]); |
| 54 | + |
| 55 | + Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) { |
| 56 | + visit(route('password.reset', $notification->token)) |
| 57 | + ->fill('password', 'password') |
| 58 | + ->fill('password_confirmation', 'password') |
| 59 | + ->assertNoConsoleLogs() |
| 60 | + ->assertNoJavaScriptErrors() |
| 61 | + ->press('Reset password') |
| 62 | + ->assertUrlIs(route('home')) |
| 63 | + ->assertNoConsoleLogs() |
| 64 | + ->assertNoJavaScriptErrors(); |
| 65 | + |
| 66 | + return true; |
| 67 | + }); |
| 68 | +}); |
68 | 69 |
|
69 | 70 | // public function test_password_cannot_be_reset_with_invalid_token(): void
|
70 | 71 | // {
|
|
0 commit comments