Skip to content

A free open source IT asset/license management system

Added/updated tests

snipe995e2090f51d
diff --git a/tests/Feature/Categories/Api/DeleteCategoriesTest.php b/tests/Feature/Categories/Api/DeleteCategoriesTest.php
index eb9b73b050..22aeb7d424 100644
--- a/tests/Feature/Categories/Api/DeleteCategoriesTest.php
+++ b/tests/Feature/Categories/Api/DeleteCategoriesTest.php
@@ -3,6 +3,7 @@
namespace Tests\Feature\Categories\Api;
use App\Models\Asset;
+use App\Models\AssetModel;
use App\Models\Category;
use App\Models\User;
use Tests\Concerns\TestsPermissionsRequirement;
@@ -21,7 +22,7 @@ class DeleteCategoriesTest extends TestCase implements TestsPermissionsRequireme
$this->assertNotSoftDeleted($category);
}
- public function testCannotDeleteCategoryThatStillHasAssociatedItems()
+ public function testCannotDeleteCategoryThatStillHasAssociatedAssets()
{
$asset = Asset::factory()->create();
$category = $asset->model->category;
@@ -33,6 +34,18 @@ class DeleteCategoriesTest extends TestCase implements TestsPermissionsRequireme
$this->assertNotSoftDeleted($category);
}
+ public function testCannotDeleteCategoryThatStillHasAssociatedModels()
+ {
+ $model = AssetModel::factory()->create();
+ $category = $model->category;
+
+ $this->actingAsForApi(User::factory()->deleteCategories()->create())
+ ->deleteJson(route('api.categories.destroy', $category))
+ ->assertStatusMessageIs('error');
+
+ $this->assertNotSoftDeleted($category);
+ }
+
public function testCanDeleteCategory()
{
$category = Category::factory()->create();
diff --git a/tests/Feature/Categories/Ui/DeleteCategoriesTest.php b/tests/Feature/Categories/Ui/DeleteCategoriesTest.php
new file mode 100644
index 0000000000..5c5e0632cf
--- /dev/null
+++ b/tests/Feature/Categories/Ui/DeleteCategoriesTest.php
@@ -0,0 +1,60 @@
+<?php
+
+namespace Tests\Feature\Assets\Ui;
+
+use App\Events\CheckoutableCheckedIn;
+use App\Models\Asset;
+use App\Models\AssetModel;
+use App\Models\User;
+use App\Models\Category;
+use Illuminate\Support\Facades\Event;
+use Illuminate\Support\Facades\Storage;
+use Tests\TestCase;
+
+class DeleteCategoriesTest extends TestCase
+{
+ public function testPermissionNeededToDeleteCategory()
+ {
+ $this->actingAs(User::factory()->create())
+ ->delete(route('categories.destroy', Category::factory()->create()))
+ ->assertForbidden();
+ }
+
+ public function testCanDeleteCategory()
+ {
+ $category = Category::factory()->create();
+
+ $this->actingAs(User::factory()->deleteCategories()->create())
+ ->delete(route('categories.destroy', $category))
+ ->assertRedirectToRoute('categories.index')
+ ->assertSessionHas('success');
+
+ $this->assertSoftDeleted($category);
+ }
+
+ public function testCannotDeleteCategoryThatStillHasAssociatedModels()
+ {
+ $model = AssetModel::factory()->create();
+ $category = $model->category;
+
+ $this->actingAs(User::factory()->deleteCategories()->create())
+ ->delete(route('categories.destroy', $category))
+ ->assertRedirectToRoute('categories.index')
+ ->assertSessionHas('error');
+ $this->assertNotSoftDeleted($category);
+ }
+
+ public function testCannotDeleteCategoryThatStillHasAssociatedAssets()
+ {
+ $asset = Asset::factory()->create();
+ $category = $asset->model->category;
+
+ $this->actingAs(User::factory()->deleteCategories()->create())
+ ->delete(route('categories.destroy', $category))
+ ->assertRedirectToRoute('categories.index')
+ ->assertSessionHas('error');
+
+ $this->assertNotSoftDeleted($category);
+ }
+
+}