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:
@@ -4,6 +4,7 @@ namespace Tests\Unit\Catalog;
|
||||
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Catalog\Enums\CatalogItemType;
|
||||
use App\Domains\Catalog\Enums\EventProductType;
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Catalog\Enums\InventoryPolicy;
|
||||
use App\Domains\Catalog\Enums\ProductLayout;
|
||||
@@ -19,8 +20,11 @@ use App\Domains\Catalog\Models\Inventory;
|
||||
use App\Domains\Catalog\Models\ItemAttribute;
|
||||
use App\Domains\Catalog\Models\Variant;
|
||||
use App\Domains\Catalog\Models\VariantDefinition;
|
||||
use App\Domains\Event\Models\Event;
|
||||
use App\Domains\Event\Models\EventDate;
|
||||
use App\Domains\Shared\Enums\FieldType;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use App\Domains\Ticket\Models\Ticket;
|
||||
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Tests\TestCase;
|
||||
@@ -61,6 +65,8 @@ class CatalogModelsTest extends TestCase
|
||||
'category_id' => '10',
|
||||
'brand_id' => '20',
|
||||
'inventory_id' => '30',
|
||||
'event_id' => '40',
|
||||
'event_product_type' => EventProductType::Entry->value,
|
||||
'type' => CatalogItemType::Standard->value,
|
||||
'precio' => '12.50',
|
||||
'inventory_policy' => InventoryPolicy::Tracked->value,
|
||||
@@ -72,17 +78,21 @@ class CatalogModelsTest extends TestCase
|
||||
$this->assertSame(10, $item->category_id);
|
||||
$this->assertSame(20, $item->brand_id);
|
||||
$this->assertSame(30, $item->inventory_id);
|
||||
$this->assertSame(40, $item->event_id);
|
||||
$this->assertSame(EventProductType::Entry, $item->event_product_type);
|
||||
$this->assertSame(CatalogItemType::Standard, $item->type);
|
||||
$this->assertSame('12.50', $item->precio);
|
||||
$this->assertSame(InventoryPolicy::Tracked, $item->inventory_policy);
|
||||
$this->assertTrue($item->has_tickets);
|
||||
$this->assertInstanceOf(Tenant::class, $item->tenant()->getRelated());
|
||||
$this->assertInstanceOf(Event::class, $item->event()->getRelated());
|
||||
$this->assertInstanceOf(Category::class, $item->category()->getRelated());
|
||||
$this->assertInstanceOf(Brand::class, $item->brand()->getRelated());
|
||||
$this->assertInstanceOf(Inventory::class, $item->inventory()->getRelated());
|
||||
$this->assertInstanceOf(BundleComponent::class, $item->bundleComponents()->getRelated());
|
||||
$this->assertInstanceOf(BundleComponent::class, $item->bundleComponentUsages()->getRelated());
|
||||
$this->assertInstanceOf(Variant::class, $item->variants()->getRelated());
|
||||
$this->assertInstanceOf(Ticket::class, $item->sourceTickets()->getRelated());
|
||||
$this->assertInstanceOf(Attribute::class, $item->attributes()->getRelated());
|
||||
$this->assertInstanceOf(ItemAttribute::class, $item->itemAttributes()->getRelated());
|
||||
$this->assertInstanceOf(FeaturedItem::class, $item->featuredItems()->getRelated());
|
||||
@@ -125,13 +135,20 @@ class CatalogModelsTest extends TestCase
|
||||
public function test_variant_has_direct_catalog_and_inventory_relations(): void
|
||||
{
|
||||
$variant = new Variant;
|
||||
$variant->setRawAttributes(['catalog_item_id' => '10', 'inventory_id' => '20']);
|
||||
$variant->setRawAttributes([
|
||||
'catalog_item_id' => '10',
|
||||
'event_date_id' => '15',
|
||||
'inventory_id' => '20',
|
||||
]);
|
||||
|
||||
$this->assertSame('variantes', $variant->getTable());
|
||||
$this->assertSame(10, $variant->catalog_item_id);
|
||||
$this->assertSame(20, $variant->inventory_id);
|
||||
$this->assertSame(15, $variant->event_date_id);
|
||||
$this->assertInstanceOf(CatalogItem::class, $variant->catalogItem()->getRelated());
|
||||
$this->assertInstanceOf(Inventory::class, $variant->inventory()->getRelated());
|
||||
$this->assertInstanceOf(EventDate::class, $variant->eventDate()->getRelated());
|
||||
$this->assertInstanceOf(Ticket::class, $variant->sourceTickets()->getRelated());
|
||||
$this->assertInstanceOf(VariantDefinition::class, $variant->definitions()->getRelated());
|
||||
$this->assertInstanceOf(Attachment::class, $variant->attachments()->getRelated());
|
||||
$this->assertSame('catalog_items_attachments', $variant->attachments()->getTable());
|
||||
@@ -155,6 +172,28 @@ class CatalogModelsTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function test_event_date_identifies_a_variant_without_catalog_attributes(): void
|
||||
{
|
||||
$item = new CatalogItem;
|
||||
$item->nombre = 'Entrada General';
|
||||
|
||||
$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 20:00:00');
|
||||
$variant->setRelation('catalogItem', $item);
|
||||
$variant->setRelation('eventDate', $eventDate);
|
||||
$variant->setRelation('definitions', new EloquentCollection);
|
||||
|
||||
$this->assertSame('Entrada General (Fecha: 2026-10-09)', $variant->getName());
|
||||
$this->assertSame('2026-10-09 09:00:00', $variant->getMinimumUseDate()->format('Y-m-d H:i:s'));
|
||||
$this->assertSame('2026-10-09 18:00:00', $variant->getMaximumUseDate()->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
public function test_inventory_maps_stock_without_a_polymorphic_owner(): void
|
||||
{
|
||||
$inventory = $this->trackedInventory(realStock: 10, reservedStock: 3);
|
||||
|
||||
Reference in New Issue
Block a user