Skip to content

Commit

Permalink
check that failure message is passed through response
Browse files Browse the repository at this point in the history
  • Loading branch information
afeld committed Apr 29, 2015
1 parent 31b5b8c commit daebeb7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
6 changes: 5 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ export default function slackin({

let chanId = slack.channel ? slack.channel.id : null;
invite({ token, org, email, channel: chanId }, function(err){
if (err) return next(err);
if (err) {
return res
.status(400)
.send({ msg: err.message });
}
res.status(200).end();
});
});
Expand Down
44 changes: 36 additions & 8 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@ import slackin from '../lib/index';

describe('slackin', () => {
describe('POST /invite', () => {
it("returns success for a successful invite", (done) => {
let opts = {
token: 'mytoken',
org: 'myorg'
};

// TODO simplify mocking
nock(`https://${opts.org}.slack.com`)
let mockNumUsers = (org) => {
nock(`https://${org}.slack.com`)
.get('/api/rtm.start?token=mytoken')
.reply(200, {
team: {
Expand All @@ -20,7 +14,16 @@ describe('slackin', () => {
},
users: [{}]
});
};

it("returns success for a successful invite", (done) => {
let opts = {
token: 'mytoken',
org: 'myorg'
};

// TODO simplify mocking
mockNumUsers(opts.org);
nock(`https://${opts.org}.slack.com`)
.post('/api/users.admin.invite')
.reply(200, { ok: true });
Expand All @@ -34,5 +37,30 @@ describe('slackin', () => {
.expect(200, {})
.end(done);
});

it("returns a failure for a failure message", (done) => {
let opts = {
token: 'mytoken',
org: 'myorg'
};

// TODO simplify mocking
mockNumUsers(opts.org);
nock(`https://${opts.org}.slack.com`)
.post('/api/users.admin.invite')
.reply(200, {
ok: false,
error: "other error"
});

let app = slackin(opts);

request(app)
.post('/invite')
.send({ email: '[email protected]' })
// .expect('Content-Type', /json/)
.expect(400, { msg: "other error" })
.end(done);
});
});
});

0 comments on commit daebeb7

Please sign in to comment.