1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-14 13:15:01 -05:00
mail/test/unit/admin-dao-test.js

142 lines
4.0 KiB
JavaScript
Raw Normal View History

2014-10-07 14:32:23 -04:00
'use strict';
2014-10-07 14:32:23 -04:00
var RestDAO = require('../../src/js/dao/rest-dao'),
AdminDAO = require('../../src/js/dao/admin-dao');
2014-10-07 14:32:23 -04:00
describe('Admin DAO unit tests', function() {
2014-10-07 14:32:23 -04:00
var adminDao, restDaoStub,
emailAddress = 'test@example.com',
password = 'secret';
2014-10-07 14:32:23 -04:00
beforeEach(function() {
restDaoStub = sinon.createStubInstance(RestDAO);
adminDao = new AdminDAO(restDaoStub);
});
afterEach(function() {});
describe('createUser', function() {
it('should fail due to incomplete args', function(done) {
var opt = {
emailAddress: emailAddress
};
2014-10-07 14:32:23 -04:00
adminDao.createUser(opt, function(err) {
expect(err).to.exist;
done();
});
});
2014-10-07 14:32:23 -04:00
it('should fail if user already exists', function(done) {
var opt = {
emailAddress: emailAddress,
password: password,
phone: '12345'
};
2014-10-07 14:32:23 -04:00
restDaoStub.post.withArgs(opt, '/user').yields({
code: 409
});
2014-10-07 14:32:23 -04:00
adminDao.createUser(opt, function(err) {
expect(err.message).to.contain('already taken');
expect(restDaoStub.post.calledOnce).to.be.true;
done();
});
2014-10-07 14:32:23 -04:00
});
2014-10-07 14:32:23 -04:00
it('should fail due to unknown error', function(done) {
var opt = {
emailAddress: emailAddress,
password: password,
phone: '12345'
};
2014-10-07 14:32:23 -04:00
restDaoStub.post.withArgs(opt, '/user').yields(new Error());
2014-10-07 14:32:23 -04:00
adminDao.createUser(opt, function(err) {
expect(err).to.exist;
expect(restDaoStub.post.calledOnce).to.be.true;
done();
});
2014-10-07 14:32:23 -04:00
});
2014-10-07 14:32:23 -04:00
it('should work', function(done) {
var opt = {
emailAddress: emailAddress,
password: password,
phone: '12345'
};
2014-10-07 14:32:23 -04:00
restDaoStub.post.withArgs(opt, '/user').yields();
2014-10-07 14:32:23 -04:00
adminDao.createUser(opt, function(err) {
expect(err).to.not.exist;
expect(restDaoStub.post.calledOnce).to.be.true;
done();
});
});
2014-10-07 14:32:23 -04:00
});
2014-10-07 14:32:23 -04:00
describe('validateUser', function() {
it('should fail due to incomplete args', function(done) {
var opt = {
emailAddress: emailAddress
};
2014-09-19 12:59:13 -04:00
2014-10-07 14:32:23 -04:00
adminDao.validateUser(opt, function(err) {
expect(err).to.exist;
done();
2014-09-19 12:59:13 -04:00
});
2014-10-07 14:32:23 -04:00
});
2014-09-19 12:59:13 -04:00
2014-10-07 14:32:23 -04:00
it('should fail due to error in rest api', function(done) {
var opt = {
emailAddress: emailAddress,
token: 'H45Z6D'
};
2014-09-19 12:59:13 -04:00
2014-10-07 14:32:23 -04:00
restDaoStub.post.withArgs(opt, '/user/validate').yields(new Error());
2014-09-19 12:59:13 -04:00
2014-10-07 14:32:23 -04:00
adminDao.validateUser(opt, function(err) {
expect(err).to.exist;
expect(restDaoStub.post.calledOnce).to.be.true;
done();
2014-09-19 12:59:13 -04:00
});
2014-10-07 14:32:23 -04:00
});
it('should work with no error object', function(done) {
var opt = {
emailAddress: emailAddress,
token: 'H45Z6D'
};
2014-09-19 12:59:13 -04:00
2014-10-07 14:32:23 -04:00
restDaoStub.post.withArgs(opt, '/user/validate').yields();
2014-09-19 12:59:13 -04:00
2014-10-07 14:32:23 -04:00
adminDao.validateUser(opt, function(err) {
expect(err).to.not.exist;
expect(restDaoStub.post.calledOnce).to.be.true;
done();
});
});
2014-09-19 12:59:13 -04:00
2014-10-07 14:32:23 -04:00
it('should work with 202', function(done) {
var opt = {
emailAddress: emailAddress,
token: 'H45Z6D'
};
restDaoStub.post.withArgs(opt, '/user/validate').yields({
code: 202
2014-09-19 12:59:13 -04:00
});
2014-10-07 14:32:23 -04:00
adminDao.validateUser(opt, function(err) {
expect(err).to.not.exist;
expect(restDaoStub.post.calledOnce).to.be.true;
done();
2014-09-19 12:59:13 -04:00
});
});
});
});