diff --git a/tests/Feature/Api/Users/UsersIndexTest.php b/tests/Feature/Api/Users/UsersIndexTest.php new file mode 100644 index 0000000000..16893cd174 --- /dev/null +++ b/tests/Feature/Api/Users/UsersIndexTest.php @@ -0,0 +1,64 @@ +markTestIncomplete(); + + [$companyA, $companyB] = Company::factory()->count(2)->create(); + + $userA = User::factory()->for($companyA)->create(); + $userB = User::factory()->for($companyB)->create(); + + $superUser = $companyA->users()->save(User::factory()->superuser()->make()); + $userInCompanyA = $companyA->users()->save(User::factory()->viewUsers()->make()); + $userInCompanyB = $companyB->users()->save(User::factory()->viewUsers()->make()); + + $this->settings->disableMultipleFullCompanySupport(); + + Passport::actingAs($superUser); + $response = $this->getJson(route('api.users.index')); + $this->assertResponseContainsInRows($response, $userA, 'first_name'); + $this->assertResponseContainsInRows($response, $userB, 'first_name'); + + Passport::actingAs($userInCompanyA); + $response = $this->getJson(route('api.users.index')); + $this->assertResponseContainsInRows($response, $userA, 'first_name'); + $this->assertResponseContainsInRows($response, $userB, 'first_name'); + + Passport::actingAs($userInCompanyB); + $response = $this->getJson(route('api.users.index')); + $this->assertResponseContainsInRows($response, $userA, 'first_name'); + $this->assertResponseContainsInRows($response, $userB, 'first_name'); + + $this->settings->enableMultipleFullCompanySupport(); + + Passport::actingAs($superUser); + $response = $this->getJson(route('api.users.index')); + $this->assertResponseContainsInRows($response, $userA, 'first_name'); + $this->assertResponseContainsInRows($response, $userB, 'first_name'); + + Passport::actingAs($userInCompanyA); + $response = $this->getJson(route('api.users.index')); + $this->assertResponseContainsInRows($response, $userA, 'first_name'); + $this->assertResponseDoesNotContainInRows($response, $userB, 'first_name'); + + Passport::actingAs($userInCompanyB); + $response = $this->getJson(route('api.users.index')); + $this->assertResponseDoesNotContainInRows($response, $userA, 'first_name'); + $this->assertResponseContainsInRows($response, $userB, 'first_name'); + } +}