2024-09-12 13:54:44 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Categories\Api;
|
|
|
|
|
|
|
|
use App\Models\Asset;
|
|
|
|
use App\Models\Category;
|
|
|
|
use App\Models\User;
|
|
|
|
use Tests\Concerns\TestsPermissionsRequirement;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class DeleteCategoriesTest extends TestCase implements TestsPermissionsRequirement
|
|
|
|
{
|
|
|
|
public function testRequiresPermission()
|
|
|
|
{
|
|
|
|
$category = Category::factory()->create();
|
|
|
|
|
|
|
|
$this->actingAsForApi(User::factory()->create())
|
|
|
|
->deleteJson(route('api.categories.destroy', $category))
|
|
|
|
->assertForbidden();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCanDeleteCategory()
|
|
|
|
{
|
|
|
|
$category = Category::factory()->create();
|
|
|
|
|
|
|
|
$this->actingAsForApi(User::factory()->deleteCategories()->create())
|
|
|
|
->deleteJson(route('api.categories.destroy', $category))
|
|
|
|
->assertStatusMessageIs('success');
|
|
|
|
|
2024-09-16 14:20:24 -07:00
|
|
|
$this->assertSoftDeleted($category);
|
2024-09-12 13:54:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testCannotDeleteCategoryThatStillHasAssociatedItems()
|
|
|
|
{
|
|
|
|
$asset = Asset::factory()->create();
|
|
|
|
$category = $asset->model->category;
|
|
|
|
|
|
|
|
$this->actingAsForApi(User::factory()->deleteCategories()->create())
|
|
|
|
->deleteJson(route('api.categories.destroy', $category))
|
|
|
|
->assertStatusMessageIs('error');
|
|
|
|
|
2024-09-16 14:20:24 -07:00
|
|
|
$this->assertNotSoftDeleted($category);
|
2024-09-12 13:54:44 -07:00
|
|
|
}
|
|
|
|
}
|