2024-09-09 14:35:38 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Accessories\Api;
|
|
|
|
|
2024-09-16 16:52:10 -07:00
|
|
|
use App\Models\Accessory;
|
|
|
|
use App\Models\Company;
|
2024-09-09 14:35:38 -07:00
|
|
|
use App\Models\User;
|
2024-09-16 17:00:08 -07:00
|
|
|
use Tests\Concerns\TestsFullMultipleCompaniesSupport;
|
2024-09-16 16:35:21 -07:00
|
|
|
use Tests\Concerns\TestsPermissionsRequirement;
|
2024-09-09 14:35:38 -07:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
2024-09-16 17:00:08 -07:00
|
|
|
class IndexAccessoryTest extends TestCase implements TestsFullMultipleCompaniesSupport, TestsPermissionsRequirement
|
2024-09-09 14:35:38 -07:00
|
|
|
{
|
2024-09-16 16:35:21 -07:00
|
|
|
public function testRequiresPermission()
|
2024-09-09 14:35:38 -07:00
|
|
|
{
|
|
|
|
$this->actingAsForApi(User::factory()->create())
|
|
|
|
->getJson(route('api.accessories.index'))
|
|
|
|
->assertForbidden();
|
|
|
|
}
|
2024-09-16 16:52:10 -07:00
|
|
|
|
2024-09-16 17:00:08 -07:00
|
|
|
public function testAdheresToFullMultipleCompaniesSupportScoping()
|
2024-09-16 16:52:10 -07:00
|
|
|
{
|
|
|
|
[$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);
|
|
|
|
}
|
2024-09-18 16:13:34 -07:00
|
|
|
|
|
|
|
public function testCanGetAccessories()
|
|
|
|
{
|
|
|
|
$user = User::factory()->viewAccessories()->create();
|
|
|
|
|
|
|
|
$accessoryA = Accessory::factory()->create(['name' => 'Accessory A']);
|
|
|
|
$accessoryB = Accessory::factory()->create(['name' => 'Accessory B']);
|
|
|
|
|
|
|
|
$this->actingAsForApi($user)
|
|
|
|
->getJson(route('api.accessories.index'))
|
|
|
|
->assertOk()
|
|
|
|
->assertResponseContainsInRows($accessoryA)
|
|
|
|
->assertResponseContainsInRows($accessoryB);
|
|
|
|
}
|
2024-09-09 14:35:38 -07:00
|
|
|
}
|