feat(migration): enhance Mutual SMEP catalog seeding with featured groups and highlighted products
This commit is contained in:
@@ -23,6 +23,7 @@ class SeedMutualSmepCatalogTest extends TestCase
|
||||
protected function tearDown(): void
|
||||
{
|
||||
foreach ([
|
||||
'featured_items',
|
||||
'featured_groups',
|
||||
'catalog_items_attachments',
|
||||
'attachments',
|
||||
@@ -61,11 +62,58 @@ class SeedMutualSmepCatalogTest extends TestCase
|
||||
511,
|
||||
count(Storage::disk('s3')->allFiles('tenants/mutual_smep/catalog-v1')),
|
||||
);
|
||||
$this->assertDatabaseHas('featured_groups', [
|
||||
'tenant_code' => 'mutual_smep',
|
||||
'code' => 'productos-smep',
|
||||
'source_type' => 'all',
|
||||
]);
|
||||
$this->assertDatabaseCount('featured_groups', 7);
|
||||
$this->assertSame([
|
||||
'Productos destacados',
|
||||
'Dormitorio y Blanco',
|
||||
'Electrodomésticos',
|
||||
'Climatización',
|
||||
'Tecnología',
|
||||
'Bicicletas y Aire Libre',
|
||||
'Bazar',
|
||||
], DB::table('featured_groups')->orderBy('group_order')->pluck('group_name')->all());
|
||||
|
||||
DB::table('featured_groups')->orderBy('group_order')->each(function (object $group): void {
|
||||
$this->assertSame('manual', $group->source_type);
|
||||
$this->assertSame('carousel', $group->group_layout);
|
||||
$this->assertSame('column_with_image', $group->product_layout);
|
||||
if ($group->code === 'productos-destacados-smep') {
|
||||
$this->assertNull($group->category_id);
|
||||
} else {
|
||||
$this->assertNotNull($group->category_id);
|
||||
$this->assertDatabaseHas('categorias', [
|
||||
'id' => $group->category_id,
|
||||
'tenant_code' => 'mutual_smep',
|
||||
'categoria_id' => null,
|
||||
'nombre' => $group->group_name,
|
||||
]);
|
||||
}
|
||||
$this->assertGreaterThan(
|
||||
0,
|
||||
DB::table('featured_items')->where('featured_group_id', $group->id)->count(),
|
||||
);
|
||||
});
|
||||
|
||||
$highlightedGroupId = DB::table('featured_groups')
|
||||
->where('code', 'productos-destacados-smep')
|
||||
->value('id');
|
||||
$highlightedSlugs = DB::table('featured_items')
|
||||
->join('catalog_items', 'catalog_items.id', '=', 'featured_items.catalog_item_id')
|
||||
->where('featured_items.featured_group_id', $highlightedGroupId)
|
||||
->orderBy('featured_items.order')
|
||||
->pluck('catalog_items.slug')
|
||||
->all();
|
||||
$variantProductSlugs = DB::table('catalog_items')
|
||||
->whereExists(fn ($query) => $query
|
||||
->selectRaw('1')
|
||||
->from('variantes')
|
||||
->whereColumn('variantes.catalog_item_id', 'catalog_items.id'))
|
||||
->pluck('slug')
|
||||
->all();
|
||||
|
||||
$this->assertCount(13, $highlightedSlugs);
|
||||
$this->assertSame([], array_values(array_diff($variantProductSlugs, $highlightedSlugs)));
|
||||
$this->assertSame(155, DB::table('featured_items')->count());
|
||||
$this->assertDatabaseHas('catalog_items', [
|
||||
'tenant_code' => 'mutual_smep',
|
||||
'slug' => 'motorola-g15',
|
||||
@@ -77,6 +125,7 @@ class SeedMutualSmepCatalogTest extends TestCase
|
||||
$migration->down();
|
||||
|
||||
foreach ([
|
||||
'featured_items',
|
||||
'featured_groups',
|
||||
'catalog_items_attachments',
|
||||
'attachments',
|
||||
@@ -226,5 +275,11 @@ class SeedMutualSmepCatalogTest extends TestCase
|
||||
$table->string('group_name');
|
||||
$table->unsignedInteger('group_order')->default(0);
|
||||
});
|
||||
Schema::create('featured_items', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('featured_group_id')->constrained('featured_groups')->cascadeOnDelete();
|
||||
$table->foreignId('catalog_item_id')->constrained('catalog_items')->cascadeOnDelete();
|
||||
$table->unsignedInteger('order')->default(0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user