2023-06-07 16:10:29 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Api\Departments;
|
|
|
|
|
|
|
|
use App\Models\Company;
|
|
|
|
use App\Models\Department;
|
|
|
|
use App\Models\User;
|
|
|
|
use Laravel\Passport\Passport;
|
|
|
|
use Tests\Support\InteractsWithSettings;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class DepartmentsIndexTest extends TestCase
|
|
|
|
{
|
|
|
|
use InteractsWithSettings;
|
|
|
|
|
|
|
|
public function testDepartmentsIndexAdheresToCompanyScoping()
|
|
|
|
{
|
2023-06-22 12:48:09 -07:00
|
|
|
$this->markTestIncomplete(
|
|
|
|
'Waiting for removal of Company::scopeCompanyables in DepartmentsController@index'
|
|
|
|
);
|
2023-06-07 16:10:29 -07:00
|
|
|
|
|
|
|
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
|
|
|
|
|
|
|
$departmentA = Department::factory()->for($companyA)->create();
|
|
|
|
$departmentB = Department::factory()->for($companyB)->create();
|
|
|
|
|
|
|
|
$superUser = $companyA->users()->save(User::factory()->superuser()->make());
|
|
|
|
$userInCompanyA = $companyA->users()->save(User::factory()->viewDepartments()->make());
|
|
|
|
$userInCompanyB = $companyB->users()->save(User::factory()->viewDepartments()->make());
|
|
|
|
|
|
|
|
$this->settings->disableMultipleFullCompanySupport();
|
|
|
|
|
|
|
|
Passport::actingAs($superUser);
|
2023-06-22 14:41:56 -07:00
|
|
|
$this->getJson(route('api.departments.index'))
|
|
|
|
->assertResponseContainsInRows($departmentA)
|
|
|
|
->assertResponseContainsInRows($departmentB);
|
2023-06-07 16:10:29 -07:00
|
|
|
|
|
|
|
Passport::actingAs($userInCompanyA);
|
2023-06-22 14:41:56 -07:00
|
|
|
$this->getJson(route('api.departments.index'))
|
|
|
|
->assertResponseContainsInRows($departmentA)
|
|
|
|
->assertResponseContainsInRows($departmentB);
|
2023-06-07 16:10:29 -07:00
|
|
|
|
|
|
|
Passport::actingAs($userInCompanyB);
|
2023-06-22 14:41:56 -07:00
|
|
|
$this->getJson(route('api.departments.index'))
|
|
|
|
->assertResponseContainsInRows($departmentA)
|
|
|
|
->assertResponseContainsInRows($departmentB);
|
2023-06-07 16:10:29 -07:00
|
|
|
|
|
|
|
$this->settings->enableMultipleFullCompanySupport();
|
|
|
|
|
|
|
|
Passport::actingAs($superUser);
|
2023-06-22 14:41:56 -07:00
|
|
|
$this->getJson(route('api.departments.index'))
|
|
|
|
->assertResponseContainsInRows($departmentA)
|
|
|
|
->assertResponseContainsInRows($departmentB);
|
2023-06-07 16:10:29 -07:00
|
|
|
|
|
|
|
Passport::actingAs($userInCompanyA);
|
2023-06-22 14:41:56 -07:00
|
|
|
$this->getJson(route('api.departments.index'))
|
|
|
|
->assertResponseContainsInRows($departmentA)
|
|
|
|
->assertResponseDoesNotContainInRows($departmentB);
|
2023-06-07 16:10:29 -07:00
|
|
|
|
|
|
|
Passport::actingAs($userInCompanyB);
|
2023-06-22 14:41:56 -07:00
|
|
|
$this->getJson(route('api.departments.index'))
|
|
|
|
->assertResponseDoesNotContainInRows($departmentA)
|
|
|
|
->assertResponseContainsInRows($departmentB);
|
2023-06-07 16:10:29 -07:00
|
|
|
}
|
|
|
|
}
|