Add tests for ticket validity and event date formatting

- Create TicketValiditySchemaTest to verify database schema for ticket validity.
- Update CatalogModelsTest to include tests for event date attributes and selection options.
- Introduce EventDateTextFormatterTest for formatting event dates in Spanish.
- Refactor EventModelsTest to include validity time relationships.
- Add SaleDetailResourceTest to ensure correct serialization of purchase items.
- Enhance TicketTest with validity time checks and status management.
- Implement ValidityTimeResourceTest to validate resource output for different validity types.
- Add ValidityTimeTest to verify casting and validity checks for validity time types.
This commit is contained in:
2026-08-11 12:41:35 -03:00
parent b294e5c46e
commit 02cf3f3773
166 changed files with 10203 additions and 1849 deletions

View File

@@ -45,7 +45,7 @@ class CatalogItemDetailControllerTest extends TestCase
$this->assertStringContainsString($itemImage->path, $response->json('data.images.0'));
}
public function test_it_selects_the_first_variant_and_returns_its_images_by_default(): void
public function test_it_filters_unavailable_variants_and_selects_the_first_available_one(): void
{
Storage::fake('s3');
$tenant = $this->createTenant('detail-default');
@@ -66,14 +66,21 @@ class CatalogItemDetailControllerTest extends TestCase
$response
->assertOk()
->assertJsonPath('data.selected_variant.id', $firstVariant->id)
->assertJsonPath('data.selected_variant.stock_tecnico', 0)
->assertJsonCount(1, 'data.variants')
->assertJsonPath('data.variants.0.id', $secondVariant->id)
->assertJsonPath('data.selected_variant.id', $secondVariant->id)
->assertJsonPath('data.selected_variant.stock_tecnico', 6)
->assertJsonCount(1, 'data.selected_variant.images');
$response
->assertJsonMissingPath('data.stock_tecnico')
->assertJsonMissingPath('data.images');
$this->assertStringContainsString($firstImage->path, $response->json('data.selected_variant.images.0'));
$this->assertStringContainsString($secondImage->path, $response->json('data.selected_variant.images.0'));
$this->assertStringNotContainsString($firstImage->path, $response->json('data.selected_variant.images.0'));
$this->assertStringNotContainsString($itemImage->path, $response->json('data.selected_variant.images.0'));
$this->getJson(
"/api/tenants/{$tenant->codigo}/catalog-items/{$item->id}?variant_id={$firstVariant->id}"
)->assertNotFound();
}
public function test_it_selects_the_requested_variant_and_lists_variant_values_and_stock(): void
@@ -117,17 +124,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')
@@ -170,6 +180,102 @@ 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',
]);
$unusedEventDate = $tenant->eventDates()->create([
'date' => '2026-10-10',
'time_start' => '10:00',
'time_end' => '19:00',
]);
$item = $this->createItem($tenant, 'Entry');
$attribute = Attribute::query()->create([
'tenant_codigo' => $tenant->codigo,
'codigo' => 'event_date',
'nombre' => 'Fecha',
'is_required' => true,
'type' => FieldType::EventDate,
]);
$item->itemAttributes()->create(['attribute_id' => $attribute->id]);
$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', $attribute->id)
->assertJsonPath('data.attributes.0.codigo', 'event_date')
->assertJsonPath('data.attributes.0.type', 'event_date')
->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')
->assertJsonPath('data.attributes.0.options.0.validity_time_id', $eventDate->validity_time_id)
->assertJsonPath('data.attributes.0.options.0.validity_time.type', 'fixed_window')
->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.value', (string) $eventDate->id)
->assertJsonPath(
'data.variants.0.values.event_date.label',
'09/10/2026',
);
$this->assertDatabaseCount('attribute_options', 0);
}
public function test_it_orders_item_attributes_by_sort_order_and_then_attribute_label(): void
{
$tenant = $this->createTenant('detail-attribute-order');
$item = $this->createItem($tenant, 'Ordered attributes');
$variant = $this->createVariant($item, 10, 0);
$attributes = collect([
['code' => 'zeta', 'label' => 'Zeta', 'sort_order' => 2],
['code' => 'priority', 'label' => 'Priority', 'sort_order' => 1],
['code' => 'alpha', 'label' => 'Alpha', 'sort_order' => 2],
])->mapWithKeys(function (array $data) use ($tenant, $item): array {
$attribute = Attribute::query()->create([
'tenant_codigo' => $tenant->codigo,
'codigo' => $data['code'],
'nombre' => $data['label'],
'type' => FieldType::String,
]);
$itemAttribute = $item->itemAttributes()->create([
'attribute_id' => $attribute->id,
'sort_order' => $data['sort_order'],
]);
return [$data['code'] => $itemAttribute];
});
foreach (['zeta', 'priority', 'alpha'] as $code) {
$variant->definitions()->create([
'item_attribute_id' => $attributes[$code]->id,
'value' => $code,
]);
}
$response = $this->getJson("/api/tenants/{$tenant->codigo}/catalog-items/{$item->id}")
->assertOk()
->assertJsonPath('data.attributes.0.codigo', 'priority')
->assertJsonPath('data.attributes.0.sort_order', 1)
->assertJsonPath('data.attributes.1.codigo', 'alpha')
->assertJsonPath('data.attributes.2.codigo', 'zeta');
$this->assertSame(
['priority', 'alpha', 'zeta'],
array_keys($response->json('data.variants.0.values')),
);
}
private function createItem(
Tenant $tenant,
string $name,