Skip to content

Commit

Permalink
issue #26 Test comment works as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
vctr-dev committed Aug 15, 2019
1 parent 88e1052 commit 97af864
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/actions/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function executeCommentAction({ args, config, credentials }) {
} = args;

if (!message) {
throw new Error('No comment to post onto pull request');
return Promise.reject(new Error('No comment to post onto pull request'));
}

const client = new BitbucketClient({
Expand Down
70 changes: 70 additions & 0 deletions lib/actions/comment.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
'use strict';

const chai = require('chai');
const nock = require('nock');

const { executeCommentAction } = require('./comment');

const HTTP_CREATED = 201;

describe('Action Comment', () => {
describe('executeCommentAction', () => {
let config, credentials, args, postCommentNock;
beforeEach(() => {
config = {
bitbucket: {
repoUser: 'my-user',
repoSlug: 'my-repo',
},
};
credentials = {
bitbucket: {
username: 'user1',
password: 'pass1',
},
};
args = {
pullRequestID: 10,
commentMessage: 'foo bar',
};
postCommentNock = nock('https://api.bitbucket.org/2.0')
.post('/repositories/my-user/my-repo/pullrequests/10/comments')
.once()
.reply(HTTP_CREATED, {});
});

afterEach(() => {
nock.cleanAll();
});

it('returns error if there are no comments to post', done => {
delete args.commentMessage;
executeCommentAction({
args,
config,
credentials,
})
.then(() => done('expected error when there is no comment message to post'))
.catch(({ message }) => {
chai.expect(message).to.equal('No comment to post onto pull request');
chai.expect(postCommentNock.isDone(), 'Request should not be called').to.be.false;
done();
});
});

it('returns success when posting comment with all args', done => {
executeCommentAction({
args,
config,
credentials,
})
.then(() => {
chai.expect(postCommentNock.isDone(), 'Request should have been called once').to.be.true;
done();
})
.catch(({ message }) => {
done(message);
});
});
});
});

0 comments on commit 97af864

Please sign in to comment.