From 6893bd8b046ef9da33f9efe90a5e2dde10a8d242 Mon Sep 17 00:00:00 2001 From: Denis Wolf Date: Sun, 17 Nov 2013 23:41:38 +0200 Subject: [PATCH] tests: topic.js: extract mock data init in .post --- tests/topics.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/topics.js b/tests/topics.js index 149063bd0f..de875ab868 100644 --- a/tests/topics.js +++ b/tests/topics.js @@ -19,16 +19,21 @@ var Topics = require('../src/topics'); describe('Topic\'s', function() { var newTopic; var newPost; - var userInfo; describe('.post', function() { - it('should create a new topic with proper parameters', function(done) { - var userId = 1, - categoryId = 1, - title = 'Test Topic Title', - content = 'The content of test topic'; + var topic; + + beforeEach(function(){ + topic = { + userId: 1, + categoryId: 1, + title: 'Test Topic Title', + content: 'The content of test topic' + }; + }); - Topics.post(userId, title, content, categoryId, 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); @@ -40,12 +45,9 @@ describe('Topic\'s', function() { }); it('should fail to create new topic with wrong parameters', function(done) { - var uid = null, - cid = 1, - title = 'Test Topic Title', - content = 'The content of test topic'; + 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(); });