58 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use function Pest\Laravel\get;
use function Pest\Laravel\post;
uses(RefreshDatabase::class);
it('can display the login page', function () {
$response = get('/login');
$response->assertStatus(200);
$response->assertSee('Email:');
$response->assertSee('Password:');
$response->assertSee('Войти');
});
it('can authenticate a user', function () {
$user = User::factory()->create([
'password' => bcrypt('password123'),
]);
$response = post('/login', [
'email' => $user->email,
'password' => 'password123',
]);
$response->assertRedirect('/dashboard');
expect(auth()->check())->toBeTrue();
});
it('cannot authenticate a user with invalid credentials', function () {
$user = User::factory()->create([
'password' => bcrypt('password123'),
]);
$response = post('/login', [
'email' => $user->email,
'password' => 'wrongpassword',
]);
$response->assertSessionHasErrors();
expect(auth()->check())->toBeFalse();
});
it('can logout a user', function () {
$user = User::factory()->create();
$response = $this->actingAs($user)->post('/logout');
$response->assertRedirect('/');
expect(auth()->check())->toBeFalse();
});