WebAuthnDeviceLostControllerTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace Tests\Feature\Auth;
  3. use App\Models\User;
  4. use Tests\FeatureTestCase;
  5. use Illuminate\Support\Facades\Notification;
  6. class WebAuthnDeviceLostControllerTest extends FeatureTestCase
  7. {
  8. /**
  9. * @var \App\Models\User
  10. */
  11. protected $user;
  12. /**
  13. * @test
  14. */
  15. public function setUp(): void
  16. {
  17. parent::setUp();
  18. $this->user = User::factory()->create();
  19. }
  20. /**
  21. * @test
  22. */
  23. public function test_sendRecoveryEmail_sends_notification_on_success()
  24. {
  25. Notification::fake();
  26. $response = $this->json('POST', '/webauthn/lost', [
  27. 'email' => $this->user->email,
  28. ]);
  29. Notification::assertSentTo($this->user, \DarkGhostHunter\Larapass\Notifications\AccountRecoveryNotification::class);
  30. $response->assertStatus(200)
  31. ->assertJsonStructure([
  32. 'message'
  33. ]);
  34. }
  35. /**
  36. * @test
  37. */
  38. public function test_sendRecoveryEmail_does_not_send_anything_on_error()
  39. {
  40. Notification::fake();
  41. $response = $this->json('POST', '/webauthn/lost', [
  42. 'email' => 'bad@email.com',
  43. ]);
  44. Notification::assertNothingSent();
  45. $response->assertStatus(422)
  46. ->assertJsonValidationErrors([
  47. 'email'
  48. ]);
  49. }
  50. }