Skip to content

Commit

Permalink
Fixed imports and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémi committed Jul 21, 2017
1 parent 69de8e0 commit 2a9f769
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/clients/HookClient.js
@@ -1,6 +1,4 @@
const PageableStream = require('./PageableStream');
const HTTPClient = require('./HTTPClient');
const logger = require('../utils/logger');

const endpoints = {
createHook: {
Expand Down
52 changes: 52 additions & 0 deletions tests/clients/HookClient.spec.js
Expand Up @@ -53,6 +53,32 @@ describe('hookClient', () => {
});
});

it('should return an error message when request fails with statusCode 400', done => {
// Given
const hook = { type: 'web', name: 'Hook', url: 'https://localhost/hookName' };
const error = { message: 'Error !', statusCode: 400 };
hookClient.httpClient.sendEndpointRequest = sinon.stub().returns(Promise.reject(error));

// When / Then
hookClient.createHook(token, hook).then(result => {
done('should have failed');
}).catch(err => {
expect(err).to.be.equals('A hook with this name already exists.');
expect(hookClient.httpClient.sendEndpointRequest).to.have.been.calledOnce;
expect(hookClient.httpClient.sendEndpointRequest).to.have.been.calledWithExactly(
{
method: 'POST',
path: '/api/dispatcher/hooks'
},
{
headers: { 'x-auth-token': token },
body: hook
}
);
done();
});
});

it('should return the created hook', done => {
// Given
const hook = { type: 'web', name: 'Hook', url: 'https://localhost/hookName' };
Expand Down Expand Up @@ -109,6 +135,32 @@ describe('hookClient', () => {
});
});

it('should return an error message when request fails with a 404', done => {
// Given
const name = 'aHook';
const error = { message: 'Error !', statusCode: 404 };
hookClient.httpClient.sendEndpointRequest = sinon.stub().returns(Promise.reject(error));

// When / Then
hookClient.deleteHook(token, name).then(result => {
done('should have failed');
}).catch(err => {
expect(err).to.be.equals('The hook you are trying to remove does not exist.');
expect(hookClient.httpClient.sendEndpointRequest).to.have.been.calledOnce;
expect(hookClient.httpClient.sendEndpointRequest).to.have.been.calledWithExactly(
{
method: 'DELETE',
path: '/api/dispatcher/hooks/:hook'
},
{
headers: { 'x-auth-token': token },
pathVariables: { hook: name }
}
);
done();
});
});

it('should return nothing when hook is deleted', done => {
// Given
const name = 'aHook';
Expand Down

0 comments on commit 2a9f769

Please sign in to comment.