<?php

declare(strict_types=1);

use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Spatie\Activitylog\Models\Activity;

uses(RefreshDatabase::class);

beforeEach(function () {
    $this->seed();
});

test('unauthorized users cannot view activity logs', function () {
    $user = User::where('email', 'user@example.com')->first();
    
    $this->actingAs($user)
        ->get(route('logs.index'))
        ->assertStatus(403);
});

test('authorized users can view activity logs page and see list of logs', function () {
    $admin = User::where('email', 'admin@example.com')->first();
    
    // Trigger some log
    activity()
        ->causedBy($admin)
        ->log('Admin viewed the settings page test');

    $this->actingAs($admin)
        ->get(route('logs.index'))
        ->assertOk()
        ->assertSee('Admin viewed the settings page test');
});
