Files
animethemes-server/tests/Feature/Http/Api/Wiki/Video/Script/ScriptRestoreTest.php
T
2025-06-27 02:52:13 -03:00

87 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Http\Api\Wiki\Video\Script;
use App\Enums\Auth\ExtendedCrudPermission;
use App\Models\Auth\User;
use App\Models\Wiki\Video\VideoScript;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;
/**
* Class ScriptRestoreTest.
*/
class ScriptRestoreTest extends TestCase
{
/**
* The Script Restore Endpoint shall be protected by sanctum.
*
* @return void
*/
public function test_protected(): void
{
$script = VideoScript::factory()->trashed()->createOne();
$response = $this->patch(route('api.videoscript.restore', ['videoscript' => $script]));
$response->assertUnauthorized();
}
/**
* The Script Restore Endpoint shall forbid users without the restore video script permission.
*
* @return void
*/
public function test_forbidden(): void
{
$script = VideoScript::factory()->trashed()->createOne();
$user = User::factory()->createOne();
Sanctum::actingAs($user);
$response = $this->patch(route('api.videoscript.restore', ['videoscript' => $script]));
$response->assertForbidden();
}
/**
* The Script Restore Endpoint shall forbid users from restoring a script that isn't trashed.
*
* @return void
*/
public function test_trashed(): void
{
$script = VideoScript::factory()->createOne();
$user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE->format(VideoScript::class))->createOne();
Sanctum::actingAs($user);
$response = $this->patch(route('api.videoscript.restore', ['videoscript' => $script]));
$response->assertForbidden();
}
/**
* The Script Restore Endpoint shall restore the script.
*
* @return void
*/
public function test_restored(): void
{
$script = VideoScript::factory()->trashed()->createOne();
$user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE->format(VideoScript::class))->createOne();
Sanctum::actingAs($user);
$response = $this->patch(route('api.videoscript.restore', ['videoscript' => $script]));
$response->assertOk();
static::assertNotSoftDeleted($script);
}
}