mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-11 13:57:41 -08:00
Add tests for delete supplier endpoint
This commit is contained in:
parent
b06e8d442d
commit
7f40f55343
|
@ -361,6 +361,11 @@ class UserFactory extends Factory
|
|||
return $this->appendPermission(['statuslabels.delete' => '1']);
|
||||
}
|
||||
|
||||
public function deleteSuppliers()
|
||||
{
|
||||
return $this->appendPermission(['suppliers.delete' => '1']);
|
||||
}
|
||||
|
||||
private function appendPermission(array $permission)
|
||||
{
|
||||
return $this->state(function ($currentState) use ($permission) {
|
||||
|
|
51
tests/Feature/Suppliers/Api/DeleteSupplierTest.php
Normal file
51
tests/Feature/Suppliers/Api/DeleteSupplierTest.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Suppliers\Api;
|
||||
|
||||
use App\Models\Asset;
|
||||
use App\Models\AssetMaintenance;
|
||||
use App\Models\Supplier;
|
||||
use App\Models\User;
|
||||
use Tests\Concerns\TestsPermissionsRequirement;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DeleteSupplierTest extends TestCase implements TestsPermissionsRequirement
|
||||
{
|
||||
public function testRequiresPermission()
|
||||
{
|
||||
$supplier = Supplier::factory()->create();
|
||||
|
||||
$this->actingAsForApi(User::factory()->create())
|
||||
->deleteJson(route('api.suppliers.destroy', $supplier))
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
public function testCannotDeleteSupplierWithDataStillAssociated()
|
||||
{
|
||||
$supplierWithAsset = Supplier::factory()->hasAssets()->create();
|
||||
$supplierWithAssetMaintenance = Supplier::factory()->has(AssetMaintenance::factory(), 'asset_maintenances')->create();
|
||||
$supplierWithLicense = Supplier::factory()->hasLicenses()->create();
|
||||
|
||||
$actor = $this->actingAsForApi(User::factory()->deleteSuppliers()->create());
|
||||
|
||||
$actor->deleteJson(route('api.suppliers.destroy', $supplierWithAsset))->assertStatusMessageIs('error');
|
||||
$actor->deleteJson(route('api.suppliers.destroy', $supplierWithAssetMaintenance))->assertStatusMessageIs('error');
|
||||
$actor->deleteJson(route('api.suppliers.destroy', $supplierWithLicense))->assertStatusMessageIs('error');
|
||||
|
||||
$this->assertNotSoftDeleted($supplierWithAsset);
|
||||
$this->assertNotSoftDeleted($supplierWithAssetMaintenance);
|
||||
$this->assertNotSoftDeleted($supplierWithLicense);
|
||||
}
|
||||
|
||||
public function testCanDeleteSupplier()
|
||||
{
|
||||
$supplier = Supplier::factory()->create();
|
||||
|
||||
$this->actingAsForApi(User::factory()->deleteSuppliers()->create())
|
||||
->deleteJson(route('api.suppliers.destroy', $supplier))
|
||||
->assertOk()
|
||||
->assertStatusMessageIs('success');
|
||||
|
||||
$this->assertSoftDeleted($supplier);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue