@@ -2,6 +2,7 @@ const { expect, assert, use } = require('chai');
22const chaiAsPromised = require ( 'chai-as-promised' ) ;
33const { omit, cloneDeep } = require ( 'lodash' ) ;
44const { default : ThemesHandler } = require ( '../../../../src/tools/auth0/handlers/themes' ) ;
5+ const { preserveKeywords } = require ( '../../../../src/keywordPreservation' ) ;
56
67use ( 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+
326372module . exports = {
327373 mockTheme,
328374} ;
0 commit comments