<?php

declare(strict_types=1);

use App\Enums\Auth\ExtendedCrudPermission;
use App\Models\Auth\User;
use App\Models\Wiki\Audio;
use Laravel\Sanctum\Sanctum;

use function Pest\Laravel\delete;

test('protected', function (): void {
    $audio = Audio::factory()->createOne();

    $response = delete(route('api.audio.forceDelete', ['audio' => $audio]));

    $response->assertUnauthorized();
});

test('forbidden', function (): void {
    $audio = Audio::factory()->createOne();

    $user = User::factory()->createOne();

    Sanctum::actingAs($user);

    $response = delete(route('api.audio.forceDelete', ['audio' => $audio]));

    $response->assertForbidden();
});

test('deleted', function (): void {
    $audio = Audio::factory()->createOne();

    $user = User::factory()->withPermissions(ExtendedCrudPermission::FORCE_DELETE->format(Audio::class))->createOne();

    Sanctum::actingAs($user);

    $response = delete(route('api.audio.forceDelete', ['audio' => $audio]));

    $response->assertOk();
    $this->assertModelMissing($audio);
});
