2024-09-12 13:39:36 -07:00
|
|
|
<?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
|
2024-09-12 13:39:36 -07:00
|
|
|
{
|
|
|
|
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-12 13:39:36 -07:00
|
|
|
}
|
|
|
|
|
2024-09-16 14:25:11 -07:00
|
|
|
public function testCannotDeleteAssetModelThatStillHasAssociatedAssets()
|
2024-09-12 13:39:36 -07:00
|
|
|
{
|
2024-09-16 14:25:11 -07:00
|
|
|
$assetModel = Asset::factory()->create()->model;
|
2024-09-12 13:39:36 -07:00
|
|
|
|
|
|
|
$this->actingAsForApi(User::factory()->deleteAssetModels()->create())
|
|
|
|
->deleteJson(route('api.models.destroy', $assetModel))
|
2024-09-16 14:25:11 -07:00
|
|
|
->assertStatusMessageIs('error');
|
2024-09-12 13:39:36 -07:00
|
|
|
|
2024-09-16 14:25:11 -07:00
|
|
|
$this->assertNotSoftDeleted($assetModel);
|
2024-09-12 13:39:36 -07:00
|
|
|
}
|
|
|
|
|
2024-09-16 14:25:11 -07:00
|
|
|
public function testCanDeleteAssetModel()
|
2024-09-12 13:39:36 -07:00
|
|
|
{
|
2024-09-16 14:25:11 -07:00
|
|
|
$assetModel = AssetModel::factory()->create();
|
2024-09-12 13:39:36 -07:00
|
|
|
|
|
|
|
$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-12 13:39:36 -07:00
|
|
|
|
2024-09-16 14:25:11 -07:00
|
|
|
$this->assertSoftDeleted($assetModel);
|
2024-09-12 13:39:36 -07:00
|
|
|
}
|
|
|
|
}
|