refactor(ticket): implement fixed validity time generation for event date and time windows in TicketGeneratorService

This commit is contained in:
2026-08-07 10:43:05 -03:00
parent 717ee5d194
commit 91af233941
22 changed files with 665 additions and 0 deletions

View File

@@ -6,12 +6,17 @@ use App\Domains\Attachable\Enums\AttachmentType;
use App\Domains\Attachable\Models\Attachment;
use App\Domains\Auth\Models\User;
use App\Domains\Catalog\Enums\CatalogItemType;
use App\Domains\Catalog\Models\Attribute;
use App\Domains\Catalog\Models\CatalogItem;
use App\Domains\Catalog\Models\Inventory;
use App\Domains\Event\Models\EventDate;
use App\Domains\Notification\Events\TicketsAvailable;
use App\Domains\Purchase\Models\Purchase;
use App\Domains\Shared\Enums\FieldType;
use App\Domains\Tenant\Models\Tenant;
use App\Domains\Ticket\Enums\ValidityTimeType;
use App\Domains\Ticket\Exceptions\TicketGenerationException;
use App\Domains\Ticket\Models\ValidityTime;
use App\Domains\Ticket\Services\TicketGeneratorService;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Foundation\Testing\RefreshDatabase;
@@ -180,6 +185,56 @@ class TicketGeneratorServiceTest extends TestCase
]);
}
public function test_event_date_and_time_window_are_snapshotted_as_a_fixed_window(): void
{
$item = $this->createTicketableItem('scheduled-meal');
$eventDate = EventDate::query()->create([
'tenant_code' => $this->tenant->codigo,
'date' => '2026-08-20',
'time_start' => '09:00:00',
'time_end' => '23:59:59',
]);
$timeWindow = ValidityTime::query()->create([
'type' => ValidityTimeType::TimeWindow,
'start_time' => '22:00:00',
'end_time' => '02:00:00',
]);
$schedule = Attribute::query()->create([
'tenant_codigo' => $this->tenant->codigo,
'codigo' => 'schedule',
'nombre' => 'Schedule',
'type' => FieldType::Select,
]);
$schedule->options()->create([
'value' => 'night',
'label' => '22:00 - 02:00',
'validity_time_id' => $timeWindow->id,
]);
$itemSchedule = $item->itemAttributes()->create([
'attribute_id' => $schedule->id,
]);
$inventory = Inventory::query()->create();
$variant = $item->variants()->create([
'event_date_id' => $eventDate->id,
'inventory_id' => $inventory->id,
]);
$variant->definitions()->create([
'item_attribute_id' => $itemSchedule->id,
'value' => 'night',
]);
$tickets = $this->service->generate($item, $this->user, 2, $variant->id);
$this->assertCount(2, $tickets);
$this->assertSame(1, $tickets->pluck('validity_time_id')->unique()->count());
$this->assertNotSame($timeWindow->id, $tickets->first()->validity_time_id);
$fixedWindow = $tickets->first()->validityTime;
$this->assertSame(ValidityTimeType::FixedWindow, $fixedWindow->type);
$this->assertSame('2026-08-20 22:00:00', $fixedWindow->fixed_starts_at->format('Y-m-d H:i:s'));
$this->assertSame('2026-08-21 02:00:00', $fixedWindow->fixed_expires_at->format('Y-m-d H:i:s'));
}
public function test_marking_a_purchase_as_paid_ignores_items_without_tickets(): void
{
Event::fake([TicketsAvailable::class]);