refactor(tenant): introduce TenantInformationService for loading tenant data and resolving website extras

This commit is contained in:
2026-07-29 15:48:01 -03:00
parent 27d4f9fac6
commit 8e3ee7eff6
8 changed files with 436 additions and 33 deletions

View File

@@ -2,7 +2,9 @@
namespace Tests\Feature\Tenant;
use App\Domains\Attachable\Models\Attachment;
use App\Domains\Tenant\Models\Tenant;
use App\Domains\Tenant\Services\TenantInformationService;
use Database\Seeders\WebsiteTypeSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
@@ -99,10 +101,10 @@ class StoreTenantWithExtrasTest extends TestCase
$response->assertCreated();
$config = Tenant::query()
$tenant = Tenant::query()
->where('codigo', 'festival')
->sole()
->websiteExtras()
->sole();
$config = $tenant->websiteExtras()
->sole()
->config;
@@ -112,7 +114,53 @@ class StoreTenantWithExtrasTest extends TestCase
'id' => $config[0],
'type' => 'image',
]);
$response->assertJsonPath('data.extras.carousel.0', $config[0]);
$attachment = Attachment::query()->findOrFail($config[0]);
$carouselUrl = $response->json('data.extras.carousel.0');
$this->assertIsString($carouselUrl);
$this->assertStringContainsString($attachment->key, $carouselUrl);
app(TenantInformationService::class)->load($tenant);
$this->assertInstanceOf(
Attachment::class,
$tenant->websiteExtras->sole()->resolvedConfig()[0]
);
}
public function test_it_returns_scalar_attachment_fields_as_temporary_urls(): void
{
$image = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==';
$response = $this->postJson('/api/tenants', array_merge($this->tenantData(), [
'website_type_code' => 'onticket',
'extras' => [
'heroConfig' => [
'title_html' => '<h1>Festival</h1>',
'background_image_id' => $image,
],
],
]));
$response->assertCreated();
$heroConfig = Tenant::query()
->where('codigo', 'festival')
->sole()
->websiteExtras()
->whereHas(
'websiteTypeExtra',
fn ($query) => $query->where('nombre', 'heroConfig')
)
->sole()
->config;
$attachment = Attachment::query()->findOrFail($heroConfig['background_image_id']);
$backgroundUrl = $response->json('data.extras.heroConfig.background_image_id');
$this->assertIsString($backgroundUrl);
$this->assertStringContainsString($attachment->key, $backgroundUrl);
}
/**