refactor(catalog): add event date attribute with dynamic options and update related logic

This commit is contained in:
2026-08-07 10:03:31 -03:00
parent 14d53d1e0b
commit 717ee5d194
11 changed files with 224 additions and 86 deletions

View File

@@ -96,6 +96,7 @@ class CatalogServiceTest extends TestCase
public function test_it_allows_the_same_event_date_with_different_attribute_values(): void
{
$sector = $this->createAttribute('sector');
$eventDateAttribute = $this->createAttribute('event_date', FieldType::EventDate);
$eventDate = $this->tenant->eventDates()->create([
'date' => '2026-10-09',
'time_start' => '09:00',
@@ -107,7 +108,7 @@ class CatalogServiceTest extends TestCase
'slug' => 'entry-by-sector',
'nombre' => 'Entry by sector',
'precio' => 100,
'attribute_codes' => [$sector->codigo],
'attribute_codes' => [$eventDateAttribute->codigo, $sector->codigo],
'variants' => [
[
'event_date_id' => $eventDate->id,
@@ -125,11 +126,20 @@ class CatalogServiceTest extends TestCase
[$eventDate->id, $eventDate->id],
$item->variants->pluck('event_date_id')->all(),
);
$this->assertSame(
['event_date', 'sector'],
$item->itemAttributes->pluck('attribute.codigo')->all(),
);
$this->assertSame(
FieldType::EventDate,
$item->itemAttributes->first()->attribute->type,
);
}
public function test_it_rejects_duplicate_variant_combinations(): void
{
$sector = $this->createAttribute('sector');
$eventDateAttribute = $this->createAttribute('event_date', FieldType::EventDate);
$eventDate = $this->tenant->eventDates()->create([
'date' => '2026-10-09',
'time_start' => '09:00',
@@ -142,7 +152,7 @@ class CatalogServiceTest extends TestCase
'slug' => 'duplicate-entry',
'nombre' => 'Duplicate entry',
'precio' => 100,
'attribute_codes' => [$sector->codigo],
'attribute_codes' => [$eventDateAttribute->codigo, $sector->codigo],
'variants' => [
['event_date_id' => $eventDate->id, 'values' => ['sector' => 'VIP']],
['event_date_id' => $eventDate->id, 'values' => ['sector' => ' vip ']],
@@ -277,13 +287,15 @@ class CatalogServiceTest extends TestCase
]);
}
private function createAttribute(string $code): Attribute
{
private function createAttribute(
string $code,
FieldType $type = FieldType::String,
): Attribute {
return Attribute::query()->create([
'tenant_codigo' => $this->tenant->codigo,
'codigo' => $code,
'nombre' => ucfirst($code),
'type' => FieldType::String,
'type' => $type,
]);
}
}