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

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

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

Loading…
Cancel
Save