Skip to content

Commit

Permalink
Add login and logout test cases for user authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeWithDennis committed Oct 30, 2024
1 parent afc0851 commit d622afe
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/Feature/Filament/Pages/Auth/LoginTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

use App\Models\User;
use Filament\Facades\Filament;

test('an unauthenticated user can access the login page', function () {
$this->get(Filament::getLoginUrl())
->assertOk();
});

test('an unauthenticated user can not access the admin panel', function () {
$this->get('admin')
->assertRedirect(Filament::getLoginUrl());
});

test('an authenticated user can access the admin panel', function () {
$user = User::factory()->create([
'name' => 'John Doe',
'email' => '[email protected]',
]);

$this->actingAs($user)
->get('admin')
->assertOk();
});

test('an authenticated user can logout', function () {
$user = User::factory()->create([
'name' => 'John Doe',
'email' => '[email protected]',
]);

$this->actingAs($user)
->get('admin')
->assertOk();

$this->post('admin/logout')
->assertRedirect(Filament::getLoginUrl());
});

0 comments on commit d622afe

Please sign in to comment.