mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 05:04:07 -08:00
Add tests for delete companies endpoint
This commit is contained in:
parent
8ce2512f55
commit
910f13c1f7
|
@ -246,11 +246,6 @@ class UserFactory extends Factory
|
|||
return $this->appendPermission(['components.view' => '1']);
|
||||
}
|
||||
|
||||
public function createCompanies()
|
||||
{
|
||||
return $this->appendPermission(['companies.create' => '1']);
|
||||
}
|
||||
|
||||
public function createComponents()
|
||||
{
|
||||
return $this->appendPermission(['components.create' => '1']);
|
||||
|
@ -276,6 +271,16 @@ class UserFactory extends Factory
|
|||
return $this->appendPermission(['components.checkout' => '1']);
|
||||
}
|
||||
|
||||
public function createCompanies()
|
||||
{
|
||||
return $this->appendPermission(['companies.create' => '1']);
|
||||
}
|
||||
|
||||
public function deleteCompanies()
|
||||
{
|
||||
return $this->appendPermission(['companies.delete' => '1']);
|
||||
}
|
||||
|
||||
public function viewUsers()
|
||||
{
|
||||
return $this->appendPermission(['users.view' => '1']);
|
||||
|
|
49
tests/Feature/Companies/Api/DeleteCompaniesTest.php
Normal file
49
tests/Feature/Companies/Api/DeleteCompaniesTest.php
Normal file
|
@ -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');
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue