forked from angular-fullstack/generator-angular-fullstack
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathuser.model.spec.js
56 lines (46 loc) · 1.23 KB
/
user.model.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict';
var app = require('../../app');
var User = require('./user.model');
var user = new User({
provider: 'local',
name: 'Fake User',
email: '[email protected]',
password: 'password'
});
describe('User Model', function() {
// Clear users before testing
before(function() {
return User.remove().exec();
});
afterEach(function() {
return User.remove().exec();
});
it('should begin with no users', function(done) {
User.find({}, function(err, users) {
users.should.have.length(0);
done();
});
});
it('should fail when saving a duplicate user', function(done) {
user.save(function() {
var userDup = new User(user);
userDup.save(function(err) {
err.should.be.instanceOf(Error);
done();
});
});
});
it('should fail when saving without an email', function(done) {
user.email = '';
user.save(function(err) {
err.should.be.instanceOf(Error);
done();
});
});
it("should authenticate user if password is valid", function() {
return user.authenticate('password').should.be.true;
});
it("should not authenticate user if password is invalid", function() {
return user.authenticate('blah').should.not.be.true;
});
});