A free open source IT asset/license management system
Added accessory tests
snipe38ee93d1bdd5
diff --git a/tests/Feature/Accessories/Api/IndexAccessoryTest.php b/tests/Feature/Accessories/Api/IndexAccessoryTest.phpindex a27d458583..54696d98c8 100644--- a/tests/Feature/Accessories/Api/IndexAccessoryTest.php+++ b/tests/Feature/Accessories/Api/IndexAccessoryTest.php@@ -252,4 +252,55 @@ class IndexAccessoryTest extends TestCase implements TestsFullMultipleCompaniesS->assertResponseContainsInRows($targetAccessory)->assertResponseDoesNotContainInRows($otherAccessory);}++ public function test_advanced_search_category_csv_of_ids_matches_by_where_in(): void+ {+ // Multi-select scrollbox path: the modal widget submits an array+ // of category ids as the filter value+ $user = User::factory()->superuser()->create();++ $cat1 = Category::factory()->forAccessories()->create(['name' => 'Peripherals']);+ $cat2 = Category::factory()->forAccessories()->create(['name' => 'Cables']);+ $cat3 = Category::factory()->forAccessories()->create(['name' => 'Software']);++ $inCat1 = Accessory::factory()->create(['category_id' => $cat1->id, 'name' => 'Mouse']);+ $inCat2 = Accessory::factory()->create(['category_id' => $cat2->id, 'name' => 'HDMI']);+ $inCat3 = Accessory::factory()->create(['category_id' => $cat3->id, 'name' => 'License XYZ']);++ $this->actingAsForApi($user)+ ->getJson(route('api.accessories.index', [+ 'filter' => json_encode(['category' => $cat1->id . ',' . $cat2->id]),+ ]))+ ->assertOk()+ ->assertResponseContainsInRows($inCat1)+ ->assertResponseContainsInRows($inCat2)+ ->assertResponseDoesNotContainInRows($inCat3);+ }++ public function test_advanced_search_category_single_name_still_matches_via_like_path(): void+ {+ // Guard that the new whereIn branch does not swallow single-+ // value name lookups. A hand-typed "Peripherals" value in the+ // category filter should still fall through to the relation-+ // LIKE path, same as pre-prototype behavior, because the value+ // is not an integer CSV.+ $user = User::factory()->superuser()->create();++ $target = Category::factory()->forAccessories()->create(['name' => 'Peripherals']);+ $other = Category::factory()->forAccessories()->create(['name' => 'Cables']);++ // Pin names so a Faker collision (AccessoryFactory draws from+ // a 4-value pool) does not false-fail the "other not in rows"+ // check when both accessories randomly land on the same name.+ $targetAccessory = Accessory::factory()->create(['category_id' => $target->id, 'name' => 'In-Peripherals Pick']);+ $otherAccessory = Accessory::factory()->create(['category_id' => $other->id, 'name' => 'In-Cables Pick']);++ $this->actingAsForApi($user)+ ->getJson(route('api.accessories.index', [+ 'filter' => json_encode(['category' => 'Peripherals']),+ ]))+ ->assertOk()+ ->assertResponseContainsInRows($targetAccessory)+ ->assertResponseDoesNotContainInRows($otherAccessory);+ }}