feat(seeder): add SocialMediaSeeder and integrate social media data into TenantSeeder
This commit is contained in:
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;
|
||||
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Database\Seeders\SocialMediaSeeder;
|
||||
use Database\Seeders\TenantSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@@ -16,7 +17,10 @@ class TenantSeederTest extends TestCase
|
||||
{
|
||||
Storage::fake('s3');
|
||||
|
||||
$this->seed(TenantSeeder::class);
|
||||
$this->seed([
|
||||
SocialMediaSeeder::class,
|
||||
TenantSeeder::class,
|
||||
]);
|
||||
|
||||
$tenant = Tenant::query()->where('codigo', 'sonder')->firstOrFail();
|
||||
$images = $tenant->mainCarouselImages()->get();
|
||||
@@ -35,4 +39,34 @@ class TenantSeederTest extends TestCase
|
||||
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