Add tests for delete status label endpoint

This commit is contained in:
Marcus Moore 2024-09-16 13:37:08 -07:00
parent c269184c60
commit b06e8d442d
No known key found for this signature in database
2 changed files with 50 additions and 0 deletions

View file

@ -356,6 +356,11 @@ class UserFactory extends Factory
return $this->appendPermission(['kits.delete' => '1']); return $this->appendPermission(['kits.delete' => '1']);
} }
public function deleteStatusLabels()
{
return $this->appendPermission(['statuslabels.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) {

View 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);
}
}