forked from angular-fullstack/generator-angular-fullstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.model.spec(sequelizeModels).js
52 lines (42 loc) · 1.21 KB
/
user.model.spec(sequelizeModels).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
'use strict';
var app = require('../../app');
var User = require('../../sqldb').User;
var userTemplate = {
provider: 'local',
name: 'Fake User',
email: '[email protected]',
password: 'password'
};
var user = User.build(userTemplate);
describe('User Model', function() {
before(function() {
// Sync and clear users before testing
User.sync().then(function() {
return User.destroy({where: {}});
});
});
afterEach(function() {
return User.destroy({where: {}});
});
it('should begin with no users', function() {
return User.findAll()
.should.eventually.have.length(0);
});
it('should fail when saving a duplicate user', function() {
return user.save()
.then(function() {
var userDup = User.build(userTemplate);
return userDup.save();
}).should.be.rejected;
});
it('should fail when saving without an email', function() {
user.email = '';
return user.save().should.be.rejected;
});
it('should authenticate user if password is valid', function() {
user.authenticate('password').should.be.true;
});
it('should not authenticate user if password is invalid', function() {
user.authenticate('blah').should.not.be.true;
});
});