test(catalog): cover partial variant option resolution
This commit is contained in:
@@ -296,6 +296,64 @@ class CatalogItemDetailControllerTest extends TestCase
|
||||
->assertJsonPath('data.attributes.0.show_in_selector', false);
|
||||
}
|
||||
|
||||
public function test_it_resolves_available_variant_options_from_partial_selections(): void
|
||||
{
|
||||
$tenant = $this->createTenant('variant-options');
|
||||
$item = $this->createItem($tenant, 'Numbered entry');
|
||||
$sector = Attribute::query()->create([
|
||||
'tenant_codigo' => $tenant->codigo,
|
||||
'codigo' => 'sector',
|
||||
'nombre' => 'Sector',
|
||||
'type' => FieldType::Select,
|
||||
]);
|
||||
$seat = Attribute::query()->create([
|
||||
'tenant_codigo' => $tenant->codigo,
|
||||
'codigo' => 'seat',
|
||||
'nombre' => 'Seat',
|
||||
'type' => FieldType::Select,
|
||||
]);
|
||||
$itemSector = $item->itemAttributes()->create([
|
||||
'attribute_id' => $sector->id,
|
||||
'sort_order' => 0,
|
||||
]);
|
||||
$itemSeat = $item->itemAttributes()->create([
|
||||
'attribute_id' => $seat->id,
|
||||
'sort_order' => 1,
|
||||
]);
|
||||
$first = $this->createVariant($item, 1, 0);
|
||||
$second = $this->createVariant($item, 1, 0);
|
||||
$third = $this->createVariant($item, 1, 0);
|
||||
|
||||
foreach ([[$first, 'A', '1'], [$second, 'A', '2'], [$third, 'B', '3']] as [$variant, $sectorValue, $seatValue]) {
|
||||
$variant->definitions()->createMany([
|
||||
['item_attribute_id' => $itemSector->id, 'value' => $sectorValue],
|
||||
['item_attribute_id' => $itemSeat->id, 'value' => $seatValue],
|
||||
]);
|
||||
}
|
||||
|
||||
$this->postJson(
|
||||
"/api/tenants/{$tenant->codigo}/catalog-items/{$item->id}/variant-options",
|
||||
[
|
||||
'selected_values' => ['sector' => 'A'],
|
||||
'excluded_variant_ids' => [$second->id],
|
||||
],
|
||||
)
|
||||
->assertOk()
|
||||
->assertJsonPath('data.valid', true)
|
||||
->assertJsonPath('data.resolved_variant_id', null)
|
||||
->assertJsonCount(2, 'data.variants')
|
||||
->assertJsonCount(1, 'data.options.sector')
|
||||
->assertJsonCount(1, 'data.options.seat')
|
||||
->assertJsonPath('data.options.seat.0.value', '1');
|
||||
|
||||
$this->postJson(
|
||||
"/api/tenants/{$tenant->codigo}/catalog-items/{$item->id}/variant-options",
|
||||
['selected_values' => ['sector' => 'A', 'seat' => '1']],
|
||||
)
|
||||
->assertOk()
|
||||
->assertJsonPath('data.resolved_variant_id', $first->id);
|
||||
}
|
||||
|
||||
private function createItem(
|
||||
Tenant $tenant,
|
||||
string $name,
|
||||
|
||||
Reference in New Issue
Block a user