Skip to content

A free open source IT asset/license management system

Add tests for delete depreciation endpoint

Marcus Moore79a4bb731694
diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php
index f30733854f..598de7c39c 100644
--- a/database/factories/UserFactory.php
+++ b/database/factories/UserFactory.php
@@ -336,6 +336,11 @@ class UserFactory extends Factory
return $this->appendPermission(['customfields.delete' => '1']);
}
+ public function deleteDepreciations()
+ {
+ return $this->appendPermission(['depreciations.delete' => '1']);
+ }
+
private function appendPermission(array $permission)
{
return $this->state(function ($currentState) use ($permission) {
diff --git a/tests/Feature/Depreciations/Api/DeleteDepreciationTest.php b/tests/Feature/Depreciations/Api/DeleteDepreciationTest.php
new file mode 100644
index 0000000000..2e93f92092
--- /dev/null
+++ b/tests/Feature/Depreciations/Api/DeleteDepreciationTest.php
@@ -0,0 +1,42 @@
+<?php
+
+namespace Tests\Feature\Depreciations\Api;
+
+use App\Models\Depreciation;
+use App\Models\User;
+use Tests\Concerns\TestsPermissionsRequirement;
+use Tests\TestCase;
+
+class DeleteDepreciationTest extends TestCase implements TestsPermissionsRequirement
+{
+ public function testRequiresPermission()
+ {
+ $depreciation = Depreciation::factory()->create();
+
+ $this->actingAsForApi(User::factory()->create())
+ ->deleteJson(route('api.depreciations.destroy', $depreciation))
+ ->assertForbidden();
+ }
+
+ public function testCanDeleteDepreciation()
+ {
+ $depreciation = Depreciation::factory()->create();
+
+ $this->actingAsForApi(User::factory()->deleteDepreciations()->create())
+ ->deleteJson(route('api.depreciations.destroy', $depreciation))
+ ->assertStatusMessageIs('success');
+
+ $this->assertDatabaseMissing('depreciations', ['id' => $depreciation->id]);
+ }
+
+ public function testCannotDeleteDepreciationThatHasAssociatedModels()
+ {
+ $depreciation = Depreciation::factory()->hasModels()->create();
+
+ $this->actingAsForApi(User::factory()->deleteDepreciations()->create())
+ ->deleteJson(route('api.depreciations.destroy', $depreciation))
+ ->assertStatusMessageIs('error');
+
+ $this->assertNotNull($depreciation->fresh(), 'Depreciation unexpectedly deleted');
+ }
+}