snipe-it/tests/Feature/Depreciations/Api/DeleteDepreciationsTest.php

45 lines
1.4 KiB
PHP
Raw Normal View History

<?php
namespace Tests\Feature\Depreciations\Api;
use App\Models\Depreciation;
use App\Models\User;
use Tests\Concerns\TestsPermissionsRequirement;
use Tests\TestCase;
2024-09-16 14:38:38 -07:00
class DeleteDepreciationsTest extends TestCase implements TestsPermissionsRequirement
{
public function testRequiresPermission()
{
$depreciation = Depreciation::factory()->create();
$this->actingAsForApi(User::factory()->create())
->deleteJson(route('api.depreciations.destroy', $depreciation))
->assertForbidden();
2024-09-16 14:32:38 -07:00
$this->assertDatabaseHas('depreciations', ['id' => $depreciation->id]);
}
2024-09-16 14:25:11 -07:00
public function testCannotDeleteDepreciationThatHasAssociatedModels()
{
2024-09-16 14:25:11 -07:00
$depreciation = Depreciation::factory()->hasModels()->create();
$this->actingAsForApi(User::factory()->deleteDepreciations()->create())
->deleteJson(route('api.depreciations.destroy', $depreciation))
2024-09-16 14:25:11 -07:00
->assertStatusMessageIs('error');
2024-09-16 14:34:55 -07:00
$this->assertDatabaseHas('depreciations', ['id' => $depreciation->id]);
}
2024-09-16 14:25:11 -07:00
public function testCanDeleteDepreciation()
{
2024-09-16 14:25:11 -07:00
$depreciation = Depreciation::factory()->create();
$this->actingAsForApi(User::factory()->deleteDepreciations()->create())
->deleteJson(route('api.depreciations.destroy', $depreciation))
2024-09-16 14:25:11 -07:00
->assertStatusMessageIs('success');
2024-09-16 14:25:11 -07:00
$this->assertDatabaseMissing('depreciations', ['id' => $depreciation->id]);
}
}