diff --git a/tests/topics.js b/tests/topics.js index 3b7655fbbf..063451cc3e 100644 --- a/tests/topics.js +++ b/tests/topics.js @@ -1,6 +1,3 @@ - - - var winston = require('winston'); process.on('uncaughtException', function (err) { @@ -19,61 +16,64 @@ reds.createClient = function () { var Topics = require('../src/topics'); -describe('Topics', function() { - var newTopic; - var newPost; - var userInfo; +describe('Topic\'s', function() { + var topic; + + beforeEach(function(){ + topic = { + userId: 1, + categoryId: 1, + title: 'Test Topic Title', + content: 'The content of test topic' + }; + }); describe('.post', function() { - it('should post a new topic', function(done) { - var uid = 1, - cid = 1, - title = 'Test Topic Title', - content = 'The content of test topic'; - Topics.post(uid, title, content, cid, function(err, result) { + 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(); }); }); - it('should fail posting a topic', function(done) { - var uid = null, - cid = 1, - title = 'Test Topic Title', - content = 'The content of test topic'; + it('should fail to create new topic with wrong parameters', function(done) { + topic.userId = null; - Topics.post(uid, title, content, cid, function(err, result) { + Topics.post(topic.userId, topic.title, topic.content, topic.categoryId, function(err, result) { assert.equal(err.message, 'not-logged-in'); done(); }); }); }); - 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('.getTopicData', function() { + it('should not receive errors', function(done) { + Topics.getTopicData(newTopic.tid, done); + }); + }); + + describe('.getTopicDataWithUser', function() { + it('should not receive errors', function(done) { + Topics.getTopicDataWithUser(newTopic.tid, done); }); }); }); - - 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){