From b2017c26df24423f0cd62c80a6d58dda3276b572 Mon Sep 17 00:00:00 2001 From: kushalshit27 <43465488+kushalshit27@users.noreply.github.com> Date: Tue, 4 Feb 2025 10:45:43 +0530 Subject: [PATCH] refine unit test for prompts --- src/context/index.ts | 2 +- src/tools/auth0/handlers/prompts.ts | 8 +- test/context/directory/prompts.test.ts | 243 ++++++++++--------- test/context/yaml/context.test.js | 21 +- test/tools/auth0/handlers/databases.tests.js | 6 +- test/tools/auth0/handlers/prompts.tests.ts | 13 +- test/utils.js | 14 +- 7 files changed, 172 insertions(+), 135 deletions(-) diff --git a/src/context/index.ts b/src/context/index.ts index f44ea884..7cf7b7e0 100644 --- a/src/context/index.ts +++ b/src/context/index.ts @@ -26,7 +26,7 @@ const nonPrimitiveProps: (keyof Config)[] = [ 'INCLUDED_PROPS', ]; -const EA_FEATURES = ['ACUL', 'wewewe']; +const EA_FEATURES = ['ACUL']; export const setupContext = async ( config: Config, diff --git a/src/tools/auth0/handlers/prompts.ts b/src/tools/auth0/handlers/prompts.ts index f923cc4f..d832faa5 100644 --- a/src/tools/auth0/handlers/prompts.ts +++ b/src/tools/auth0/handlers/prompts.ts @@ -531,8 +531,12 @@ export default class PromptsHandler extends DefaultHandler { await this.updateCustomTextSettings(customText); await this.updateCustomPromptsPartials(partials); - // Update screen renderers - await this.updateScreenRenderers(screenRenderers); + const includeExperimentalEA = this.config('AUTH0_EXPERIMENTAL_EA') || false; + + if (includeExperimentalEA) { + // Update screen renderers + await this.updateScreenRenderers(screenRenderers); + } this.updated += 1; this.didUpdate(prompts); diff --git a/test/context/directory/prompts.test.ts b/test/context/directory/prompts.test.ts index f6018a49..705de2b0 100644 --- a/test/context/directory/prompts.test.ts +++ b/test/context/directory/prompts.test.ts @@ -15,7 +15,10 @@ import { const dir = path.join(testDataDir, 'directory', 'promptsDump'); const promptsDirectory = path.join(dir, constants.PROMPTS_DIRECTORY); -const promptsScreenSettingsDirectory = path.join(promptsDirectory, constants.PROMPTS_SCREEN_RENDER_DIRECTORY); +const promptsScreenSettingsDirectory = path.join( + promptsDirectory, + constants.PROMPTS_SCREEN_RENDER_DIRECTORY +); const promptsSettingsFile = 'prompts.json'; const customTextFile = 'custom-text.json'; @@ -83,62 +86,64 @@ describe('#directory context prompts', () => { const settingsfiles = { [constants.PROMPTS_SCREEN_RENDER_DIRECTORY]: { [signupIdSettingsFile]: JSON.stringify({ - 'prompt': 'signup-id', - 'screen': 'signup-id', - 'rendering_mode': 'standard', - 'context_configuration': [], - 'default_head_tags_disabled': false, - 'head_tags': [ + prompt: 'signup-id', + screen: 'signup-id', + rendering_mode: 'standard', + context_configuration: [], + default_head_tags_disabled: false, + head_tags: [ { - 'tag': 'script', - 'attributes': { - 'src': 'URL_TO_YOUR_ASSET', - 'async': true, - 'defer': true, - 'integrity': [ - 'ASSET_SHA' - ] - } - } - ] + tag: 'script', + attributes: { + src: 'URL_TO_YOUR_ASSET', + async: true, + defer: true, + integrity: ['ASSET_SHA'], + }, + }, + ], }), [loginIdSettingsFile]: JSON.stringify({ - 'prompt': 'login-id', - 'screen': 'login-id', - 'rendering_mode': 'advanced', - 'context_configuration': [], - 'default_head_tags_disabled': false, - 'head_tags': [ + prompt: 'login-id', + screen: 'login-id', + rendering_mode: 'advanced', + context_configuration: [], + default_head_tags_disabled: false, + head_tags: [ { - 'tag': 'script', - 'attributes': { - 'src': 'http://127.0.0.1:8080/index.js', - 'defer': true - } + tag: 'script', + attributes: { + src: 'http://127.0.0.1:8080/index.js', + defer: true, + }, }, { - 'tag': 'link', - 'attributes': { - 'rel': 'stylesheet', - 'href': 'http://127.0.0.1:8090/index.css' - } + tag: 'link', + attributes: { + rel: 'stylesheet', + href: 'http://127.0.0.1:8090/index.css', + }, }, { - 'tag': 'meta', - 'attributes': { - 'name': 'viewport', - 'content': 'width=device-width, initial-scale=1' - } - } - ] + tag: 'meta', + attributes: { + name: 'viewport', + content: 'width=device-width, initial-scale=1', + }, + }, + ], }), - } + }, }; const repoDir = path.join(testDataDir, 'directory', 'prompts'); createDir(repoDir, files); - const settingsDir = path.join(repoDir,constants.PROMPTS_DIRECTORY, constants.PROMPTS_SCREEN_RENDER_DIRECTORY); + const settingsDir = path.join( + repoDir, + constants.PROMPTS_DIRECTORY, + constants.PROMPTS_SCREEN_RENDER_DIRECTORY + ); createDir(settingsDir, settingsfiles); const partialsDir = path.join( @@ -169,13 +174,15 @@ describe('#directory context prompts', () => { ); const signupIdSettingsFiles = { - 'signup-id_signup-id.json': '{ "prompt": "signup-id", "screen": "signup-id", "rendering_mode": "advanced","default_head_tags_disabled": false,' + + 'signup-id_signup-id.json': + '{ "prompt": "signup-id", "screen": "signup-id", "rendering_mode": "advanced","default_head_tags_disabled": false,' + '"context_configuration": [ "branding.settings", "branding.themes.default"], "head_tags": [{"attributes": {"async": true, "defer": true , ' + '"integrity": ["sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g=="], "src": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"}, "tag": "script"}]}', - 'login-id_login-id.json': '{ "prompt": "login-id", "screen": "login-id", "rendering_mode": "standard", "context_configuration": [],"default_head_tags_disabled": false}', + 'login-id_login-id.json': + '{ "prompt": "login-id", "screen": "login-id", "rendering_mode": "standard", "context_configuration": [],"default_head_tags_disabled": false}', }; - createDir(repoDir, { [screenSettingsDir]:signupIdSettingsFiles }); + createDir(repoDir, { [screenSettingsDir]: signupIdSettingsFiles }); const config = { AUTH0_INPUT_FILE: repoDir, @@ -227,32 +234,32 @@ describe('#directory context prompts', () => { }, screenRenderers: [ { - 'prompt': 'login-id', - 'screen': 'login-id', - 'rendering_mode': 'standard', - 'context_configuration': [], - 'default_head_tags_disabled': false, + prompt: 'login-id', + screen: 'login-id', + rendering_mode: 'standard', + context_configuration: [], + default_head_tags_disabled: false, }, { - 'prompt': 'signup-id', - 'screen': 'signup-id', - 'rendering_mode': 'advanced', - 'context_configuration': ['branding.settings','branding.themes.default'], - 'default_head_tags_disabled': false, - 'head_tags': [ + prompt: 'signup-id', + screen: 'signup-id', + rendering_mode: 'advanced', + context_configuration: ['branding.settings', 'branding.themes.default'], + default_head_tags_disabled: false, + head_tags: [ { - 'tag': 'script', - 'attributes': { - 'src': 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js', - 'async': true, - 'defer': true, - 'integrity': [ - 'sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==' - ] - } - } - ] - } + tag: 'script', + attributes: { + src: 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js', + async: true, + defer: true, + integrity: [ + 'sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==', + ], + }, + }, + ], + }, ], }); }); @@ -504,32 +511,32 @@ describe('#directory context prompts', () => { }, screenRenderers: [ { - 'prompt': 'login-id', - 'screen': 'login-id', - 'rendering_mode': 'standard', - 'context_configuration': [], - 'default_head_tags_disabled': false, + prompt: 'login-id', + screen: 'login-id', + rendering_mode: 'standard', + context_configuration: [], + default_head_tags_disabled: false, }, { - 'prompt': 'signup-id', - 'screen': 'signup-id', - 'rendering_mode': 'advanced', - 'context_configuration': ['branding.settings','branding.themes.default'], - 'default_head_tags_disabled': false, - 'head_tags': [ + prompt: 'signup-id', + screen: 'signup-id', + rendering_mode: 'advanced', + context_configuration: ['branding.settings', 'branding.themes.default'], + default_head_tags_disabled: false, + head_tags: [ { - 'tag': 'script', - 'attributes': { - 'src': 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js', - 'async': true, - 'defer': true, - 'integrity': [ - 'sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==' - ] - } - } - ] - } + tag: 'script', + attributes: { + src: 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js', + async: true, + defer: true, + integrity: [ + 'sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==', + ], + }, + }, + ], + }, ], }; @@ -579,33 +586,37 @@ describe('#directory context prompts', () => { identifier_first: context.assets.prompts.identifier_first, }); - expect(loadJSON(path.join(promptsScreenSettingsDirectory, loginIdSettingsFile), {})).to.deep.equal({ - 'prompt': 'login-id', - 'screen': 'login-id', - 'rendering_mode': 'standard', - 'context_configuration': [], - 'default_head_tags_disabled': false, + expect( + loadJSON(path.join(promptsScreenSettingsDirectory, loginIdSettingsFile), {}) + ).to.deep.equal({ + prompt: 'login-id', + screen: 'login-id', + rendering_mode: 'standard', + context_configuration: [], + default_head_tags_disabled: false, }); - expect(loadJSON(path.join(promptsScreenSettingsDirectory, signupIdSettingsFile), {})).to.deep.equal({ - 'prompt': 'signup-id', - 'screen': 'signup-id', - 'rendering_mode': 'advanced', - 'context_configuration': ['branding.settings','branding.themes.default'], - 'default_head_tags_disabled': false, - 'head_tags': [ + expect( + loadJSON(path.join(promptsScreenSettingsDirectory, signupIdSettingsFile), {}) + ).to.deep.equal({ + prompt: 'signup-id', + screen: 'signup-id', + rendering_mode: 'advanced', + context_configuration: ['branding.settings', 'branding.themes.default'], + default_head_tags_disabled: false, + head_tags: [ { - 'tag': 'script', - 'attributes': { - 'src': 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js', - 'async': true, - 'defer': true, - 'integrity': [ - 'sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==' - ] - } - } - ] + tag: 'script', + attributes: { + src: 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js', + async: true, + defer: true, + integrity: [ + 'sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==', + ], + }, + }, + ], }); }); }); diff --git a/test/context/yaml/context.test.js b/test/context/yaml/context.test.js index d084c256..991f7e03 100644 --- a/test/context/yaml/context.test.js +++ b/test/context/yaml/context.test.js @@ -234,7 +234,11 @@ describe('#YAML context validation', () => { { body: './emailTemplates/mfa_oob_code.html', enabled: true, template: 'mfa_oob_code' }, { body: './emailTemplates/password_reset.html', enabled: true, template: 'password_reset' }, { body: './emailTemplates/reset_email.html', enabled: true, template: 'reset_email' }, - { body: './emailTemplates/reset_email_by_code.html',enabled: true,template: 'reset_email_by_code' }, + { + body: './emailTemplates/reset_email_by_code.html', + enabled: true, + template: 'reset_email_by_code', + }, { body: './emailTemplates/stolen_credentials.html', enabled: true, @@ -293,7 +297,6 @@ describe('#YAML context validation', () => { prompts: { customText: {}, partials: {}, - screenRenderers: [], }, customDomains: [], themes: [], @@ -310,6 +313,7 @@ describe('#YAML context validation', () => { const tenantFile = path.join(dir, 'tenant.yml'); const config = { AUTH0_INPUT_FILE: tenantFile, + AUTH0_EXPERIMENTAL_EA: true, AUTH0_EXCLUDED_DEFAULTS: ['emailProvider'], }; const context = new Context(config, mockMgmtClient()); @@ -352,7 +356,11 @@ describe('#YAML context validation', () => { { body: './emailTemplates/mfa_oob_code.html', enabled: true, template: 'mfa_oob_code' }, { body: './emailTemplates/password_reset.html', enabled: true, template: 'password_reset' }, { body: './emailTemplates/reset_email.html', enabled: true, template: 'reset_email' }, - { body: './emailTemplates/reset_email_by_code.html',enabled: true,template: 'reset_email_by_code' }, + { + body: './emailTemplates/reset_email_by_code.html', + enabled: true, + template: 'reset_email_by_code', + }, { body: './emailTemplates/stolen_credentials.html', enabled: true, @@ -471,7 +479,11 @@ describe('#YAML context validation', () => { { body: './emailTemplates/mfa_oob_code.html', enabled: true, template: 'mfa_oob_code' }, { body: './emailTemplates/password_reset.html', enabled: true, template: 'password_reset' }, { body: './emailTemplates/reset_email.html', enabled: true, template: 'reset_email' }, - { body: './emailTemplates/reset_email_by_code.html',enabled: true,template: 'reset_email_by_code' }, + { + body: './emailTemplates/reset_email_by_code.html', + enabled: true, + template: 'reset_email_by_code', + }, { body: './emailTemplates/stolen_credentials.html', enabled: true, @@ -529,7 +541,6 @@ describe('#YAML context validation', () => { prompts: { customText: {}, partials: {}, - screenRenderers: [], }, logStreams: [], customDomains: [], diff --git a/test/tools/auth0/handlers/databases.tests.js b/test/tools/auth0/handlers/databases.tests.js index 89791839..68325d4a 100644 --- a/test/tools/auth0/handlers/databases.tests.js +++ b/test/tools/auth0/handlers/databases.tests.js @@ -865,7 +865,7 @@ describe('#databases handler', () => { active: true, }, profile_required: true, - verification_method:'link' + verification_method: 'link', }, username: { signup: { @@ -1098,7 +1098,7 @@ describe('#databases handler', () => { active: true, }, profile_required: true, - verification_method:'otp', + verification_method: 'otp', }, username: { signup: { @@ -1481,7 +1481,7 @@ describe('#databases handler', () => { active: true, }, profile_required: true, - verification_method:'link', + verification_method: 'link', }, username: { signup: { diff --git a/test/tools/auth0/handlers/prompts.tests.ts b/test/tools/auth0/handlers/prompts.tests.ts index b63e9a1a..01a1200e 100644 --- a/test/tools/auth0/handlers/prompts.tests.ts +++ b/test/tools/auth0/handlers/prompts.tests.ts @@ -13,6 +13,14 @@ const mockPromptsSettings = { }; describe('#prompts handler', () => { + const config = function (key) { + return config.data && config.data[key]; + }; + + config.data = { + AUTH0_EXPERIMENTAL_EA: true, + }; + describe('#prompts process', () => { it('should get prompts settings, custom texts, template partials and screen renderer', async () => { const supportedLanguages: Language[] = ['es', 'fr', 'en']; @@ -120,6 +128,7 @@ describe('#prompts handler', () => { const handler = new promptsHandler({ client: auth0, + config: config, }); const getCustomPartial = sinon.stub(handler, 'getCustomPartial'); @@ -187,6 +196,7 @@ describe('#prompts handler', () => { const handler = new promptsHandler({ client: auth0, + config: config, }); sinon.stub(handler, 'updateCustomPartials').callsFake(() => { didCallUpdatePartials = true; @@ -296,6 +306,7 @@ describe('#prompts handler', () => { const handler = new promptsHandler({ client: auth0, + config: config, }); sinon.stub(handler, 'updateCustomPartials').callsFake(() => { @@ -349,7 +360,7 @@ describe('#prompts handler', () => { }), }; - const handler = new promptsHandler({ client: auth0 }); + const handler = new promptsHandler({ client: auth0, config: config }); const getCustomPartial = sinon.stub(handler, 'getCustomPartial'); getCustomPartial.withArgs({ prompt: 'login' }).resolves({}); getCustomPartial.withArgs({ prompt: 'login-id' }).resolves({}); diff --git a/test/utils.js b/test/utils.js index 4017a978..77aed095 100644 --- a/test/utils.js +++ b/test/utils.js @@ -16,14 +16,14 @@ export const testDataDir = path.resolve(localDir, 'testData'); export function mockPagedData(params, key, data) { return params?.include_totals ? { - data: { - [key]: data, - total: data?.length || 0, - }, - } + data: { + [key]: data, + total: data?.length || 0, + }, + } : { - data, - }; + data, + }; } export function mockMgmtClient() {