feat(tenant): add site title and favicon support for tenants and website types

This commit is contained in:
2026-08-14 08:55:59 -03:00
parent 4de08ff2f2
commit bfdaf1c38b
17 changed files with 355 additions and 6 deletions

View File

@@ -127,6 +127,62 @@ class BootstrapTenantControllerTest extends TestCase
->assertJsonPath('data.dominio', 'acme.com');
}
public function test_it_resolves_browser_branding_from_the_tenant_before_the_website_type(): void
{
$typeFavicon = Attachment::query()->create([
'key' => (string) Str::uuid(),
'path' => 'website-types/type-favicon.png',
'filename' => 'type-favicon.png',
'type' => AttachmentType::Image,
'mime_type' => 'image/png',
]);
$tenantFavicon = Attachment::query()->create([
'key' => (string) Str::uuid(),
'path' => 'tenants/tenant-favicon.png',
'filename' => 'tenant-favicon.png',
'type' => AttachmentType::Image,
'mime_type' => 'image/png',
]);
$websiteType = WebsiteType::query()->create([
'codigo' => 'store',
'nombre' => 'Tienda',
'site_title' => 'Website type title',
'favicon_id' => $typeFavicon->id,
]);
$tenant = $this->createTenant([
'website_type_code' => $websiteType->codigo,
]);
$typeResponse = $this->getJson('/api/tenants/bootstrap/acme.com');
$typeResponse
->assertOk()
->assertJsonPath('data.site_title', 'Website type title');
$this->assertStringContainsString($typeFavicon->key, $typeResponse->json('data.favicon'));
$tenant->update([
'site_title' => 'Tenant title',
'favicon_id' => $tenantFavicon->id,
]);
$tenantResponse = $this->getJson('/api/tenants/bootstrap/acme.com');
$tenantResponse
->assertOk()
->assertJsonPath('data.site_title', 'Tenant title');
$this->assertStringContainsString($tenantFavicon->key, $tenantResponse->json('data.favicon'));
}
public function test_it_uses_default_browser_branding_when_none_is_configured(): void
{
$this->createTenant();
$this->getJson('/api/tenants/bootstrap/acme.com')
->assertOk()
->assertJsonPath('data.site_title', 'ShopitFront')
->assertJsonPath('data.favicon', null);
}
public function test_it_returns_only_the_tenant_categories_in_the_bootstrap(): void
{
$tenant = $this->createTenant();
@@ -755,21 +811,28 @@ class BootstrapTenantControllerTest extends TestCase
'footer_bg_color' => '#444444',
'header_logo' => $base64Image,
'footer_logo' => $ftrUuid,
'site_title' => 'Acme Store',
'favicon' => $base64Image,
]);
$response->assertCreated();
$tenant = Tenant::query()->with('headerLogo')->where('codigo', 'acme')->firstOrFail();
$tenant = Tenant::query()->with(['headerLogo', 'favicon'])->where('codigo', 'acme')->firstOrFail();
$this->assertNotNull($tenant->header_logo_id);
$this->assertNotNull($tenant->favicon_id);
$headerUrl = $response->json('data.header_logo');
$faviconUrl = $response->json('data.favicon');
$response->assertJsonPath('data.site_title', 'Acme Store');
$this->assertStringContainsString($tenant->headerLogo->key, $headerUrl);
$this->assertStringContainsString($tenant->favicon->key, $faviconUrl);
$this->assertTrue(
str_contains($headerUrl, 'Expires=') || str_contains($headerUrl, 'expiration=') || str_contains($headerUrl, 'X-Amz-Expires=')
);
$this->assertDatabaseHas('attachments', ['key' => $tenant->headerLogo->key]);
$this->assertDatabaseHas('attachments', ['key' => $tenant->favicon->key]);
}
}