Skip to content

Commit 79a4bb7

Browse files
committed
Add tests for delete depreciation endpoint
1 parent 2f76c1b commit 79a4bb7

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

database/factories/UserFactory.php

+5
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@ public function deleteCustomFieldsets()
336336
return $this->appendPermission(['customfields.delete' => '1']);
337337
}
338338

339+
public function deleteDepreciations()
340+
{
341+
return $this->appendPermission(['depreciations.delete' => '1']);
342+
}
343+
339344
private function appendPermission(array $permission)
340345
{
341346
return $this->state(function ($currentState) use ($permission) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Tests\Feature\Depreciations\Api;
4+
5+
use App\Models\Depreciation;
6+
use App\Models\User;
7+
use Tests\Concerns\TestsPermissionsRequirement;
8+
use Tests\TestCase;
9+
10+
class DeleteDepreciationTest extends TestCase implements TestsPermissionsRequirement
11+
{
12+
public function testRequiresPermission()
13+
{
14+
$depreciation = Depreciation::factory()->create();
15+
16+
$this->actingAsForApi(User::factory()->create())
17+
->deleteJson(route('api.depreciations.destroy', $depreciation))
18+
->assertForbidden();
19+
}
20+
21+
public function testCanDeleteDepreciation()
22+
{
23+
$depreciation = Depreciation::factory()->create();
24+
25+
$this->actingAsForApi(User::factory()->deleteDepreciations()->create())
26+
->deleteJson(route('api.depreciations.destroy', $depreciation))
27+
->assertStatusMessageIs('success');
28+
29+
$this->assertDatabaseMissing('depreciations', ['id' => $depreciation->id]);
30+
}
31+
32+
public function testCannotDeleteDepreciationThatHasAssociatedModels()
33+
{
34+
$depreciation = Depreciation::factory()->hasModels()->create();
35+
36+
$this->actingAsForApi(User::factory()->deleteDepreciations()->create())
37+
->deleteJson(route('api.depreciations.destroy', $depreciation))
38+
->assertStatusMessageIs('error');
39+
40+
$this->assertNotNull($depreciation->fresh(), 'Depreciation unexpectedly deleted');
41+
}
42+
}

0 commit comments

Comments
 (0)