2FAuth/tests/Feature/Http/Auth/WebAuthnDeviceLostControllerTest.php
2022-11-25 15:20:36 +01:00

64 lines
1.3 KiB
PHP

<?php
namespace Tests\Feature\Http\Auth;
use App\Models\User;
use Illuminate\Support\Facades\Notification;
use Tests\FeatureTestCase;
class WebAuthnDeviceLostControllerTest extends FeatureTestCase
{
/**
* @var \App\Models\User
*/
protected $user;
/**
* @test
*/
public function setUp() : void
{
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);
$response->assertStatus(200)
->assertJsonStructure([
'message',
]);
}
/**
* @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([
'email',
]);
}
}