2023-06-07 14:22:22 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Api\Consumables;
|
|
|
|
|
|
|
|
use App\Models\Company;
|
|
|
|
use App\Models\Consumable;
|
|
|
|
use App\Models\User;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
2024-06-03 16:54:59 -07:00
|
|
|
class ConsumableIndexTest extends TestCase
|
2023-06-07 14:22:22 -07:00
|
|
|
{
|
|
|
|
public function testConsumableIndexAdheresToCompanyScoping()
|
|
|
|
{
|
|
|
|
[$companyA, $companyB] = Company::factory()->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();
|
|
|
|
|
2023-06-22 17:37:30 -07:00
|
|
|
$this->actingAsForApi($superUser)
|
|
|
|
->getJson(route('api.consumables.index'))
|
2023-06-22 14:41:56 -07:00
|
|
|
->assertResponseContainsInRows($consumableA)
|
|
|
|
->assertResponseContainsInRows($consumableB);
|
2023-06-07 14:22:22 -07:00
|
|
|
|
2023-06-22 17:37:30 -07:00
|
|
|
$this->actingAsForApi($userInCompanyA)
|
|
|
|
->getJson(route('api.consumables.index'))
|
2023-06-22 14:41:56 -07:00
|
|
|
->assertResponseContainsInRows($consumableA)
|
|
|
|
->assertResponseContainsInRows($consumableB);
|
2023-06-07 14:22:22 -07:00
|
|
|
|
2023-06-22 17:37:30 -07:00
|
|
|
$this->actingAsForApi($userInCompanyB)
|
|
|
|
->getJson(route('api.consumables.index'))
|
2023-06-22 14:41:56 -07:00
|
|
|
->assertResponseContainsInRows($consumableA)
|
|
|
|
->assertResponseContainsInRows($consumableB);
|
2023-06-07 14:22:22 -07:00
|
|
|
|
|
|
|
$this->settings->enableMultipleFullCompanySupport();
|
|
|
|
|
2023-06-22 17:37:30 -07:00
|
|
|
$this->actingAsForApi($superUser)
|
|
|
|
->getJson(route('api.consumables.index'))
|
2023-06-22 14:41:56 -07:00
|
|
|
->assertResponseContainsInRows($consumableA)
|
|
|
|
->assertResponseContainsInRows($consumableB);
|
2023-06-07 14:22:22 -07:00
|
|
|
|
2023-06-22 17:37:30 -07:00
|
|
|
$this->actingAsForApi($userInCompanyA)
|
|
|
|
->getJson(route('api.consumables.index'))
|
2023-06-22 14:41:56 -07:00
|
|
|
->assertResponseContainsInRows($consumableA)
|
|
|
|
->assertResponseDoesNotContainInRows($consumableB);
|
2023-06-07 14:22:22 -07:00
|
|
|
|
2023-06-22 17:37:30 -07:00
|
|
|
$this->actingAsForApi($userInCompanyB)
|
|
|
|
->getJson(route('api.consumables.index'))
|
2023-06-22 14:41:56 -07:00
|
|
|
->assertResponseDoesNotContainInRows($consumableA)
|
|
|
|
->assertResponseContainsInRows($consumableB);
|
2023-06-07 14:22:22 -07:00
|
|
|
}
|
|
|
|
}
|