Add tests for delete asset model endpoint

This commit is contained in:
Marcus Moore 2024-09-12 13:39:36 -07:00
parent b336c6273d
commit 2044570e95
No known key found for this signature in database
2 changed files with 56 additions and 0 deletions

View file

@ -141,6 +141,11 @@ class UserFactory extends Factory
return $this->appendPermission(['assets.view.requestable' => '1']); return $this->appendPermission(['assets.view.requestable' => '1']);
} }
public function deleteAssetModels()
{
return $this->appendPermission(['models.delete' => '1']);
}
public function viewAccessories() public function viewAccessories()
{ {
return $this->appendPermission(['accessories.view' => '1']); return $this->appendPermission(['accessories.view' => '1']);

View file

@ -0,0 +1,51 @@
<?php
namespace Tests\Feature\AssetModels\Api;
use App\Models\Asset;
use App\Models\AssetModel;
use App\Models\User;
use Tests\Concerns\TestsMultipleFullCompanySupport;
use Tests\Concerns\TestsPermissionsRequirement;
use Tests\TestCase;
class DeleteAssetModelsTest extends TestCase implements TestsMultipleFullCompanySupport, TestsPermissionsRequirement
{
public function testRequiresPermission()
{
$assetModel = AssetModel::factory()->create();
$this->actingAsForApi(User::factory()->create())
->deleteJson(route('api.models.destroy', $assetModel))
->assertForbidden();
}
public function testCanDeleteAssetModel()
{
$assetModel = AssetModel::factory()->create();
$this->actingAsForApi(User::factory()->deleteAssetModels()->create())
->deleteJson(route('api.models.destroy', $assetModel))
->assertStatusMessageIs('success');
$this->assertTrue($assetModel->fresh()->trashed());
}
public function testCannotDeleteAssetModelThatStillHasAssociatedAssets()
{
$asset = Asset::factory()->create();
$this->actingAsForApi(User::factory()->deleteAssetModels()->create())
->deleteJson(route('api.models.destroy', $asset->model))
->assertStatusMessageIs('error');
$this->assertFalse($asset->model->fresh()->trashed());
}
public function testAdheresToMultipleFullCompanySupportScoping()
{
// TODO: Implement testAdheresToMultipleFullCompanySupportScoping() method.
$this->markTestIncomplete();
}
}