A free open source IT asset/license management system
Added/updated tests
snipecd4e268c7263
diff --git a/tests/Feature/Components/Api/ComponentAssetsTest.php b/tests/Feature/Components/Api/ComponentAssetsTest.phpnew file mode 100644index 0000000000..02edcecb2e--- /dev/null+++ b/tests/Feature/Components/Api/ComponentAssetsTest.php@@ -0,0 +1,64 @@+<?php++namespace Tests\Feature\Components\Api;++use App\Models\Asset;+use App\Models\Component;+use App\Models\User;+use Illuminate\Testing\Fluent\AssertableJson;+use Tests\TestCase;++class ComponentAssetsTest extends TestCase+{+ public function test_requires_permission()+ {+ $component = Component::factory()->create();++ $this->actingAsForApi(User::factory()->create())+ ->getJson(route('api.components.assets', $component))+ ->assertForbidden();+ }++ public function test_can_search_assets_assigned_to_specific_component()+ {+ $component = Component::factory()->create();+ $user = User::factory()->viewAssets()->create();++ $matchingAsset = Asset::factory()->create([+ 'name' => 'Laptop 1331',+ 'asset_tag' => 'ASSET-1331',+ ]);++ $nonMatchingAsset = Asset::factory()->create([+ 'name' => 'Laptop 9999',+ 'asset_tag' => 'ASSET-9999',+ ]);++ $component->assets()->attach($matchingAsset->id, [+ 'component_id' => $component->id,+ 'asset_id' => $matchingAsset->id,+ 'assigned_qty' => 2,+ 'created_at' => now(),+ 'created_by' => $user->id,+ ]);++ $component->assets()->attach($nonMatchingAsset->id, [+ 'component_id' => $component->id,+ 'asset_id' => $nonMatchingAsset->id,+ 'assigned_qty' => 1,+ 'created_at' => now(),+ 'created_by' => $user->id,+ ]);++ $this->actingAsForApi($user)+ ->getJson(route('api.components.assets', $component).'?search=1331')+ ->assertOk()+ ->assertJson(function (AssertableJson $json) use ($matchingAsset) {+ $json->where('total', 1)+ ->count('rows', 1)+ ->where('rows.0.name.id', $matchingAsset->id)+ ->where('rows.0.assigned_qty', 2)+ ->etc();+ });+ }+}diff --git a/tests/Feature/Search/SearchableTraitTest.php b/tests/Feature/Search/SearchableTraitTest.phpindex f9d38481fc..7626069a69 100644--- a/tests/Feature/Search/SearchableTraitTest.php+++ b/tests/Feature/Search/SearchableTraitTest.php@@ -13,6 +13,7 @@ use App\Models\Statuslabel;use App\Models\Supplier;use App\Models\User;use Illuminate\Testing\Fluent\AssertableJson;+use PHPUnit\Framework\Attributes\Group;use Tests\TestCase;/**@@ -272,9 +273,8 @@ class SearchableTraitTest extends TestCase/*** Test User free-text search on attributes- *- * @group skip-flaky*/+ #[Group('skip-flaky')]public function test_user_free_text_search_on_attributes(){// Note: User search includes the acting user in results, making this test flaky