feat(tenant): add main carousel images to tenant seeder and implement corresponding tests
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
BIN
public/images/sonder-main-carousel/01-urban-team.png
Normal file
BIN
public/images/sonder-main-carousel/01-urban-team.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 MiB |
BIN
public/images/sonder-main-carousel/02-running-shoes.png
Normal file
BIN
public/images/sonder-main-carousel/02-running-shoes.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.1 MiB |
BIN
public/images/sonder-main-carousel/03-streetwear.png
Normal file
BIN
public/images/sonder-main-carousel/03-streetwear.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 MiB |
BIN
public/images/sonder-main-carousel/04-football-training.png
Normal file
BIN
public/images/sonder-main-carousel/04-football-training.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.1 MiB |
BIN
public/images/sonder-main-carousel/05-activewear-essentials.png
Normal file
BIN
public/images/sonder-main-carousel/05-activewear-essentials.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.0 MiB |
BIN
public/images/sonder-main-carousel/06-city-runners.png
Normal file
BIN
public/images/sonder-main-carousel/06-city-runners.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.0 MiB |
38
tests/Feature/Seeders/TenantSeederTest.php
Normal file
38
tests/Feature/Seeders/TenantSeederTest.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Seeders;
|
||||
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Database\Seeders\TenantSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TenantSeederTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_it_loads_the_sonder_main_carousel_images_in_order(): void
|
||||
{
|
||||
Storage::fake('s3');
|
||||
|
||||
$this->seed(TenantSeeder::class);
|
||||
|
||||
$tenant = Tenant::query()->where('codigo', 'sonder')->firstOrFail();
|
||||
$images = $tenant->mainCarouselImages()->get();
|
||||
|
||||
$this->assertSame([
|
||||
'01-urban-team.png',
|
||||
'02-running-shoes.png',
|
||||
'03-streetwear.png',
|
||||
'04-football-training.png',
|
||||
'05-activewear-essentials.png',
|
||||
'06-city-runners.png',
|
||||
], $images->pluck('filename')->all());
|
||||
$this->assertSame([0, 1, 2, 3, 4, 5], $images->pluck('pivot.orden')->all());
|
||||
|
||||
foreach ($images as $image) {
|
||||
Storage::disk('s3')->assertExists($image->path);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user