Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aebbade
commit 2ac4fbc
Showing
11 changed files
with
489 additions
and
1 deletion.
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
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,22 @@ | ||
import ListResource from './ListResource'; | ||
import ClientResource from './ClientResource'; | ||
|
||
/** | ||
* Client list class | ||
* | ||
* @class | ||
*/ | ||
export default class ClientList extends ListResource { | ||
/** | ||
* Creates a new {@link ClientList}. | ||
* | ||
* @param {object} resource resource loaded from the API. | ||
* @param {string} environment the environment this resource is associated to. | ||
* @param {?object} traversal traversal from which traverson can continue. | ||
*/ | ||
constructor(resource, environment, traversal) { | ||
super(resource, environment, 'ec:acc/client', traversal); | ||
this.ListClass = ClientList; | ||
this.ItemClass = ClientResource; | ||
} | ||
} |
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,34 @@ | ||
import Resource from './Resource'; | ||
|
||
/** | ||
* ClientResource class | ||
* | ||
* @class | ||
*/ | ||
export default class ClientResource extends Resource { | ||
getClientID() { | ||
return this.getProperty('clientID'); | ||
} | ||
|
||
getCallbackURL() { | ||
return this.getProperty('callbackURL'); | ||
} | ||
|
||
getConfig() { | ||
return this.getProperty('config'); | ||
} | ||
|
||
setCallbackURL(value) { | ||
if (!value) { | ||
throw new Error('callbackURL must be defined.'); | ||
} | ||
return this.setProperty('callbackURL', value); | ||
} | ||
|
||
setConfig(value) { | ||
if (!value) { | ||
throw new Error('config must be defined.'); | ||
} | ||
return this.setProperty('config', value); | ||
} | ||
} |
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,116 @@ | ||
/* eslint no-unused-expressions:0 */ | ||
|
||
const chai = require('chai'); | ||
const sinon = require('sinon'); | ||
const sinonChai = require('sinon-chai'); | ||
const fs = require('fs'); | ||
|
||
const ClientResource = require('../lib/resources/ClientResource').default; | ||
const ClientList = require('../lib/resources/ClientList').default; | ||
const Resource = require('../lib/resources/Resource').default; | ||
const ListResource = require('../lib/resources/ListResource').default; | ||
|
||
const should = chai.should(); | ||
chai.use(sinonChai); | ||
|
||
function capitalizeFirstLetter(string) { | ||
return string.charAt(0).toUpperCase() + string.slice(1); | ||
} | ||
|
||
describe('Client ListResource', () => { | ||
let listJson; | ||
let list; | ||
before(() => { | ||
return new Promise((resolve, reject) => { | ||
fs.readFile(`${__dirname}/mocks/client-list.json`, 'utf-8', (err, res) => { | ||
if (err) { | ||
return reject(err); | ||
} | ||
return resolve(JSON.parse(res)); | ||
}); | ||
}) | ||
.then((json) => { | ||
listJson = json; | ||
}); | ||
}); | ||
beforeEach(() => { | ||
list = new ClientList(listJson); | ||
}); | ||
afterEach(() => { | ||
list = null; | ||
}); | ||
it('should be instance of ListResource', () => { | ||
list.should.be.instanceOf(ListResource); | ||
}); | ||
it('should be instance of ClientList', () => { | ||
list.should.be.instanceOf(ClientList); | ||
}); | ||
it('should have TokenResource items', () => { | ||
list.getAllItems().forEach(item => item.should.be.instanceOf(ClientResource)); | ||
}); | ||
}); | ||
|
||
describe('Token Resource', () => { | ||
let resourceJson; | ||
let resource; | ||
before(() => { | ||
return new Promise((resolve, reject) => { | ||
fs.readFile(`${__dirname}/mocks/client-single.json`, 'utf-8', (err, res) => { | ||
if (err) { | ||
return reject(err); | ||
} | ||
return resolve(JSON.parse(res)); | ||
}); | ||
}) | ||
.then((json) => { | ||
resourceJson = json; | ||
}); | ||
}); | ||
beforeEach(() => { | ||
resource = new ClientResource(resourceJson); | ||
}); | ||
afterEach(() => { | ||
resource = null; | ||
}); | ||
it('should be instance of Resource', () => { | ||
resource.should.be.instanceOf(Resource); | ||
}); | ||
it('should be instance of ClientResource', () => { | ||
resource.should.be.instanceOf(ClientResource); | ||
}); | ||
|
||
const getter = [ | ||
'clientID', 'callbackURL', 'config', | ||
]; | ||
getter.forEach((name) => { | ||
it(`should call resource.getProperty with ${name}`, () => { | ||
const spy = sinon.spy(resource, 'getProperty'); | ||
|
||
const property = resource[`get${capitalizeFirstLetter(name)}`](); | ||
spy.should.have.been.called.once; | ||
spy.should.have.been.calledWith(name); | ||
property.should.be.equal(resource.getProperty(name)); | ||
|
||
spy.restore(); | ||
}); | ||
}); | ||
|
||
const setter = [ | ||
'callbackURL', 'config', | ||
]; | ||
setter.forEach((name) => { | ||
it(`should call resource.setProperty with ${name}`, () => { | ||
const spy = sinon.spy(resource, 'setProperty'); | ||
|
||
resource[`set${capitalizeFirstLetter(name)}`](resource.getProperty(name)); | ||
spy.should.have.been.called.once; | ||
spy.should.have.been.calledWith(name, resource.getProperty(name)); | ||
|
||
spy.restore(); | ||
}); | ||
it(`should throw on set${capitalizeFirstLetter(name)} with undefined value`, () => { | ||
const throws = () => resource[`set${capitalizeFirstLetter(name)}`](); | ||
throws.should.throw(Error); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.