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:
@@ -4,7 +4,6 @@ namespace Tests\Unit\Catalog;
|
||||
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Catalog\Enums\CatalogItemType;
|
||||
use App\Domains\Catalog\Enums\EventProductType;
|
||||
use App\Domains\Catalog\Enums\FeaturedGroupSource;
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Catalog\Enums\InventoryPolicy;
|
||||
@@ -21,13 +20,11 @@ use App\Domains\Catalog\Models\Inventory;
|
||||
use App\Domains\Catalog\Models\ItemAttribute;
|
||||
use App\Domains\Catalog\Models\Variant;
|
||||
use App\Domains\Catalog\Models\VariantDefinition;
|
||||
use App\Domains\Event\Models\Event;
|
||||
use App\Domains\Event\Models\EventDate;
|
||||
use App\Domains\Shared\Enums\FieldType;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use App\Domains\Ticket\Models\Ticket;
|
||||
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CatalogModelsTest extends TestCase
|
||||
@@ -59,6 +56,18 @@ class CatalogModelsTest extends TestCase
|
||||
$this->assertInstanceOf(AttributeOption::class, $attribute->options()->getRelated());
|
||||
}
|
||||
|
||||
public function test_event_date_is_an_attribute_type_with_dynamic_options(): void
|
||||
{
|
||||
$attribute = new Attribute;
|
||||
$attribute->type = FieldType::EventDate->value;
|
||||
|
||||
$this->assertSame(FieldType::EventDate, $attribute->type);
|
||||
$this->assertTrue($attribute->type->supportsOptions());
|
||||
$this->assertTrue($attribute->type->usesDynamicOptions());
|
||||
$this->assertContains('event_date', FieldType::values());
|
||||
$this->assertInstanceOf(EventDate::class, $attribute->eventDates()->getRelated());
|
||||
}
|
||||
|
||||
public function test_catalog_item_is_the_catalog_root(): void
|
||||
{
|
||||
$item = new CatalogItem;
|
||||
@@ -66,8 +75,6 @@ class CatalogModelsTest extends TestCase
|
||||
'category_id' => '10',
|
||||
'brand_id' => '20',
|
||||
'inventory_id' => '30',
|
||||
'event_id' => '40',
|
||||
'event_product_type' => EventProductType::Entry->value,
|
||||
'type' => CatalogItemType::Standard->value,
|
||||
'precio' => '12.50',
|
||||
'inventory_policy' => InventoryPolicy::Tracked->value,
|
||||
@@ -79,14 +86,11 @@ class CatalogModelsTest extends TestCase
|
||||
$this->assertSame(10, $item->category_id);
|
||||
$this->assertSame(20, $item->brand_id);
|
||||
$this->assertSame(30, $item->inventory_id);
|
||||
$this->assertSame(40, $item->event_id);
|
||||
$this->assertSame(EventProductType::Entry, $item->event_product_type);
|
||||
$this->assertSame(CatalogItemType::Standard, $item->type);
|
||||
$this->assertSame('12.50', $item->precio);
|
||||
$this->assertSame(InventoryPolicy::Tracked, $item->inventory_policy);
|
||||
$this->assertTrue($item->has_tickets);
|
||||
$this->assertInstanceOf(Tenant::class, $item->tenant()->getRelated());
|
||||
$this->assertInstanceOf(Event::class, $item->event()->getRelated());
|
||||
$this->assertInstanceOf(Category::class, $item->category()->getRelated());
|
||||
$this->assertInstanceOf(Brand::class, $item->brand()->getRelated());
|
||||
$this->assertInstanceOf(Inventory::class, $item->inventory()->getRelated());
|
||||
@@ -160,24 +164,6 @@ class CatalogModelsTest extends TestCase
|
||||
$this->assertSame('catalog_items_attachments', $variant->attachments()->getTable());
|
||||
}
|
||||
|
||||
public function test_variant_use_dates_override_or_inherit_catalog_item_dates(): void
|
||||
{
|
||||
$item = new CatalogItem;
|
||||
$item->minimum_use_date = Carbon::parse('2026-08-01 09:00:00');
|
||||
$item->maximum_use_date = Carbon::parse('2026-08-31 18:00:00');
|
||||
|
||||
$variant = new Variant;
|
||||
$variant->maximum_use_date = Carbon::parse('2026-08-15 18:00:00');
|
||||
$variant->setRelation('catalogItem', $item);
|
||||
|
||||
$this->assertTrue(
|
||||
$variant->getMinimumUseDate()->equalTo($item->minimum_use_date),
|
||||
);
|
||||
$this->assertTrue(
|
||||
$variant->getMaximumUseDate()->equalTo($variant->maximum_use_date),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_event_date_identifies_a_variant_without_catalog_attributes(): void
|
||||
{
|
||||
$item = new CatalogItem;
|
||||
@@ -189,15 +175,86 @@ class CatalogModelsTest extends TestCase
|
||||
$eventDate->time_end = '18:00:00';
|
||||
|
||||
$variant = new Variant;
|
||||
$variant->minimum_use_date = Carbon::parse('2026-10-09 08:00:00');
|
||||
$variant->maximum_use_date = Carbon::parse('2026-10-09 20:00:00');
|
||||
$variant->setRelation('catalogItem', $item);
|
||||
$variant->setRelation('eventDate', $eventDate);
|
||||
$variant->setRelation('definitions', new EloquentCollection);
|
||||
|
||||
$this->assertSame('Entrada General', $variant->getName());
|
||||
$this->assertSame('2026-10-09 09:00:00', $variant->getMinimumUseDate()->format('Y-m-d H:i:s'));
|
||||
$this->assertSame('2026-10-09 18:00:00', $variant->getMaximumUseDate()->format('Y-m-d H:i:s'));
|
||||
$this->assertSame('2026-10-09', $variant->eventDate->date->format('Y-m-d'));
|
||||
}
|
||||
|
||||
public function test_variant_exposes_selection_values_with_api_labels(): void
|
||||
{
|
||||
$attribute = new Attribute;
|
||||
$attribute->codigo = 'size';
|
||||
$attribute->setRelation('options', new EloquentCollection([
|
||||
new AttributeOption(['value' => 'M', 'label' => 'Medium']),
|
||||
]));
|
||||
|
||||
$itemAttribute = new ItemAttribute;
|
||||
$itemAttribute->allow_multi_select = false;
|
||||
$itemAttribute->setRelation('attribute', $attribute);
|
||||
|
||||
$definition = new VariantDefinition(['value' => 'M']);
|
||||
$definition->item_attribute_id = 1;
|
||||
$definition->setRelation('itemAttribute', $itemAttribute);
|
||||
|
||||
$eventDate = new EventDate([
|
||||
'date' => '2026-10-09',
|
||||
'time_start' => '09:00:00',
|
||||
'time_end' => '18:00:00',
|
||||
]);
|
||||
$eventDate->id = 20;
|
||||
|
||||
$variant = new Variant;
|
||||
$variant->setRelation('definitions', new EloquentCollection([$definition]));
|
||||
$variant->setRelation('eventDates', new EloquentCollection([$eventDate]));
|
||||
|
||||
$this->assertSame(
|
||||
['value' => 'M', 'label' => 'Medium'],
|
||||
$variant->selectionOptions()->get('size'),
|
||||
);
|
||||
$this->assertSame(
|
||||
['value' => '20', 'label' => '09/10/2026'],
|
||||
$variant->selectionOptions()->get('event_date'),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_variant_orders_selection_options_by_item_order_and_attribute_label(): void
|
||||
{
|
||||
$definitions = collect([
|
||||
['id' => 1, 'code' => 'zeta', 'label' => 'Zeta', 'sort_order' => 2],
|
||||
['id' => 2, 'code' => 'priority', 'label' => 'Priority', 'sort_order' => 1],
|
||||
['id' => 3, 'code' => 'alpha', 'label' => 'Alpha', 'sort_order' => 2],
|
||||
])->map(function (array $data): VariantDefinition {
|
||||
$attribute = new Attribute([
|
||||
'codigo' => $data['code'],
|
||||
'nombre' => $data['label'],
|
||||
]);
|
||||
$attribute->setRelation('options', new EloquentCollection);
|
||||
|
||||
$itemAttribute = new ItemAttribute([
|
||||
'sort_order' => $data['sort_order'],
|
||||
'allow_multi_select' => false,
|
||||
]);
|
||||
$itemAttribute->id = $data['id'];
|
||||
$itemAttribute->setRelation('attribute', $attribute);
|
||||
|
||||
$definition = new VariantDefinition(['value' => $data['code']]);
|
||||
$definition->item_attribute_id = $itemAttribute->id;
|
||||
$definition->setRelation('itemAttribute', $itemAttribute);
|
||||
|
||||
return $definition;
|
||||
});
|
||||
|
||||
$variant = new Variant;
|
||||
$variant->setRelation('definitions', new EloquentCollection($definitions));
|
||||
$variant->setRelation('eventDates', new EloquentCollection);
|
||||
|
||||
$this->assertSame(
|
||||
['priority', 'alpha', 'zeta'],
|
||||
$variant->selectionOptions()->keys()->all(),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_inventory_maps_stock_without_a_polymorphic_owner(): void
|
||||
@@ -226,6 +283,27 @@ class CatalogModelsTest extends TestCase
|
||||
$this->assertTrue($item->isAvailable());
|
||||
}
|
||||
|
||||
public function test_catalog_item_only_exposes_available_tracked_variants(): void
|
||||
{
|
||||
$unavailable = (new Variant)->setRelation('inventory', $this->trackedInventory(3, 3));
|
||||
$available = (new Variant)->setRelation('inventory', $this->trackedInventory(5, 2));
|
||||
$unavailable->id = 10;
|
||||
$available->id = 20;
|
||||
$item = new CatalogItem;
|
||||
$item->inventory_policy = InventoryPolicy::Tracked;
|
||||
$item->setRelation('variants', new EloquentCollection([$unavailable, $available]));
|
||||
|
||||
$this->assertSame([$available], $item->visibleVariants()->all());
|
||||
$this->assertSame(
|
||||
[$unavailable, $available],
|
||||
$item->visibleVariants($unavailable->id)->all(),
|
||||
);
|
||||
|
||||
$item->inventory_policy = InventoryPolicy::Unlimited;
|
||||
|
||||
$this->assertSame([$unavailable, $available], $item->visibleVariants()->all());
|
||||
}
|
||||
|
||||
public function test_catalog_item_prioritizes_its_inventory_over_variants(): void
|
||||
{
|
||||
$item = new CatalogItem;
|
||||
|
||||
Reference in New Issue
Block a user