Add failing test for api

This commit is contained in:
Marcus Moore 2025-03-05 15:57:18 -08:00
parent 8c21d625fc
commit 00cbebd1e3
No known key found for this signature in database

View file

@ -5,6 +5,7 @@ namespace Tests\Feature\Accessories\Api;
use App\Models\Accessory;
use App\Models\Company;
use App\Models\User;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\Concerns\TestsFullMultipleCompaniesSupport;
use Tests\Concerns\TestsPermissionsRequirement;
use Tests\TestCase;
@ -53,9 +54,17 @@ class DeleteAccessoriesTest extends TestCase implements TestsFullMultipleCompani
$this->assertSoftDeleted($accessoryC);
}
public function testCannotDeleteAccessoryThatHasCheckouts()
public static function checkedOutAccessories()
{
$accessory = Accessory::factory()->checkedOutToUser()->create();
yield 'checked out to user' => [fn() => Accessory::factory()->checkedOutToUser()->create()];
yield 'checked out to asset' => [fn() => Accessory::factory()->checkedOutToAsset()->create()];
yield 'checked out to location' => [fn() => Accessory::factory()->checkedOutToLocation()->create()];
}
#[DataProvider('checkedOutAccessories')]
public function testCannotDeleteAccessoryThatHasCheckouts($data)
{
$accessory = $data();
$this->actingAsForApi(User::factory()->deleteAccessories()->create())
->deleteJson(route('api.accessories.destroy', $accessory))