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

@@ -5,6 +5,8 @@ namespace Database\Seeders;
use App\Domains\Catalog\Models\Attribute;
use App\Domains\Shared\Enums\FieldType;
use App\Domains\Tenant\Models\Tenant;
use App\Domains\Ticket\Enums\ValidityTimeType;
use App\Domains\Ticket\Models\ValidityTime;
use Illuminate\Database\Seeder;
class AttributeSeeder extends Seeder
@@ -17,12 +19,8 @@ class AttributeSeeder extends Seeder
$tenants = Tenant::all();
foreach ($tenants as $tenant) {
// Event dates replace catalog attributes for Fiesta Futbol Infantil.
if ($tenant->codigo === 'fiesta_futbol_infantil') {
Attribute::query()
->where('tenant_codigo', $tenant->codigo)
->whereIn('codigo', ['color', 'talle', 'talle_numerico', 'fecha'])
->delete();
$this->seedFiestaFutbolInfantilAttributes($tenant);
continue;
}
@@ -91,23 +89,130 @@ class AttributeSeeder extends Seeder
],
]);
// Seed Fecha attribute
// Las opciones de fecha se resuelven dinámicamente desde event_dates.
$this->seedAttribute($tenant, [
'codigo' => 'fecha',
'codigo' => 'event_date',
'nombre' => 'Fecha',
'type' => FieldType::Select->value,
'type' => FieldType::EventDate->value,
'is_required' => true,
'options' => [
['value' => '2026-10-09', 'label' => '09/10/2026', 'sort_order' => 1],
['value' => '2026-10-10', 'label' => '10/10/2026', 'sort_order' => 2],
['value' => '2026-10-11', 'label' => '11/10/2026', 'sort_order' => 3],
['value' => '2026-10-12', 'label' => '12/10/2026', 'sort_order' => 4],
],
]);
}
}
private function seedFiestaFutbolInfantilAttributes(Tenant $tenant): void
{
Attribute::query()
->where('tenant_codigo', $tenant->codigo)
->whereNotIn('codigo', [
'event_date',
'servicio',
'color',
'horario',
'talle',
'tipo_alojamiento',
])
->delete();
$this->seedAttribute($tenant, [
'codigo' => 'event_date',
'nombre' => 'Fecha',
'type' => FieldType::EventDate->value,
'is_required' => true,
]);
$breakfastValidityTime = $this->timeWindow('07:00:00', '12:00:00');
$lunchValidityTime = $this->timeWindow('12:00:00', '15:00:00');
$dinnerValidityTime = $this->timeWindow('20:00:00', '24:00:00');
$this->seedAttribute($tenant, [
'codigo' => 'tipo_alojamiento',
'nombre' => 'TipoAlojamiento',
'type' => FieldType::Select->value,
'is_required' => true,
'options' => [
['value' => 'Carpa', 'label' => 'Carpa', 'sort_order' => 1],
['value' => 'Motorhome', 'label' => 'Motorhome', 'sort_order' => 2],
],
]);
$this->seedAttribute($tenant, [
'codigo' => 'servicio',
'nombre' => 'Servicio',
'type' => FieldType::Select->value,
'is_required' => true,
'options' => [
['value' => 'Comedor', 'label' => 'Comedor', 'sort_order' => 1],
['value' => 'Vianda', 'label' => 'Vianda', 'sort_order' => 2],
],
]);
$this->seedAttribute($tenant, [
'codigo' => 'color',
'nombre' => 'Color',
'type' => FieldType::Select->value,
'is_required' => true,
'metadata_schema' => [
'hex' => ['type' => 'string'],
],
'options' => [
['value' => 'Verde', 'label' => 'Verde', 'sort_order' => 1, 'metadata' => ['hex' => '#00973F']],
['value' => 'Blanco', 'label' => 'Blanco', 'sort_order' => 2, 'metadata' => ['hex' => '#FFFFFF']],
],
]);
$this->seedAttribute($tenant, [
'codigo' => 'horario',
'nombre' => 'Horario',
'type' => FieldType::Select->value,
'is_required' => true,
'options' => [
[
'value' => 'Desayuno',
'label' => 'Desayuno',
'sort_order' => 1,
'validity_time_id' => $breakfastValidityTime->id,
],
[
'value' => 'Almuerzo',
'label' => 'Almuerzo',
'sort_order' => 2,
'validity_time_id' => $lunchValidityTime->id,
],
[
'value' => 'Cena',
'label' => 'Cena',
'sort_order' => 3,
'validity_time_id' => $dinnerValidityTime->id,
],
],
]);
$this->seedAttribute($tenant, [
'codigo' => 'talle',
'nombre' => 'Talle',
'type' => FieldType::Select->value,
'is_required' => true,
'options' => [
['value' => '14', 'label' => '14', 'sort_order' => 1],
['value' => 'S', 'label' => 'S', 'sort_order' => 2],
['value' => 'M', 'label' => 'M', 'sort_order' => 3],
['value' => 'L', 'label' => 'L', 'sort_order' => 4],
['value' => 'XL', 'label' => 'XL', 'sort_order' => 5],
['value' => 'XXL', 'label' => 'XXL', 'sort_order' => 6],
],
]);
}
private function timeWindow(string $startTime, string $endTime): ValidityTime
{
return ValidityTime::query()->firstOrCreate([
'type' => ValidityTimeType::TimeWindow,
'start_time' => $startTime,
'end_time' => $endTime,
]);
}
/**
* @param array<string, mixed> $data
*/

