tellform/app/tests/user.server.model.test.js

91 lines
1.8 KiB
JavaScript
Raw Normal View History

2016-03-30 01:21:45 +00:00
'use strict';
2015-06-29 22:51:29 +00:00
2016-03-30 01:21:45 +00:00
/**
* Module dependencies.
*/
var should = require('should'),
mongoose = require('mongoose'),
User = mongoose.model('User');
2015-06-29 22:51:29 +00:00
2016-03-30 01:21:45 +00:00
/**
* Globals
*/
var user, user2;
2015-06-29 22:51:29 +00:00
2016-03-30 01:21:45 +00:00
/**
* Unit tests
*/
describe('User Model Unit Tests:', function() {
beforeEach(function(done) {
user = new User({
firstName: 'Full',
lastName: 'Name',
2016-11-09 20:25:38 +00:00
username: 'test',
2016-03-30 01:21:45 +00:00
email: 'test@test.com',
password: 'password',
provider: 'local'
});
user2 = new User({
firstName: 'Full',
lastName: 'Name',
2016-11-09 20:25:38 +00:00
username: 'test',
2016-03-30 01:21:45 +00:00
email: 'test@test.com',
password: 'password',
provider: 'local'
});
2015-06-29 22:51:29 +00:00
2016-03-30 01:21:45 +00:00
done();
});
2015-06-29 22:51:29 +00:00
2016-03-30 01:21:45 +00:00
describe('Method Save', function() {
it('should begin with no users', function(done) {
User.find({}, function(err, users) {
users.should.have.length(0);
done();
});
});
2015-06-29 22:51:29 +00:00
2016-03-30 01:21:45 +00:00
it('should be able to save without problems', function(done) {
user.save(done);
});
2015-06-29 22:51:29 +00:00
2016-03-30 01:21:45 +00:00
it('should fail to save an existing user again', function(done) {
user.save(function() {
user2.save(function(err) {
should.exist(err);
done();
2016-11-09 20:25:38 +00:00
});
2016-03-30 01:21:45 +00:00
});
});
2015-06-29 22:51:29 +00:00
2016-11-09 20:25:38 +00:00
it('should be able to show an error when try to save without username', function(done) {
user.username = '';
user.save(function(err) {
2016-03-30 01:21:45 +00:00
should.exist(err);
done();
});
});
});
2015-06-29 22:51:29 +00:00
2016-03-30 01:21:45 +00:00
describe('Method findUniqueUsername', function() {
beforeEach(function(done) {
User.find({}, function(err, users) {
users.should.have.length(0);
user.save(done);
});
});
2015-08-07 21:02:44 +00:00
2016-03-30 01:21:45 +00:00
it('should be able to find unique version of existing username without problems', function(done) {
User.findUniqueUsername(user.username, null, function (availableUsername) {
availableUsername.should.not.equal(user.username);
done();
});
});
2015-08-07 21:02:44 +00:00
2016-03-30 01:21:45 +00:00
});
2015-08-07 21:02:44 +00:00
2016-03-30 01:21:45 +00:00
afterEach(function(done) {
User.remove().exec(done);
});
});