authentikate/tests/Feature/TokensPageTest.php
Javier Feliz 2e95a2a271
Some checks failed
linter / quality (push) Successful in 5m47s
tests / ci (push) Failing after 10m17s
Move tokens to their own page
2025-08-02 15:54:30 -04:00

69 lines
2.2 KiB
PHP

<?php
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->admin = User::factory()->create(['is_admin' => true]);
$this->user = User::factory()->create(['is_admin' => false]);
});
describe('Tokens Page', function () {
it('allows any authenticated user to access the tokens page', function () {
$this->actingAs($this->user);
$response = $this->get(route('tokens'));
$response->assertStatus(200);
$response->assertSee('Authentication Tokens');
$response->assertSee('Manage your active authentication tokens');
});
it('allows admin users to access the tokens page', function () {
$this->actingAs($this->admin);
$response = $this->get(route('tokens'));
$response->assertStatus(200);
$response->assertSee('Authentication Tokens');
$response->assertSee('Manage your active authentication tokens');
});
it('redirects unauthenticated users to login', function () {
$response = $this->get(route('tokens'));
$response->assertRedirect(route('login'));
});
it('shows the tokens navigation link to all authenticated users', function () {
// Test regular user sees the link
$this->actingAs($this->user);
$response = $this->get(route('dashboard'));
$response->assertSee('Tokens');
// Test admin user also sees the link
$this->actingAs($this->admin);
$response = $this->get(route('dashboard'));
$response->assertSee('Tokens');
});
it('properly displays the page title', function () {
$this->actingAs($this->user);
$response = $this->get(route('tokens'));
$response->assertSee('<title>Authentication Tokens</title>', false);
});
it('shows empty state when user has no tokens', function () {
$this->actingAs($this->user);
$response = $this->get(route('tokens'));
$response->assertSee('No tokens');
$response->assertSee('authorized any applications');
});
});