2024-09-16 13:37:08 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\StatusLabels\Api;
|
|
|
|
|
|
|
|
use App\Models\Statuslabel;
|
|
|
|
use App\Models\User;
|
|
|
|
use Tests\Concerns\TestsPermissionsRequirement;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
2024-09-16 14:38:38 -07:00
|
|
|
class DeleteStatusLabelsTest extends TestCase implements TestsPermissionsRequirement
|
2024-09-16 13:37:08 -07:00
|
|
|
{
|
|
|
|
public function testRequiresPermission()
|
|
|
|
{
|
|
|
|
$statusLabel = Statuslabel::factory()->create();
|
|
|
|
|
|
|
|
$this->actingAsForApi(User::factory()->create())
|
|
|
|
->deleteJson(route('api.statuslabels.destroy', $statusLabel))
|
|
|
|
->assertForbidden();
|
2024-09-16 14:32:38 -07:00
|
|
|
|
|
|
|
$this->assertNotSoftDeleted($statusLabel);
|
2024-09-16 13:37:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|