File size: 1,527 Bytes
7f88cfb | 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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | 'use strict';
/**
* Module dependencies.
*/
var should = require('should'),
mongoose = require('mongoose'),
User = mongoose.model('User'),
Comment = mongoose.model('Comment');
/**
* Globals
*/
var user, comment;
/**
* Unit tests
*/
describe('Comment Model Unit Tests:', function() {
beforeEach(function(done) {
user = new User({
firstName: 'Full',
lastName: 'Name',
displayName: 'Full Name',
email: 'test@test.com',
username: 'username',
password: 'password'
});
user.save(function() {
comment = new Comment({
projectid: '111111111111',
message: 'Hello World',
author: 'username',
date: Date.now()
});
done();
});
});
describe('Method Save', function() {
it('should be able to save without problems', function(done) {
return comment.save(function(err) {
should.not.exist(err);
done();
});
});
it('should have error when saving without projectid', function(done) {
comment.projectid ='';
return comment.save(function(err) {
should.exist(err);
done();
});
});
it('should have error when saving without user', function(done) {
comment.author ='';
return comment.save(function(err) {
should.exist(err);
done();
});
});
});
afterEach(function(done) {
Comment.remove().exec();
User.remove().exec();
done();
});
});
|