forked from auth0/auth0-deploy-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add handlers for the Branding and Prompts API endpoints. (auth0#70)
- Loading branch information
1 parent
ae7d3d4
commit 3dca3a4
Showing
6 changed files
with
369 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import DefaultHandler from './default'; | ||
|
||
export const schema = { type: 'object' }; | ||
|
||
export default class BrandingHandler extends DefaultHandler { | ||
constructor(options) { | ||
super({ | ||
...options, | ||
type: 'branding' | ||
}); | ||
} | ||
|
||
async getType() { | ||
try { | ||
return await this.client.branding.getSettings(); | ||
} catch (err) { | ||
if (err.statusCode === 404) return {}; | ||
throw err; | ||
} | ||
} | ||
|
||
async processChanges(assets) { | ||
const { branding } = assets; | ||
|
||
// Do nothing if not set | ||
if (!branding) return; | ||
|
||
await this.client.branding.updateSettings(branding); | ||
this.updated += 1; | ||
this.didUpdate(branding); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import DefaultHandler from './default'; | ||
|
||
export const schema = { type: 'object' }; | ||
|
||
export default class PromptsHandler extends DefaultHandler { | ||
constructor(options) { | ||
super({ | ||
...options, | ||
type: 'prompts' | ||
}); | ||
} | ||
|
||
async getType() { | ||
try { | ||
return await this.client.prompts.getSettings(); | ||
} catch (err) { | ||
if (err.statusCode === 404) return {}; | ||
throw err; | ||
} | ||
} | ||
|
||
async processChanges(assets) { | ||
const { prompts } = assets; | ||
|
||
// Do nothing if not set | ||
if (!prompts) return; | ||
|
||
await this.client.prompts.updateSettings(prompts); | ||
this.updated += 1; | ||
this.didUpdate(prompts); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const { expect } = require('chai'); | ||
const branding = require('../../../src/auth0/handlers/branding'); | ||
|
||
describe('#branding handler', () => { | ||
describe('#branding process', () => { | ||
it('should get branding', async () => { | ||
const auth0 = { | ||
branding: { | ||
getSettings: () => ({ | ||
logo_url: 'https://example.com/logo.png' | ||
}) | ||
} | ||
}; | ||
|
||
const handler = new branding.default({ client: auth0 }); | ||
const data = await handler.getType(); | ||
expect(data).to.deep.equal({ | ||
logo_url: 'https://example.com/logo.png' | ||
}); | ||
}); | ||
|
||
it('should update branding settings', async () => { | ||
const auth0 = { | ||
branding: { | ||
updateSettings: (data) => { | ||
expect(data).to.be.an('object'); | ||
expect(data.logo_url).to.equal('https://example.com/logo.png'); | ||
return Promise.resolve(data); | ||
} | ||
} | ||
}; | ||
|
||
const handler = new branding.default({ client: auth0 }); | ||
const stageFn = Object.getPrototypeOf(handler).processChanges; | ||
|
||
await stageFn.apply(handler, [ | ||
{ branding: { logo_url: 'https://example.com/logo.png' } } | ||
]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const { expect } = require('chai'); | ||
const prompts = require('../../../src/auth0/handlers/prompts'); | ||
|
||
describe('#prompts handler', () => { | ||
describe('#prompts process', () => { | ||
it('should get prompts', async () => { | ||
const auth0 = { | ||
prompts: { | ||
getSettings: () => ({ | ||
universal_login_experience: 'new' | ||
}) | ||
} | ||
}; | ||
|
||
const handler = new prompts.default({ client: auth0 }); | ||
const data = await handler.getType(); | ||
expect(data).to.deep.equal({ | ||
universal_login_experience: 'new' | ||
}); | ||
}); | ||
|
||
it('should update prompts settings', async () => { | ||
const auth0 = { | ||
prompts: { | ||
updateSettings: (data) => { | ||
expect(data).to.be.an('object'); | ||
expect(data.universal_login_experience).to.equal('new'); | ||
return Promise.resolve(data); | ||
} | ||
} | ||
}; | ||
|
||
const handler = new prompts.default({ client: auth0 }); | ||
const stageFn = Object.getPrototypeOf(handler).processChanges; | ||
|
||
await stageFn.apply(handler, [ | ||
{ prompts: { universal_login_experience: 'new' } } | ||
]); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.