feat(variant): refactor selection values to expose options with labels; update related resources and tests for consistency
This commit is contained in:
@@ -117,17 +117,20 @@ class CatalogItemDetailControllerTest extends TestCase
|
||||
->assertOk()
|
||||
->assertJsonPath('data.variants.0.id', $firstVariant->id)
|
||||
->assertJsonPath('data.variants.0.stock_tecnico', 4)
|
||||
->assertJsonPath('data.variants.0.values.size', 'S')
|
||||
->assertJsonPath('data.variants.0.values.size.value', 'S')
|
||||
->assertJsonPath('data.variants.0.values.size.label', 'Small')
|
||||
->assertJsonPath('data.variants.1.id', $secondVariant->id)
|
||||
->assertJsonPath('data.variants.1.stock_tecnico', 7)
|
||||
->assertJsonPath('data.variants.1.values.size', 'M')
|
||||
->assertJsonPath('data.variants.1.values.size.value', 'M')
|
||||
->assertJsonPath('data.variants.1.values.size.label', 'Medium')
|
||||
->assertJsonPath('data.attributes.0.codigo', 'size')
|
||||
->assertJsonPath('data.attributes.0.options.0.value', 'S')
|
||||
->assertJsonPath('data.attributes.0.options.1.value', 'M')
|
||||
->assertJsonCount(2, 'data.attributes.0.options')
|
||||
->assertJsonPath('data.selected_variant.id', $secondVariant->id)
|
||||
->assertJsonPath('data.selected_variant.stock_tecnico', 7)
|
||||
->assertJsonPath('data.selected_variant.values.size', 'M')
|
||||
->assertJsonPath('data.selected_variant.values.size.value', 'M')
|
||||
->assertJsonPath('data.selected_variant.values.size.label', 'Medium')
|
||||
->assertJsonCount(1, 'data.selected_variant.images');
|
||||
$response
|
||||
->assertJsonMissingPath('data.stock_tecnico')
|
||||
@@ -207,10 +210,14 @@ class CatalogItemDetailControllerTest extends TestCase
|
||||
->assertJsonCount(2, 'data.attributes.0.options')
|
||||
->assertJsonPath('data.attributes.0.options.0.id', $eventDate->id)
|
||||
->assertJsonPath('data.attributes.0.options.0.value', (string) $eventDate->id)
|
||||
->assertJsonPath('data.attributes.0.options.0.label', '09/10/2026 · 09:00 a 18:00')
|
||||
->assertJsonPath('data.attributes.0.options.0.label', '09/10/2026')
|
||||
->assertJsonPath('data.attributes.0.options.1.id', $unusedEventDate->id)
|
||||
->assertJsonPath('data.attributes.0.options.1.value', (string) $unusedEventDate->id)
|
||||
->assertJsonPath('data.variants.0.values.event_date', (string) $eventDate->id);
|
||||
->assertJsonPath('data.variants.0.values.event_date.value', (string) $eventDate->id)
|
||||
->assertJsonPath(
|
||||
'data.variants.0.values.event_date.label',
|
||||
'09/10/2026',
|
||||
);
|
||||
|
||||
$this->assertDatabaseCount('attribute_options', 0);
|
||||
}
|
||||
|
||||
@@ -186,6 +186,43 @@ class CatalogModelsTest extends TestCase
|
||||
$this->assertSame('2026-10-09', $variant->eventDate->date->format('Y-m-d'));
|
||||
}
|
||||
|
||||
public function test_variant_exposes_selection_values_with_api_labels(): void
|
||||
{
|
||||
$attribute = new Attribute;
|
||||
$attribute->codigo = 'size';
|
||||
$attribute->setRelation('options', new EloquentCollection([
|
||||
new AttributeOption(['value' => 'M', 'label' => 'Medium']),
|
||||
]));
|
||||
|
||||
$itemAttribute = new ItemAttribute;
|
||||
$itemAttribute->allow_multi_select = false;
|
||||
$itemAttribute->setRelation('attribute', $attribute);
|
||||
|
||||
$definition = new VariantDefinition(['value' => 'M']);
|
||||
$definition->item_attribute_id = 1;
|
||||
$definition->setRelation('itemAttribute', $itemAttribute);
|
||||
|
||||
$eventDate = new EventDate([
|
||||
'date' => '2026-10-09',
|
||||
'time_start' => '09:00:00',
|
||||
'time_end' => '18:00:00',
|
||||
]);
|
||||
$eventDate->id = 20;
|
||||
|
||||
$variant = new Variant;
|
||||
$variant->setRelation('definitions', new EloquentCollection([$definition]));
|
||||
$variant->setRelation('eventDates', new EloquentCollection([$eventDate]));
|
||||
|
||||
$this->assertSame(
|
||||
['value' => 'M', 'label' => 'Medium'],
|
||||
$variant->selectionOptions()->get('size'),
|
||||
);
|
||||
$this->assertSame(
|
||||
['value' => '20', 'label' => '09/10/2026'],
|
||||
$variant->selectionOptions()->get('event_date'),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_inventory_maps_stock_without_a_polymorphic_owner(): void
|
||||
{
|
||||
$inventory = $this->trackedInventory(realStock: 10, reservedStock: 3);
|
||||
|
||||
Reference in New Issue
Block a user