mirror of
https://github.com/fergalmoran/roboto-promoto.git
synced 2025-12-22 09:37:37 +00:00
60 lines
1.4 KiB
JavaScript
60 lines
1.4 KiB
JavaScript
'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;
|
|
});
|
|
|
|
}); |