Skip to content

Commit

Permalink
Added two test to the test module
Browse files Browse the repository at this point in the history
  • Loading branch information
philliphenslee committed Oct 22, 2015
1 parent 6f2a4e2 commit 82d3d5b
Showing 1 changed file with 44 additions and 16 deletions.
60 changes: 44 additions & 16 deletions lib/slack/test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,23 @@ describe('test', function () {
// function (method, params, callback)
describe('#api', function () {

before(function () {

var scope = nock('https://slack.com')
.post('/api/api.test')
.reply(200, { ok: true, args: { foo: 'bar' } });
});

it('exists as method on test', function (done) {
expect(typeof test.api).to.equal('function');
done();
})

it('should throw and error without a valid callback', function (done) {
expect(function () {
test.api(null, null);
}).to.throw('callback must be a function');
done();
});

it('should return an error to callback if missing required arguments', function (done) {

var scope = nock('https://slack.com')
.post('/api/api.test')
.reply(200, { ok: true, args: { foo: 'bar' } });
test.api(null, function (err, result) {
expect(err).to.not.equal(null);
expect(err.message).to.equal('must supply valid argument(s)');
Expand All @@ -50,19 +54,24 @@ describe('test', function () {
done();

});
});

// function (method, params, callback)
describe('#auth', function () {

beforeEach(function () {
it('should return an api error to caller', function (done) {

var scope = nock('https://slack.com')
.post('/api/auth.test')
.reply(200, {
ok: true,
});
.post('/api/api.test')
.reply(200, { ok: false, error: 'invalid api request' });

test.api({foo: 'bar'}, function (err, result) {
expect(err).to.be.an('error');
expect(err.message).to.equal('invalid api request');
done();
});

});
});

// function (method, params, callback)
describe('#auth', function () {

it('exists as method on test', function (done) {
expect(typeof test.auth).to.equal('function');
Expand All @@ -77,13 +86,32 @@ describe('test', function () {
});

it('should return an api response', function (done) {
var scope = nock('https://slack.com')
.post('/api/auth.test')
.reply(200, {
ok: true,
});
test.auth(function (err, result) {
expect(result).to.be.an('object');
expect(result.ok).to.equal(true);
done();
});

});

it('should return an api error to caller', function (done) {

var scope = nock('https://slack.com')
.post('/api/auth.test')
.reply(200, { ok: false, error: 'invalid api request' });

test.auth(function (err, result) {
expect(err).to.be.an('error');
expect(err.message).to.equal('invalid api request');
done();
});

});
});
after(function () {
cache = null;
Expand Down

0 comments on commit 82d3d5b

Please sign in to comment.