feat: Add event management to tenant and catalog
- Introduced Event and EventDate models with relationships to Tenant and CatalogItem. - Added active_event_id to Tenant model to track the currently active event. - Updated TenantResource to include active event details in the response. - Enhanced Ticket model to link to CatalogItem and Variant, allowing for event-specific ticketing. - Implemented migrations to create events and link them to catalog items and variants. - Updated seeders to populate events and their associated dates for the Fiesta Futbol Infantil tenant. - Modified Ticket generation logic to respect event dates over standard ticket dates. - Added tests for event and ticket functionalities, ensuring proper relationships and date handling.
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
namespace Tests\Unit\Ticket;
|
||||
|
||||
use App\Domains\Auth\Models\User;
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Catalog\Models\Variant;
|
||||
use App\Domains\Event\Models\EventDate;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use App\Domains\Ticket\Models\Ticket;
|
||||
use Illuminate\Support\Carbon;
|
||||
@@ -39,6 +42,8 @@ class TicketTest extends TestCase
|
||||
$this->assertSame(10, $ticket->user_id);
|
||||
$this->assertInstanceOf(Tenant::class, $ticket->tenant()->getRelated());
|
||||
$this->assertInstanceOf(User::class, $ticket->user()->getRelated());
|
||||
$this->assertInstanceOf(CatalogItem::class, $ticket->sourceCatalogItem()->getRelated());
|
||||
$this->assertInstanceOf(Variant::class, $ticket->sourceVariant()->getRelated());
|
||||
}
|
||||
|
||||
public function test_unused_ticket_without_date_restrictions_is_valid(): void
|
||||
@@ -114,4 +119,30 @@ class TicketTest extends TestCase
|
||||
$this->assertFalse($ticket->is_expired);
|
||||
$this->assertTrue($ticket->is_used);
|
||||
}
|
||||
|
||||
public function test_event_date_has_priority_over_ticket_and_variant_dates(): void
|
||||
{
|
||||
Carbon::setTestNow('2026-10-09 19:00:00');
|
||||
|
||||
$eventDate = new EventDate;
|
||||
$eventDate->date = '2026-10-09';
|
||||
$eventDate->time_start = '09:00:00';
|
||||
$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 22:00:00');
|
||||
$variant->setRelation('eventDate', $eventDate);
|
||||
|
||||
$ticket = new Ticket([
|
||||
'starts_at' => Carbon::parse('2026-10-09 07:00:00'),
|
||||
'expires_at' => Carbon::parse('2026-10-10 23:59:59'),
|
||||
]);
|
||||
$ticket->setRelation('sourceVariant', $variant);
|
||||
|
||||
$this->assertSame('2026-10-09 09:00:00', $ticket->getEffectiveStartsAt()->format('Y-m-d H:i:s'));
|
||||
$this->assertSame('2026-10-09 18:00:00', $ticket->getEffectiveExpiresAt()->format('Y-m-d H:i:s'));
|
||||
$this->assertFalse($ticket->isValid());
|
||||
$this->assertTrue($ticket->is_expired);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user