Files
animethemes-server/tests/Feature/Http/Api/Document/Page/PageDestroyTest.php
T
2025-07-24 01:22:29 -03:00

76 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Http\Api\Document\Page;
use App\Enums\Auth\CrudPermission;
use App\Models\Auth\User;
use App\Models\Document\Page;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;
class PageDestroyTest extends TestCase
{
/**
* The Page Destroy Endpoint shall be protected by sanctum.
*/
public function testProtected(): void
{
$page = Page::factory()->createOne();
$response = $this->delete(route('api.page.destroy', ['page' => $page]));
$response->assertUnauthorized();
}
/**
* The Page Destroy Endpoint shall forbid users without the delete page permission.
*/
public function testForbidden(): void
{
$page = Page::factory()->createOne();
$user = User::factory()->createOne();
Sanctum::actingAs($user);
$response = $this->delete(route('api.page.destroy', ['page' => $page]));
$response->assertForbidden();
}
/**
* The Page Destroy Endpoint shall forbid users from updating a page that is trashed.
*/
public function testTrashed(): void
{
$page = Page::factory()->trashed()->createOne();
$user = User::factory()->withPermissions(CrudPermission::DELETE->format(Page::class))->createOne();
Sanctum::actingAs($user);
$response = $this->delete(route('api.page.destroy', ['page' => $page]));
$response->assertNotFound();
}
/**
* The Page Destroy Endpoint shall delete the page.
*/
public function testDeleted(): void
{
$page = Page::factory()->createOne();
$user = User::factory()->withPermissions(CrudPermission::DELETE->format(Page::class))->createOne();
Sanctum::actingAs($user);
$response = $this->delete(route('api.page.destroy', ['page' => $page]));
$response->assertOk();
static::assertSoftDeleted($page);
}
}