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

@@ -0,0 +1,46 @@
<?php
namespace App\Domains\FiestaFutbolInfantil\Resources;
use App\Domains\Catalog\Models\CatalogItem;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
/** @mixin CatalogItem */
class AccommodationResource extends JsonResource
{
/** @return array<string, mixed> */
public function toArray(Request $request): array
{
if ($this->resource === null) {
return [
'id' => null,
'name' => 'Alojamiento',
'variants' => [],
];
}
$typeAttribute = $this->itemAttributes
->first(fn ($itemAttribute) => $itemAttribute->attribute?->codigo === 'tipo_alojamiento');
$options = $typeAttribute?->attribute?->options?->keyBy('value') ?? collect();
return [
'id' => $this->id,
'name' => $this->nombre,
'variants' => $this->variants->map(function ($variant) use ($typeAttribute, $options): array {
$value = $variant->definitions
->firstWhere('item_attribute_id', $typeAttribute?->id)
?->value;
return [
'id' => $variant->id,
'title' => $options->get($value)?->label ?? $value,
'value' => $value,
'description' => $variant->descripcion,
'stock' => $variant->inventory->real_stock,
'price' => number_format($variant->getPrice(), 2, '.', ''),
];
})->values(),
];
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Domains\FiestaFutbolInfantil\Resources;
use App\Domains\Catalog\Models\CatalogItem;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
/** @mixin CatalogItem */
class EntryResource extends JsonResource
{
/** @return array<string, mixed> */
public function toArray(Request $request): array
{
$variant = $this->variants->sole();
return [
'id' => $this->id,
'title' => $this->nombre,
'description' => $this->descripcion,
'event_date_ids' => $variant->selectedEventDates()->pluck('id')->values(),
'stock' => $variant->inventory->real_stock,
'price' => $this->precio,
];
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Domains\FiestaFutbolInfantil\Resources;
use App\Domains\Catalog\Models\CatalogItem;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
/** @mixin CatalogItem */
class FoodResource extends JsonResource
{
/** @return array<string, mixed> */
public function toArray(Request $request): array
{
if ($this->resource === null) {
return [
'id' => null,
'name' => 'Comida',
'variants' => [],
];
}
return [
'id' => $this->id,
'name' => $this->nombre,
'variants' => $this->variants->map(function ($variant): array {
$values = $variant->selectionValues();
$eventDate = $variant->selectedEventDates()->first();
return [
'id' => $variant->id,
'event_date_id' => $eventDate?->id,
'event_date' => $eventDate?->date?->format('Y-m-d'),
'schedule' => $values->get('horario'),
'service' => $values->get('servicio'),
'description' => $variant->descripcion,
'stock' => $variant->inventory->real_stock,
'price' => number_format($variant->getPrice(), 2, '.', ''),
];
})->values(),
];
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace App\Domains\FiestaFutbolInfantil\Resources;
use App\Domains\Catalog\Models\CatalogItem;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
/** @mixin CatalogItem */
class MerchandiseResource extends JsonResource
{
/** @return array<string, mixed> */
public function toArray(Request $request): array
{
$itemAttributes = $this->itemAttributes->keyBy(
fn ($itemAttribute) => $itemAttribute->attribute?->codigo
);
$colorAttribute = $itemAttributes->get('color');
$sizeAttribute = $itemAttributes->get('talle');
$colorOptions = $colorAttribute?->attribute?->options?->keyBy('value') ?? collect();
$sizeOptions = $sizeAttribute?->attribute?->options?->keyBy('value') ?? collect();
return [
'id' => $this->id,
'title' => $this->nombre,
'description' => $this->descripcion,
'max_units_per_user' => $this->max_units_per_user,
'variants' => $this->variants->map(function ($variant) use (
$colorAttribute,
$sizeAttribute,
$colorOptions,
$sizeOptions,
): array {
$colorValue = $variant->definitions
->firstWhere('item_attribute_id', $colorAttribute?->id)
?->value;
$sizeValue = $variant->definitions
->firstWhere('item_attribute_id', $sizeAttribute?->id)
?->value;
return [
'id' => $variant->id,
'color' => $colorOptions->get($colorValue)?->label ?? $colorValue,
'color_value' => $colorValue,
'size' => $sizeOptions->get($sizeValue)?->label ?? $sizeValue,
'size_value' => $sizeValue,
'stock' => $variant->inventory->real_stock,
'price' => number_format($variant->getPrice(), 2, '.', ''),
];
})->values(),
];
}
}