mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Add tests for delete category endpoint
This commit is contained in:
parent
0ec415d4d0
commit
8ce2512f55
|
@ -296,6 +296,11 @@ class UserFactory extends Factory
|
||||||
return $this->appendPermission(['users.delete' => '1']);
|
return $this->appendPermission(['users.delete' => '1']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function deleteCategories()
|
||||||
|
{
|
||||||
|
return $this->appendPermission(['categories.delete' => '1']);
|
||||||
|
}
|
||||||
|
|
||||||
public function canEditOwnLocation()
|
public function canEditOwnLocation()
|
||||||
{
|
{
|
||||||
return $this->appendPermission(['self.edit_location' => '1']);
|
return $this->appendPermission(['self.edit_location' => '1']);
|
||||||
|
|
44
tests/Feature/Categories/Api/DeleteCategoriesTest.php
Normal file
44
tests/Feature/Categories/Api/DeleteCategoriesTest.php
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
<?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');
|
||||||
|
|
||||||
|
$this->assertTrue($category->fresh()->trashed());
|
||||||
|
}
|
||||||
|
|
||||||
|
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');
|
||||||
|
|
||||||
|
$this->assertFalse($category->fresh()->trashed());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue