Updated User model tests
This commit is contained in:
@ -2,43 +2,40 @@ var chai = require('chai');
|
|||||||
var should = chai.should();
|
var should = chai.should();
|
||||||
var User = require('../models/User');
|
var User = require('../models/User');
|
||||||
|
|
||||||
describe('Users', function() {
|
describe('User Model', function() {
|
||||||
|
it('should create a new user', function(done) {
|
||||||
|
var user = new User({
|
||||||
before(function(done) {
|
email: 'test@gmail.com',
|
||||||
user = new User({
|
|
||||||
email: 'janedoe@gmail.com',
|
|
||||||
password: 'password'
|
password: 'password'
|
||||||
});
|
});
|
||||||
done();
|
user.save(function(err) {
|
||||||
|
if (err) return done(err);
|
||||||
|
done();
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
it('email should be a string', function() {
|
it('should not create a user with the unique email', function(done) {
|
||||||
user.email.should.be.a('string');
|
var user = new User({
|
||||||
|
email: 'test@gmail.com',
|
||||||
|
password: 'password'
|
||||||
|
});
|
||||||
|
user.save(function(err) {
|
||||||
|
if (err) return done();
|
||||||
|
done('Created a user with duplicate email');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('password should be a string', function() {
|
it('should find user by email', function(done) {
|
||||||
user.password.should.be.a('string');
|
User.findOne({ email: 'test@gmail.com' }, function(err, user) {
|
||||||
});
|
if (err) return done(err);
|
||||||
|
user.email.should.equal('test@gmail.com');
|
||||||
it('should save a user', function(done) {
|
|
||||||
user.save();
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should find our newly created user', function(done) {
|
|
||||||
User.findOne({ email: user.email }, function(err, user) {
|
|
||||||
should.exist(user);
|
|
||||||
user.email.should.equal('janedoe@gmail.com');
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not allow users with duplicate emails', function(done) {
|
it('should delete a user', function(done) {
|
||||||
user.save(function(err) {
|
User.remove({ email: 'test@gmail.com' }, function(err) {
|
||||||
if (err) {
|
if (err) return done(err);
|
||||||
err.code.should.equal(11000);
|
|
||||||
}
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user