-
-
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 predefined kit endpoint
- Loading branch information
1 parent
53c673d
commit c269184
Showing
4 changed files
with
87 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
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,23 @@ | ||
<?php | ||
|
||
namespace Database\Factories; | ||
|
||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
/** | ||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\PredefinedKit> | ||
*/ | ||
class PredefinedKitFactory extends Factory | ||
{ | ||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function definition(): array | ||
{ | ||
return [ | ||
'name' => $this->faker->words(3, true), | ||
]; | ||
} | ||
} |
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
57 changes: 57 additions & 0 deletions
57
tests/Feature/PredefinedKits/Api/DeletePredefinedKitTest.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,57 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\PredefinedKits\Api; | ||
|
||
use App\Models\PredefinedKit; | ||
use App\Models\User; | ||
use Illuminate\Support\Facades\DB; | ||
use Tests\Concerns\TestsPermissionsRequirement; | ||
use Tests\TestCase; | ||
|
||
class DeletePredefinedKitTest extends TestCase implements TestsPermissionsRequirement | ||
{ | ||
public function testRequiresPermission() | ||
{ | ||
$predefinedKit = PredefinedKit::factory()->create(); | ||
|
||
$this->actingAsForApi(User::factory()->create()) | ||
->deleteJson(route('api.kits.destroy', $predefinedKit)) | ||
->assertForbidden(); | ||
} | ||
|
||
public function testCanDeletePredefinedKits() | ||
{ | ||
$predefinedKit = PredefinedKit::factory()->create(); | ||
|
||
$this->actingAsForApi(User::factory()->deletePredefinedKits()->create()) | ||
->deleteJson(route('api.kits.destroy', $predefinedKit)) | ||
->assertOk() | ||
->assertStatusMessageIs('success'); | ||
|
||
$this->assertDatabaseMissing('kits', ['id' => $predefinedKit->id]); | ||
} | ||
|
||
public function testAssociatedDataDetachedWhenPredefinedKitDeleted() | ||
{ | ||
$predefinedKit = PredefinedKit::factory() | ||
->hasAccessories() | ||
->hasConsumables() | ||
->hasLicenses() | ||
->hasModels() | ||
->create(); | ||
|
||
$this->assertGreaterThan(0, $predefinedKit->accessories->count(), 'Precondition failed: PredefinedKit has no accessories'); | ||
$this->assertGreaterThan(0, $predefinedKit->consumables->count(), 'Precondition failed: PredefinedKit has no consumables'); | ||
$this->assertGreaterThan(0, $predefinedKit->licenses->count(), 'Precondition failed: PredefinedKit has no licenses'); | ||
$this->assertGreaterThan(0, $predefinedKit->models->count(), 'Precondition failed: PredefinedKit has no models'); | ||
|
||
$this->actingAsForApi(User::factory()->deletePredefinedKits()->create()) | ||
->deleteJson(route('api.kits.destroy', $predefinedKit)) | ||
->assertStatusMessageIs('success'); | ||
|
||
$this->assertEquals(0, DB::table('kits_accessories')->where('kit_id', $predefinedKit->id)->count()); | ||
$this->assertEquals(0, DB::table('kits_consumables')->where('kit_id', $predefinedKit->id)->count()); | ||
$this->assertEquals(0, DB::table('kits_licenses')->where('kit_id', $predefinedKit->id)->count()); | ||
$this->assertEquals(0, DB::table('kits_models')->where('kit_id', $predefinedKit->id)->count()); | ||
} | ||
} |