mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
Add tests for delete depreciation endpoint
This commit is contained in:
parent
2f76c1bc5b
commit
79a4bb7316
|
@ -336,6 +336,11 @@ class UserFactory extends Factory
|
||||||
return $this->appendPermission(['customfields.delete' => '1']);
|
return $this->appendPermission(['customfields.delete' => '1']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function deleteDepreciations()
|
||||||
|
{
|
||||||
|
return $this->appendPermission(['depreciations.delete' => '1']);
|
||||||
|
}
|
||||||
|
|
||||||
private function appendPermission(array $permission)
|
private function appendPermission(array $permission)
|
||||||
{
|
{
|
||||||
return $this->state(function ($currentState) use ($permission) {
|
return $this->state(function ($currentState) use ($permission) {
|
||||||
|
|
42
tests/Feature/Depreciations/Api/DeleteDepreciationTest.php
Normal file
42
tests/Feature/Depreciations/Api/DeleteDepreciationTest.php
Normal file
|
@ -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');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue