Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions services/platform/convex/branding/__tests__/queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,35 @@ describe('getBrandingHandler', () => {
accentColor: undefined,
});
});

it('returns null for URLs when storage fetch fails', async () => {
const { ctx } = createMockQueryCtx({
_id: 'branding_1',
organizationId: 'org_1',
appName: 'Acme',
logoStorageId: 'storage_logo',
faviconLightStorageId: 'storage_fav_light',
faviconDarkStorageId: 'storage_fav_dark',
updatedAt: 1000,
});

ctx.storage.getUrl
.mockResolvedValueOnce('https://storage.example.com/storage_logo')
.mockRejectedValueOnce(new Error('Storage unavailable'))
.mockResolvedValueOnce('https://storage.example.com/storage_fav_dark');

const result = await getBrandingHandler(ctx as unknown as QueryCtx, {
organizationId: 'org_1',
});

expect(result).toEqual({
appName: 'Acme',
textLogo: undefined,
logoUrl: 'https://storage.example.com/storage_logo',
faviconLightUrl: null,
faviconDarkUrl: 'https://storage.example.com/storage_fav_dark',
brandColor: undefined,
accentColor: undefined,
});
});
});
24 changes: 17 additions & 7 deletions services/platform/convex/branding/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,24 @@ export async function getBrandingHandler(

if (!branding) return null;

async function safeGetUrl(storageId: string | undefined) {
if (!storageId) return null;
try {
return await ctx.storage.getUrl(storageId);
} catch (error) {
console.warn(
'[Branding] Failed to resolve storage URL',
storageId,
error,
);
return null;
}
}

const [logoUrl, faviconLightUrl, faviconDarkUrl] = await Promise.all([
branding.logoStorageId ? ctx.storage.getUrl(branding.logoStorageId) : null,
branding.faviconLightStorageId
? ctx.storage.getUrl(branding.faviconLightStorageId)
: null,
branding.faviconDarkStorageId
? ctx.storage.getUrl(branding.faviconDarkStorageId)
: null,
safeGetUrl(branding.logoStorageId),
safeGetUrl(branding.faviconLightStorageId),
safeGetUrl(branding.faviconDarkStorageId),
]);

return {
Expand Down
Loading
Loading