From 8eb1c487bcaa1fb6ec71d85985226d49c01e3cea Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 16 Sep 2024 16:52:10 -0700 Subject: [PATCH] implement FMCS test for accessory index --- .../Accessories/Api/IndexAccessoryTest.php | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/tests/Feature/Accessories/Api/IndexAccessoryTest.php b/tests/Feature/Accessories/Api/IndexAccessoryTest.php index aeadb808bd..4722bdd551 100644 --- a/tests/Feature/Accessories/Api/IndexAccessoryTest.php +++ b/tests/Feature/Accessories/Api/IndexAccessoryTest.php @@ -2,11 +2,14 @@ namespace Tests\Feature\Accessories\Api; +use App\Models\Accessory; +use App\Models\Company; use App\Models\User; +use Tests\Concerns\TestsMultipleFullCompanySupport; use Tests\Concerns\TestsPermissionsRequirement; use Tests\TestCase; -class IndexAccessoryTest extends TestCase implements TestsPermissionsRequirement +class IndexAccessoryTest extends TestCase implements TestsMultipleFullCompanySupport, TestsPermissionsRequirement { public function testRequiresPermission() { @@ -14,4 +17,40 @@ class IndexAccessoryTest extends TestCase implements TestsPermissionsRequirement ->getJson(route('api.accessories.index')) ->assertForbidden(); } + + public function testAdheresToMultipleFullCompanySupportScoping() + { + [$companyA, $companyB] = Company::factory()->count(2)->create(); + + $accessoryA = Accessory::factory()->for($companyA)->create(['name' => 'Accessory A']); + $accessoryB = Accessory::factory()->for($companyB)->create(['name' => 'Accessory B']); + $accessoryC = Accessory::factory()->for($companyB)->create(['name' => 'Accessory C']); + + $superUser = $companyA->users()->save(User::factory()->superuser()->make()); + $userInCompanyA = $companyA->users()->save(User::factory()->viewAccessories()->make()); + $userInCompanyB = $companyB->users()->save(User::factory()->viewAccessories()->make()); + + $this->settings->enableMultipleFullCompanySupport(); + + $this->actingAsForApi($userInCompanyA) + ->getJson(route('api.accessories.index')) + ->assertOk() + ->assertResponseContainsInRows($accessoryA) + ->assertResponseDoesNotContainInRows($accessoryB) + ->assertResponseDoesNotContainInRows($accessoryC); + + $this->actingAsForApi($userInCompanyB) + ->getJson(route('api.accessories.index')) + ->assertOk() + ->assertResponseDoesNotContainInRows($accessoryA) + ->assertResponseContainsInRows($accessoryB) + ->assertResponseContainsInRows($accessoryC); + + $this->actingAsForApi($superUser) + ->getJson(route('api.accessories.index')) + ->assertOk() + ->assertResponseContainsInRows($accessoryA) + ->assertResponseContainsInRows($accessoryB) + ->assertResponseContainsInRows($accessoryC); + } }