View File

@@ -2,8 +2,6 @@
namespace Database\Seeders;
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;
@@ -12,8 +10,8 @@ use App\Domains\Catalog\Models\CatalogItem;
use App\Domains\Catalog\Models\Category;
use App\Domains\Catalog\Models\FeaturedGroup;
use App\Domains\Catalog\Services\CatalogService;
use App\Domains\Event\Models\Event;
use App\Domains\Tenant\Models\Tenant;
use App\Domains\Ticket\Enums\TicketGenerationPolicy;
use Illuminate\Database\Seeder;
use RuntimeException;
@@ -30,151 +28,104 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
}
$this->deleteExistingCatalog($tenant);
FeaturedGroup::query()->where('tenant_code', $tenant->codigo)->delete();
Category::query()->where('tenant_code', $tenant->codigo)->update(['categoria_id' => null]);
Category::query()->where('tenant_code', $tenant->codigo)->delete();
$event = Event::query()->updateOrCreate(
[
'tenant_code' => $tenant->codigo,
'name' => 'Fiesta Nacional del Fútbol Infantil',
],
['address' => 'Sunchales, Santa Fe'],
);
$event->dates()->delete();
$categories = collect([
'entradas' => 'Entradas',
'alojamientos' => 'Alojamientos',
'comidas' => 'Comidas',
'merchandising' => 'Merchandising',
])->map(fn (string $name): Category => Category::query()->create([
'nombre' => $name,
'tenant_code' => $tenant->codigo,
]));
$tenant->update([
'event_title' => 'Fiesta Nacional del Fútbol Infantil',
'event_location' => 'Sunchales, Santa Fe',
]);
$tenant->eventDates()->delete();
$eventDates = collect(['2026-10-09', '2026-10-10', '2026-10-11', '2026-10-12'])
->mapWithKeys(function (string $date) use ($event): array {
$eventDate = $event->dates()->create([
'date' => $date,
'time_start' => '00:00:00',
'time_end' => '23:59:59',
]);
->map(fn (string $date) => $tenant->eventDates()->create([
'date' => $date,
'time_start' => '00:00:00',
'time_end' => '23:59:59',
]));
$dateIds = $eventDates->pluck('id')->map(fn ($id): int => (int) $id)->values();
return [$date => $eventDate];
});
$tenant->active_event_id = $event->id;
$tenant->save();
$ticketCategory = Category::query()->firstOrCreate([
'nombre' => 'Entradas',
'tenant_code' => $tenant->codigo,
]);
$foodCategory = Category::query()->firstOrCreate([
'nombre' => 'Gastronomía',
'tenant_code' => $tenant->codigo,
]);
$mealCategory = Category::query()->updateOrCreate([
'nombre' => 'Comidas',
'tenant_code' => $tenant->codigo,
], [
'categoria_id' => $foodCategory->id,
]);
$drinkCategory = Category::query()->updateOrCreate([
'nombre' => 'Bebidas',
'tenant_code' => $tenant->codigo,
], [
'categoria_id' => $foodCategory->id,
]);
$parkingCategory = Category::query()->firstOrCreate([
'nombre' => 'Estacionamiento',
'tenant_code' => $tenant->codigo,
$this->createProduct($tenant, [
'slug' => 'camiseta',
'nombre' => 'Camiseta',
'category_id' => $categories['merchandising']->id,
'precio' => 18000,
'attribute_codes' => ['color', 'talle'],
'variants' => collect(['Verde', 'Blanco'])
->crossJoin(['14', 'S', 'M', 'L', 'XL', 'XXL'])
->map(fn (array $values, int $index): array => [
'real_stock' => [24, 3, 18, 0, 12, 2, 25, 0, 14, 1, 19, 8][$index],
'values' => ['color' => $values[0], 'talle' => $values[1]],
])->all(),
]);
$dates = $eventDates->keys()->all();
$minimumUseDate = $dates[0].' 00:00:00';
$maximumUseDate = $dates[array_key_last($dates)].' 23:59:59';
$generalAdmission = $this->catalogService->create([
'tenant_code' => $tenant->codigo,
'event_id' => $event->id,
'event_product_type' => EventProductType::Entry->value,
'category_id' => $ticketCategory->id,
'slug' => 'entrada-general',
'nombre' => 'Entrada General',
'descripcion' => 'Acceso total al predio. No incluye acceso a estacionamiento. Niños menores de 5 años ingresan gratis.',
'precio' => 10000,
'inventory_policy' => InventoryPolicy::Unlimited->value,
'has_tickets' => true,
'minimum_use_date' => $minimumUseDate,
'maximum_use_date' => $maximumUseDate,
'variants' => array_map(
fn (string $date): array => [
'real_stock' => 0,
'event_date_id' => $eventDates->get($date)->id,
],
$dates,
),
$this->createProduct($tenant, [
'slug' => 'alojamiento',
'nombre' => 'Alojamiento',
'category_id' => $categories['alojamientos']->id,
'precio' => 35000,
'attribute_codes' => ['tipo_alojamiento'],
'variants' => collect(['Carpa', 'Motorhome'])->map(fn (string $type, int $index): array => [
'real_stock' => [0, 3][$index],
'values' => ['tipo_alojamiento' => $type],
])->all(),
]);
$items = [
['slug' => 'hamburguesa-papa-frita', 'nombre' => 'Hamburguesa con papa frita', 'precio' => 8000, 'category_id' => $mealCategory->id],
['slug' => 'pancho', 'nombre' => 'Pancho', 'precio' => 4000, 'category_id' => $mealCategory->id],
['slug' => 'coca-cola-500ml', 'nombre' => 'Coca Cola 500ml', 'precio' => 3000, 'category_id' => $drinkCategory->id],
['slug' => 'agua-mineral-1l', 'nombre' => 'Agua Mineral 1L', 'precio' => 2500, 'category_id' => $drinkCategory->id],
['slug' => 'estacionamiento-auto', 'nombre' => 'Estacionamiento Auto', 'precio' => 5000, 'category_id' => $parkingCategory->id],
['slug' => 'estacionamiento-moto', 'nombre' => 'Estacionamiento Moto', 'precio' => 2000, 'category_id' => $parkingCategory->id],
];
$this->createProduct($tenant, [
'slug' => 'comida',
'nombre' => 'Comida',
'category_id' => $categories['comidas']->id,
'precio' => 4000,
'attribute_codes' => ['event_date', 'horario', 'servicio'],
'variants' => $eventDates
->crossJoin(['Desayuno', 'Almuerzo', 'Cena'], ['Comedor', 'Vianda'])
->map(fn (array $values, int $index): array => [
'real_stock' => [80, 3, 65, 0, 42, 2, 70, 18, 0, 5, 55, 40, 90, 1, 35, 0, 60, 8, 75, 22, 0, 4, 50, 30][$index],
'event_date_ids' => [(int) $values[0]->id],
'descripcion' => sprintf(
'%s del %s - %s',
$values[1],
$values[0]->date->format('d/m/Y'),
$values[2],
),
'precio' => $this->foodPrice($values[1]),
'values' => ['horario' => $values[1], 'servicio' => $values[2]],
])->all(),
]);
$createdItems = [];
foreach ($items as $item) {
$createdItems[$item['slug']] = $this->catalogService->create([
'tenant_code' => $tenant->codigo,
'event_id' => $event->id,
'event_product_type' => EventProductType::Product->value,
'descripcion' => $item['descripcion'] ?? $item['nombre'],
'inventory_policy' => InventoryPolicy::Unlimited->value,
'real_stock' => 0,
'minimum_use_date' => $minimumUseDate,
'maximum_use_date' => $maximumUseDate,
...$item,
]);
}
$this->catalogService->create([
'tenant_code' => $tenant->codigo,
'event_id' => $event->id,
'event_product_type' => EventProductType::Entry->value,
'type' => CatalogItemType::Bundle->value,
'slug' => 'entrada-general-todos-los-dias',
'nombre' => 'Entrada General - Todos los días',
'descripcion' => 'Incluye una entrada para cada día de la Fiesta Nacional del Fútbol Infantil.',
$this->createProduct($tenant, [
'slug' => 'abono',
'nombre' => 'Abono',
'category_id' => $categories['entradas']->id,
'precio' => 40000,
'category_id' => $ticketCategory->id,
'components' => $generalAdmission->variants
->map(fn ($variant): array => [
'catalog_item_id' => $generalAdmission->id,
'variant_id' => $variant->id,
'quantity' => 1,
])
->all(),
'has_tickets' => true,
'attribute_codes' => ['event_date'],
'multi_select_attribute_codes' => ['event_date'],
'variants' => [[
'real_stock' => 120,
'event_date_ids' => $dateIds->all(),
]],
]);
$this->catalogService->create([
FeaturedGroup::query()->create([
'tenant_code' => $tenant->codigo,
'event_id' => $event->id,
'event_product_type' => EventProductType::Product->value,
'type' => CatalogItemType::Bundle->value,
'slug' => 'combo-2-panchos-2-hamburguesas',
'nombre' => 'Combo 2 Panchos + 2 Hamburguesas',
'descripcion' => 'Incluye 2 panchos y 2 hamburguesas con papa frita.',
'precio' => 24000,
'category_id' => $mealCategory->id,
'components' => [
[
'catalog_item_id' => $createdItems['pancho']->id,
'quantity' => 2,
],
[
'catalog_item_id' => $createdItems['hamburguesa-papa-frita']->id,
'quantity' => 2,
],
],
]);
$this->seedFeaturedGroups($tenant, [
'Entradas' => $ticketCategory,
'Estacionamiento' => $parkingCategory,
'Comidas' => $mealCategory,
'Bebidas' => $drinkCategory,
'source_type' => FeaturedGroupSource::All,
'category_id' => null,
'product_layout' => ProductLayout::Row,
'group_layout' => GroupLayout::SimpleVertical,
'group_name' => 'Productos',
'group_order' => 0,
]);
}
@@ -182,51 +133,30 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
{
CatalogItem::query()
->where('tenant_code', $tenant->codigo)
->where('type', CatalogItemType::Bundle->value)
->each(fn (CatalogItem $item) => $this->catalogService->delete($item));
CatalogItem::query()
->where('tenant_code', $tenant->codigo)
->where('type', CatalogItemType::Standard->value)
->orderByRaw("CASE WHEN type = 'bundle' THEN 0 ELSE 1 END")
->each(fn (CatalogItem $item) => $this->catalogService->delete($item));
}
/** @param array<string, Category> $categories */
private function seedFeaturedGroups(Tenant $tenant, array $categories): void
/** @param array<string, mixed> $data */
private function createProduct(Tenant $tenant, array $data): CatalogItem
{
FeaturedGroup::query()->where('tenant_code', $tenant->codigo)->delete();
return $this->catalogService->create([
'tenant_code' => $tenant->codigo,
'descripcion' => $data['nombre'],
'inventory_policy' => InventoryPolicy::Tracked->value,
...$data,
'has_tickets' => true,
'ticket_generation_policy' => TicketGenerationPolicy::OnePerUnit->value,
]);
}
$groups = [
'Entradas' => [
'product_layout' => ProductLayout::Row,
'group_layout' => GroupLayout::SimpleVertical,
],
'Estacionamiento' => [
'product_layout' => ProductLayout::ColumnWithCart,
'group_layout' => GroupLayout::Simple,
],
'Comidas' => [
'product_layout' => ProductLayout::ColumnWithCart,
'group_layout' => GroupLayout::Simple,
],
'Bebidas' => [
'product_layout' => ProductLayout::ColumnWithCart,
'group_layout' => GroupLayout::Simple,
],
];
$groupOrder = 0;
foreach ($groups as $groupName => $config) {
FeaturedGroup::query()->create([
'tenant_code' => $tenant->codigo,
'source_type' => FeaturedGroupSource::Category,
'category_id' => $categories[$groupName]->id,
'product_layout' => $config['product_layout'],
'group_layout' => $config['group_layout'],
'group_name' => $groupName,
'group_order' => $groupOrder++,
]);
}
private function foodPrice(string $schedule): int
{
return match ($schedule) {
'Desayuno' => 4000,
'Almuerzo' => 10000,
'Cena' => 8000,
default => throw new RuntimeException("Horario de comida desconocido: {$schedule}"),
};
}
}

View File

@@ -71,6 +71,30 @@ class MenuSeeder extends Seeder
'parent_menu_code' => 'main.adminapp',
'route' => '/admin/staff',
],
[
'code' => 'adminapp.fiesta-futbol-infantil.entradas',
'label' => 'Entradas',
'parent_menu_code' => 'main.adminapp',
'route' => '/admin/entradas',
],
[
'code' => 'adminapp.fiesta-futbol-infantil.alojamientos',
'label' => 'Alojamientos',
'parent_menu_code' => 'main.adminapp',
'route' => '/admin/alojamientos',
],
[
'code' => 'adminapp.fiesta-futbol-infantil.merchandising',
'label' => 'Merchandising',
'parent_menu_code' => 'main.adminapp',
'route' => '/admin/merchandising',
],
[
'code' => 'adminapp.fiesta-futbol-infantil.comida',
'label' => 'Comida',
'parent_menu_code' => 'main.adminapp',
'route' => '/admin/comidas',
],
[
'code' => 'account',
'label' => 'Mi cuenta',
@@ -222,6 +246,18 @@ class MenuSeeder extends Seeder
'sonder',
'fiesta_futbol_infantil',
];
$fiestaCategoryMenuCodes = [
'adminapp.fiesta-futbol-infantil.entradas',
'adminapp.fiesta-futbol-infantil.alojamientos',
'adminapp.fiesta-futbol-infantil.merchandising',
'adminapp.fiesta-futbol-infantil.comida',
];
$fiestaExcludedAdminMenuCodes = [
'adminapp.inicio',
'adminapp.catalog',
'adminapp.categories',
'adminapp.combos',
];
$frequentlyAskedQuestions = [
[
'pregunta' => '¿Hay algún límite de compra?',
@@ -279,6 +315,12 @@ class MenuSeeder extends Seeder
$menuCodes = array_diff($menuCodes, $helpMenuCodes);
}
if ($tenant->codigo !== 'fiesta_futbol_infantil') {
$menuCodes = array_diff($menuCodes, $fiestaCategoryMenuCodes);
} else {
$menuCodes = array_diff($menuCodes, $fiestaExcludedAdminMenuCodes);
}
// Usar sync para asociar los menues al tenant
$tenant->menues()->sync($menuCodes);

View File

@@ -56,6 +56,8 @@ class TenantSeeder extends Seeder
'success_color' => '#198754',
'header_bg_color' => '#ffffff',
'footer_bg_color' => '#313131',
'display_categories' => true,
'display_seach_bar' => true,
'header_logo' => $this->uploadedImage('images/tennants/sonder/sonder_header.png', 'sonder_header.png'),
'footer_logo' => $this->uploadedImage('images/tennants/sonder/sonder_footer.png', 'sonder_footer.png'),
'social_media' => self::SOCIAL_MEDIA,
@@ -107,6 +109,8 @@ class TenantSeeder extends Seeder
'success_color' => '#198754',
'header_bg_color' => '#ffffff',
'footer_bg_color' => '#015327',
'display_categories' => false,
'display_seach_bar' => false,
'header_logo' => $this->uploadedImage(
'images/tennants/fiesta_futbol_infantil/futbol_infantil_header.png',
'futbol_infantil_header.png',