diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 746d88a589..8b110b23d6 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -141,6 +141,11 @@ class UserFactory extends Factory return $this->appendPermission(['assets.view.requestable' => '1']); } + public function deleteAssetModels() + { + return $this->appendPermission(['models.delete' => '1']); + } + public function viewAccessories() { return $this->appendPermission(['accessories.view' => '1']); diff --git a/tests/Feature/AssetModels/Api/DeleteAssetModelsTest.php b/tests/Feature/AssetModels/Api/DeleteAssetModelsTest.php new file mode 100644 index 0000000000..6389b8f2aa --- /dev/null +++ b/tests/Feature/AssetModels/Api/DeleteAssetModelsTest.php @@ -0,0 +1,51 @@ +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(); + } +}