Added/updated tests

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe
2025-05-09 19:17:53 +01:00
parent 9b91584776
commit 995e2090f5
2 changed files with 74 additions and 1 deletions

View File

@@ -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();

View File

@@ -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);
}
}