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:
38
tests/Unit/Event/EventDateTextFormatterTest.php
Normal file
38
tests/Unit/Event/EventDateTextFormatterTest.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Event;
|
||||
|
||||
use App\Domains\Event\Services\EventDateTextFormatter;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class EventDateTextFormatterTest extends TestCase
|
||||
{
|
||||
/** @param array<int, string> $dates */
|
||||
#[DataProvider('dateCases')]
|
||||
public function test_it_formats_event_dates_in_spanish(array $dates, ?string $expected): void
|
||||
{
|
||||
$this->assertSame($expected, (new EventDateTextFormatter)->format($dates));
|
||||
}
|
||||
|
||||
/** @return array<string, array{array<int, string>, string|null}> */
|
||||
public static function dateCases(): array
|
||||
{
|
||||
return [
|
||||
'no dates' => [[], null],
|
||||
'one date' => [['2026-10-09'], '9 de Octubre 2026'],
|
||||
'same month sorted' => [
|
||||
['2026-10-12', '2026-10-09', '2026-10-11', '2026-10-10'],
|
||||
'9, 10, 11 y 12 de Octubre 2026',
|
||||
],
|
||||
'different months' => [
|
||||
['2026-11-01', '2026-10-31'],
|
||||
'31 de Octubre y 1 de Noviembre 2026',
|
||||
],
|
||||
'different years' => [
|
||||
['2027-01-01', '2026-12-31'],
|
||||
'31 de Diciembre 2026 y 1 de Enero 2027',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -2,48 +2,40 @@
|
||||
|
||||
namespace Tests\Unit\Event;
|
||||
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Catalog\Models\Variant;
|
||||
use App\Domains\Event\Models\Event;
|
||||
use App\Domains\Event\Models\EventDate;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use App\Domains\Ticket\Models\ValidityTime;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EventModelsTest extends TestCase
|
||||
{
|
||||
public function test_event_maps_its_tenant_dates_and_catalog_items(): void
|
||||
{
|
||||
$event = new Event;
|
||||
|
||||
$this->assertFalse($event->usesTimestamps());
|
||||
$this->assertInstanceOf(Tenant::class, $event->tenant()->getRelated());
|
||||
$this->assertInstanceOf(EventDate::class, $event->dates()->getRelated());
|
||||
$this->assertInstanceOf(CatalogItem::class, $event->catalogItems()->getRelated());
|
||||
}
|
||||
|
||||
public function test_event_date_maps_schedule_and_variants(): void
|
||||
{
|
||||
$eventDate = new EventDate;
|
||||
$eventDate->setRawAttributes([
|
||||
'event_id' => '10',
|
||||
'tenant_code' => 'acme',
|
||||
'validity_time_id' => '12',
|
||||
'date' => '2026-10-09',
|
||||
'time_start' => '09:00:00',
|
||||
'time_end' => '18:30:00',
|
||||
]);
|
||||
|
||||
$this->assertFalse($eventDate->usesTimestamps());
|
||||
$this->assertSame(10, $eventDate->event_id);
|
||||
$this->assertSame('acme', $eventDate->tenant_code);
|
||||
$this->assertSame(12, $eventDate->validity_time_id);
|
||||
$this->assertSame('2026-10-09 09:00:00', $eventDate->startsAt()->format('Y-m-d H:i:s'));
|
||||
$this->assertSame('2026-10-09 18:30:00', $eventDate->endsAt()->format('Y-m-d H:i:s'));
|
||||
$this->assertInstanceOf(Event::class, $eventDate->event()->getRelated());
|
||||
$this->assertInstanceOf(Tenant::class, $eventDate->tenant()->getRelated());
|
||||
$this->assertInstanceOf(ValidityTime::class, $eventDate->validityTime()->getRelated());
|
||||
$this->assertInstanceOf(EventDate::class, (new ValidityTime)->eventDate()->getRelated());
|
||||
$this->assertInstanceOf(Variant::class, $eventDate->variants()->getRelated());
|
||||
}
|
||||
|
||||
public function test_tenant_has_many_events_and_one_active_event(): void
|
||||
public function test_tenant_has_many_event_dates(): void
|
||||
{
|
||||
$tenant = new Tenant;
|
||||
|
||||
$this->assertInstanceOf(Event::class, $tenant->events()->getRelated());
|
||||
$this->assertInstanceOf(Event::class, $tenant->activeEvent()->getRelated());
|
||||
$this->assertInstanceOf(EventDate::class, $tenant->eventDates()->getRelated());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user