Skip to content
Open
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
1 change: 1 addition & 0 deletions src/tools/auth0/handlers/themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ export default class ThemesHandler extends DefaultHandler {
...options,
type: 'themes',
id: 'themeId',
identifiers: ['themeId'],
});
}

Expand Down
46 changes: 46 additions & 0 deletions test/tools/auth0/handlers/themes.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { expect, assert, use } = require('chai');
const chaiAsPromised = require('chai-as-promised');
const { omit, cloneDeep } = require('lodash');
const { default: ThemesHandler } = require('../../../../src/tools/auth0/handlers/themes');
const { preserveKeywords } = require('../../../../src/keywordPreservation');

use(chaiAsPromised);

Expand Down Expand Up @@ -323,6 +324,51 @@ describe('#themes handler', () => {
});
});

describe('#themes keyword preservation', () => {
const CDN_URL = 'https://cdn.example.com';
const themeId = 'my-theme-id';

const localThemeWithKeywords = {
themeId,
fonts: { font_url: '##CDN_URL##/fonts/custom.woff2' },
widget: { logo_url: '##CDN_URL##/logo.png' },
};

const remoteThemeWithResolvedUrls = {
themeId,
fonts: { font_url: `${CDN_URL}/fonts/custom.woff2` },
widget: { logo_url: `${CDN_URL}/logo.png` },
};

it('should preserve keyword placeholders in theme fields when themeId is in handler identifiers', () => {
const result = preserveKeywords({
localAssets: { themes: [localThemeWithKeywords] },
remoteAssets: { themes: [remoteThemeWithResolvedUrls] },
keywordMappings: { CDN_URL },
auth0Handlers: [{ id: 'themeId', identifiers: ['themeId'], type: 'themes' }],
});

expect(result.themes[0].fonts.font_url).to.equal('##CDN_URL##/fonts/custom.woff2');
expect(result.themes[0].widget.logo_url).to.equal('##CDN_URL##/logo.png');
});

it('should NOT preserve keyword placeholders when themeId is absent from handler identifiers', () => {
// Regression: prior to the fix, ThemesHandler used identifiers ['id', 'name'].
// getPreservableFieldsFromAssets looks for the identifier field on each array item to build
// a dot-notation address; if the field is missing (themes have themeId, not id/name),
// it silently returns no addresses and the raw remote URLs are returned unchanged.
const result = preserveKeywords({
localAssets: { themes: [localThemeWithKeywords] },
remoteAssets: { themes: [remoteThemeWithResolvedUrls] },
keywordMappings: { CDN_URL },
auth0Handlers: [{ id: 'themeId', identifiers: ['id', 'name'], type: 'themes' }],
});

expect(result.themes[0].fonts.font_url).to.equal(`${CDN_URL}/fonts/custom.woff2`);
expect(result.themes[0].widget.logo_url).to.equal(`${CDN_URL}/logo.png`);
});
});

module.exports = {
mockTheme,
};