mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Add tests for delete departments endpoint
This commit is contained in:
parent
3105f53aff
commit
38b9f4a438
|
@ -206,6 +206,11 @@ class UserFactory extends Factory
|
||||||
return $this->appendPermission(['consumables.checkout' => '1']);
|
return $this->appendPermission(['consumables.checkout' => '1']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function deleteDepartments()
|
||||||
|
{
|
||||||
|
return $this->appendPermission(['departments.delete' => '1']);
|
||||||
|
}
|
||||||
|
|
||||||
public function viewDepartments()
|
public function viewDepartments()
|
||||||
{
|
{
|
||||||
return $this->appendPermission(['departments.view' => '1']);
|
return $this->appendPermission(['departments.view' => '1']);
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace Tests\Feature\Companies\Api;
|
namespace Tests\Feature\Companies\Api;
|
||||||
|
|
||||||
use App\Models\Asset;
|
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Tests\Concerns\TestsPermissionsRequirement;
|
use Tests\Concerns\TestsPermissionsRequirement;
|
||||||
|
|
65
tests/Feature/Departments/Api/DeleteDepartmentTest.php
Normal file
65
tests/Feature/Departments/Api/DeleteDepartmentTest.php
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Departments\Api;
|
||||||
|
|
||||||
|
use App\Models\Company;
|
||||||
|
use App\Models\Department;
|
||||||
|
use App\Models\User;
|
||||||
|
use Tests\Concerns\TestsMultipleFullCompanySupport;
|
||||||
|
use Tests\Concerns\TestsPermissionsRequirement;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class DeleteDepartmentTest extends TestCase implements TestsMultipleFullCompanySupport, TestsPermissionsRequirement
|
||||||
|
{
|
||||||
|
|
||||||
|
public function testRequiresPermission()
|
||||||
|
{
|
||||||
|
$department = Department::factory()->create();
|
||||||
|
|
||||||
|
$this->actingAsForApi(User::factory()->create())
|
||||||
|
->deleteJson(route('api.departments.destroy', $department))
|
||||||
|
->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCanDeleteDepartment()
|
||||||
|
{
|
||||||
|
$department = Department::factory()->create();
|
||||||
|
|
||||||
|
$this->actingAsForApi(User::factory()->deleteDepartments()->create())
|
||||||
|
->deleteJson(route('api.departments.destroy', $department))
|
||||||
|
->assertStatusMessageIs('success');
|
||||||
|
|
||||||
|
$this->assertDatabaseMissing('departments', ['id' => $department->id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAdheresToMultipleFullCompanySupportScoping()
|
||||||
|
{
|
||||||
|
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
||||||
|
|
||||||
|
$departmentA = Department::factory()->for($companyA)->create();
|
||||||
|
$departmentB = Department::factory()->for($companyB)->create();
|
||||||
|
$departmentC = Department::factory()->for($companyB)->create();
|
||||||
|
|
||||||
|
$superUser = $companyA->users()->save(User::factory()->superuser()->make());
|
||||||
|
$userInCompanyA = $companyA->users()->save(User::factory()->deleteDepartments()->make());
|
||||||
|
$userInCompanyB = $companyB->users()->save(User::factory()->deleteDepartments()->make());
|
||||||
|
|
||||||
|
$this->settings->enableMultipleFullCompanySupport();
|
||||||
|
|
||||||
|
$this->actingAsForApi($userInCompanyA)
|
||||||
|
->deleteJson(route('api.departments.destroy', $departmentB))
|
||||||
|
->assertStatusMessageIs('error');
|
||||||
|
|
||||||
|
$this->actingAsForApi($userInCompanyB)
|
||||||
|
->deleteJson(route('api.departments.destroy', $departmentA))
|
||||||
|
->assertStatusMessageIs('error');
|
||||||
|
|
||||||
|
$this->actingAsForApi($superUser)
|
||||||
|
->deleteJson(route('api.departments.destroy', $departmentC))
|
||||||
|
->assertStatusMessageIs('success');
|
||||||
|
|
||||||
|
$this->assertNotNull($departmentA->fresh(), 'Department unexpectedly deleted');
|
||||||
|
$this->assertNotNull($departmentB->fresh(), 'Department unexpectedly deleted');
|
||||||
|
$this->assertNull($departmentC->fresh(), 'Department was not deleted');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue