count(2)->create(); $consumableA = Consumable::factory()->for($companyA)->create(); $consumableB = Consumable::factory()->for($companyB)->create(); $superUser = $companyA->users()->save(User::factory()->superuser()->make()); $userInCompanyA = $companyA->users()->save(User::factory()->viewConsumables()->make()); $userInCompanyB = $companyB->users()->save(User::factory()->viewConsumables()->make()); $this->settings->disableMultipleFullCompanySupport(); Passport::actingAs($superUser); $this->getJson(route('api.consumables.index')) ->assertResponseContainsInRows($consumableA) ->assertResponseContainsInRows($consumableB); Passport::actingAs($userInCompanyA); $this->getJson(route('api.consumables.index')) ->assertResponseContainsInRows($consumableA) ->assertResponseContainsInRows($consumableB); Passport::actingAs($userInCompanyB); $this->getJson(route('api.consumables.index')) ->assertResponseContainsInRows($consumableA) ->assertResponseContainsInRows($consumableB); $this->settings->enableMultipleFullCompanySupport(); Passport::actingAs($superUser); $this->getJson(route('api.consumables.index')) ->assertResponseContainsInRows($consumableA) ->assertResponseContainsInRows($consumableB); Passport::actingAs($userInCompanyA); $this->getJson(route('api.consumables.index')) ->assertResponseContainsInRows($consumableA) ->assertResponseDoesNotContainInRows($consumableB); Passport::actingAs($userInCompanyB); $this->getJson(route('api.consumables.index')) ->assertResponseDoesNotContainInRows($consumableA) ->assertResponseContainsInRows($consumableB); } }