tests: topic.js: extract mock data init in getters

v1.18.x
Denis Wolf 12 years ago
parent 6893bd8b04
commit cbbb7a7c8e

@ -17,29 +17,24 @@ reds.createClient = function () {
var Topics = require('../src/topics'); var Topics = require('../src/topics');
describe('Topic\'s', function() { describe('Topic\'s', function() {
var newTopic; var topic;
var newPost;
beforeEach(function(){
topic = {
userId: 1,
categoryId: 1,
title: 'Test Topic Title',
content: 'The content of test topic'
};
});
describe('.post', function() { describe('.post', function() {
var topic;
beforeEach(function(){
topic = {
userId: 1,
categoryId: 1,
title: 'Test Topic Title',
content: 'The content of test topic'
};
});
it('should create a new topic with proper parameters', function(done) { it('should create a new topic with proper parameters', function(done) {
Topics.post(topic.userId, topic.title, topic.content, topic.categoryId, function(err, result) { Topics.post(topic.userId, topic.title, topic.content, topic.categoryId, function(err, result) {
assert.equal(err, null, 'was created with error'); assert.equal(err, null, 'was created with error');
assert.ok(result); assert.ok(result);
newTopic = result.topicData;
newPost = result.postData;
done(); done();
}); });
}); });
@ -54,25 +49,35 @@ describe('Topic\'s', function() {
}); });
}); });
describe('.getTopicData', function() { describe('Get methods', function() {
it('should get Topic data', function(done) { var newTopic;
Topics.getTopicData(newTopic.tid, function(err, result) { var newPost;
done.apply(this.arguments);
beforeEach(function(done){
Topics.post(topic.userId, topic.title, topic.content, topic.categoryId, function(err, result) {
newTopic = result.topicData;
newPost = result.postData;
done();
}); });
}); });
});
describe('.getTopicDataWithUser', function() { describe('.getTopicData', function() {
it('should get Topic data with user info', function(done) { it('should get Topic data', function(done) {
Topics.getTopicDataWithUser(newTopic.tid, function(err, result) { Topics.getTopicData(newTopic.tid, function(err, result) {
done.apply(this.arguments);
});
});
});
done.apply(this.arguments); describe('.getTopicDataWithUser', function() {
it('should get Topic data with user info', function(done) {
Topics.getTopicDataWithUser(newTopic.tid, function(err, result) {
done.apply(this.arguments);
});
}); });
}); });
}); });
after(function() { after(function() {
RDB.send_command('flushdb', [], function(error){ RDB.send_command('flushdb', [], function(error){
if(error){ if(error){

Loading…
Cancel
Save