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 Laravel\Passport\Passport;
|
2023-06-07 16:16:30 -07:00
|
|
|
use Tests\Support\InteractsWithResponses;
|
2023-06-07 14:22:22 -07:00
|
|
|
use Tests\Support\InteractsWithSettings;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class ConsumablesIndexTest extends TestCase
|
|
|
|
{
|
2023-06-07 16:16:30 -07:00
|
|
|
use InteractsWithResponses;
|
2023-06-07 14:22:22 -07:00
|
|
|
use InteractsWithSettings;
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
Passport::actingAs($superUser);
|
|
|
|
$response = $this->getJson(route('api.consumables.index'));
|
2023-06-07 16:16:30 -07:00
|
|
|
$this->assertResponseContainsInRows($response, $consumableA);
|
|
|
|
$this->assertResponseContainsInRows($response, $consumableB);
|
2023-06-07 14:22:22 -07:00
|
|
|
|
|
|
|
Passport::actingAs($userInCompanyA);
|
|
|
|
$response = $this->getJson(route('api.consumables.index'));
|
2023-06-07 16:16:30 -07:00
|
|
|
$this->assertResponseContainsInRows($response, $consumableA);
|
|
|
|
$this->assertResponseContainsInRows($response, $consumableB);
|
2023-06-07 14:22:22 -07:00
|
|
|
|
|
|
|
Passport::actingAs($userInCompanyB);
|
|
|
|
$response = $this->getJson(route('api.consumables.index'));
|
2023-06-07 16:16:30 -07:00
|
|
|
$this->assertResponseContainsInRows($response, $consumableA);
|
|
|
|
$this->assertResponseContainsInRows($response, $consumableB);
|
2023-06-07 14:22:22 -07:00
|
|
|
|
|
|
|
$this->settings->enableMultipleFullCompanySupport();
|
|
|
|
|
|
|
|
Passport::actingAs($superUser);
|
|
|
|
$response = $this->getJson(route('api.consumables.index'));
|
2023-06-07 16:16:30 -07:00
|
|
|
$this->assertResponseContainsInRows($response, $consumableA);
|
|
|
|
$this->assertResponseContainsInRows($response, $consumableB);
|
2023-06-07 14:22:22 -07:00
|
|
|
|
|
|
|
Passport::actingAs($userInCompanyA);
|
|
|
|
$response = $this->getJson(route('api.consumables.index'));
|
2023-06-07 16:16:30 -07:00
|
|
|
$this->assertResponseContainsInRows($response, $consumableA);
|
|
|
|
$this->assertResponseDoesNotContainInRows($response, $consumableB);
|
2023-06-07 14:22:22 -07:00
|
|
|
|
|
|
|
Passport::actingAs($userInCompanyB);
|
|
|
|
$response = $this->getJson(route('api.consumables.index'));
|
2023-06-07 16:16:30 -07:00
|
|
|
$this->assertResponseDoesNotContainInRows($response, $consumableA);
|
|
|
|
$this->assertResponseContainsInRows($response, $consumableB);
|
2023-06-07 14:22:22 -07:00
|
|
|
}
|
|
|
|
}
|