Skip to content

A free open source IT asset/license management system

Added license filter tests

sniped7f44fdda463
diff --git a/tests/Feature/Licenses/Api/LicenseIndexTest.php b/tests/Feature/Licenses/Api/LicenseIndexTest.php
index 63140e106e..fda741b95e 100644
--- a/tests/Feature/Licenses/Api/LicenseIndexTest.php
+++ b/tests/Feature/Licenses/Api/LicenseIndexTest.php
@@ -5,6 +5,7 @@ namespace Tests\Feature\Licenses\Api;
use App\Models\Company;
use App\Models\License;
use App\Models\User;
+use Illuminate\Testing\Fluent\AssertableJson;
use Tests\TestCase;
class LicenseIndexTest extends TestCase
@@ -54,4 +55,76 @@ class LicenseIndexTest extends TestCase
->assertResponseDoesNotContainInRows($licenseA)
->assertResponseContainsInRows($licenseB);
}
+
+ public function test_returns_result_via_filter()
+ {
+
+ License::factory()->create(['name' => 'MY AWESOME LICENSE NAME 1']);
+ License::factory()->count(2)->create(['name' => 'MY AWESOME LICENSE NAME 2']);
+ License::factory()->count(2)->create(['name' => 'MY AWESOME LICENSE NAME 3']);
+ License::factory()->count(2)->create(['name' => 'MY TERRIBLE LICENSE NAME']);
+
+ $this->actingAsForApi(User::factory()->viewLicenses()->create())
+ ->getJson(route('api.licenses.index', [
+ 'filter' => '{"name":"AWESOME LICENSE NAME"}',
+ ]))
+ ->assertOk()
+ ->assertJsonStructure([
+ 'total',
+ 'rows',
+ ])
+ ->assertJson(fn (AssertableJson $json) => $json->has('rows', 5)->etc());
+ }
+
+ public function test_returns_result_via_filter_for_manufacturer()
+ {
+
+ License::factory()->count(5)->office()->create();
+ License::factory()->count(3)->indesign()->create();
+ License::factory()->count(3)->acrobat()->create();
+
+ $this->actingAsForApi(User::factory()->viewLicenses()->create())
+ ->getJson(route('api.licenses.index', [
+ 'filter' => '{"manufacturer":"adobe"}',
+ ]))
+ ->assertOk()
+ ->assertJsonStructure([
+ 'total',
+ 'rows',
+ ])
+ ->assertJson(fn (AssertableJson $json) => $json->has('rows', 6)->etc());
+
+ $this->actingAsForApi(User::factory()->viewLicenses()->create())
+ ->getJson(route('api.licenses.index', [
+ 'filter' => '{"manufacturer":"blah"}',
+ ]))
+ ->assertOk()
+ ->assertJsonStructure([
+ 'total',
+ 'rows',
+ ])
+ ->assertJson(fn (AssertableJson $json) => $json->has('rows', 0)->etc());
+
+ $this->actingAsForApi(User::factory()->viewLicenses()->create())
+ ->getJson(route('api.licenses.index', [
+ 'filter' => '{"manufacturer":"microsoft"}',
+ ]))
+ ->assertOk()
+ ->assertJsonStructure([
+ 'total',
+ 'rows',
+ ])
+ ->assertJson(fn (AssertableJson $json) => $json->has('rows', 5)->etc());
+
+ $this->actingAsForApi(User::factory()->viewLicenses()->create())
+ ->getJson(route('api.licenses.index', [
+ 'search' => 'adobe',
+ ]))
+ ->assertOk()
+ ->assertJsonStructure([
+ 'total',
+ 'rows',
+ ])
+ ->assertJson(fn (AssertableJson $json) => $json->has('rows', 6)->etc());
+ }
}