-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for delete depreciation endpoint
- Loading branch information
1 parent
2f76c1b
commit 79a4bb7
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
tests/Feature/Depreciations/Api/DeleteDepreciationTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
} | ||
} |