|
9 | 9 | use Illuminate\Support\Facades\Event; |
10 | 10 | use Illuminate\Support\Facades\URL; |
11 | 11 |
|
12 | | -it('can render the email verification screen', function (): void { |
13 | | - $user = User::factory()->unverified()->create(); |
| 12 | +describe('Email verification', function (): void { |
| 13 | + it('can render the email verification screen', function (): void { |
| 14 | + $user = User::factory()->unverified()->create(); |
14 | 15 |
|
15 | | - $response = $this->actingAs($user)->get('/verify-email'); |
| 16 | + $response = $this->actingAs($user)->get('/verify-email'); |
16 | 17 |
|
17 | | - $response->assertStatus(200); |
18 | | -}); |
| 18 | + $response->assertStatus(200); |
| 19 | + }); |
19 | 20 |
|
20 | | -it('can verify email', function (): void { |
21 | | - $user = User::factory()->unverified()->create(); |
| 21 | + it('can verify email', function (): void { |
| 22 | + $user = User::factory()->unverified()->create(); |
22 | 23 |
|
23 | | - Event::fake(); |
| 24 | + Event::fake(); |
24 | 25 |
|
25 | | - $verificationUrl = URL::temporarySignedRoute( |
26 | | - 'verification.verify', |
27 | | - now()->addMinutes(60), |
28 | | - ['id' => $user->id, 'hash' => sha1((string) $user->email)] |
29 | | - ); |
| 26 | + $verificationUrl = URL::temporarySignedRoute( |
| 27 | + 'verification.verify', |
| 28 | + now()->addMinutes(60), |
| 29 | + ['id' => $user->id, 'hash' => sha1((string) $user->email)] |
| 30 | + ); |
30 | 31 |
|
31 | | - $response = $this->actingAs($user)->get($verificationUrl); |
| 32 | + $response = $this->actingAs($user)->get($verificationUrl); |
32 | 33 |
|
33 | | - Event::assertDispatched(Verified::class); |
34 | | - $this->assertTrue($user->fresh()->hasVerifiedEmail()); |
35 | | - $response->assertRedirect(route('dashboard', absolute: false).'?verified=1'); |
36 | | -}); |
| 34 | + Event::assertDispatched(Verified::class); |
| 35 | + $this->assertTrue($user->fresh()->hasVerifiedEmail()); |
| 36 | + $response->assertRedirect(route('dashboard', absolute: false).'?verified=1'); |
| 37 | + }); |
| 38 | + |
| 39 | + it('does not verify email with invalid hash', function (): void { |
| 40 | + $user = User::factory()->unverified()->create(); |
| 41 | + |
| 42 | + $verificationUrl = URL::temporarySignedRoute( |
| 43 | + 'verification.verify', |
| 44 | + now()->addMinutes(60), |
| 45 | + ['id' => $user->id, 'hash' => sha1('wrong-email')] |
| 46 | + ); |
| 47 | + |
| 48 | + $this->actingAs($user)->get($verificationUrl); |
| 49 | + |
| 50 | + $this->assertFalse($user->fresh()->hasVerifiedEmail()); |
| 51 | + }); |
| 52 | + |
| 53 | + it('can resend verification notification', function (): void { |
| 54 | + $user = User::factory()->unverified()->create(); |
| 55 | + |
| 56 | + $response = $this->actingAs($user) |
| 57 | + ->post('/email/verification-notification'); |
| 58 | + |
| 59 | + $response->assertSessionHas('status', 'verification-link-sent'); |
| 60 | + }); |
| 61 | + |
| 62 | + it('redirects to dashboard if email already verified when requesting verification notification', function (): void { |
| 63 | + $user = User::factory()->create(); |
| 64 | + |
| 65 | + $response = $this->actingAs($user) |
| 66 | + ->post('/email/verification-notification'); |
| 67 | + |
| 68 | + $response->assertRedirect(route('dashboard', absolute: false)); |
| 69 | + }); |
| 70 | + |
| 71 | + it('redirects to dashboard if email already verified when visiting verification prompt', function (): void { |
| 72 | + $user = User::factory()->create(); |
| 73 | + |
| 74 | + $response = $this->actingAs($user) |
| 75 | + ->get('/verify-email'); |
| 76 | + |
| 77 | + $response->assertRedirect(route('dashboard', absolute: false)); |
| 78 | + }); |
37 | 79 |
|
38 | | -it('does not verify email with invalid hash', function (): void { |
39 | | - $user = User::factory()->unverified()->create(); |
| 80 | + it('redirects to dashboard if email already verified when verifying email', function (): void { |
| 81 | + $user = User::factory()->create(); |
40 | 82 |
|
41 | | - $verificationUrl = URL::temporarySignedRoute( |
42 | | - 'verification.verify', |
43 | | - now()->addMinutes(60), |
44 | | - ['id' => $user->id, 'hash' => sha1('wrong-email')] |
45 | | - ); |
| 83 | + $verificationUrl = URL::temporarySignedRoute( |
| 84 | + 'verification.verify', |
| 85 | + now()->addMinutes(60), |
| 86 | + ['id' => $user->id, 'hash' => sha1((string) $user->email)] |
| 87 | + ); |
46 | 88 |
|
47 | | - $this->actingAs($user)->get($verificationUrl); |
| 89 | + $response = $this->actingAs($user)->get($verificationUrl); |
48 | 90 |
|
49 | | - $this->assertFalse($user->fresh()->hasVerifiedEmail()); |
| 91 | + $response->assertRedirect(route('dashboard', absolute: false).'?verified=1'); |
| 92 | + }); |
50 | 93 | }); |
0 commit comments