Skip to content

Commit

Permalink
Add client method to retreive all components from baracks
Browse files Browse the repository at this point in the history
  • Loading branch information
Grégoire Weber committed Mar 10, 2017
1 parent 7e8cf3e commit 369d7d1
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
14 changes: 14 additions & 0 deletions clients/Barracks.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,20 @@ class Barracks {
});
}

getComponents(token) {
return new Promise(resolve => {
logger.debug('Getting components');
const stream = new PageableStream();
resolve(stream);
this.client.retrieveAllPages(stream, 'getComponents', {
headers: {
'x-auth-token': token
}
},
'components');
});
}

createVersion(token, version) {
return new Promise((resolve, reject) => {
this.client.sendEndpointRequest('createVersion', {
Expand Down
28 changes: 27 additions & 1 deletion clients/Barracks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1346,8 +1346,34 @@ describe('Barracks', () => {
});
});

describe('#createVersion()', () => {
describe('#createComponent()', () => {

it('should return a stream object and deleguate to the client', done => {
// Given
const options = {
headers: { 'x-auth-token': token }
};

barracks.client.retrieveAllPages = sinon.spy();

// When / Then
barracks.getComponents(token).then(result => {
expect(result).to.be.instanceOf(PageableStream);
expect(barracks.client.retrieveAllPages).to.have.been.calledOnce;
expect(barracks.client.retrieveAllPages).to.have.been.calledWithExactly(
new PageableStream(),
'getComponents',
options,
'components'
);
done();
}).catch(err => {
done(err);
});
});
});

describe('#createVersion()', () => {

const filename = 'file.txt';
const filePath = 'path/to/file.txt';
Expand Down
4 changes: 4 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ module.exports = {
createVersion: {
method: 'POST',
path: '/api/member/components/:componentRef/versions'
},
getComponents: {
method: 'GET',
path: '/api/member/components'
}
}
},
Expand Down

0 comments on commit 369d7d1

Please sign in to comment.