feat(variant): refactor selection values to expose options with labels; update related resources and tests for consistency
This commit is contained in:
@@ -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