From 37ce046240dce174b115762e63dd1f7c5e147d9e Mon Sep 17 00:00:00 2001 From: Kris Date: Fri, 5 Jul 2024 15:31:50 +0200 Subject: [PATCH] :white_check_mark: add tests for email verification (#2735) --- .../Frontend/Auth/EmailVerificationTest.php | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 tests/Feature/Frontend/Auth/EmailVerificationTest.php diff --git a/tests/Feature/Frontend/Auth/EmailVerificationTest.php b/tests/Feature/Frontend/Auth/EmailVerificationTest.php new file mode 100644 index 000000000..3c50dc54e --- /dev/null +++ b/tests/Feature/Frontend/Auth/EmailVerificationTest.php @@ -0,0 +1,80 @@ + null])->create(); + $response = $this->actingAs($user) + ->followingRedirects() + ->post(route('verification.resend')); + $response->assertOk(); + + Notification::assertSentTo($user, VerifyEmail::class); + } + + public function testEmailVerificationJSONNotification(): void { + Notification::fake(); + + $user = User::factory(['email_verified_at' => null])->create(); + $response = $this->actingAs($user) + ->followingRedirects() + ->post(route('verification.resend'), [], [ + 'Accept' => 'application/json', + ]); + $response->assertAccepted(); + + Notification::assertSentTo($user, VerifyEmail::class); + } + + public function testEmailVerificationNotificationWithVerifiedEmail(): void { + Notification::fake(); + + $user = User::factory(['email_verified_at' => today()])->create(); + $response = $this->actingAs($user) + ->followingRedirects() + ->post(route('verification.resend')); + $response->assertOk(); + + // test json response (should be 204 with already verified email) + $response = $this->actingAs($user) + ->followingRedirects() + ->post(route('verification.resend'), [], [ + 'Accept' => 'application/json', + ]); + $response->assertNoContent(); + + Notification::assertNothingSent(); + } + + public function testEmailVerificationNotificationWithTooManyRequests(): void { + Notification::fake(); + + $user = User::factory(['email_verified_at' => null])->create(); + for ($i = 0; $i < 6; $i++) { + $response = $this->actingAs($user) + ->followingRedirects() + ->post(route('verification.resend')); + $response->assertOk(); + } + + $response = $this->actingAs($user) + ->post(route('verification.resend')); + $response->assertTooManyRequests(); + + // but should still send the email once + Notification::assertSentTo($user, VerifyEmail::class, 1); + } + +}