feat(tenant): add main carousel images to tenant seeder and implement corresponding tests

This commit is contained in:
2026-07-23 14:53:00 -03:00
parent c31be9c927
commit 12d496544d
8 changed files with 83 additions and 9 deletions

View File

@@ -2,6 +2,7 @@
namespace Database\Seeders;
use App\Domains\Attachable\Services\AttachmentService;
use App\Domains\Tenant\Models\Tenant;
use App\Domains\Tenant\Services\TenantService;
use Illuminate\Database\Seeder;
@@ -9,9 +10,16 @@ use Illuminate\Http\UploadedFile;
class TenantSeeder extends Seeder
{
public function __construct(protected TenantService $tenantService)
{
}
private const SONDER_MAIN_CAROUSEL_IMAGES = [
'01-urban-team.png',
'02-running-shoes.png',
'03-streetwear.png',
'04-football-training.png',
'05-activewear-essentials.png',
'06-city-runners.png',
];
public function __construct(protected TenantService $tenantService) {}
/**
* Run the database seeds.
@@ -21,7 +29,7 @@ class TenantSeeder extends Seeder
// Check if tenant 'sonder' already exists and delete it to prevent duplicates
$existing = Tenant::query()->where('codigo', 'sonder')->first();
if ($existing) {
$attachmentService = app(\App\Domains\Attachable\Services\AttachmentService::class);
$attachmentService = app(AttachmentService::class);
if ($existing->headerLogo) {
try {
$attachmentService->delete($existing->headerLogo);
@@ -36,6 +44,13 @@ class TenantSeeder extends Seeder
// Ignore exception on cleanup
}
}
foreach ($existing->mainCarouselImages as $mainCarouselImage) {
try {
$attachmentService->delete($mainCarouselImage);
} catch (\Throwable $e) {
// Ignore exception on cleanup
}
}
$existing->delete();
}
@@ -72,7 +87,24 @@ class TenantSeeder extends Seeder
true
);
$tenant = $this->tenantService->create([
$mainCarouselImages = [];
foreach (self::SONDER_MAIN_CAROUSEL_IMAGES as $filename) {
$imagePath = public_path("images/sonder-main-carousel/{$filename}");
if (! file_exists($imagePath)) {
throw new \RuntimeException("Image not found at path: {$imagePath}");
}
$mainCarouselImages[] = new UploadedFile(
$imagePath,
$filename,
'image/png',
null,
true
);
}
$this->tenantService->create([
'codigo' => 'sonder',
'nombre' => 'Sonder',
'dominio' => 'localhost',
@@ -84,26 +116,30 @@ class TenantSeeder extends Seeder
'footer_bg_color' => '#313131',
'header_logo' => $headerLogo,
'footer_logo' => $footerLogo,
'main_carousel_images' => $mainCarouselImages,
]);
// Check if tenant 'fiesta_futbol_infantil' already exists
$existingFiesta = Tenant::query()->where('codigo', 'fiesta_futbol_infantil')->first();
if ($existingFiesta) {
$attachmentService = app(\App\Domains\Attachable\Services\AttachmentService::class);
$attachmentService = app(AttachmentService::class);
if ($existingFiesta->headerLogo) {
try {
$attachmentService->delete($existingFiesta->headerLogo);
} catch (\Throwable $e) {}
} catch (\Throwable $e) {
}
}
if ($existingFiesta->footerLogo && $existingFiesta->footer_logo_id !== $existingFiesta->header_logo_id) {
try {
$attachmentService->delete($existingFiesta->footerLogo);
} catch (\Throwable $e) {}
} catch (\Throwable $e) {
}
}
if ($existingFiesta->heroBgImage) {
try {
$attachmentService->delete($existingFiesta->heroBgImage);
} catch (\Throwable $e) {}
} catch (\Throwable $e) {
}
}
$existingFiesta->delete();
}