From 82d3d5b6392c0af18ef74c56667b2918e7870a2f Mon Sep 17 00:00:00 2001 From: Phillip Henslee Date: Thu, 22 Oct 2015 08:25:07 -0500 Subject: [PATCH] Added two test to the test module --- lib/slack/test.spec.js | 60 +++++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/lib/slack/test.spec.js b/lib/slack/test.spec.js index 6592cfc..ef9733c 100644 --- a/lib/slack/test.spec.js +++ b/lib/slack/test.spec.js @@ -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)'); @@ -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'); @@ -77,6 +86,11 @@ 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); @@ -84,6 +98,20 @@ describe('test', function () { }); }); + + 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;