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:
@@ -13,7 +13,6 @@ use App\Domains\Catalog\Services\CatalogService;
|
||||
use App\Domains\Shared\Enums\FieldType;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -94,71 +93,138 @@ class CatalogServiceTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function test_variant_use_dates_override_or_inherit_catalog_item_dates(): void
|
||||
public function test_it_allows_the_same_event_date_with_different_attribute_values(): void
|
||||
{
|
||||
$attribute = $this->createAttribute('day');
|
||||
$itemMinimum = Carbon::parse('2026-08-01 09:00:00');
|
||||
$itemMaximum = Carbon::parse('2026-08-31 18:00:00');
|
||||
$variantMaximum = Carbon::parse('2026-08-15 18:00:00');
|
||||
$sector = $this->createAttribute('sector');
|
||||
$eventDateAttribute = $this->createAttribute('event_date', FieldType::EventDate);
|
||||
$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' => 'dated-variants',
|
||||
'nombre' => 'Dated variants',
|
||||
'slug' => 'entry-by-sector',
|
||||
'nombre' => 'Entry by sector',
|
||||
'precio' => 100,
|
||||
'minimum_use_date' => $itemMinimum,
|
||||
'maximum_use_date' => $itemMaximum,
|
||||
'attribute_codes' => [$attribute->codigo],
|
||||
'attribute_codes' => [$eventDateAttribute->codigo, $sector->codigo],
|
||||
'variants' => [
|
||||
[
|
||||
'real_stock' => 5,
|
||||
'maximum_use_date' => $variantMaximum,
|
||||
'values' => [$attribute->codigo => 'Saturday'],
|
||||
'event_date_id' => $eventDate->id,
|
||||
'values' => ['sector' => 'General'],
|
||||
],
|
||||
[
|
||||
'event_date_id' => $eventDate->id,
|
||||
'values' => ['sector' => 'VIP'],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$variant = $item->variants->firstOrFail();
|
||||
|
||||
$this->assertNull($variant->minimum_use_date);
|
||||
$this->assertTrue($variant->maximum_use_date->equalTo($variantMaximum));
|
||||
$this->assertTrue($variant->getMinimumUseDate()->equalTo($itemMinimum));
|
||||
$this->assertTrue($variant->getMaximumUseDate()->equalTo($variantMaximum));
|
||||
$this->assertCount(2, $item->variants);
|
||||
$this->assertSame(
|
||||
[$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_an_invalid_effective_variant_use_date_range(): void
|
||||
public function test_it_creates_a_variant_with_multiple_event_dates(): void
|
||||
{
|
||||
$attribute = $this->createAttribute('day');
|
||||
$eventDateAttribute = $this->createAttribute('event_date', FieldType::EventDate);
|
||||
$firstDate = $this->tenant->eventDates()->create([
|
||||
'date' => '2026-10-09',
|
||||
'time_start' => '00:00:00',
|
||||
'time_end' => '23:59:59',
|
||||
]);
|
||||
$secondDate = $this->tenant->eventDates()->create([
|
||||
'date' => '2026-10-10',
|
||||
'time_start' => '00:00:00',
|
||||
'time_end' => '23:59:59',
|
||||
]);
|
||||
|
||||
$item = $this->service->create([
|
||||
'tenant_code' => $this->tenant->codigo,
|
||||
'slug' => 'multi-date-pass',
|
||||
'nombre' => 'Multi-date pass',
|
||||
'precio' => 100,
|
||||
'attribute_codes' => [$eventDateAttribute->codigo],
|
||||
'multi_select_attribute_codes' => ['event_date'],
|
||||
'variants' => [[
|
||||
'real_stock' => 5,
|
||||
'event_date_ids' => [$secondDate->id, $firstDate->id],
|
||||
]],
|
||||
]);
|
||||
|
||||
$variant = $item->variants->sole();
|
||||
$this->assertNull($variant->event_date_id);
|
||||
$this->assertSame([$firstDate->id, $secondDate->id], $variant->eventDates->pluck('id')->all());
|
||||
$this->assertSame(
|
||||
[(string) $firstDate->id, (string) $secondDate->id],
|
||||
$variant->selectionValues()->get('event_date'),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_it_creates_multiple_values_for_any_multi_select_attribute(): void
|
||||
{
|
||||
$color = $this->createAttribute('color', FieldType::Select);
|
||||
$color->options()->createMany([
|
||||
['value' => 'Green', 'label' => 'Green', 'sort_order' => 1],
|
||||
['value' => 'White', 'label' => 'White', 'sort_order' => 2],
|
||||
]);
|
||||
|
||||
$item = $this->service->create([
|
||||
'tenant_code' => $this->tenant->codigo,
|
||||
'slug' => 'multi-color-shirt',
|
||||
'nombre' => 'Multi-color shirt',
|
||||
'precio' => 100,
|
||||
'attribute_codes' => ['color'],
|
||||
'multi_select_attribute_codes' => ['color'],
|
||||
'variants' => [[
|
||||
'real_stock' => 5,
|
||||
'values' => ['color' => ['White', 'Green']],
|
||||
]],
|
||||
]);
|
||||
|
||||
$variant = $item->variants->sole();
|
||||
$this->assertSame(['White', 'Green'], $variant->definitions->pluck('value')->all());
|
||||
$this->assertSame(['White', 'Green'], $variant->selectionValues()->get('color'));
|
||||
}
|
||||
|
||||
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',
|
||||
'time_end' => '18:00',
|
||||
]);
|
||||
|
||||
try {
|
||||
$this->service->create([
|
||||
'tenant_code' => $this->tenant->codigo,
|
||||
'slug' => 'invalid-dated-variant',
|
||||
'nombre' => 'Invalid dated variant',
|
||||
'slug' => 'duplicate-entry',
|
||||
'nombre' => 'Duplicate entry',
|
||||
'precio' => 100,
|
||||
'minimum_use_date' => '2026-08-10 09:00:00',
|
||||
'maximum_use_date' => '2026-08-31 18:00:00',
|
||||
'attribute_codes' => [$attribute->codigo],
|
||||
'attribute_codes' => [$eventDateAttribute->codigo, $sector->codigo],
|
||||
'variants' => [
|
||||
[
|
||||
'real_stock' => 5,
|
||||
'maximum_use_date' => '2026-08-09 18:00:00',
|
||||
'values' => [$attribute->codigo => 'Saturday'],
|
||||
],
|
||||
['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.0.maximum_use_date',
|
||||
$exception->errors(),
|
||||
);
|
||||
$this->assertArrayHasKey('variants.1', $exception->errors());
|
||||
}
|
||||
|
||||
$this->assertDatabaseMissing('catalog_items', [
|
||||
'slug' => 'invalid-dated-variant',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_it_rejects_direct_inventory_together_with_variants(): void
|
||||
@@ -283,13 +349,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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user