feat(seeder): add SocialMediaSeeder and integrate social media data into TenantSeeder
This commit is contained in:
@@ -23,6 +23,7 @@ class DatabaseSeeder extends Seeder
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->call([
|
$this->call([
|
||||||
|
SocialMediaSeeder::class,
|
||||||
TenantSeeder::class,
|
TenantSeeder::class,
|
||||||
AttributeSeeder::class,
|
AttributeSeeder::class,
|
||||||
CategorySeeder::class,
|
CategorySeeder::class,
|
||||||
|
|||||||
42
database/seeders/SocialMediaSeeder.php
Normal file
42
database/seeders/SocialMediaSeeder.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use App\Domains\Tenant\Models\SocialMedia;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
|
class SocialMediaSeeder extends Seeder
|
||||||
|
{
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
$socialMedia = [
|
||||||
|
[
|
||||||
|
'code' => 'facebook',
|
||||||
|
'icon' => 'fa-brands fa-facebook',
|
||||||
|
'name' => 'Facebook',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => 'instagram',
|
||||||
|
'icon' => 'fa-brands fa-instagram',
|
||||||
|
'name' => 'Instagram',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => 'whatsapp',
|
||||||
|
'icon' => 'fa-brands fa-whatsapp',
|
||||||
|
'name' => 'WhatsApp',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => 'linkedin',
|
||||||
|
'icon' => 'fa-brands fa-linkedin-in',
|
||||||
|
'name' => 'LinkedIn',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($socialMedia as $socialMediaData) {
|
||||||
|
SocialMedia::query()->updateOrCreate(
|
||||||
|
['code' => $socialMediaData['code']],
|
||||||
|
$socialMediaData
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,6 +19,29 @@ class TenantSeeder extends Seeder
|
|||||||
'06-city-runners.png',
|
'06-city-runners.png',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
private const SOCIAL_MEDIA = [
|
||||||
|
[
|
||||||
|
'code' => 'instagram',
|
||||||
|
'url' => 'https://www.instagram.com/sonderargentina/',
|
||||||
|
'orden' => 0,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => 'facebook',
|
||||||
|
'url' => 'https://www.facebook.com/SonderArgentina/',
|
||||||
|
'orden' => 1,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => 'linkedin',
|
||||||
|
'url' => 'https://www.linkedin.com/company/35664983/',
|
||||||
|
'orden' => 2,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => 'whatsapp',
|
||||||
|
'url' => 'https://wa.me/5493412602222',
|
||||||
|
'orden' => 3,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
public function __construct(protected TenantService $tenantService) {}
|
public function __construct(protected TenantService $tenantService) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -117,6 +140,7 @@ class TenantSeeder extends Seeder
|
|||||||
'header_logo' => $headerLogo,
|
'header_logo' => $headerLogo,
|
||||||
'footer_logo' => $footerLogo,
|
'footer_logo' => $footerLogo,
|
||||||
'main_carousel_images' => $mainCarouselImages,
|
'main_carousel_images' => $mainCarouselImages,
|
||||||
|
'social_media' => self::SOCIAL_MEDIA,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Check if tenant 'fiesta_futbol_infantil' already exists
|
// Check if tenant 'fiesta_futbol_infantil' already exists
|
||||||
@@ -214,6 +238,7 @@ class TenantSeeder extends Seeder
|
|||||||
'location' => 'Sunchales, Santa Fe',
|
'location' => 'Sunchales, Santa Fe',
|
||||||
'dates' => ['2026-10-09', '2026-10-10', '2026-10-11', '2026-10-12'],
|
'dates' => ['2026-10-09', '2026-10-10', '2026-10-11', '2026-10-12'],
|
||||||
],
|
],
|
||||||
|
'social_media' => self::SOCIAL_MEDIA,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
52
tests/Feature/Seeders/SocialMediaSeederTest.php
Normal file
52
tests/Feature/Seeders/SocialMediaSeederTest.php
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Seeders;
|
||||||
|
|
||||||
|
use App\Domains\Tenant\Models\SocialMedia;
|
||||||
|
use Database\Seeders\SocialMediaSeeder;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class SocialMediaSeederTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
public function test_it_seeds_the_supported_social_media_with_font_awesome_icons(): void
|
||||||
|
{
|
||||||
|
$this->seed(SocialMediaSeeder::class);
|
||||||
|
|
||||||
|
$this->assertSame([
|
||||||
|
[
|
||||||
|
'code' => 'facebook',
|
||||||
|
'icon' => 'fa-brands fa-facebook',
|
||||||
|
'name' => 'Facebook',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => 'instagram',
|
||||||
|
'icon' => 'fa-brands fa-instagram',
|
||||||
|
'name' => 'Instagram',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => 'linkedin',
|
||||||
|
'icon' => 'fa-brands fa-linkedin-in',
|
||||||
|
'name' => 'LinkedIn',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => 'whatsapp',
|
||||||
|
'icon' => 'fa-brands fa-whatsapp',
|
||||||
|
'name' => 'WhatsApp',
|
||||||
|
],
|
||||||
|
], SocialMedia::query()
|
||||||
|
->orderBy('code')
|
||||||
|
->get(['code', 'icon', 'name'])
|
||||||
|
->toArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_can_run_more_than_once_without_creating_duplicates(): void
|
||||||
|
{
|
||||||
|
$this->seed(SocialMediaSeeder::class);
|
||||||
|
$this->seed(SocialMediaSeeder::class);
|
||||||
|
|
||||||
|
$this->assertSame(4, SocialMedia::query()->count());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace Tests\Feature\Seeders;
|
namespace Tests\Feature\Seeders;
|
||||||
|
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use Database\Seeders\SocialMediaSeeder;
|
||||||
use Database\Seeders\TenantSeeder;
|
use Database\Seeders\TenantSeeder;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
@@ -16,7 +17,10 @@ class TenantSeederTest extends TestCase
|
|||||||
{
|
{
|
||||||
Storage::fake('s3');
|
Storage::fake('s3');
|
||||||
|
|
||||||
$this->seed(TenantSeeder::class);
|
$this->seed([
|
||||||
|
SocialMediaSeeder::class,
|
||||||
|
TenantSeeder::class,
|
||||||
|
]);
|
||||||
|
|
||||||
$tenant = Tenant::query()->where('codigo', 'sonder')->firstOrFail();
|
$tenant = Tenant::query()->where('codigo', 'sonder')->firstOrFail();
|
||||||
$images = $tenant->mainCarouselImages()->get();
|
$images = $tenant->mainCarouselImages()->get();
|
||||||
@@ -35,4 +39,34 @@ class TenantSeederTest extends TestCase
|
|||||||
Storage::disk('s3')->assertExists($image->path);
|
Storage::disk('s3')->assertExists($image->path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_it_assigns_social_media_to_both_tenants_in_order(): void
|
||||||
|
{
|
||||||
|
Storage::fake('s3');
|
||||||
|
|
||||||
|
$this->seed([
|
||||||
|
SocialMediaSeeder::class,
|
||||||
|
TenantSeeder::class,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$expectedCodes = ['instagram', 'facebook', 'linkedin', 'whatsapp'];
|
||||||
|
$expectedUrls = [
|
||||||
|
'https://www.instagram.com/sonderargentina/',
|
||||||
|
'https://www.facebook.com/SonderArgentina/',
|
||||||
|
'https://www.linkedin.com/company/35664983/',
|
||||||
|
'https://wa.me/5493412602222',
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach (['sonder', 'fiesta_futbol_infantil'] as $tenantCode) {
|
||||||
|
$socialMedia = Tenant::query()
|
||||||
|
->where('codigo', $tenantCode)
|
||||||
|
->firstOrFail()
|
||||||
|
->socialMedia()
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$this->assertSame($expectedCodes, $socialMedia->pluck('code')->all());
|
||||||
|
$this->assertSame($expectedUrls, $socialMedia->pluck('pivot.url')->all());
|
||||||
|
$this->assertSame([0, 1, 2, 3], $socialMedia->pluck('pivot.orden')->all());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user