Skip to content

Commit 3dca3a4

Browse files
chrisscottDrew Fyock
authored and
Drew Fyock
committed
Add handlers for the Branding and Prompts API endpoints. (auth0#70)
1 parent ae7d3d4 commit 3dca3a4

File tree

6 files changed

+369
-257
lines changed

6 files changed

+369
-257
lines changed

src/auth0/handlers/branding.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import DefaultHandler from './default';
2+
3+
export const schema = { type: 'object' };
4+
5+
export default class BrandingHandler extends DefaultHandler {
6+
constructor(options) {
7+
super({
8+
...options,
9+
type: 'branding'
10+
});
11+
}
12+
13+
async getType() {
14+
try {
15+
return await this.client.branding.getSettings();
16+
} catch (err) {
17+
if (err.statusCode === 404) return {};
18+
throw err;
19+
}
20+
}
21+
22+
async processChanges(assets) {
23+
const { branding } = assets;
24+
25+
// Do nothing if not set
26+
if (!branding) return;
27+
28+
await this.client.branding.updateSettings(branding);
29+
this.updated += 1;
30+
this.didUpdate(branding);
31+
}
32+
}

src/auth0/handlers/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import * as guardianFactors from './guardianFactors';
1313
import * as guardianFactorProviders from './guardianFactorProviders';
1414
import * as guardianFactorTemplates from './guardianFactorTemplates';
1515
import * as roles from './roles';
16+
import * as branding from './branding';
17+
import * as prompts from './prompts';
1618

1719
export {
1820
rules,
@@ -29,5 +31,7 @@ export {
2931
guardianFactors,
3032
guardianFactorProviders,
3133
guardianFactorTemplates,
32-
roles
34+
roles,
35+
branding,
36+
prompts
3337
};

src/auth0/handlers/prompts.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import DefaultHandler from './default';
2+
3+
export const schema = { type: 'object' };
4+
5+
export default class PromptsHandler extends DefaultHandler {
6+
constructor(options) {
7+
super({
8+
...options,
9+
type: 'prompts'
10+
});
11+
}
12+
13+
async getType() {
14+
try {
15+
return await this.client.prompts.getSettings();
16+
} catch (err) {
17+
if (err.statusCode === 404) return {};
18+
throw err;
19+
}
20+
}
21+
22+
async processChanges(assets) {
23+
const { prompts } = assets;
24+
25+
// Do nothing if not set
26+
if (!prompts) return;
27+
28+
await this.client.prompts.updateSettings(prompts);
29+
this.updated += 1;
30+
this.didUpdate(prompts);
31+
}
32+
}
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const { expect } = require('chai');
2+
const branding = require('../../../src/auth0/handlers/branding');
3+
4+
describe('#branding handler', () => {
5+
describe('#branding process', () => {
6+
it('should get branding', async () => {
7+
const auth0 = {
8+
branding: {
9+
getSettings: () => ({
10+
logo_url: 'https://example.com/logo.png'
11+
})
12+
}
13+
};
14+
15+
const handler = new branding.default({ client: auth0 });
16+
const data = await handler.getType();
17+
expect(data).to.deep.equal({
18+
logo_url: 'https://example.com/logo.png'
19+
});
20+
});
21+
22+
it('should update branding settings', async () => {
23+
const auth0 = {
24+
branding: {
25+
updateSettings: (data) => {
26+
expect(data).to.be.an('object');
27+
expect(data.logo_url).to.equal('https://example.com/logo.png');
28+
return Promise.resolve(data);
29+
}
30+
}
31+
};
32+
33+
const handler = new branding.default({ client: auth0 });
34+
const stageFn = Object.getPrototypeOf(handler).processChanges;
35+
36+
await stageFn.apply(handler, [
37+
{ branding: { logo_url: 'https://example.com/logo.png' } }
38+
]);
39+
});
40+
});
41+
});

tests/auth0/handlers/prompts.tests.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const { expect } = require('chai');
2+
const prompts = require('../../../src/auth0/handlers/prompts');
3+
4+
describe('#prompts handler', () => {
5+
describe('#prompts process', () => {
6+
it('should get prompts', async () => {
7+
const auth0 = {
8+
prompts: {
9+
getSettings: () => ({
10+
universal_login_experience: 'new'
11+
})
12+
}
13+
};
14+
15+
const handler = new prompts.default({ client: auth0 });
16+
const data = await handler.getType();
17+
expect(data).to.deep.equal({
18+
universal_login_experience: 'new'
19+
});
20+
});
21+
22+
it('should update prompts settings', async () => {
23+
const auth0 = {
24+
prompts: {
25+
updateSettings: (data) => {
26+
expect(data).to.be.an('object');
27+
expect(data.universal_login_experience).to.equal('new');
28+
return Promise.resolve(data);
29+
}
30+
}
31+
};
32+
33+
const handler = new prompts.default({ client: auth0 });
34+
const stageFn = Object.getPrototypeOf(handler).processChanges;
35+
36+
await stageFn.apply(handler, [
37+
{ prompts: { universal_login_experience: 'new' } }
38+
]);
39+
});
40+
});
41+
});

0 commit comments

Comments
 (0)