2014-10-07 14:32:23 -04:00
|
|
|
'use strict';
|
2014-09-15 11:09:13 -04:00
|
|
|
|
2014-11-21 09:06:29 -05:00
|
|
|
var RestDAO = require('../../../src/js/service/rest'),
|
|
|
|
AdminDAO = require('../../../src/js/service/admin'),
|
|
|
|
appConfig = require('../../../src/js/app-config');
|
2014-09-15 11:09:13 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe('Admin DAO unit tests', function() {
|
2014-09-15 11:09:13 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
var adminDao, restDaoStub,
|
|
|
|
emailAddress = 'test@example.com',
|
|
|
|
password = 'secret';
|
2014-09-15 11:09:13 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
beforeEach(function() {
|
|
|
|
restDaoStub = sinon.createStubInstance(RestDAO);
|
2014-11-21 09:06:29 -05:00
|
|
|
adminDao = new AdminDAO(restDaoStub, appConfig);
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function() {});
|
|
|
|
|
|
|
|
describe('createUser', function() {
|
|
|
|
it('should fail due to incomplete args', function(done) {
|
|
|
|
var opt = {
|
|
|
|
emailAddress: emailAddress
|
|
|
|
};
|
2014-09-15 11:09:13 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
adminDao.createUser(opt, function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-09-15 11:09:13 -04:00
|
|
|
|
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-09-15 11:09:13 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
restDaoStub.post.withArgs(opt, '/user').yields({
|
|
|
|
code: 409
|
2014-09-15 11:09:13 -04:00
|
|
|
});
|
|
|
|
|
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-09-15 11:09:13 -04:00
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2014-09-15 11:09:13 -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-09-15 11:09:13 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
restDaoStub.post.withArgs(opt, '/user').yields(new Error());
|
2014-09-15 11:09:13 -04:00
|
|
|
|
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-09-15 11:09:13 -04:00
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2014-09-15 11:09:13 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
it('should work', function(done) {
|
|
|
|
var opt = {
|
|
|
|
emailAddress: emailAddress,
|
|
|
|
password: password,
|
|
|
|
phone: '12345'
|
|
|
|
};
|
2014-09-15 11:09:13 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
restDaoStub.post.withArgs(opt, '/user').yields();
|
2014-09-15 11:09:13 -04:00
|
|
|
|
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-09-15 11:09:13 -04:00
|
|
|
});
|
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2014-09-15 11:09:13 -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
|
|
|
});
|
|
|
|
});
|
2014-09-15 11:09:13 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|