implement FMCS test for accessory index

This commit is contained in:
Marcus Moore 2024-09-16 16:52:10 -07:00
parent e835637ef0
commit 8eb1c487bc
No known key found for this signature in database

View file

@ -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);
}
}