Skip to content

Commit 33b9dfc

Browse files
authored
Fix: a0deploy keyword replacement mappings not applied to theme.json (#1379)
Fix: a0deploy replacement mapping not working in theme.json file
1 parent 406a6fc commit 33b9dfc

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

src/tools/auth0/handlers/themes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ export default class ThemesHandler extends DefaultHandler {
429429
...options,
430430
type: 'themes',
431431
id: 'themeId',
432+
identifiers: ['themeId'],
432433
});
433434
}
434435

test/tools/auth0/handlers/themes.tests.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const { expect, assert, use } = require('chai');
22
const chaiAsPromised = require('chai-as-promised');
33
const { omit, cloneDeep } = require('lodash');
44
const { default: ThemesHandler } = require('../../../../src/tools/auth0/handlers/themes');
5+
const { preserveKeywords } = require('../../../../src/keywordPreservation');
56

67
use(chaiAsPromised);
78

@@ -323,6 +324,51 @@ describe('#themes handler', () => {
323324
});
324325
});
325326

327+
describe('#themes keyword preservation', () => {
328+
const CDN_URL = 'https://cdn.example.com';
329+
const themeId = 'my-theme-id';
330+
331+
const localThemeWithKeywords = {
332+
themeId,
333+
fonts: { font_url: '##CDN_URL##/fonts/custom.woff2' },
334+
widget: { logo_url: '##CDN_URL##/logo.png' },
335+
};
336+
337+
const remoteThemeWithResolvedUrls = {
338+
themeId,
339+
fonts: { font_url: `${CDN_URL}/fonts/custom.woff2` },
340+
widget: { logo_url: `${CDN_URL}/logo.png` },
341+
};
342+
343+
it('should preserve keyword placeholders in theme fields when themeId is in handler identifiers', () => {
344+
const result = preserveKeywords({
345+
localAssets: { themes: [localThemeWithKeywords] },
346+
remoteAssets: { themes: [remoteThemeWithResolvedUrls] },
347+
keywordMappings: { CDN_URL },
348+
auth0Handlers: [{ id: 'themeId', identifiers: ['themeId'], type: 'themes' }],
349+
});
350+
351+
expect(result.themes[0].fonts.font_url).to.equal('##CDN_URL##/fonts/custom.woff2');
352+
expect(result.themes[0].widget.logo_url).to.equal('##CDN_URL##/logo.png');
353+
});
354+
355+
it('should NOT preserve keyword placeholders when themeId is absent from handler identifiers', () => {
356+
// Regression: prior to the fix, ThemesHandler used identifiers ['id', 'name'].
357+
// getPreservableFieldsFromAssets looks for the identifier field on each array item to build
358+
// a dot-notation address; if the field is missing (themes have themeId, not id/name),
359+
// it silently returns no addresses and the raw remote URLs are returned unchanged.
360+
const result = preserveKeywords({
361+
localAssets: { themes: [localThemeWithKeywords] },
362+
remoteAssets: { themes: [remoteThemeWithResolvedUrls] },
363+
keywordMappings: { CDN_URL },
364+
auth0Handlers: [{ id: 'themeId', identifiers: ['id', 'name'], type: 'themes' }],
365+
});
366+
367+
expect(result.themes[0].fonts.font_url).to.equal(`${CDN_URL}/fonts/custom.woff2`);
368+
expect(result.themes[0].widget.logo_url).to.equal(`${CDN_URL}/logo.png`);
369+
});
370+
});
371+
326372
module.exports = {
327373
mockTheme,
328374
};

0 commit comments

Comments
 (0)