refactor(tenant): introduce TenantInformationService for loading tenant data and resolving website extras
This commit is contained in:
@@ -5,6 +5,7 @@ namespace Tests\Feature\Seeders;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Database\Seeders\SocialMediaSeeder;
|
||||
use Database\Seeders\TenantSeeder;
|
||||
use Database\Seeders\WebsiteTypeSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Tests\TestCase;
|
||||
@@ -18,6 +19,7 @@ class TenantSeederTest extends TestCase
|
||||
Storage::fake('s3');
|
||||
|
||||
$this->seed([
|
||||
WebsiteTypeSeeder::class,
|
||||
SocialMediaSeeder::class,
|
||||
TenantSeeder::class,
|
||||
]);
|
||||
@@ -42,4 +44,65 @@ class TenantSeederTest extends TestCase
|
||||
$this->assertSame([0, 1, 2, 3], $socialMedia->pluck('pivot.orden')->all());
|
||||
}
|
||||
}
|
||||
|
||||
public function test_it_assigns_each_tenant_its_website_type_and_extras(): void
|
||||
{
|
||||
Storage::fake('s3');
|
||||
|
||||
$this->seed([
|
||||
WebsiteTypeSeeder::class,
|
||||
SocialMediaSeeder::class,
|
||||
TenantSeeder::class,
|
||||
]);
|
||||
|
||||
$sonder = Tenant::query()
|
||||
->where('codigo', 'sonder')
|
||||
->with('websiteExtras.websiteTypeExtra')
|
||||
->sole();
|
||||
|
||||
$this->assertSame('shopit', $sonder->website_type_code);
|
||||
|
||||
$carousel = $sonder->websiteExtras
|
||||
->firstWhere('websiteTypeExtra.nombre', 'carousel');
|
||||
|
||||
$this->assertNotNull($carousel);
|
||||
$this->assertCount(6, $carousel->config);
|
||||
|
||||
foreach ($carousel->config as $attachmentId) {
|
||||
$this->assertDatabaseHas('attachments', [
|
||||
'id' => $attachmentId,
|
||||
'type' => 'image',
|
||||
]);
|
||||
}
|
||||
|
||||
$fiesta = Tenant::query()
|
||||
->where('codigo', 'fiesta_futbol_infantil')
|
||||
->with('websiteExtras.websiteTypeExtra')
|
||||
->sole();
|
||||
|
||||
$this->assertSame('onticket', $fiesta->website_type_code);
|
||||
|
||||
$extras = $fiesta->websiteExtras->keyBy('websiteTypeExtra.nombre');
|
||||
$this->assertEqualsCanonicalizing(
|
||||
['heroConfig', 'eventConfig'],
|
||||
$extras->keys()->all(),
|
||||
);
|
||||
|
||||
$heroConfig = $extras->get('heroConfig')->config;
|
||||
$this->assertSame('<h1>Fiesta Fútbol Infantil</h1>', $heroConfig['title_html']);
|
||||
$this->assertIsInt($heroConfig['background_image_id']);
|
||||
$this->assertDatabaseHas('attachments', [
|
||||
'id' => $heroConfig['background_image_id'],
|
||||
'type' => 'image',
|
||||
]);
|
||||
|
||||
$this->assertSame([
|
||||
'title' => 'Fiesta Fútbol Infantil',
|
||||
'location' => 'Rosario, Santa Fe',
|
||||
'dates' => [
|
||||
'2026-12-05',
|
||||
'2026-12-06',
|
||||
],
|
||||
], $extras->get('eventConfig')->config);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user