Skip to content

Commit

Permalink
update unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
kushalshit27 committed Feb 4, 2025
1 parent a076896 commit 517fec5
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/tools/auth0/handlers/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ export default class PromptsHandler extends DefaultHandler {

const includeExperimentalEA = this.config('AUTH0_EXPERIMENTAL_EA') || false;

console.log('CLOG: includeExperimentalEA', includeExperimentalEA);
if (includeExperimentalEA) {
// Update screen renderers
await this.updateScreenRenderers(screenRenderers);
Expand Down
107 changes: 107 additions & 0 deletions test/tools/auth0/handlers/prompts.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,111 @@ describe('#prompts handler', () => {
expect(numberOfUpdatePartialsCalls).to.equal(3);
});

it('should update prompts settings and custom text/partials, not screen renderer settings when AUTH0_EXPERIMENTAL_EA=false', async () => {
let didCallUpdatePromptsSettings = false;
let didCallUpdateCustomText = false;
let didCallUpdatePartials = false;
let numberOfUpdateCustomTextCalls = 0;
let numberOfUpdatePartialsCalls = 0;
let didCallUpdateScreenRenderer = false;

const customTextToSet = {
en: {
login: {
buttonText: 'button text2',
description: 'description text',
title: 'title text',
},
'mfa-webauthn': {},
},
fr: {
login: {
buttonText: 'french button text',
description: 'french description text',
title: 'french title text',
},
},
};

const partialsToSet: Prompts['partials'] = {
login: {
login: {
'form-content-start': '<div>TEST</div>',
},
},
'signup-id': {
'signup-id': {
'form-content-start': '<div>TEST</div>',
},
},
'signup-password': {
'signup-password': {
'form-content-start': '<div>TEST</div>',
},
},
};
const screenRenderersToSet: Prompts['screenRenderers'] = [];

const auth0 = {
prompts: {
updateCustomTextByLanguage: () => {
didCallUpdateCustomText = true;
numberOfUpdateCustomTextCalls++;
return Promise.resolve({ data: {} });
},
update: (data) => {
didCallUpdatePromptsSettings = true;
expect(data).to.deep.equal(mockPromptsSettings);
return Promise.resolve({ data });
},
updateRendering: () => {
didCallUpdateScreenRenderer = true;
return Promise.resolve({ data: {} });
},
_getRestClient: (endpoint) => ({
get: (...options) => Promise.resolve({ endpoint, method: 'get', options }),
}),
},
pool: new PromisePoolExecutor({
concurrencyLimit: 3,
frequencyLimit: 1000,
frequencyWindow: 1000, // 1 sec
}),
};

config.data.AUTH0_EXPERIMENTAL_EA = false;

const handler = new promptsHandler({
client: auth0,
config: config,
});

sinon.stub(handler, 'updateCustomPartials').callsFake(() => {
didCallUpdatePartials = true;
numberOfUpdatePartialsCalls++;
return Promise.resolve({});
});

const stageFn = Object.getPrototypeOf(handler).processChanges;

await stageFn.apply(handler, [
{
prompts: {
...mockPromptsSettings,
customText: customTextToSet,
partials: partialsToSet,
screenRenderers: screenRenderersToSet,
},
},
]);
expect(didCallUpdatePromptsSettings).to.equal(true);
expect(didCallUpdateCustomText).to.equal(true);
expect(didCallUpdatePartials).to.equal(true);
expect(didCallUpdateScreenRenderer).to.equal(false);
expect(numberOfUpdateCustomTextCalls).to.equal(3);
expect(numberOfUpdatePartialsCalls).to.equal(3);
});

it('should not fail if tenant languages or partials are undefined', async () => {
const auth0 = {
tenants: {
Expand All @@ -360,6 +465,8 @@ describe('#prompts handler', () => {
}),
};

config.data.AUTH0_EXPERIMENTAL_EA = true;

const handler = new promptsHandler({ client: auth0, config: config });
const getCustomPartial = sinon.stub(handler, 'getCustomPartial');
getCustomPartial.withArgs({ prompt: 'login' }).resolves({});
Expand Down

0 comments on commit 517fec5

Please sign in to comment.