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;
|
2023-06-07 16:16:30 -07:00
|
|
|
use Tests\Support\InteractsWithResponses;
|
2023-06-07 16:10:29 -07:00
|
|
|
use Tests\Support\InteractsWithSettings;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class DepartmentsIndexTest extends TestCase
|
|
|
|
{
|
2023-06-07 16:16:30 -07:00
|
|
|
use InteractsWithResponses;
|
2023-06-07 16:10:29 -07:00
|
|
|
use InteractsWithSettings;
|
|
|
|
|
|
|
|
public function testDepartmentsIndexAdheresToCompanyScoping()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
|
|
|
|
[$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);
|
|
|
|
$response = $this->getJson(route('api.departments.index'));
|
2023-06-07 16:16:30 -07:00
|
|
|
$this->assertResponseContainsInRows($response, $departmentA);
|
|
|
|
$this->assertResponseContainsInRows($response, $departmentB);
|
2023-06-07 16:10:29 -07:00
|
|
|
|
|
|
|
Passport::actingAs($userInCompanyA);
|
|
|
|
$response = $this->getJson(route('api.departments.index'));
|
2023-06-07 16:16:30 -07:00
|
|
|
$this->assertResponseContainsInRows($response, $departmentA);
|
|
|
|
$this->assertResponseContainsInRows($response, $departmentB);
|
2023-06-07 16:10:29 -07:00
|
|
|
|
|
|
|
Passport::actingAs($userInCompanyB);
|
|
|
|
$response = $this->getJson(route('api.departments.index'));
|
2023-06-07 16:16:30 -07:00
|
|
|
$this->assertResponseContainsInRows($response, $departmentA);
|
|
|
|
$this->assertResponseContainsInRows($response, $departmentB);
|
2023-06-07 16:10:29 -07:00
|
|
|
|
|
|
|
$this->settings->enableMultipleFullCompanySupport();
|
|
|
|
|
|
|
|
Passport::actingAs($superUser);
|
|
|
|
$response = $this->getJson(route('api.departments.index'));
|
2023-06-07 16:16:30 -07:00
|
|
|
$this->assertResponseContainsInRows($response, $departmentA);
|
|
|
|
$this->assertResponseContainsInRows($response, $departmentB);
|
2023-06-07 16:10:29 -07:00
|
|
|
|
|
|
|
Passport::actingAs($userInCompanyA);
|
|
|
|
$response = $this->getJson(route('api.departments.index'));
|
2023-06-07 16:16:30 -07:00
|
|
|
$this->assertResponseContainsInRows($response, $departmentA);
|
|
|
|
$this->assertResponseDoesNotContainInRows($response, $departmentB);
|
2023-06-07 16:10:29 -07:00
|
|
|
|
|
|
|
Passport::actingAs($userInCompanyB);
|
|
|
|
$response = $this->getJson(route('api.departments.index'));
|
2023-06-07 16:16:30 -07:00
|
|
|
$this->assertResponseDoesNotContainInRows($response, $departmentA);
|
|
|
|
$this->assertResponseContainsInRows($response, $departmentB);
|
2023-06-07 16:10:29 -07:00
|
|
|
}
|
|
|
|
}
|