2FAuth/tests/Feature/Http/Auth/WebAuthnDeviceLostControllerTest.php

64 lines
1.3 KiB
PHP
Raw Normal View History

2022-03-31 08:38:35 +02:00
<?php
2022-03-31 12:09:25 +02:00
namespace Tests\Feature\Http\Auth;
2022-03-31 08:38:35 +02:00
use App\Models\User;
use Illuminate\Support\Facades\Notification;
2022-11-22 15:15:52 +01:00
use Tests\FeatureTestCase;
2022-03-31 08:38:35 +02:00
class WebAuthnDeviceLostControllerTest extends FeatureTestCase
{
/**
* @var \App\Models\User
2022-11-22 15:15:52 +01:00
*/
2022-03-31 08:38:35 +02:00
protected $user;
/**
* @test
*/
2022-11-22 15:15:52 +01:00
public function setUp() : void
2022-03-31 08:38:35 +02:00
{
parent::setUp();
$this->user = User::factory()->create();
}
/**
* @test
*/
public function test_sendRecoveryEmail_sends_notification_on_success()
{
Notification::fake();
$response = $this->json('POST', '/webauthn/lost', [
'email' => $this->user->email,
]);
Notification::assertSentTo($this->user, \App\Notifications\WebauthnRecoveryNotification::class);
2022-03-31 08:38:35 +02:00
$response->assertStatus(200)
->assertJsonStructure([
2022-11-22 15:15:52 +01:00
'message',
2022-03-31 08:38:35 +02:00
]);
}
/**
* @test
*/
public function test_sendRecoveryEmail_does_not_send_anything_on_error()
{
Notification::fake();
$response = $this->json('POST', '/webauthn/lost', [
'email' => 'bad@email.com',
]);
Notification::assertNothingSent();
$response->assertStatus(422)
->assertJsonValidationErrors([
2022-11-22 15:15:52 +01:00
'email',
2022-03-31 08:38:35 +02:00
]);
}
2022-11-22 15:15:52 +01:00
}