-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15512 from marcusmoore/testing/fmcs
Added tests for delete methods in api
- Loading branch information
Showing
28 changed files
with
1,239 additions
and
55 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
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
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,8 @@ | ||
<?php | ||
|
||
namespace Tests\Concerns; | ||
|
||
interface TestsFullMultipleCompaniesSupport | ||
{ | ||
public function testAdheresToFullMultipleCompaniesSupportScoping(); | ||
} |
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,8 @@ | ||
<?php | ||
|
||
namespace Tests\Concerns; | ||
|
||
interface TestsPermissionsRequirement | ||
{ | ||
public function testRequiresPermission(); | ||
} |
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,77 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\Accessories\Api; | ||
|
||
use App\Models\Accessory; | ||
use App\Models\Company; | ||
use App\Models\User; | ||
use Tests\Concerns\TestsFullMultipleCompaniesSupport; | ||
use Tests\Concerns\TestsPermissionsRequirement; | ||
use Tests\TestCase; | ||
|
||
class DeleteAccessoriesTest extends TestCase implements TestsFullMultipleCompaniesSupport, TestsPermissionsRequirement | ||
{ | ||
public function testRequiresPermission() | ||
{ | ||
$accessory = Accessory::factory()->create(); | ||
|
||
$this->actingAsForApi(User::factory()->create()) | ||
->deleteJson(route('api.accessories.destroy', $accessory)) | ||
->assertForbidden(); | ||
|
||
$this->assertNotSoftDeleted($accessory); | ||
} | ||
|
||
public function testAdheresToFullMultipleCompaniesSupportScoping() | ||
{ | ||
[$companyA, $companyB] = Company::factory()->count(2)->create(); | ||
|
||
$accessoryA = Accessory::factory()->for($companyA)->create(); | ||
$accessoryB = Accessory::factory()->for($companyB)->create(); | ||
$accessoryC = Accessory::factory()->for($companyB)->create(); | ||
|
||
$superUser = $companyA->users()->save(User::factory()->superuser()->make()); | ||
$userInCompanyA = $companyA->users()->save(User::factory()->deleteAccessories()->make()); | ||
$userInCompanyB = $companyB->users()->save(User::factory()->deleteAccessories()->make()); | ||
|
||
$this->settings->enableMultipleFullCompanySupport(); | ||
|
||
$this->actingAsForApi($userInCompanyA) | ||
->deleteJson(route('api.accessories.destroy', $accessoryB)) | ||
->assertStatusMessageIs('error'); | ||
|
||
$this->actingAsForApi($userInCompanyB) | ||
->deleteJson(route('api.accessories.destroy', $accessoryA)) | ||
->assertStatusMessageIs('error'); | ||
|
||
$this->actingAsForApi($superUser) | ||
->deleteJson(route('api.accessories.destroy', $accessoryC)) | ||
->assertStatusMessageIs('success'); | ||
|
||
$this->assertNotSoftDeleted($accessoryA); | ||
$this->assertNotSoftDeleted($accessoryB); | ||
$this->assertSoftDeleted($accessoryC); | ||
} | ||
|
||
public function testCannotDeleteAccessoryThatHasCheckouts() | ||
{ | ||
$accessory = Accessory::factory()->checkedOutToUser()->create(); | ||
|
||
$this->actingAsForApi(User::factory()->deleteAccessories()->create()) | ||
->deleteJson(route('api.accessories.destroy', $accessory)) | ||
->assertStatusMessageIs('error'); | ||
|
||
$this->assertNotSoftDeleted($accessory); | ||
} | ||
|
||
public function testCanDeleteAccessory() | ||
{ | ||
$accessory = Accessory::factory()->create(); | ||
|
||
$this->actingAsForApi(User::factory()->deleteAccessories()->create()) | ||
->deleteJson(route('api.accessories.destroy', $accessory)) | ||
->assertStatusMessageIs('success'); | ||
|
||
$this->assertSoftDeleted($accessory); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
tests/Feature/AssetMaintenances/Api/DeleteAssetMaintenancesTest.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,70 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\AssetMaintenances\Api; | ||
|
||
use App\Models\AssetMaintenance; | ||
use App\Models\Company; | ||
use App\Models\User; | ||
use Tests\Concerns\TestsFullMultipleCompaniesSupport; | ||
use Tests\Concerns\TestsPermissionsRequirement; | ||
use Tests\TestCase; | ||
|
||
class DeleteAssetMaintenancesTest extends TestCase implements TestsFullMultipleCompaniesSupport, TestsPermissionsRequirement | ||
{ | ||
public function testRequiresPermission() | ||
{ | ||
$assetMaintenance = AssetMaintenance::factory()->create(); | ||
|
||
$this->actingAsForApi(User::factory()->create()) | ||
->deleteJson(route('api.maintenances.destroy', $assetMaintenance)) | ||
->assertForbidden(); | ||
|
||
$this->assertNotSoftDeleted($assetMaintenance); | ||
} | ||
|
||
public function testAdheresToFullMultipleCompaniesSupportScoping() | ||
{ | ||
[$companyA, $companyB] = Company::factory()->count(2)->create(); | ||
|
||
$assetMaintenanceA = AssetMaintenance::factory()->create(); | ||
$assetMaintenanceB = AssetMaintenance::factory()->create(); | ||
$assetMaintenanceC = AssetMaintenance::factory()->create(); | ||
|
||
$assetMaintenanceA->asset->update(['company_id' => $companyA->id]); | ||
$assetMaintenanceB->asset->update(['company_id' => $companyB->id]); | ||
$assetMaintenanceC->asset->update(['company_id' => $companyB->id]); | ||
|
||
$superUser = $companyA->users()->save(User::factory()->superuser()->make()); | ||
$userInCompanyA = $companyA->users()->save(User::factory()->editAssets()->make()); | ||
$userInCompanyB = $companyB->users()->save(User::factory()->editAssets()->make()); | ||
|
||
$this->settings->enableMultipleFullCompanySupport(); | ||
|
||
$this->actingAsForApi($userInCompanyA) | ||
->deleteJson(route('api.maintenances.destroy', $assetMaintenanceB)) | ||
->assertStatusMessageIs('error'); | ||
|
||
$this->actingAsForApi($userInCompanyB) | ||
->deleteJson(route('api.maintenances.destroy', $assetMaintenanceA)) | ||
->assertStatusMessageIs('error'); | ||
|
||
$this->actingAsForApi($superUser) | ||
->deleteJson(route('api.maintenances.destroy', $assetMaintenanceC)) | ||
->assertStatusMessageIs('success'); | ||
|
||
$this->assertNotSoftDeleted($assetMaintenanceA); | ||
$this->assertNotSoftDeleted($assetMaintenanceB); | ||
$this->assertSoftDeleted($assetMaintenanceC); | ||
} | ||
|
||
public function testCanDeleteAssetMaintenance() | ||
{ | ||
$assetMaintenance = AssetMaintenance::factory()->create(); | ||
|
||
$this->actingAsForApi(User::factory()->editAssets()->create()) | ||
->deleteJson(route('api.maintenances.destroy', $assetMaintenance)) | ||
->assertStatusMessageIs('success'); | ||
|
||
$this->assertSoftDeleted($assetMaintenance); | ||
} | ||
} |
Oops, something went wrong.