-
-
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 companies endpoint
- Loading branch information
1 parent
8ce2512
commit 910f13c
Showing
2 changed files
with
59 additions
and
5 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,49 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\Companies\Api; | ||
|
||
use App\Models\Asset; | ||
use App\Models\Company; | ||
use App\Models\User; | ||
use Tests\Concerns\TestsPermissionsRequirement; | ||
use Tests\TestCase; | ||
|
||
class DeleteCompaniesTest extends TestCase implements TestsPermissionsRequirement | ||
{ | ||
public function testRequiresPermission() | ||
{ | ||
$company = Company::factory()->create(); | ||
|
||
$this->actingAsForApi(User::factory()->create()) | ||
->deleteJson(route('api.companies.destroy', $company)) | ||
->assertForbidden(); | ||
} | ||
|
||
public function testCanDeleteCompany() | ||
{ | ||
$company = Company::factory()->create(); | ||
|
||
$this->actingAsForApi(User::factory()->deleteCompanies()->create()) | ||
->deleteJson(route('api.companies.destroy', $company)) | ||
->assertStatusMessageIs('success'); | ||
|
||
$this->assertDatabaseMissing('companies', ['id' => $company->id]); | ||
} | ||
|
||
public function testCannotDeleteCompanyThatHasAssociatedItems() | ||
{ | ||
$companyWithAssets = Company::factory()->hasAssets()->create(); | ||
$companyWithAccessories = Company::factory()->hasAccessories()->create(); | ||
$companyWithConsumables = Company::factory()->hasConsumables()->create(); | ||
$companyWithComponents = Company::factory()->hasComponents()->create(); | ||
$companyWithUsers = Company::factory()->hasUsers()->create(); | ||
|
||
$actor = $this->actingAsForApi(User::factory()->deleteCompanies()->create()); | ||
|
||
$actor->deleteJson(route('api.companies.destroy', $companyWithAssets))->assertStatusMessageIs('error'); | ||
$actor->deleteJson(route('api.companies.destroy', $companyWithAccessories))->assertStatusMessageIs('error'); | ||
$actor->deleteJson(route('api.companies.destroy', $companyWithConsumables))->assertStatusMessageIs('error'); | ||
$actor->deleteJson(route('api.companies.destroy', $companyWithComponents))->assertStatusMessageIs('error'); | ||
$actor->deleteJson(route('api.companies.destroy', $companyWithUsers))->assertStatusMessageIs('error'); | ||
} | ||
} |