KSA-ORACLE/tests/Feature/Auth/AuthenticationTest.php
Nyavokevin f96ec3d299
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
first commit
2025-09-02 10:31:17 +03:00

67 lines
1.7 KiB
PHP

<?php
use App\Models\User;
uses(\Illuminate\Foundation\Testing\RefreshDatabase::class);
test('login screen can be rendered', function () {
$response = $this->get(route('login'));
$response->assertStatus(200);
});
test('users can authenticate using the login screen', function () {
$user = User::factory()->create();
$response = $this->post(route('login.store'), [
'email' => $user->email,
'password' => 'password',
]);
$this->assertAuthenticated();
$response->assertRedirect(route('dashboard', absolute: false));
});
test('users can not authenticate with invalid password', function () {
$user = User::factory()->create();
$this->post(route('login.store'), [
'email' => $user->email,
'password' => 'wrong-password',
]);
$this->assertGuest();
});
test('users can logout', function () {
$user = User::factory()->create();
$response = $this->actingAs($user)->post(route('logout'));
$this->assertGuest();
$response->assertRedirect(route('home'));
});
test('users are rate limited', function () {
$user = User::factory()->create();
for ($i = 0; $i < 5; $i++) {
$this->post(route('login.store'), [
'email' => $user->email,
'password' => 'wrong-password',
])->assertStatus(302)->assertSessionHasErrors([
'email' => 'These credentials do not match our records.',
]);
}
$response = $this->post(route('login.store'), [
'email' => $user->email,
'password' => 'wrong-password',
]);
$response->assertSessionHasErrors('email');
$errors = session('errors');
$this->assertStringContainsString('Too many login attempts', $errors->first('email'));
});