Migrate to response macros for readability
This commit is contained in:
parent
8aae5beaba
commit
a35d83d14a
11 changed files with 218 additions and 211 deletions
|
@ -7,13 +7,11 @@ use App\Models\Company;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Testing\Fluent\AssertableJson;
|
use Illuminate\Testing\Fluent\AssertableJson;
|
||||||
use Laravel\Passport\Passport;
|
use Laravel\Passport\Passport;
|
||||||
use Tests\Support\InteractsWithResponses;
|
|
||||||
use Tests\Support\InteractsWithSettings;
|
use Tests\Support\InteractsWithSettings;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class AssetIndexTest extends TestCase
|
class AssetIndexTest extends TestCase
|
||||||
{
|
{
|
||||||
use InteractsWithResponses;
|
|
||||||
use InteractsWithSettings;
|
use InteractsWithSettings;
|
||||||
|
|
||||||
public function testAssetIndexReturnsExpectedAssets()
|
public function testAssetIndexReturnsExpectedAssets()
|
||||||
|
@ -50,35 +48,35 @@ class AssetIndexTest extends TestCase
|
||||||
$this->settings->disableMultipleFullCompanySupport();
|
$this->settings->disableMultipleFullCompanySupport();
|
||||||
|
|
||||||
Passport::actingAs($superUser);
|
Passport::actingAs($superUser);
|
||||||
$response = $this->getJson(route('api.assets.index'));
|
$this->getJson(route('api.assets.index'))
|
||||||
$this->assertResponseContainsInRows($response, $assetA, 'asset_tag');
|
->assertResponseContainsInRows($assetA, 'asset_tag')
|
||||||
$this->assertResponseContainsInRows($response, $assetB, 'asset_tag');
|
->assertResponseContainsInRows($assetB, 'asset_tag');
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyA);
|
Passport::actingAs($userInCompanyA);
|
||||||
$response = $this->getJson(route('api.assets.index'));
|
$this->getJson(route('api.assets.index'))
|
||||||
$this->assertResponseContainsInRows($response, $assetA, 'asset_tag');
|
->assertResponseContainsInRows($assetA, 'asset_tag')
|
||||||
$this->assertResponseContainsInRows($response, $assetB, 'asset_tag');
|
->assertResponseContainsInRows($assetB, 'asset_tag');
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyB);
|
Passport::actingAs($userInCompanyB);
|
||||||
$response = $this->getJson(route('api.assets.index'));
|
$this->getJson(route('api.assets.index'))
|
||||||
$this->assertResponseContainsInRows($response, $assetA, 'asset_tag');
|
->assertResponseContainsInRows($assetA, 'asset_tag')
|
||||||
$this->assertResponseContainsInRows($response, $assetB, 'asset_tag');
|
->assertResponseContainsInRows($assetB, 'asset_tag');
|
||||||
|
|
||||||
$this->settings->enableMultipleFullCompanySupport();
|
$this->settings->enableMultipleFullCompanySupport();
|
||||||
|
|
||||||
Passport::actingAs($superUser);
|
Passport::actingAs($superUser);
|
||||||
$response = $this->getJson(route('api.assets.index'));
|
$this->getJson(route('api.assets.index'))
|
||||||
$this->assertResponseContainsInRows($response, $assetA, 'asset_tag');
|
->assertResponseContainsInRows($assetA, 'asset_tag')
|
||||||
$this->assertResponseContainsInRows($response, $assetB, 'asset_tag');
|
->assertResponseContainsInRows($assetB, 'asset_tag');
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyA);
|
Passport::actingAs($userInCompanyA);
|
||||||
$response = $this->getJson(route('api.assets.index'));
|
$this->getJson(route('api.assets.index'))
|
||||||
$this->assertResponseContainsInRows($response, $assetA, 'asset_tag');
|
->assertResponseContainsInRows($assetA, 'asset_tag')
|
||||||
$this->assertResponseDoesNotContainInRows($response, $assetB, 'asset_tag');
|
->assertResponseDoesNotContainInRows($assetB, 'asset_tag');
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyB);
|
Passport::actingAs($userInCompanyB);
|
||||||
$response = $this->getJson(route('api.assets.index'));
|
$this->getJson(route('api.assets.index'))
|
||||||
$this->assertResponseDoesNotContainInRows($response, $assetA, 'asset_tag');
|
->assertResponseDoesNotContainInRows($assetA, 'asset_tag')
|
||||||
$this->assertResponseContainsInRows($response, $assetB, 'asset_tag');
|
->assertResponseContainsInRows($assetB, 'asset_tag');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,11 @@ use App\Models\Asset;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Laravel\Passport\Passport;
|
use Laravel\Passport\Passport;
|
||||||
use Tests\Support\InteractsWithResponses;
|
|
||||||
use Tests\Support\InteractsWithSettings;
|
use Tests\Support\InteractsWithSettings;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class AssetsForSelectListTest extends TestCase
|
class AssetsForSelectListTest extends TestCase
|
||||||
{
|
{
|
||||||
use InteractsWithResponses;
|
|
||||||
use InteractsWithSettings;
|
use InteractsWithSettings;
|
||||||
|
|
||||||
public function testAssetsCanBeSearchedForByAssetTag()
|
public function testAssetsCanBeSearchedForByAssetTag()
|
||||||
|
@ -45,35 +43,35 @@ class AssetsForSelectListTest extends TestCase
|
||||||
$this->settings->disableMultipleFullCompanySupport();
|
$this->settings->disableMultipleFullCompanySupport();
|
||||||
|
|
||||||
Passport::actingAs($superUser);
|
Passport::actingAs($superUser);
|
||||||
$response = $this->getJson(route('assets.selectlist', ['search' => '000']));
|
$this->getJson(route('assets.selectlist', ['search' => '000']))
|
||||||
$this->assertResponseContainsInResults($response, $assetA);
|
->assertResponseContainsInResults($assetA)
|
||||||
$this->assertResponseContainsInResults($response, $assetB);
|
->assertResponseContainsInResults($assetB);
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyA);
|
Passport::actingAs($userInCompanyA);
|
||||||
$response = $this->getJson(route('assets.selectlist', ['search' => '000']));
|
$this->getJson(route('assets.selectlist', ['search' => '000']))
|
||||||
$this->assertResponseContainsInResults($response, $assetA);
|
->assertResponseContainsInResults($assetA)
|
||||||
$this->assertResponseContainsInResults($response, $assetB);
|
->assertResponseContainsInResults($assetB);
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyB);
|
Passport::actingAs($userInCompanyB);
|
||||||
$response = $this->getJson(route('assets.selectlist', ['search' => '000']));
|
$this->getJson(route('assets.selectlist', ['search' => '000']))
|
||||||
$this->assertResponseContainsInResults($response, $assetA);
|
->assertResponseContainsInResults($assetA)
|
||||||
$this->assertResponseContainsInResults($response, $assetB);
|
->assertResponseContainsInResults($assetB);
|
||||||
|
|
||||||
$this->settings->enableMultipleFullCompanySupport();
|
$this->settings->enableMultipleFullCompanySupport();
|
||||||
|
|
||||||
Passport::actingAs($superUser);
|
Passport::actingAs($superUser);
|
||||||
$response = $this->getJson(route('assets.selectlist', ['search' => '000']));
|
$this->getJson(route('assets.selectlist', ['search' => '000']))
|
||||||
$this->assertResponseContainsInResults($response, $assetA);
|
->assertResponseContainsInResults($assetA)
|
||||||
$this->assertResponseContainsInResults($response, $assetB);
|
->assertResponseContainsInResults($assetB);
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyA);
|
Passport::actingAs($userInCompanyA);
|
||||||
$response = $this->getJson(route('assets.selectlist', ['search' => '000']));
|
$this->getJson(route('assets.selectlist', ['search' => '000']))
|
||||||
$this->assertResponseContainsInResults($response, $assetA);
|
->assertResponseContainsInResults($assetA)
|
||||||
$this->assertResponseDoesNotContainInResults($response, $assetB);
|
->assertResponseDoesNotContainInResults($assetB);
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyB);
|
Passport::actingAs($userInCompanyB);
|
||||||
$response = $this->getJson(route('assets.selectlist', ['search' => '000']));
|
$this->getJson(route('assets.selectlist', ['search' => '000']))
|
||||||
$this->assertResponseDoesNotContainInResults($response, $assetA);
|
->assertResponseDoesNotContainInResults($assetA)
|
||||||
$this->assertResponseContainsInResults($response, $assetB);
|
->assertResponseContainsInResults($assetB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,11 @@ use App\Models\Asset;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Laravel\Passport\Passport;
|
use Laravel\Passport\Passport;
|
||||||
use Tests\Support\InteractsWithResponses;
|
|
||||||
use Tests\Support\InteractsWithSettings;
|
use Tests\Support\InteractsWithSettings;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class RequestableAssetsTest extends TestCase
|
class RequestableAssetsTest extends TestCase
|
||||||
{
|
{
|
||||||
use InteractsWithResponses;
|
|
||||||
use InteractsWithSettings;
|
use InteractsWithSettings;
|
||||||
|
|
||||||
public function testViewingRequestableAssetsRequiresCorrectPermission()
|
public function testViewingRequestableAssetsRequiresCorrectPermission()
|
||||||
|
@ -27,10 +25,10 @@ class RequestableAssetsTest extends TestCase
|
||||||
$nonRequestableAsset = Asset::factory()->nonrequestable()->create(['asset_tag' => 'non-requestable']);
|
$nonRequestableAsset = Asset::factory()->nonrequestable()->create(['asset_tag' => 'non-requestable']);
|
||||||
|
|
||||||
Passport::actingAs(User::factory()->viewRequestableAssets()->create());
|
Passport::actingAs(User::factory()->viewRequestableAssets()->create());
|
||||||
$response = $this->getJson(route('api.assets.requestable'))->assertOk();
|
$this->getJson(route('api.assets.requestable'))
|
||||||
|
->assertOk()
|
||||||
$this->assertResponseContainsInRows($response, $requestableAsset, 'asset_tag');
|
->assertResponseContainsInRows($requestableAsset, 'asset_tag')
|
||||||
$this->assertResponseDoesNotContainInRows($response, $nonRequestableAsset, 'asset_tag');
|
->assertResponseDoesNotContainInRows($nonRequestableAsset, 'asset_tag');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRequestableAssetsAreScopedToCompanyWhenMultipleCompanySupportEnabled()
|
public function testRequestableAssetsAreScopedToCompanyWhenMultipleCompanySupportEnabled()
|
||||||
|
@ -47,35 +45,35 @@ class RequestableAssetsTest extends TestCase
|
||||||
$this->settings->disableMultipleFullCompanySupport();
|
$this->settings->disableMultipleFullCompanySupport();
|
||||||
|
|
||||||
Passport::actingAs($superUser);
|
Passport::actingAs($superUser);
|
||||||
$response = $this->getJson(route('api.assets.requestable'));
|
$this->getJson(route('api.assets.requestable'))
|
||||||
$this->assertResponseContainsInRows($response, $assetA, 'asset_tag');
|
->assertResponseContainsInRows($assetA, 'asset_tag')
|
||||||
$this->assertResponseContainsInRows($response, $assetB, 'asset_tag');
|
->assertResponseContainsInRows($assetB, 'asset_tag');
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyA);
|
Passport::actingAs($userInCompanyA);
|
||||||
$response = $this->getJson(route('api.assets.requestable'));
|
$this->getJson(route('api.assets.requestable'))
|
||||||
$this->assertResponseContainsInRows($response, $assetA, 'asset_tag');
|
->assertResponseContainsInRows($assetA, 'asset_tag')
|
||||||
$this->assertResponseContainsInRows($response, $assetB, 'asset_tag');
|
->assertResponseContainsInRows($assetB, 'asset_tag');
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyB);
|
Passport::actingAs($userInCompanyB);
|
||||||
$response = $this->getJson(route('api.assets.requestable'));
|
$this->getJson(route('api.assets.requestable'))
|
||||||
$this->assertResponseContainsInRows($response, $assetA, 'asset_tag');
|
->assertResponseContainsInRows($assetA, 'asset_tag')
|
||||||
$this->assertResponseContainsInRows($response, $assetB, 'asset_tag');
|
->assertResponseContainsInRows($assetB, 'asset_tag');
|
||||||
|
|
||||||
$this->settings->enableMultipleFullCompanySupport();
|
$this->settings->enableMultipleFullCompanySupport();
|
||||||
|
|
||||||
Passport::actingAs($superUser);
|
Passport::actingAs($superUser);
|
||||||
$response = $this->getJson(route('api.assets.requestable'));
|
$this->getJson(route('api.assets.requestable'))
|
||||||
$this->assertResponseContainsInRows($response, $assetA, 'asset_tag');
|
->assertResponseContainsInRows($assetA, 'asset_tag')
|
||||||
$this->assertResponseContainsInRows($response, $assetB, 'asset_tag');
|
->assertResponseContainsInRows($assetB, 'asset_tag');
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyA);
|
Passport::actingAs($userInCompanyA);
|
||||||
$response = $this->getJson(route('api.assets.requestable'));
|
$this->getJson(route('api.assets.requestable'))
|
||||||
$this->assertResponseContainsInRows($response, $assetA, 'asset_tag');
|
->assertResponseContainsInRows($assetA, 'asset_tag')
|
||||||
$this->assertResponseDoesNotContainInRows($response, $assetB, 'asset_tag');
|
->assertResponseDoesNotContainInRows($assetB, 'asset_tag');
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyB);
|
Passport::actingAs($userInCompanyB);
|
||||||
$response = $this->getJson(route('api.assets.requestable'));
|
$this->getJson(route('api.assets.requestable'))
|
||||||
$this->assertResponseDoesNotContainInRows($response, $assetA, 'asset_tag');
|
->assertResponseDoesNotContainInRows($assetA, 'asset_tag')
|
||||||
$this->assertResponseContainsInRows($response, $assetB, 'asset_tag');
|
->assertResponseContainsInRows($assetB, 'asset_tag');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,11 @@ use App\Models\Company;
|
||||||
use App\Models\Component;
|
use App\Models\Component;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Laravel\Passport\Passport;
|
use Laravel\Passport\Passport;
|
||||||
use Tests\Support\InteractsWithResponses;
|
|
||||||
use Tests\Support\InteractsWithSettings;
|
use Tests\Support\InteractsWithSettings;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class ComponentIndexTest extends TestCase
|
class ComponentIndexTest extends TestCase
|
||||||
{
|
{
|
||||||
use InteractsWithResponses;
|
|
||||||
use InteractsWithSettings;
|
use InteractsWithSettings;
|
||||||
|
|
||||||
public function testComponentIndexAdheresToCompanyScoping()
|
public function testComponentIndexAdheresToCompanyScoping()
|
||||||
|
@ -29,35 +27,35 @@ class ComponentIndexTest extends TestCase
|
||||||
$this->settings->disableMultipleFullCompanySupport();
|
$this->settings->disableMultipleFullCompanySupport();
|
||||||
|
|
||||||
Passport::actingAs($superUser);
|
Passport::actingAs($superUser);
|
||||||
$response = $this->getJson(route('api.components.index'));
|
$this->getJson(route('api.components.index'))
|
||||||
$this->assertResponseContainsInRows($response, $componentA);
|
->assertResponseContainsInRows($componentA)
|
||||||
$this->assertResponseContainsInRows($response, $componentB);
|
->assertResponseContainsInRows($componentB);
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyA);
|
Passport::actingAs($userInCompanyA);
|
||||||
$response = $this->getJson(route('api.components.index'));
|
$this->getJson(route('api.components.index'))
|
||||||
$this->assertResponseContainsInRows($response, $componentA);
|
->assertResponseContainsInRows($componentA)
|
||||||
$this->assertResponseContainsInRows($response, $componentB);
|
->assertResponseContainsInRows($componentB);
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyB);
|
Passport::actingAs($userInCompanyB);
|
||||||
$response = $this->getJson(route('api.components.index'));
|
$this->getJson(route('api.components.index'))
|
||||||
$this->assertResponseContainsInRows($response, $componentA);
|
->assertResponseContainsInRows($componentA)
|
||||||
$this->assertResponseContainsInRows($response, $componentB);
|
->assertResponseContainsInRows($componentB);
|
||||||
|
|
||||||
$this->settings->enableMultipleFullCompanySupport();
|
$this->settings->enableMultipleFullCompanySupport();
|
||||||
|
|
||||||
Passport::actingAs($superUser);
|
Passport::actingAs($superUser);
|
||||||
$response = $this->getJson(route('api.components.index'));
|
$this->getJson(route('api.components.index'))
|
||||||
$this->assertResponseContainsInRows($response, $componentA);
|
->assertResponseContainsInRows($componentA)
|
||||||
$this->assertResponseContainsInRows($response, $componentB);
|
->assertResponseContainsInRows($componentB);
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyA);
|
Passport::actingAs($userInCompanyA);
|
||||||
$response = $this->getJson(route('api.components.index'));
|
$this->getJson(route('api.components.index'))
|
||||||
$this->assertResponseContainsInRows($response, $componentA);
|
->assertResponseContainsInRows($componentA)
|
||||||
$this->assertResponseDoesNotContainInRows($response, $componentB);
|
->assertResponseDoesNotContainInRows($componentB);
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyB);
|
Passport::actingAs($userInCompanyB);
|
||||||
$response = $this->getJson(route('api.components.index'));
|
$this->getJson(route('api.components.index'))
|
||||||
$this->assertResponseDoesNotContainInRows($response, $componentA);
|
->assertResponseDoesNotContainInRows($componentA)
|
||||||
$this->assertResponseContainsInRows($response, $componentB);
|
->assertResponseContainsInRows($componentB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,11 @@ use App\Models\Company;
|
||||||
use App\Models\Consumable;
|
use App\Models\Consumable;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Laravel\Passport\Passport;
|
use Laravel\Passport\Passport;
|
||||||
use Tests\Support\InteractsWithResponses;
|
|
||||||
use Tests\Support\InteractsWithSettings;
|
use Tests\Support\InteractsWithSettings;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class ConsumablesIndexTest extends TestCase
|
class ConsumablesIndexTest extends TestCase
|
||||||
{
|
{
|
||||||
use InteractsWithResponses;
|
|
||||||
use InteractsWithSettings;
|
use InteractsWithSettings;
|
||||||
|
|
||||||
public function testConsumableIndexAdheresToCompanyScoping()
|
public function testConsumableIndexAdheresToCompanyScoping()
|
||||||
|
@ -29,35 +27,35 @@ class ConsumablesIndexTest extends TestCase
|
||||||
$this->settings->disableMultipleFullCompanySupport();
|
$this->settings->disableMultipleFullCompanySupport();
|
||||||
|
|
||||||
Passport::actingAs($superUser);
|
Passport::actingAs($superUser);
|
||||||
$response = $this->getJson(route('api.consumables.index'));
|
$this->getJson(route('api.consumables.index'))
|
||||||
$this->assertResponseContainsInRows($response, $consumableA);
|
->assertResponseContainsInRows($consumableA)
|
||||||
$this->assertResponseContainsInRows($response, $consumableB);
|
->assertResponseContainsInRows($consumableB);
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyA);
|
Passport::actingAs($userInCompanyA);
|
||||||
$response = $this->getJson(route('api.consumables.index'));
|
$this->getJson(route('api.consumables.index'))
|
||||||
$this->assertResponseContainsInRows($response, $consumableA);
|
->assertResponseContainsInRows($consumableA)
|
||||||
$this->assertResponseContainsInRows($response, $consumableB);
|
->assertResponseContainsInRows($consumableB);
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyB);
|
Passport::actingAs($userInCompanyB);
|
||||||
$response = $this->getJson(route('api.consumables.index'));
|
$this->getJson(route('api.consumables.index'))
|
||||||
$this->assertResponseContainsInRows($response, $consumableA);
|
->assertResponseContainsInRows($consumableA)
|
||||||
$this->assertResponseContainsInRows($response, $consumableB);
|
->assertResponseContainsInRows($consumableB);
|
||||||
|
|
||||||
$this->settings->enableMultipleFullCompanySupport();
|
$this->settings->enableMultipleFullCompanySupport();
|
||||||
|
|
||||||
Passport::actingAs($superUser);
|
Passport::actingAs($superUser);
|
||||||
$response = $this->getJson(route('api.consumables.index'));
|
$this->getJson(route('api.consumables.index'))
|
||||||
$this->assertResponseContainsInRows($response, $consumableA);
|
->assertResponseContainsInRows($consumableA)
|
||||||
$this->assertResponseContainsInRows($response, $consumableB);
|
->assertResponseContainsInRows($consumableB);
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyA);
|
Passport::actingAs($userInCompanyA);
|
||||||
$response = $this->getJson(route('api.consumables.index'));
|
$this->getJson(route('api.consumables.index'))
|
||||||
$this->assertResponseContainsInRows($response, $consumableA);
|
->assertResponseContainsInRows($consumableA)
|
||||||
$this->assertResponseDoesNotContainInRows($response, $consumableB);
|
->assertResponseDoesNotContainInRows($consumableB);
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyB);
|
Passport::actingAs($userInCompanyB);
|
||||||
$response = $this->getJson(route('api.consumables.index'));
|
$this->getJson(route('api.consumables.index'))
|
||||||
$this->assertResponseDoesNotContainInRows($response, $consumableA);
|
->assertResponseDoesNotContainInRows($consumableA)
|
||||||
$this->assertResponseContainsInRows($response, $consumableB);
|
->assertResponseContainsInRows($consumableB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,11 @@ use App\Models\Company;
|
||||||
use App\Models\Department;
|
use App\Models\Department;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Laravel\Passport\Passport;
|
use Laravel\Passport\Passport;
|
||||||
use Tests\Support\InteractsWithResponses;
|
|
||||||
use Tests\Support\InteractsWithSettings;
|
use Tests\Support\InteractsWithSettings;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class DepartmentsIndexTest extends TestCase
|
class DepartmentsIndexTest extends TestCase
|
||||||
{
|
{
|
||||||
use InteractsWithResponses;
|
|
||||||
use InteractsWithSettings;
|
use InteractsWithSettings;
|
||||||
|
|
||||||
public function testDepartmentsIndexAdheresToCompanyScoping()
|
public function testDepartmentsIndexAdheresToCompanyScoping()
|
||||||
|
@ -33,35 +31,35 @@ class DepartmentsIndexTest extends TestCase
|
||||||
$this->settings->disableMultipleFullCompanySupport();
|
$this->settings->disableMultipleFullCompanySupport();
|
||||||
|
|
||||||
Passport::actingAs($superUser);
|
Passport::actingAs($superUser);
|
||||||
$response = $this->getJson(route('api.departments.index'));
|
$this->getJson(route('api.departments.index'))
|
||||||
$this->assertResponseContainsInRows($response, $departmentA);
|
->assertResponseContainsInRows($departmentA)
|
||||||
$this->assertResponseContainsInRows($response, $departmentB);
|
->assertResponseContainsInRows($departmentB);
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyA);
|
Passport::actingAs($userInCompanyA);
|
||||||
$response = $this->getJson(route('api.departments.index'));
|
$this->getJson(route('api.departments.index'))
|
||||||
$this->assertResponseContainsInRows($response, $departmentA);
|
->assertResponseContainsInRows($departmentA)
|
||||||
$this->assertResponseContainsInRows($response, $departmentB);
|
->assertResponseContainsInRows($departmentB);
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyB);
|
Passport::actingAs($userInCompanyB);
|
||||||
$response = $this->getJson(route('api.departments.index'));
|
$this->getJson(route('api.departments.index'))
|
||||||
$this->assertResponseContainsInRows($response, $departmentA);
|
->assertResponseContainsInRows($departmentA)
|
||||||
$this->assertResponseContainsInRows($response, $departmentB);
|
->assertResponseContainsInRows($departmentB);
|
||||||
|
|
||||||
$this->settings->enableMultipleFullCompanySupport();
|
$this->settings->enableMultipleFullCompanySupport();
|
||||||
|
|
||||||
Passport::actingAs($superUser);
|
Passport::actingAs($superUser);
|
||||||
$response = $this->getJson(route('api.departments.index'));
|
$this->getJson(route('api.departments.index'))
|
||||||
$this->assertResponseContainsInRows($response, $departmentA);
|
->assertResponseContainsInRows($departmentA)
|
||||||
$this->assertResponseContainsInRows($response, $departmentB);
|
->assertResponseContainsInRows($departmentB);
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyA);
|
Passport::actingAs($userInCompanyA);
|
||||||
$response = $this->getJson(route('api.departments.index'));
|
$this->getJson(route('api.departments.index'))
|
||||||
$this->assertResponseContainsInRows($response, $departmentA);
|
->assertResponseContainsInRows($departmentA)
|
||||||
$this->assertResponseDoesNotContainInRows($response, $departmentB);
|
->assertResponseDoesNotContainInRows($departmentB);
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyB);
|
Passport::actingAs($userInCompanyB);
|
||||||
$response = $this->getJson(route('api.departments.index'));
|
$this->getJson(route('api.departments.index'))
|
||||||
$this->assertResponseDoesNotContainInRows($response, $departmentA);
|
->assertResponseDoesNotContainInRows($departmentA)
|
||||||
$this->assertResponseContainsInRows($response, $departmentB);
|
->assertResponseContainsInRows($departmentB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,11 @@ use App\Models\Company;
|
||||||
use App\Models\License;
|
use App\Models\License;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Laravel\Passport\Passport;
|
use Laravel\Passport\Passport;
|
||||||
use Tests\Support\InteractsWithResponses;
|
|
||||||
use Tests\Support\InteractsWithSettings;
|
use Tests\Support\InteractsWithSettings;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class LicensesIndexTest extends TestCase
|
class LicensesIndexTest extends TestCase
|
||||||
{
|
{
|
||||||
use InteractsWithResponses;
|
|
||||||
use InteractsWithSettings;
|
use InteractsWithSettings;
|
||||||
|
|
||||||
public function testLicensesIndexAdheresToCompanyScoping()
|
public function testLicensesIndexAdheresToCompanyScoping()
|
||||||
|
@ -29,35 +27,35 @@ class LicensesIndexTest extends TestCase
|
||||||
$this->settings->disableMultipleFullCompanySupport();
|
$this->settings->disableMultipleFullCompanySupport();
|
||||||
|
|
||||||
Passport::actingAs($superUser);
|
Passport::actingAs($superUser);
|
||||||
$response = $this->getJson(route('api.licenses.index'));
|
$this->getJson(route('api.licenses.index'))
|
||||||
$this->assertResponseContainsInRows($response, $licenseA);
|
->assertResponseContainsInRows($licenseA)
|
||||||
$this->assertResponseContainsInRows($response, $licenseB);
|
->assertResponseContainsInRows($licenseB);
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyA);
|
Passport::actingAs($userInCompanyA);
|
||||||
$response = $this->getJson(route('api.licenses.index'));
|
$this->getJson(route('api.licenses.index'))
|
||||||
$this->assertResponseContainsInRows($response, $licenseA);
|
->assertResponseContainsInRows($licenseA)
|
||||||
$this->assertResponseContainsInRows($response, $licenseB);
|
->assertResponseContainsInRows($licenseB);
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyB);
|
Passport::actingAs($userInCompanyB);
|
||||||
$response = $this->getJson(route('api.licenses.index'));
|
$this->getJson(route('api.licenses.index'))
|
||||||
$this->assertResponseContainsInRows($response, $licenseA);
|
->assertResponseContainsInRows($licenseA)
|
||||||
$this->assertResponseContainsInRows($response, $licenseB);
|
->assertResponseContainsInRows($licenseB);
|
||||||
|
|
||||||
$this->settings->enableMultipleFullCompanySupport();
|
$this->settings->enableMultipleFullCompanySupport();
|
||||||
|
|
||||||
Passport::actingAs($superUser);
|
Passport::actingAs($superUser);
|
||||||
$response = $this->getJson(route('api.licenses.index'));
|
$this->getJson(route('api.licenses.index'))
|
||||||
$this->assertResponseContainsInRows($response, $licenseA);
|
->assertResponseContainsInRows($licenseA)
|
||||||
$this->assertResponseContainsInRows($response, $licenseB);
|
->assertResponseContainsInRows($licenseB);
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyA);
|
Passport::actingAs($userInCompanyA);
|
||||||
$response = $this->getJson(route('api.licenses.index'));
|
$this->getJson(route('api.licenses.index'))
|
||||||
$this->assertResponseContainsInRows($response, $licenseA);
|
->assertResponseContainsInRows($licenseA)
|
||||||
$this->assertResponseDoesNotContainInRows($response, $licenseB);
|
->assertResponseDoesNotContainInRows($licenseB);
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyB);
|
Passport::actingAs($userInCompanyB);
|
||||||
$response = $this->getJson(route('api.licenses.index'));
|
$this->getJson(route('api.licenses.index'))
|
||||||
$this->assertResponseDoesNotContainInRows($response, $licenseA);
|
->assertResponseDoesNotContainInRows($licenseA)
|
||||||
$this->assertResponseContainsInRows($response, $licenseB);
|
->assertResponseContainsInRows($licenseB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,11 @@ namespace Tests\Feature\Api\Users;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Laravel\Passport\Passport;
|
use Laravel\Passport\Passport;
|
||||||
use Tests\Support\InteractsWithResponses;
|
|
||||||
use Tests\Support\InteractsWithSettings;
|
use Tests\Support\InteractsWithSettings;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class UsersIndexTest extends TestCase
|
class UsersIndexTest extends TestCase
|
||||||
{
|
{
|
||||||
use InteractsWithResponses;
|
|
||||||
use InteractsWithSettings;
|
use InteractsWithSettings;
|
||||||
|
|
||||||
public function testUsersIndexAdheresToCompanyScoping()
|
public function testUsersIndexAdheresToCompanyScoping()
|
||||||
|
@ -32,35 +30,35 @@ class UsersIndexTest extends TestCase
|
||||||
$this->settings->disableMultipleFullCompanySupport();
|
$this->settings->disableMultipleFullCompanySupport();
|
||||||
|
|
||||||
Passport::actingAs($superUser);
|
Passport::actingAs($superUser);
|
||||||
$response = $this->getJson(route('api.users.index'));
|
$this->getJson(route('api.users.index'))
|
||||||
$this->assertResponseContainsInRows($response, $userA, 'first_name');
|
->assertResponseContainsInRows($userA, 'first_name')
|
||||||
$this->assertResponseContainsInRows($response, $userB, 'first_name');
|
->assertResponseContainsInRows($userB, 'first_name');
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyA);
|
Passport::actingAs($userInCompanyA);
|
||||||
$response = $this->getJson(route('api.users.index'));
|
$this->getJson(route('api.users.index'))
|
||||||
$this->assertResponseContainsInRows($response, $userA, 'first_name');
|
->assertResponseContainsInRows($userA, 'first_name')
|
||||||
$this->assertResponseContainsInRows($response, $userB, 'first_name');
|
->assertResponseContainsInRows($userB, 'first_name');
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyB);
|
Passport::actingAs($userInCompanyB);
|
||||||
$response = $this->getJson(route('api.users.index'));
|
$this->getJson(route('api.users.index'))
|
||||||
$this->assertResponseContainsInRows($response, $userA, 'first_name');
|
->assertResponseContainsInRows($userA, 'first_name')
|
||||||
$this->assertResponseContainsInRows($response, $userB, 'first_name');
|
->assertResponseContainsInRows($userB, 'first_name');
|
||||||
|
|
||||||
$this->settings->enableMultipleFullCompanySupport();
|
$this->settings->enableMultipleFullCompanySupport();
|
||||||
|
|
||||||
Passport::actingAs($superUser);
|
Passport::actingAs($superUser);
|
||||||
$response = $this->getJson(route('api.users.index'));
|
$this->getJson(route('api.users.index'))
|
||||||
$this->assertResponseContainsInRows($response, $userA, 'first_name');
|
->assertResponseContainsInRows($userA, 'first_name')
|
||||||
$this->assertResponseContainsInRows($response, $userB, 'first_name');
|
->assertResponseContainsInRows($userB, 'first_name');
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyA);
|
Passport::actingAs($userInCompanyA);
|
||||||
$response = $this->getJson(route('api.users.index'));
|
$this->getJson(route('api.users.index'))
|
||||||
$this->assertResponseContainsInRows($response, $userA, 'first_name');
|
->assertResponseContainsInRows($userA, 'first_name')
|
||||||
$this->assertResponseDoesNotContainInRows($response, $userB, 'first_name');
|
->assertResponseDoesNotContainInRows($userB, 'first_name');
|
||||||
|
|
||||||
Passport::actingAs($userInCompanyB);
|
Passport::actingAs($userInCompanyB);
|
||||||
$response = $this->getJson(route('api.users.index'));
|
$this->getJson(route('api.users.index'))
|
||||||
$this->assertResponseDoesNotContainInRows($response, $userA, 'first_name');
|
->assertResponseDoesNotContainInRows($userA, 'first_name')
|
||||||
$this->assertResponseContainsInRows($response, $userB, 'first_name');
|
->assertResponseContainsInRows($userB, 'first_name');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
66
tests/Support/CustomTestMacros.php
Normal file
66
tests/Support/CustomTestMacros.php
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Support;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Testing\TestResponse;
|
||||||
|
use PHPUnit\Framework\Assert;
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
|
trait CustomTestMacros
|
||||||
|
{
|
||||||
|
protected function registerCustomMacros()
|
||||||
|
{
|
||||||
|
$guardAgainstNullProperty = function (Model $model, string $property) {
|
||||||
|
if (is_null($model->{$property})) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
"The property ({$property}) either does not exist or is null on the model which isn't helpful for comparison."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TestResponse::macro(
|
||||||
|
'assertResponseContainsInRows',
|
||||||
|
function (Model $model, string $property = 'name') use ($guardAgainstNullProperty) {
|
||||||
|
$guardAgainstNullProperty($model, $property);
|
||||||
|
|
||||||
|
Assert::assertTrue(collect($this['rows'])->pluck($property)->contains($model->{$property}));
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
TestResponse::macro(
|
||||||
|
'assertResponseDoesNotContainInRows',
|
||||||
|
function (Model $model, string $property = 'name') use ($guardAgainstNullProperty) {
|
||||||
|
$guardAgainstNullProperty($model, $property);
|
||||||
|
|
||||||
|
Assert::assertFalse(collect($this['rows'])->pluck($property)->contains($model->{$property}));
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
TestResponse::macro(
|
||||||
|
'assertResponseContainsInResults',
|
||||||
|
function (Model $model, string $property = 'id') use ($guardAgainstNullProperty) {
|
||||||
|
$guardAgainstNullProperty($model, $property);
|
||||||
|
|
||||||
|
Assert::assertTrue(collect($this->json('results'))->pluck('id')->contains($model->{$property}));
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
TestResponse::macro(
|
||||||
|
'assertResponseDoesNotContainInResults',
|
||||||
|
function (Model $model, string $property = 'id') use ($guardAgainstNullProperty) {
|
||||||
|
$guardAgainstNullProperty($model, $property);
|
||||||
|
|
||||||
|
Assert::assertFalse(collect($this->json('results'))->pluck('id')->contains($model->{$property}));
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,47 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Support;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Illuminate\Testing\TestResponse;
|
|
||||||
use RuntimeException;
|
|
||||||
|
|
||||||
trait InteractsWithResponses
|
|
||||||
{
|
|
||||||
protected function assertResponseContainsInRows(TestResponse $response, Model $model, string $property = 'name')
|
|
||||||
{
|
|
||||||
$this->guardAgainstNullProperty($model, $property);
|
|
||||||
|
|
||||||
$this->assertTrue(collect($response['rows'])->pluck($property)->contains($model->{$property}));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function assertResponseDoesNotContainInRows(TestResponse $response, Model $model, string $property = 'name')
|
|
||||||
{
|
|
||||||
$this->guardAgainstNullProperty($model, $property);
|
|
||||||
|
|
||||||
$this->assertFalse(collect($response['rows'])->pluck($property)->contains($model->{$property}));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function assertResponseContainsInResults(TestResponse $response, Model $model, string $property = 'id')
|
|
||||||
{
|
|
||||||
$this->guardAgainstNullProperty($model, $property);
|
|
||||||
|
|
||||||
$this->assertTrue(collect($response->json('results'))->pluck('id')->contains($model->{$property}));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function assertResponseDoesNotContainInResults(TestResponse $response, Model $model, string $property = 'id')
|
|
||||||
{
|
|
||||||
$this->guardAgainstNullProperty($model, $property);
|
|
||||||
|
|
||||||
$this->assertFalse(collect($response->json('results'))->pluck('id')->contains($model->{$property}));
|
|
||||||
}
|
|
||||||
|
|
||||||
private function guardAgainstNullProperty(Model $model, string $property): void
|
|
||||||
{
|
|
||||||
if (is_null($model->{$property})) {
|
|
||||||
throw new RuntimeException(
|
|
||||||
"The property ({$property}) either does not exist or is null on the model which isn't helpful for comparison."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,11 +5,13 @@ namespace Tests;
|
||||||
use App\Http\Middleware\SecurityHeaders;
|
use App\Http\Middleware\SecurityHeaders;
|
||||||
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
|
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
|
||||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||||
|
use Tests\Support\CustomTestMacros;
|
||||||
use Tests\Support\InteractsWithSettings;
|
use Tests\Support\InteractsWithSettings;
|
||||||
|
|
||||||
abstract class TestCase extends BaseTestCase
|
abstract class TestCase extends BaseTestCase
|
||||||
{
|
{
|
||||||
use CreatesApplication;
|
use CreatesApplication;
|
||||||
|
use CustomTestMacros;
|
||||||
use LazilyRefreshDatabase;
|
use LazilyRefreshDatabase;
|
||||||
|
|
||||||
private array $globallyDisabledMiddleware = [
|
private array $globallyDisabledMiddleware = [
|
||||||
|
@ -25,5 +27,7 @@ abstract class TestCase extends BaseTestCase
|
||||||
if (collect(class_uses_recursive($this))->contains(InteractsWithSettings::class)) {
|
if (collect(class_uses_recursive($this))->contains(InteractsWithSettings::class)) {
|
||||||
$this->initializeSettings();
|
$this->initializeSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->registerCustomMacros();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue