refactor: integrate category handling for entries and food items in services and tests

This commit is contained in:
2026-08-07 14:34:59 -03:00
parent e1ad27ecf0
commit 11776f0734
6 changed files with 70 additions and 7 deletions

View File

@@ -6,6 +6,7 @@ use App\Domains\Auth\Models\User;
use App\Domains\Authorization\Enums\RoleCode;
use App\Domains\Catalog\Models\Attribute;
use App\Domains\Catalog\Models\CatalogItem;
use App\Domains\Catalog\Models\Category;
use App\Domains\Shared\Enums\FieldType;
use App\Domains\Tenant\Models\Tenant;
use App\Domains\Tenant\Models\WebsiteType;
@@ -83,8 +84,14 @@ class EntryControllerTest extends TestCase
$this->assertDatabaseCount('inventories', 2);
$this->assertDatabaseCount('variant_event_dates', 3);
CatalogItem::query()->each(function (CatalogItem $entry) use ($tenant): void {
$entryCategory = Category::query()
->where('tenant_code', $tenant->codigo)
->where('nombre', 'Entradas')
->sole();
CatalogItem::query()->each(function (CatalogItem $entry) use ($tenant, $entryCategory): void {
$this->assertSame($tenant->codigo, $entry->tenant_code);
$this->assertSame($entryCategory->id, $entry->category_id);
$this->assertSame('entrada', $entry->event_product_type->value);
$this->assertSame('tracked', $entry->inventory_policy->value);
$this->assertTrue($entry->has_tickets);

View File

@@ -5,6 +5,7 @@ namespace Tests\Feature\FiestaFutbolInfantil;
use App\Domains\Auth\Models\User;
use App\Domains\Authorization\Enums\RoleCode;
use App\Domains\Catalog\Models\Attribute;
use App\Domains\Catalog\Models\Category;
use App\Domains\Shared\Enums\FieldType;
use App\Domains\Tenant\Models\Tenant;
use App\Domains\Tenant\Models\WebsiteType;
@@ -63,6 +64,11 @@ class FoodControllerTest extends TestCase
'tenant_code' => $tenant->codigo,
'slug' => 'comida',
'nombre' => 'Comida',
'category_id' => Category::query()
->where('tenant_code', $tenant->codigo)
->where('nombre', 'Comidas')
->sole()
->id,
'precio' => 8000,
]);
}

View File

@@ -19,7 +19,7 @@ class FiestaFutbolInfantilProductSeederTest extends TestCase
{
use RefreshDatabase;
public function test_it_seeds_the_category_free_configurable_catalog(): void
public function test_it_seeds_the_configurable_catalog_with_its_categories(): void
{
$headerLogo = $this->attachment('header');
$footerLogo = $this->attachment('footer');
@@ -44,7 +44,14 @@ class FiestaFutbolInfantilProductSeederTest extends TestCase
['color', 'event_date', 'horario', 'servicio', 'talle', 'tipo_alojamiento'],
Attribute::query()->where('tenant_codigo', $tenant->codigo)->orderBy('codigo')->pluck('codigo')->all(),
);
$this->assertSame(0, Category::query()->where('tenant_code', $tenant->codigo)->count());
$this->assertSame(
['Alojamientos', 'Comidas', 'Entradas', 'Merchandising'],
Category::query()
->where('tenant_code', $tenant->codigo)
->orderBy('nombre')
->pluck('nombre')
->all(),
);
$this->assertSame(
['abono', 'alojamiento', 'camiseta', 'comida'],
CatalogItem::query()->where('tenant_code', $tenant->codigo)->orderBy('slug')->pluck('slug')->all(),
@@ -59,9 +66,24 @@ class FiestaFutbolInfantilProductSeederTest extends TestCase
foreach ($expectedVariantCounts as $slug => $count) {
$item = CatalogItem::query()->where('tenant_code', $tenant->codigo)->where('slug', $slug)->sole();
$this->assertCount($count, $item->variants);
$this->assertNull($item->category_id);
}
$this->assertSame(
[
'abono' => 'Entradas',
'alojamiento' => 'Alojamientos',
'camiseta' => 'Merchandising',
'comida' => 'Comidas',
],
CatalogItem::query()
->where('tenant_code', $tenant->codigo)
->with('category')
->orderBy('slug')
->get()
->mapWithKeys(fn (CatalogItem $item): array => [$item->slug => $item->category?->nombre])
->all(),
);
$abono = CatalogItem::query()
->where('tenant_code', $tenant->codigo)
->where('slug', 'abono')