<?php

declare(strict_types=1);

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

use function Pest\Laravel\delete;

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

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

    $response->assertUnauthorized();
});

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

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

    Sanctum::actingAs($user);

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

    $response->assertForbidden();
});

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

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

    Sanctum::actingAs($user);

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

    $response->assertNotFound();
});

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

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

    Sanctum::actingAs($user);

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

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