<?php

namespace Tests\Feature\Admin;

use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Spatie\Permission\Models\Permission;
use Tests\TestCase;

class AdminLogoutTest extends TestCase
{
    use RefreshDatabase;

    public function test_admin_user_can_logout_and_session_is_invalidated(): void
    {
        $admin = User::factory()->create();
        Permission::findOrCreate('access admin panel');
        $admin->givePermissionTo('access admin panel');

        $this->actingAs($admin)
            ->get(route('admin.dashboard'))
            ->assertOk();

        $response = $this->actingAs($admin)->post(route('logout'));

        $this->assertGuest();
        $response->assertRedirect('/');

        $this->get(route('admin.dashboard'))
            ->assertRedirect(route('admin.login'));
    }
}
