Files
meanTorrent/modules/articles/tests/server/article.server.model.tests.js

65 lines
1.1 KiB
JavaScript
Raw Normal View History

2014-02-10 13:09:31 +02:00
'use strict';
/**
* Module dependencies.
*/
var should = require('should'),
mongoose = require('mongoose'),
User = mongoose.model('User'),
Article = mongoose.model('Article');
2014-04-02 19:34:32 +03:00
/**
* Globals
*/
var user, article;
2014-02-10 13:09:31 +02:00
2014-04-02 19:34:32 +03:00
/**
* Unit tests
*/
describe('Article 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'
});
2014-02-10 13:09:31 +02:00
2014-04-02 19:34:32 +03:00
user.save(function() {
article = new Article({
title: 'Article Title',
content: 'Article Content',
user: user
2014-02-10 13:09:31 +02:00
});
2014-04-02 19:34:32 +03:00
done();
2014-02-10 13:09:31 +02:00
});
2014-04-02 19:34:32 +03:00
});
2014-02-10 13:09:31 +02:00
2014-04-02 19:34:32 +03:00
describe('Method Save', function() {
it('should be able to save without problems', function(done) {
return article.save(function(err) {
should.not.exist(err);
done();
2014-02-10 13:09:31 +02:00
});
2014-04-02 19:34:32 +03:00
});
2014-02-10 13:09:31 +02:00
2014-04-02 19:34:32 +03:00
it('should be able to show an error when try to save without title', function(done) {
article.title = '';
2014-02-10 13:09:31 +02:00
2014-04-02 19:34:32 +03:00
return article.save(function(err) {
should.exist(err);
done();
2014-02-10 13:09:31 +02:00
});
});
2014-04-02 19:34:32 +03:00
});
2014-02-10 13:09:31 +02:00
2014-04-02 19:34:32 +03:00
afterEach(function(done) {
2015-02-18 22:06:00 +02:00
Article.remove().exec(function() {
User.remove().exec(done);
});
2014-02-10 13:09:31 +02:00
});
2014-11-10 23:12:33 +02:00
});