optimized storefront page and images
This commit is contained in:
@@ -60,7 +60,7 @@ class SeedMutualSmepCatalogTest extends TestCase
|
||||
$this->assertSame(511, DB::table('catalog_items_attachments')->count());
|
||||
$this->assertSame(
|
||||
511,
|
||||
count(Storage::disk('s3')->allFiles('tenants/mutual_smep/catalog-v1')),
|
||||
count(Storage::disk('s3')->allFiles('tenants/mutual_smep/catalog-v2')),
|
||||
);
|
||||
$this->assertDatabaseCount('featured_groups', 7);
|
||||
$this->assertSame([
|
||||
@@ -113,7 +113,16 @@ class SeedMutualSmepCatalogTest extends TestCase
|
||||
|
||||
$this->assertCount(13, $highlightedSlugs);
|
||||
$this->assertSame([], array_values(array_diff($variantProductSlugs, $highlightedSlugs)));
|
||||
$this->assertSame(155, DB::table('featured_items')->count());
|
||||
$this->assertSame(46, DB::table('featured_items')->count());
|
||||
DB::table('featured_groups')
|
||||
->where('code', '!=', 'productos-destacados-smep')
|
||||
->orderBy('id')
|
||||
->each(function (object $group): void {
|
||||
$this->assertLessThanOrEqual(
|
||||
6,
|
||||
DB::table('featured_items')->where('featured_group_id', $group->id)->count(),
|
||||
);
|
||||
});
|
||||
$this->assertDatabaseHas('catalog_items', [
|
||||
'tenant_code' => 'mutual_smep',
|
||||
'slug' => 'motorola-g15',
|
||||
@@ -138,6 +147,87 @@ class SeedMutualSmepCatalogTest extends TestCase
|
||||
] as $table) {
|
||||
$this->assertSame(0, DB::table($table)->count(), $table);
|
||||
}
|
||||
$this->assertSame([], Storage::disk('s3')->allFiles('tenants/mutual_smep/catalog-v2'));
|
||||
}
|
||||
|
||||
public function test_it_limits_existing_category_groups_and_restores_them_on_rollback(): void
|
||||
{
|
||||
$catalogMigration = require database_path(
|
||||
'migrations/2026_09_24_030000_seed_mutual_smep_catalog.php'
|
||||
);
|
||||
$limitMigration = require database_path(
|
||||
'migrations/2026_09_24_050000_limit_mutual_smep_category_featured_groups.php'
|
||||
);
|
||||
|
||||
$catalogMigration->up();
|
||||
|
||||
$limitMigration->down();
|
||||
$this->assertSame(155, DB::table('featured_items')->count());
|
||||
|
||||
$limitMigration->up();
|
||||
$this->assertSame(46, DB::table('featured_items')->count());
|
||||
|
||||
$categoryGroupCounts = DB::table('featured_groups')
|
||||
->leftJoin('featured_items', 'featured_items.featured_group_id', '=', 'featured_groups.id')
|
||||
->where('featured_groups.code', '!=', 'productos-destacados-smep')
|
||||
->groupBy('featured_groups.id', 'featured_groups.group_name', 'featured_groups.group_order')
|
||||
->orderBy('featured_groups.group_order')
|
||||
->selectRaw('featured_groups.group_name, COUNT(featured_items.id) AS item_count')
|
||||
->pluck('item_count', 'featured_groups.group_name')
|
||||
->map(fn ($count): int => (int) $count)
|
||||
->all();
|
||||
|
||||
$this->assertSame([
|
||||
'Dormitorio y Blanco' => 6,
|
||||
'Electrodomésticos' => 6,
|
||||
'Climatización' => 6,
|
||||
'Tecnología' => 6,
|
||||
'Bicicletas y Aire Libre' => 6,
|
||||
'Bazar' => 3,
|
||||
], $categoryGroupCounts);
|
||||
|
||||
$limitMigration->down();
|
||||
$this->assertSame(155, DB::table('featured_items')->count());
|
||||
|
||||
$catalogMigration->down();
|
||||
}
|
||||
|
||||
public function test_it_upgrades_legacy_catalog_images_and_restores_them_on_rollback(): void
|
||||
{
|
||||
$catalogMigration = require database_path(
|
||||
'migrations/2026_09_24_030000_seed_mutual_smep_catalog.php'
|
||||
);
|
||||
$imageMigration = require database_path(
|
||||
'migrations/2026_09_24_060000_optimize_mutual_smep_catalog_images.php'
|
||||
);
|
||||
|
||||
$catalogMigration->up();
|
||||
|
||||
DB::table('attachments')->orderBy('id')->each(function (object $attachment): void {
|
||||
$optimizedPath = (string) $attachment->path;
|
||||
$legacyPath = str_replace('catalog-v2/', 'catalog-v1/', $optimizedPath);
|
||||
$contents = Storage::disk('s3')->get($optimizedPath);
|
||||
|
||||
Storage::disk('s3')->put($legacyPath, $contents.'legacy');
|
||||
Storage::disk('s3')->delete($optimizedPath);
|
||||
DB::table('attachments')->where('id', $attachment->id)->update([
|
||||
'path' => $legacyPath,
|
||||
'size' => strlen($contents.'legacy'),
|
||||
]);
|
||||
});
|
||||
|
||||
$imageMigration->up();
|
||||
|
||||
$this->assertSame(511, count(Storage::disk('s3')->allFiles('tenants/mutual_smep/catalog-v2')));
|
||||
$this->assertSame(0, DB::table('attachments')->where('path', 'like', '%catalog-v1/%')->count());
|
||||
$this->assertSame(511, DB::table('attachments')->where('path', 'like', '%catalog-v2/%')->count());
|
||||
|
||||
$imageMigration->down();
|
||||
|
||||
$this->assertSame([], Storage::disk('s3')->allFiles('tenants/mutual_smep/catalog-v2'));
|
||||
$this->assertSame(511, DB::table('attachments')->where('path', 'like', '%catalog-v1/%')->count());
|
||||
|
||||
$catalogMigration->down();
|
||||
$this->assertSame([], Storage::disk('s3')->allFiles('tenants/mutual_smep/catalog-v1'));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user