From 275cf4630e6461ba2b22c846118ac1e2f352e989 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 12 Sep 2024 13:16:37 -0700 Subject: [PATCH] Add tests for delete asset endpoint --- tests/Feature/Assets/Api/DeleteAssetTest.php | 69 ++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 tests/Feature/Assets/Api/DeleteAssetTest.php diff --git a/tests/Feature/Assets/Api/DeleteAssetTest.php b/tests/Feature/Assets/Api/DeleteAssetTest.php new file mode 100644 index 0000000000..c834ae7db4 --- /dev/null +++ b/tests/Feature/Assets/Api/DeleteAssetTest.php @@ -0,0 +1,69 @@ +create(); + + $this->actingAsForApi(User::factory()->create()) + ->deleteJson(route('api.assets.destroy', $asset)) + ->assertForbidden(); + } + + public function testCanDeleteAsset() + { + $asset = Asset::factory()->create(); + + $this->actingAsForApi(User::factory()->deleteAssets()->create()) + ->deleteJson(route('api.assets.destroy', $asset)) + ->assertStatusMessageIs('success'); + + $this->assertTrue($asset->fresh()->trashed()); + } + + public function testCannotDeleteAssetThatIsCheckedOut() + { + $this->markTestSkipped('This behavior is not functioning yet.'); + } + + public function testAdheresToMultipleFullCompanySupportScoping() + { + [$companyA, $companyB] = Company::factory()->count(2)->create(); + + $assetA = Asset::factory()->for($companyA)->create(); + $assetB = Asset::factory()->for($companyB)->create(); + $assetC = Asset::factory()->for($companyB)->create(); + + $superUser = $companyA->users()->save(User::factory()->superuser()->make()); + $userInCompanyA = $companyA->users()->save(User::factory()->deleteAssets()->make()); + $userInCompanyB = $companyB->users()->save(User::factory()->deleteAssets()->make()); + + $this->settings->enableMultipleFullCompanySupport(); + + $this->actingAsForApi($userInCompanyA) + ->deleteJson(route('api.assets.destroy', $assetB)) + ->assertStatusMessageIs('error'); + + $this->actingAsForApi($userInCompanyB) + ->deleteJson(route('api.assets.destroy', $assetA)) + ->assertStatusMessageIs('error'); + + $this->actingAsForApi($superUser) + ->deleteJson(route('api.assets.destroy', $assetC)) + ->assertStatusMessageIs('success'); + + $this->assertNull($assetA->fresh()->deleted_at, 'Asset unexpectedly deleted'); + $this->assertNull($assetB->fresh()->deleted_at, 'Asset unexpectedly deleted'); + $this->assertNotNull($assetC->fresh()->deleted_at, 'Asset was not deleted'); + } +}