3 var app = require('../..');
4 var User = require('./user.model');
6 var genUser = function() {
10 email: 'test@example.com',
16 describe('User Model', function() {
18 // Clear users before testing
19 return User.removeAsync();
22 beforeEach(function() {
26 afterEach(function() {
27 return User.removeAsync();
30 it('should begin with no users', function() {
31 return User.findAsync({}).should
32 .eventually.have.length(0);
35 it('should fail when saving a duplicate user', function() {
36 return user.saveAsync()
38 var userDup = genUser();
39 return userDup.saveAsync();
40 }).should.be.rejected;
43 describe('#email', function() {
44 it('should fail when saving without an email', function() {
46 return user.saveAsync().should.be.rejected;
50 describe('#password', function() {
51 beforeEach(function() {
52 return user.saveAsync();
55 it('should authenticate user if valid', function() {
56 user.authenticate('password').should.be.true;
59 it('should not authenticate user if invalid', function() {
60 user.authenticate('blah').should.not.be.true;
63 it('should remain the same hash unless the password is updated', function() {
64 user.name = 'Test User';
65 return user.saveAsync()
67 return u.authenticate('password');
68 }).should.eventually.be.true;