From 1c2f6c4127353911944f4db4f7c9b211dde56624 Mon Sep 17 00:00:00 2001 From: ncoronel Date: Tue, 18 Aug 2026 10:45:40 -0300 Subject: [PATCH] refactor(variant-selection): update variant options retrieval to use catalog item's variants and enhance response structure --- app/Domains/Catalog/Services/VariantSelectionService.php | 6 +++++- tests/Feature/Catalog/CatalogItemDetailControllerTest.php | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/Domains/Catalog/Services/VariantSelectionService.php b/app/Domains/Catalog/Services/VariantSelectionService.php index 7f6e0fd..581773c 100644 --- a/app/Domains/Catalog/Services/VariantSelectionService.php +++ b/app/Domains/Catalog/Services/VariantSelectionService.php @@ -38,7 +38,7 @@ class VariantSelectionService $matchingVariants = $variants ->filter(fn (Variant $variant): bool => $this->matches($variant, $normalizedSelections)) ->values(); - $attributeKeys = $this->attributeKeys($catalogItem, $variants); + $attributeKeys = $this->attributeKeys($catalogItem, $catalogItem->variants->values()); $isComplete = $attributeKeys->isNotEmpty() && $attributeKeys->every(fn (string $key): bool => array_key_exists($key, $normalizedSelections)); $resolvedVariant = $isComplete && $matchingVariants->count() === 1 @@ -46,6 +46,10 @@ class VariantSelectionService : null; return [ + 'variants' => $variants + ->map(fn (Variant $variant): array => $this->variantData($catalogItem, $variant)) + ->values() + ->all(), 'selectors' => $this->selectors( $catalogItem, $variants, diff --git a/tests/Feature/Catalog/CatalogItemDetailControllerTest.php b/tests/Feature/Catalog/CatalogItemDetailControllerTest.php index 68190d4..e163577 100644 --- a/tests/Feature/Catalog/CatalogItemDetailControllerTest.php +++ b/tests/Feature/Catalog/CatalogItemDetailControllerTest.php @@ -342,7 +342,10 @@ class CatalogItemDetailControllerTest extends TestCase ->assertOk() ->assertJsonPath('data.valid', true) ->assertJsonPath('data.resolved_variant', null) - ->assertJsonMissingPath('data.variants') + ->assertJsonCount(3, 'data.variants') + ->assertJsonPath('data.variants.0.id', $first->id) + ->assertJsonPath('data.variants.0.values.sector.value', 'A') + ->assertJsonPath('data.variants.0.values.seat.value', '1') ->assertJsonCount(2, 'data.selectors') ->assertJsonPath('data.selectors.0.key', 'sector') ->assertJsonCount(2, 'data.selectors.0.options')