-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for delete manufacturer endpoint
- Loading branch information
1 parent
50730fc
commit 53c673d
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
tests/Feature/Manufacturers/Api/DeleteManufacturerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\Manufacturers\Api; | ||
|
||
use App\Models\Asset; | ||
use App\Models\AssetModel; | ||
use App\Models\Manufacturer; | ||
use App\Models\User; | ||
use Tests\Concerns\TestsPermissionsRequirement; | ||
use Tests\TestCase; | ||
|
||
class DeleteManufacturerTest extends TestCase implements TestsPermissionsRequirement | ||
{ | ||
public function testRequiresPermission() | ||
{ | ||
$manufacturer = Manufacturer::factory()->create(); | ||
|
||
$this->actingAsForApi(User::factory()->create()) | ||
->deleteJson(route('api.manufacturers.destroy', $manufacturer)) | ||
->assertForbidden(); | ||
|
||
$this->assertNotSoftDeleted($manufacturer); | ||
} | ||
|
||
public function testCannotDeleteManufacturerWithAssociatedData() | ||
{ | ||
$manufacturerWithAccessories = Manufacturer::factory()->hasAccessories()->create(); | ||
$manufacturerWithConsumables = Manufacturer::factory()->hasConsumables()->create(); | ||
$manufacturerWithLicenses = Manufacturer::factory()->hasLicenses()->create(); | ||
|
||
$manufacturerWithAssets = Manufacturer::factory()->hasAssets()->create(); | ||
$model = AssetModel::factory()->create(['manufacturer_id' => $manufacturerWithAssets->id]); | ||
Asset::factory()->create(['model_id' => $model->id]); | ||
|
||
$this->assertGreaterThan(0, $manufacturerWithAccessories->accessories->count(), 'Precondition failed: Manufacturer has no accessories'); | ||
$this->assertGreaterThan(0, $manufacturerWithAssets->assets->count(), 'Precondition failed: Manufacturer has no assets'); | ||
$this->assertGreaterThan(0, $manufacturerWithConsumables->consumables->count(), 'Precondition failed: Manufacturer has no consumables'); | ||
$this->assertGreaterThan(0, $manufacturerWithLicenses->licenses->count(), 'Precondition failed: Manufacturer has no licenses'); | ||
|
||
$actor = $this->actingAsForApi(User::factory()->deleteManufacturers()->create()); | ||
|
||
$actor->deleteJson(route('api.manufacturers.destroy', $manufacturerWithAccessories))->assertStatusMessageIs('error'); | ||
$actor->deleteJson(route('api.manufacturers.destroy', $manufacturerWithAssets))->assertStatusMessageIs('error'); | ||
$actor->deleteJson(route('api.manufacturers.destroy', $manufacturerWithConsumables))->assertStatusMessageIs('error'); | ||
$actor->deleteJson(route('api.manufacturers.destroy', $manufacturerWithLicenses))->assertStatusMessageIs('error'); | ||
|
||
$this->assertNotSoftDeleted($manufacturerWithAssets); | ||
$this->assertNotSoftDeleted($manufacturerWithAccessories); | ||
$this->assertNotSoftDeleted($manufacturerWithConsumables); | ||
$this->assertNotSoftDeleted($manufacturerWithLicenses); | ||
} | ||
|
||
public function testCanDeleteManufacturer() | ||
{ | ||
$manufacturer = Manufacturer::factory()->create(); | ||
|
||
$this->actingAsForApi(User::factory()->deleteManufacturers()->create()) | ||
->deleteJson(route('api.manufacturers.destroy', $manufacturer)) | ||
->assertOk() | ||
->assertStatusMessageIs('success'); | ||
|
||
$this->assertSoftDeleted($manufacturer); | ||
} | ||
} |