mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Add tests for delete status label endpoint
This commit is contained in:
parent
c269184c60
commit
b06e8d442d
|
@ -356,6 +356,11 @@ class UserFactory extends Factory
|
|||
return $this->appendPermission(['kits.delete' => '1']);
|
||||
}
|
||||
|
||||
public function deleteStatusLabels()
|
||||
{
|
||||
return $this->appendPermission(['statuslabels.delete' => '1']);
|
||||
}
|
||||
|
||||
private function appendPermission(array $permission)
|
||||
{
|
||||
return $this->state(function ($currentState) use ($permission) {
|
||||
|
|
45
tests/Feature/StatusLabels/Api/DeleteStatusLabelTest.php
Normal file
45
tests/Feature/StatusLabels/Api/DeleteStatusLabelTest.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\StatusLabels\Api;
|
||||
|
||||
use App\Models\Statuslabel;
|
||||
use App\Models\User;
|
||||
use Tests\Concerns\TestsPermissionsRequirement;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DeleteStatusLabelTest extends TestCase implements TestsPermissionsRequirement
|
||||
{
|
||||
public function testRequiresPermission()
|
||||
{
|
||||
$statusLabel = Statuslabel::factory()->create();
|
||||
|
||||
$this->actingAsForApi(User::factory()->create())
|
||||
->deleteJson(route('api.statuslabels.destroy', $statusLabel))
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
public function testCannotDeleteStatusLabelWhileStillAssociatedToAssets()
|
||||
{
|
||||
$statusLabel = Statuslabel::factory()->hasAssets()->create();
|
||||
|
||||
$this->assertGreaterThan(0, $statusLabel->assets->count(), 'Precondition failed: StatusLabel has no assets');
|
||||
|
||||
$this->actingAsForApi(User::factory()->deleteStatusLabels()->create())
|
||||
->deleteJson(route('api.statuslabels.destroy', $statusLabel))
|
||||
->assertStatusMessageIs('error');
|
||||
|
||||
$this->assertNotSoftDeleted($statusLabel);
|
||||
}
|
||||
|
||||
public function testCanDeleteStatusLabel()
|
||||
{
|
||||
$statusLabel = Statuslabel::factory()->create();
|
||||
|
||||
$this->actingAsForApi(User::factory()->deleteStatusLabels()->create())
|
||||
->deleteJson(route('api.statuslabels.destroy', $statusLabel))
|
||||
->assertOk()
|
||||
->assertStatusMessageIs('success');
|
||||
|
||||
$this->assertSoftDeleted($statusLabel);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue