Added missing endpoint + fix for mailer

This commit is contained in:
Wyatt Johnson
2017-01-09 15:50:46 -07:00
parent 4c5b85a2ae
commit ec3a114e65
7 changed files with 168 additions and 23 deletions
+7
View File
@@ -0,0 +1,7 @@
const kue = require('../services/kue');
beforeEach(() => {
// Empty the test tasks before finishing.
kue.TestQueue.splice(0, kue.TestQueue.length);
});
+34
View File
@@ -1,6 +1,7 @@
const passport = require('../../../passport');
const app = require('../../../../app');
const mailer = require('../../../../services/mailer');
const chai = require('chai');
const expect = chai.expect;
@@ -10,6 +11,39 @@ chai.use(require('chai-http'));
const User = require('../../../../models/user');
describe('/api/v1/users/:user_id/email/confirm', () => {
let mockUser;
beforeEach(() => User.createLocalUser('ana@gmail.com', '123', 'Ana').then((user) => {
mockUser = user;
}));
describe('#post', () => {
it('should send an email when we hit the endpoint', () => {
expect(mailer.task.tasks).to.have.length(0);
return chai.request(app)
.post(`/api/v1/users/${mockUser.id}/email/confirm`)
.set(passport.inject({roles: ['admin']}))
.then((res) => {
expect(res).to.have.status(204);
expect(mailer.task.tasks).to.have.length(1);
});
});
it('should send a 404 on not matching a user', () => {
return chai.request(app)
.post(`/api/v1/users/${mockUser.id}/email/confirm`)
.set(passport.inject({roles: ['admin']}))
.then((res) => {
expect(res).to.have.status(204);
expect(mailer.task.tasks).to.have.length(1);
});
});
});
});
describe('/api/v1/users/:user_id/actions', () => {
const users = [{