count(2)->create(); $licenseA = License::factory()->for($companyA)->create(); $licenseB = License::factory()->for($companyB)->create(); $superUser = $companyA->users()->save(User::factory()->superuser()->make()); $userInCompanyA = $companyA->users()->save(User::factory()->viewLicenses()->make()); $userInCompanyB = $companyB->users()->save(User::factory()->viewLicenses()->make()); $this->settings->disableMultipleFullCompanySupport(); Passport::actingAs($superUser); $this->getJson(route('api.licenses.index')) ->assertResponseContainsInRows($licenseA) ->assertResponseContainsInRows($licenseB); Passport::actingAs($userInCompanyA); $this->getJson(route('api.licenses.index')) ->assertResponseContainsInRows($licenseA) ->assertResponseContainsInRows($licenseB); Passport::actingAs($userInCompanyB); $this->getJson(route('api.licenses.index')) ->assertResponseContainsInRows($licenseA) ->assertResponseContainsInRows($licenseB); $this->settings->enableMultipleFullCompanySupport(); Passport::actingAs($superUser); $this->getJson(route('api.licenses.index')) ->assertResponseContainsInRows($licenseA) ->assertResponseContainsInRows($licenseB); Passport::actingAs($userInCompanyA); $this->getJson(route('api.licenses.index')) ->assertResponseContainsInRows($licenseA) ->assertResponseDoesNotContainInRows($licenseB); Passport::actingAs($userInCompanyB); $this->getJson(route('api.licenses.index')) ->assertResponseDoesNotContainInRows($licenseA) ->assertResponseContainsInRows($licenseB); } }