Files
animethemes-server/tests/Feature/Http/Api/Wiki/Video/Script/ScriptRestoreTest.php
T
paranarimasu 2e930b17ff feat: initial migration to Laravel 10 (#572)
* feat: initial migration to Laravel 10

* style: fix StyleCI findings
2023-04-18 16:22:36 -05:00

93 lines
2.3 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 testProtected(): void
{
$script = VideoScript::factory()->createOne();
$script->delete();
$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 testForbidden(): void
{
$script = VideoScript::factory()->createOne();
$script->delete();
$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 testTrashed(): 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 testRestored(): void
{
$script = VideoScript::factory()->createOne();
$script->delete();
$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);
}
}