refactor(catalog): Complete catalog refactor to simplify its data model and its querying.
source commits: refactor/catalog
This commit is contained in:
@@ -4,8 +4,11 @@ namespace Tests\Feature\Seeders;
|
||||
|
||||
use App\Domains\Attachable\Enums\AttachmentType;
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Bundle\Models\Bundle;
|
||||
use App\Domains\Catalog\Enums\CatalogItemType;
|
||||
use App\Domains\Catalog\Models\Attribute;
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Catalog\Models\FeaturedGroup;
|
||||
use App\Domains\Catalog\Models\Inventory;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Database\Seeders\AttributeSeeder;
|
||||
use Database\Seeders\FiestaFutbolInfantilProductSeeder;
|
||||
@@ -16,7 +19,7 @@ class FiestaFutbolInfantilProductSeederTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_it_seeds_event_attributes_and_bundles(): void
|
||||
public function test_it_seeds_event_items_for_the_new_catalog(): void
|
||||
{
|
||||
$headerLogo = Attachment::query()->create([
|
||||
'path' => 'tests/header.png',
|
||||
@@ -45,6 +48,10 @@ class FiestaFutbolInfantilProductSeederTest extends TestCase
|
||||
'footer_logo_id' => $footerLogo->id,
|
||||
]);
|
||||
|
||||
$this->seed([
|
||||
AttributeSeeder::class,
|
||||
FiestaFutbolInfantilProductSeeder::class,
|
||||
]);
|
||||
$this->seed([
|
||||
AttributeSeeder::class,
|
||||
FiestaFutbolInfantilProductSeeder::class,
|
||||
@@ -59,37 +66,77 @@ class FiestaFutbolInfantilProductSeederTest extends TestCase
|
||||
Attribute::query()->where('tenant_codigo', $tenant->codigo)->pluck('codigo')->all()
|
||||
);
|
||||
|
||||
$allDaysBundle = Bundle::query()
|
||||
->where('tenant_codigo', $tenant->codigo)
|
||||
->where('nombre', 'Entrada General - Todos los días')
|
||||
->with('items.variant.product', 'items.variant.definitions')
|
||||
$generalAdmission = CatalogItem::query()
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->where('slug', 'entrada-general')
|
||||
->with('variants.definitions')
|
||||
->sole();
|
||||
|
||||
$this->assertSame('40000.00', $allDaysBundle->precio);
|
||||
$this->assertCount(4, $allDaysBundle->items);
|
||||
$this->assertNull($generalAdmission->inventory_id);
|
||||
$this->assertCount(4, $generalAdmission->variants);
|
||||
$this->assertEqualsCanonicalizing(
|
||||
['2026-10-09', '2026-10-10', '2026-10-11', '2026-10-12'],
|
||||
$allDaysBundle->items->map(fn ($item) => $item->variant->definitions->sole()->value)->all()
|
||||
$generalAdmission->variants->map(fn ($variant) => $variant->definitions->sole()->value)->all()
|
||||
);
|
||||
$this->assertTrue($allDaysBundle->items->every(
|
||||
fn ($item) => $item->cantidad === 1 && $item->variant->product->slug === 'entrada-general'
|
||||
));
|
||||
|
||||
$foodBundle = Bundle::query()
|
||||
->where('tenant_codigo', $tenant->codigo)
|
||||
->where('nombre', 'Combo 2 Panchos + 2 Hamburguesas')
|
||||
->with('items.variant.product')
|
||||
$allDaysItem = CatalogItem::query()
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->where('nombre', 'Entrada General - Todos los días')
|
||||
->with('bundleComponents.variant.definitions')
|
||||
->sole();
|
||||
|
||||
$this->assertSame('24000.00', $foodBundle->precio);
|
||||
$this->assertSame(CatalogItemType::Bundle, $allDaysItem->type);
|
||||
$this->assertSame('40000.00', $allDaysItem->precio);
|
||||
$this->assertNull($allDaysItem->inventory_id);
|
||||
$this->assertFalse($allDaysItem->has_tickets);
|
||||
$this->assertCount(4, $allDaysItem->bundleComponents);
|
||||
$this->assertEqualsCanonicalizing(
|
||||
['2026-10-09', '2026-10-10', '2026-10-11', '2026-10-12'],
|
||||
$allDaysItem->bundleComponents
|
||||
->map(fn ($component) => $component->variant->definitions->sole()->value)
|
||||
->all()
|
||||
);
|
||||
|
||||
$foodCombo = CatalogItem::query()
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->where('nombre', 'Combo 2 Panchos + 2 Hamburguesas')
|
||||
->with('bundleComponents.catalogItem')
|
||||
->sole();
|
||||
|
||||
$this->assertSame(CatalogItemType::Bundle, $foodCombo->type);
|
||||
$this->assertSame('24000.00', $foodCombo->precio);
|
||||
$this->assertNull($foodCombo->inventory_id);
|
||||
$this->assertSame(
|
||||
[
|
||||
'pancho' => 2,
|
||||
'hamburguesa-papa-frita' => 2,
|
||||
'pancho' => 2,
|
||||
],
|
||||
$foodBundle->items->mapWithKeys(
|
||||
fn ($item) => [$item->variant->product->slug => $item->cantidad]
|
||||
)->all()
|
||||
$foodCombo->bundleComponents
|
||||
->mapWithKeys(fn ($component): array => [
|
||||
$component->catalogItem->slug => $component->quantity,
|
||||
])
|
||||
->sortKeys()
|
||||
->all()
|
||||
);
|
||||
$this->assertSame(9, CatalogItem::query()->where('tenant_code', $tenant->codigo)->count());
|
||||
$this->assertSame(10, Inventory::query()->count());
|
||||
|
||||
$this->assertSame(
|
||||
[
|
||||
'Entradas' => ['entrada-general', 'entrada-general-todos-los-dias'],
|
||||
'Estacionamiento' => ['estacionamiento-auto', 'estacionamiento-moto'],
|
||||
'Comidas' => ['hamburguesa-papa-frita', 'pancho', 'combo-2-panchos-2-hamburguesas'],
|
||||
'Bebidas' => ['coca-cola-500ml', 'agua-mineral-1l'],
|
||||
],
|
||||
FeaturedGroup::query()
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->with('featuredItems.catalogItem')
|
||||
->orderBy('group_order')
|
||||
->get()
|
||||
->mapWithKeys(fn (FeaturedGroup $group): array => [
|
||||
$group->group_name => $group->featuredItems->pluck('catalogItem.slug')->all(),
|
||||
])
|
||||
->all()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
68
tests/Feature/Seeders/ProductCatalogFromImagesSeederTest.php
Normal file
68
tests/Feature/Seeders/ProductCatalogFromImagesSeederTest.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Seeders;
|
||||
|
||||
use App\Domains\Attachable\Enums\AttachmentType;
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Catalog\Enums\ProductLayout;
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Catalog\Models\FeaturedGroup;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Database\Seeders\AttributeSeeder;
|
||||
use Database\Seeders\BrandSeeder;
|
||||
use Database\Seeders\CategorySeeder;
|
||||
use Database\Seeders\ProductCatalogFromImagesSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ProductCatalogFromImagesSeederTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_it_features_every_sonder_product_in_a_single_image_column(): void
|
||||
{
|
||||
Storage::fake('s3');
|
||||
|
||||
$logo = Attachment::query()->create([
|
||||
'path' => 'tests/sonder.png',
|
||||
'filename' => 'sonder.png',
|
||||
'type' => AttachmentType::Image,
|
||||
'mime_type' => 'image/png',
|
||||
]);
|
||||
$tenant = Tenant::query()->create([
|
||||
'codigo' => 'sonder',
|
||||
'nombre' => 'Sonder',
|
||||
'dominio' => 'sonder.localhost',
|
||||
'primary_color' => '#6376F3',
|
||||
'secondary_color' => '#A0A0A0',
|
||||
'danger_color' => '#FF8888',
|
||||
'success_color' => '#198754',
|
||||
'header_bg_color' => '#ffffff',
|
||||
'footer_bg_color' => '#313131',
|
||||
'header_logo_id' => $logo->id,
|
||||
'footer_logo_id' => $logo->id,
|
||||
]);
|
||||
|
||||
$this->seed([
|
||||
AttributeSeeder::class,
|
||||
CategorySeeder::class,
|
||||
BrandSeeder::class,
|
||||
ProductCatalogFromImagesSeeder::class,
|
||||
]);
|
||||
|
||||
$group = FeaturedGroup::query()
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->with('featuredItems.catalogItem')
|
||||
->sole();
|
||||
|
||||
$this->assertSame('Productos', $group->group_name);
|
||||
$this->assertSame(ProductLayout::ColumnWithImage, $group->product_layout);
|
||||
$this->assertSame(0, $group->group_order);
|
||||
$this->assertSame(
|
||||
CatalogItem::query()->where('tenant_code', $tenant->codigo)->orderBy('id')->pluck('slug')->all(),
|
||||
$group->featuredItems->pluck('catalogItem.slug')->all(),
|
||||
);
|
||||
$this->assertCount(10, $group->featuredItems);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user