refactor(event): move event configuration onto tenant
This commit is contained in:
@@ -170,6 +170,33 @@ class CatalogItemDetailControllerTest extends TestCase
|
||||
->assertJsonPath('data.variants.0.stock_tecnico', null);
|
||||
}
|
||||
|
||||
public function test_it_exposes_event_dates_as_a_dynamic_variant_attribute(): void
|
||||
{
|
||||
$tenant = $this->createTenant('detail-event-date');
|
||||
$tenant->update([
|
||||
'event_title' => 'Festival',
|
||||
'event_location' => 'Rosario',
|
||||
]);
|
||||
$eventDate = $tenant->eventDates()->create([
|
||||
'date' => '2026-10-09',
|
||||
'time_start' => '09:00',
|
||||
'time_end' => '18:00',
|
||||
]);
|
||||
$item = $this->createItem($tenant, 'Entry');
|
||||
$variant = $this->createVariant($item, 10, 0);
|
||||
$variant->update(['event_date_id' => $eventDate->id]);
|
||||
|
||||
$this->getJson("/api/tenants/{$tenant->codigo}/catalog-items/{$item->id}")
|
||||
->assertOk()
|
||||
->assertJsonPath('data.attributes.0.id', -1)
|
||||
->assertJsonPath('data.attributes.0.codigo', 'event_date')
|
||||
->assertJsonPath('data.attributes.0.type', 'event_date')
|
||||
->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.variants.0.values.event_date', (string) $eventDate->id);
|
||||
}
|
||||
|
||||
private function createItem(
|
||||
Tenant $tenant,
|
||||
string $name,
|
||||
|
||||
@@ -32,7 +32,6 @@ class CatalogSchemaTest extends TestCase
|
||||
$this->assertEqualsCanonicalizing([
|
||||
'id',
|
||||
'tenant_code',
|
||||
'event_id',
|
||||
'event_product_type',
|
||||
'category_id',
|
||||
'brand_id',
|
||||
@@ -186,21 +185,21 @@ class CatalogSchemaTest extends TestCase
|
||||
]));
|
||||
}
|
||||
|
||||
public function test_events_and_event_dates_are_linked_to_the_catalog(): void
|
||||
public function test_event_configuration_and_dates_belong_to_the_tenant(): void
|
||||
{
|
||||
$this->assertFalse(Schema::hasTable('events'));
|
||||
$this->assertTrue(Schema::hasColumns('tenants', [
|
||||
'event_title',
|
||||
'event_location',
|
||||
]));
|
||||
$this->assertEqualsCanonicalizing([
|
||||
'id',
|
||||
'tenant_code',
|
||||
'name',
|
||||
'address',
|
||||
], Schema::getColumnListing('events'));
|
||||
$this->assertEqualsCanonicalizing([
|
||||
'id',
|
||||
'event_id',
|
||||
'date',
|
||||
'time_start',
|
||||
'time_end',
|
||||
], Schema::getColumnListing('event_dates'));
|
||||
$this->assertTrue(Schema::hasColumn('tenants', 'active_event_id'));
|
||||
$this->assertFalse(Schema::hasColumn('catalog_items', 'event_id'));
|
||||
$this->assertFalse(Schema::hasColumn('compras', 'event_id'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,6 +93,68 @@ class CatalogServiceTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function test_it_allows_the_same_event_date_with_different_attribute_values(): void
|
||||
{
|
||||
$sector = $this->createAttribute('sector');
|
||||
$eventDate = $this->tenant->eventDates()->create([
|
||||
'date' => '2026-10-09',
|
||||
'time_start' => '09:00',
|
||||
'time_end' => '18:00',
|
||||
]);
|
||||
|
||||
$item = $this->service->create([
|
||||
'tenant_code' => $this->tenant->codigo,
|
||||
'slug' => 'entry-by-sector',
|
||||
'nombre' => 'Entry by sector',
|
||||
'precio' => 100,
|
||||
'attribute_codes' => [$sector->codigo],
|
||||
'variants' => [
|
||||
[
|
||||
'event_date_id' => $eventDate->id,
|
||||
'values' => ['sector' => 'General'],
|
||||
],
|
||||
[
|
||||
'event_date_id' => $eventDate->id,
|
||||
'values' => ['sector' => 'VIP'],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertCount(2, $item->variants);
|
||||
$this->assertSame(
|
||||
[$eventDate->id, $eventDate->id],
|
||||
$item->variants->pluck('event_date_id')->all(),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_it_rejects_duplicate_variant_combinations(): void
|
||||
{
|
||||
$sector = $this->createAttribute('sector');
|
||||
$eventDate = $this->tenant->eventDates()->create([
|
||||
'date' => '2026-10-09',
|
||||
'time_start' => '09:00',
|
||||
'time_end' => '18:00',
|
||||
]);
|
||||
|
||||
try {
|
||||
$this->service->create([
|
||||
'tenant_code' => $this->tenant->codigo,
|
||||
'slug' => 'duplicate-entry',
|
||||
'nombre' => 'Duplicate entry',
|
||||
'precio' => 100,
|
||||
'attribute_codes' => [$sector->codigo],
|
||||
'variants' => [
|
||||
['event_date_id' => $eventDate->id, 'values' => ['sector' => 'VIP']],
|
||||
['event_date_id' => $eventDate->id, 'values' => ['sector' => ' vip ']],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->fail('A validation exception was not thrown.');
|
||||
} catch (ValidationException $exception) {
|
||||
$this->assertArrayHasKey('variants.1', $exception->errors());
|
||||
}
|
||||
}
|
||||
|
||||
public function test_it_rejects_direct_inventory_together_with_variants(): void
|
||||
{
|
||||
$attribute = $this->createAttribute('size');
|
||||
|
||||
Reference in New Issue
Block a user