|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Feature\Suppliers\Api; |
| 4 | + |
| 5 | +use App\Models\Asset; |
| 6 | +use App\Models\AssetMaintenance; |
| 7 | +use App\Models\Supplier; |
| 8 | +use App\Models\User; |
| 9 | +use Tests\Concerns\TestsPermissionsRequirement; |
| 10 | +use Tests\TestCase; |
| 11 | + |
| 12 | +class DeleteSupplierTest extends TestCase implements TestsPermissionsRequirement |
| 13 | +{ |
| 14 | + public function testRequiresPermission() |
| 15 | + { |
| 16 | + $supplier = Supplier::factory()->create(); |
| 17 | + |
| 18 | + $this->actingAsForApi(User::factory()->create()) |
| 19 | + ->deleteJson(route('api.suppliers.destroy', $supplier)) |
| 20 | + ->assertForbidden(); |
| 21 | + } |
| 22 | + |
| 23 | + public function testCannotDeleteSupplierWithDataStillAssociated() |
| 24 | + { |
| 25 | + $supplierWithAsset = Supplier::factory()->hasAssets()->create(); |
| 26 | + $supplierWithAssetMaintenance = Supplier::factory()->has(AssetMaintenance::factory(), 'asset_maintenances')->create(); |
| 27 | + $supplierWithLicense = Supplier::factory()->hasLicenses()->create(); |
| 28 | + |
| 29 | + $actor = $this->actingAsForApi(User::factory()->deleteSuppliers()->create()); |
| 30 | + |
| 31 | + $actor->deleteJson(route('api.suppliers.destroy', $supplierWithAsset))->assertStatusMessageIs('error'); |
| 32 | + $actor->deleteJson(route('api.suppliers.destroy', $supplierWithAssetMaintenance))->assertStatusMessageIs('error'); |
| 33 | + $actor->deleteJson(route('api.suppliers.destroy', $supplierWithLicense))->assertStatusMessageIs('error'); |
| 34 | + |
| 35 | + $this->assertNotSoftDeleted($supplierWithAsset); |
| 36 | + $this->assertNotSoftDeleted($supplierWithAssetMaintenance); |
| 37 | + $this->assertNotSoftDeleted($supplierWithLicense); |
| 38 | + } |
| 39 | + |
| 40 | + public function testCanDeleteSupplier() |
| 41 | + { |
| 42 | + $supplier = Supplier::factory()->create(); |
| 43 | + |
| 44 | + $this->actingAsForApi(User::factory()->deleteSuppliers()->create()) |
| 45 | + ->deleteJson(route('api.suppliers.destroy', $supplier)) |
| 46 | + ->assertOk() |
| 47 | + ->assertStatusMessageIs('success'); |
| 48 | + |
| 49 | + $this->assertSoftDeleted($supplier); |
| 50 | + } |
| 51 | +} |
0 commit comments