From 5b8754ffe93de955e950873c23167ce43416e6f9 Mon Sep 17 00:00:00 2001 From: Phillip Henslee Date: Thu, 22 Oct 2015 20:52:25 -0500 Subject: [PATCH] Added test to for im module --- lib/slack/im.spec.js | 67 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 10 deletions(-) diff --git a/lib/slack/im.spec.js b/lib/slack/im.spec.js index ef67d78..8a3947c 100644 --- a/lib/slack/im.spec.js +++ b/lib/slack/im.spec.js @@ -37,15 +37,6 @@ describe('im', function () { done(); }); - it('should return an error to callback if missing required string argument', function (done) { - - im.close(null, function (err, result) { - expect(err).to.not.equal(null); - expect(err.message).to.equal('must supply valid argument(s)'); - }); - done(); - }); - it('should return an api response to caller', function (done) { var scope = nock('https://slack.com') @@ -56,9 +47,20 @@ describe('im', function () { 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/im.close') + .reply(200, { ok: false, error: 'channel_not_found' }); + + im.close('channelid', function (err, result) { + expect(err).to.be.an('error'); + expect(err.message).to.equal('channel_not_found'); + done(); + }) }); }); @@ -91,8 +93,19 @@ describe('im', function () { 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/im.list') + .reply(200, { ok: false, error: 'channel_not_found' }); + im.getList(function (err, result) { + expect(err).to.be.an('error'); + expect(err.message).to.equal('channel_not_found'); + done(); + }) }); }); @@ -133,8 +146,18 @@ describe('im', function () { 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/im.history') + .reply(200, { ok: false, error: 'channel_not_found' }); + im.getHistory('channelid', function (err, result) { + expect(err).to.be.an('error'); + expect(err.message).to.equal('channel_not_found'); + done(); + }) }); }); @@ -170,6 +193,18 @@ describe('im', function () { done(); }); }); + it('should return an api error to caller', function (done) { + + var scope = nock('https://slack.com') + .post('/api/im.mark') + .reply(200, { ok: false, error: 'channel_not_found' }); + + im.mark('channelid', function (err, result) { + expect(err).to.be.an('error'); + expect(err.message).to.equal('channel_not_found'); + done(); + }) + }); }); @@ -216,5 +251,17 @@ describe('im', function () { done(); }); }); + it('should return an api error to caller', function (done) { + + var scope = nock('https://slack.com') + .post('/api/im.open') + .reply(200, { ok: false, error: 'user_not_found' }); + + im.open('channelid', function (err, result) { + expect(err).to.be.an('error'); + expect(err.message).to.equal('user_not_found'); + done(); + }) + }); }); }); \ No newline at end of file