<?php

use App\Filament\Resources\PolicyResource;
use App\Models\Policy;
use App\Models\Tenant;
use App\Models\User;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;

uses(RefreshDatabase::class);
test('policies bulk actions are available for authenticated users', function () {
    $tenant = Tenant::factory()->create();
    $user = User::factory()->create();
    $user->tenants()->syncWithoutDetaching([
        $tenant->getKey() => ['role' => 'owner'],
    ]);

    Filament::setTenant($tenant, true);
    $policies = Policy::factory()->count(2)->create(['tenant_id' => $tenant->id]);

    Livewire::actingAs($user)
        ->test(PolicyResource\Pages\ListPolicies::class)
        ->callTableBulkAction('bulk_sync', $policies)
        ->assertHasNoTableBulkActionErrors();
});
