Skip to content

Commit

Permalink
refine unit test for prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
kushalshit27 committed Feb 4, 2025
1 parent 000b36d commit b2017c2
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 135 deletions.
2 changes: 1 addition & 1 deletion src/context/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions src/tools/auth0/handlers/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
243 changes: 127 additions & 116 deletions test/context/directory/prompts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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==',
],
},
},
],
},
],
});
});
Expand Down Expand Up @@ -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==',
],
},
},
],
},
],
};

Expand Down Expand Up @@ -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==',
],
},
},
],
});
});
});
21 changes: 16 additions & 5 deletions test/context/yaml/context.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -293,7 +297,6 @@ describe('#YAML context validation', () => {
prompts: {
customText: {},
partials: {},
screenRenderers: [],
},
customDomains: [],
themes: [],
Expand All @@ -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());
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -529,7 +541,6 @@ describe('#YAML context validation', () => {
prompts: {
customText: {},
partials: {},
screenRenderers: [],
},
logStreams: [],
customDomains: [],
Expand Down
Loading

0 comments on commit b2017c2

Please sign in to comment.