42 lines
987 B
PHP
42 lines
987 B
PHP
<?php
|
|
|
|
namespace Tests\Feature\Auth;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class LoginRequestTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_throttles_too_many_attempts(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
|
|
for ($i = 0; $i < 6; $i++) {
|
|
$this->post('/login', [
|
|
'email' => $user->email,
|
|
'password' => 'wrong-password',
|
|
]);
|
|
}
|
|
|
|
$this->post('/login', [
|
|
'email' => $user->email,
|
|
'password' => 'password',
|
|
])->assertSessionHasErrors('email');
|
|
}
|
|
|
|
public function test_successful_login_redirects(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
|
|
$this->post('/login', [
|
|
'email' => $user->email,
|
|
'password' => 'password',
|
|
])->assertRedirect(route('dashboard', absolute: false));
|
|
|
|
$this->assertAuthenticated();
|
|
}
|
|
}
|