-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): added tests for user model
- Loading branch information
Showing
5 changed files
with
84 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
'use strict'; | ||
|
||
var should = require('should'), | ||
mongoose = require('mongoose'), | ||
User = mongoose.model('User'); | ||
|
||
var user; | ||
|
||
describe('User Model', function() { | ||
before(function(done) { | ||
user = new User({ | ||
provider: 'local', | ||
name: 'Fake User', | ||
email: 'test@test.com', | ||
password: 'password' | ||
}); | ||
|
||
// Clear users before testing | ||
User.remove().exec(); | ||
done(); | ||
}); | ||
|
||
afterEach(function(done) { | ||
User.remove().exec(); | ||
done(); | ||
}); | ||
|
||
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(); | ||
var userDup = new User(user); | ||
userDup.save(function(err) { | ||
should.exist(err); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should fail when saving without an email', function(done) { | ||
user.email = ''; | ||
user.save(function(err) { | ||
should.exist(err); | ||
done(); | ||
}); | ||
}); | ||
|
||
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; | ||
}); | ||
|
||
}); |