]> git.localhorst.tv Git - alttp.git/blob - tests/Feature/Auth/PasswordResetTest.php
add discord auth
[alttp.git] / tests / Feature / Auth / PasswordResetTest.php
1 <?php
2
3 namespace Tests\Feature\Auth;
4
5 use App\Models\User;
6 use Illuminate\Auth\Notifications\ResetPassword;
7 use Illuminate\Foundation\Testing\RefreshDatabase;
8 use Illuminate\Support\Facades\Notification;
9 use Tests\TestCase;
10
11 class PasswordResetTest extends TestCase
12 {
13     use RefreshDatabase;
14
15     public function test_reset_password_link_screen_can_be_rendered()
16     {
17         $response = $this->get('/forgot-password');
18
19         $response->assertStatus(200);
20     }
21
22     public function test_reset_password_link_can_be_requested()
23     {
24         Notification::fake();
25
26         $user = User::factory()->create();
27
28         $this->post('/forgot-password', ['email' => $user->email]);
29
30         Notification::assertSentTo($user, ResetPassword::class);
31     }
32
33     public function test_reset_password_screen_can_be_rendered()
34     {
35         Notification::fake();
36
37         $user = User::factory()->create();
38
39         $this->post('/forgot-password', ['email' => $user->email]);
40
41         Notification::assertSentTo($user, ResetPassword::class, function ($notification) {
42             $response = $this->get('/reset-password/'.$notification->token);
43
44             $response->assertStatus(200);
45
46             return true;
47         });
48     }
49
50     public function test_password_can_be_reset_with_valid_token()
51     {
52         Notification::fake();
53
54         $user = User::factory()->create();
55
56         $this->post('/forgot-password', ['email' => $user->email]);
57
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             ]);
65
66             $response->assertSessionHasNoErrors();
67
68             return true;
69         });
70     }
71 }