snipe-it/tests/Feature/AssetModels/Api/DeleteAssetModelsTest.php

46 lines
1.3 KiB
PHP
Raw Normal View History

<?php
namespace Tests\Feature\AssetModels\Api;
use App\Models\Asset;
use App\Models\AssetModel;
use App\Models\User;
use Tests\Concerns\TestsPermissionsRequirement;
use Tests\TestCase;
2024-09-12 13:46:22 -07:00
class DeleteAssetModelsTest extends TestCase implements TestsPermissionsRequirement
{
public function testRequiresPermission()
{
$assetModel = AssetModel::factory()->create();
$this->actingAsForApi(User::factory()->create())
->deleteJson(route('api.models.destroy', $assetModel))
->assertForbidden();
2024-09-16 14:32:38 -07:00
$this->assertNotSoftDeleted($assetModel);
}
2024-09-16 14:25:11 -07:00
public function testCannotDeleteAssetModelThatStillHasAssociatedAssets()
{
2024-09-16 14:25:11 -07:00
$assetModel = Asset::factory()->create()->model;
$this->actingAsForApi(User::factory()->deleteAssetModels()->create())
->deleteJson(route('api.models.destroy', $assetModel))
2024-09-16 14:25:11 -07:00
->assertStatusMessageIs('error');
2024-09-16 14:25:11 -07:00
$this->assertNotSoftDeleted($assetModel);
}
2024-09-16 14:25:11 -07:00
public function testCanDeleteAssetModel()
{
2024-09-16 14:25:11 -07:00
$assetModel = AssetModel::factory()->create();
$this->actingAsForApi(User::factory()->deleteAssetModels()->create())
2024-09-12 13:46:22 -07:00
->deleteJson(route('api.models.destroy', $assetModel))
2024-09-16 14:25:11 -07:00
->assertStatusMessageIs('success');
2024-09-16 14:25:11 -07:00
$this->assertSoftDeleted($assetModel);
}
}