From ee911171bee2678f58fe11d7e497985f063ab044 Mon Sep 17 00:00:00 2001 From: ncoronel Date: Wed, 5 Aug 2026 09:18:12 -0300 Subject: [PATCH] fix(variant): simplify getName method and add test for variant without catalog attributes --- app/Domains/Catalog/Models/Variant.php | 15 +-------------- tests/Unit/Catalog/CatalogModelsTest.php | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/app/Domains/Catalog/Models/Variant.php b/app/Domains/Catalog/Models/Variant.php index fd29de2..45d6ee2 100644 --- a/app/Domains/Catalog/Models/Variant.php +++ b/app/Domains/Catalog/Models/Variant.php @@ -79,20 +79,7 @@ class Variant extends Model public function getName(): string { - $name = $this->catalogItem->nombre; - $this->loadMissing('definitions.itemAttribute.attribute'); - $definitions = $this->definitions - ->map(function (VariantDefinition $definition): ?string { - $attributeName = $definition->itemAttribute?->attribute?->nombre; - - return $attributeName - ? "{$attributeName}: {$definition->value}" - : $definition->value; - }) - ->filter() - ->implode(', '); - - return $definitions === '' ? $name : "{$name} ({$definitions})"; + return $this->catalogItem->nombre; } public function getMinimumUseDate(): ?CarbonInterface diff --git a/tests/Unit/Catalog/CatalogModelsTest.php b/tests/Unit/Catalog/CatalogModelsTest.php index 34486fa..5e1364d 100644 --- a/tests/Unit/Catalog/CatalogModelsTest.php +++ b/tests/Unit/Catalog/CatalogModelsTest.php @@ -155,6 +155,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', $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);