2014-03-06 14:51:43 -05:00
|
|
|
'use strict';
|
2013-11-15 16:16:50 -05:00
|
|
|
|
|
|
|
|
var assert = require('assert'),
|
2014-09-24 13:52:49 -04:00
|
|
|
db = require('./mocks/databasemock'),
|
2014-03-06 14:51:43 -05:00
|
|
|
topics = require('../src/topics'),
|
2014-05-23 08:57:51 -04:00
|
|
|
categories = require('../src/categories'),
|
|
|
|
|
User = require('../src/user');
|
2013-11-15 16:16:50 -05:00
|
|
|
|
2013-11-17 23:35:18 +02:00
|
|
|
describe('Topic\'s', function() {
|
2014-03-06 14:51:43 -05:00
|
|
|
var topic,
|
|
|
|
|
categoryObj;
|
|
|
|
|
|
|
|
|
|
before(function(done) {
|
2014-05-23 08:57:51 -04:00
|
|
|
var userData = {
|
|
|
|
|
username: 'John Smith',
|
|
|
|
|
password: 'swordfish',
|
|
|
|
|
email: 'john@example.com',
|
|
|
|
|
callback: undefined
|
2014-03-06 14:51:43 -05:00
|
|
|
};
|
2014-05-23 08:57:51 -04:00
|
|
|
|
|
|
|
|
User.create({username: userData.username, password: userData.password, email: userData.email}, function(err, uid) {
|
|
|
|
|
categories.create({
|
|
|
|
|
name: 'Test Category',
|
|
|
|
|
description: 'Test category created by testing script',
|
|
|
|
|
icon: 'fa-check',
|
|
|
|
|
blockclass: 'category-blue',
|
|
|
|
|
order: '5'
|
|
|
|
|
}, function(err, category) {
|
|
|
|
|
categoryObj = category;
|
|
|
|
|
|
|
|
|
|
topic = {
|
|
|
|
|
userId: uid,
|
|
|
|
|
categoryId: categoryObj.cid,
|
|
|
|
|
title: 'Test Topic Title',
|
|
|
|
|
content: 'The content of test topic'
|
|
|
|
|
};
|
|
|
|
|
done();
|
|
|
|
|
});
|
2014-03-06 14:51:43 -05:00
|
|
|
});
|
2014-05-23 08:57:51 -04:00
|
|
|
|
2014-11-11 19:47:56 -05:00
|
|
|
|
2013-11-17 23:50:19 +02:00
|
|
|
});
|
2013-11-15 16:16:50 -05:00
|
|
|
|
|
|
|
|
describe('.post', function() {
|
|
|
|
|
|
2013-11-17 23:41:38 +02:00
|
|
|
it('should create a new topic with proper parameters', function(done) {
|
2014-03-06 14:51:43 -05:00
|
|
|
topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId}, function(err, result) {
|
2013-11-15 16:16:50 -05:00
|
|
|
assert.equal(err, null, 'was created with error');
|
|
|
|
|
assert.ok(result);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2014-11-11 23:12:37 -05:00
|
|
|
it('should fail to create new topic with invalid user id', function(done) {
|
2014-03-06 14:51:43 -05:00
|
|
|
topics.post({uid: null, title: topic.title, content: topic.content, cid: topic.categoryId}, function(err, result) {
|
2014-11-11 23:03:20 -05:00
|
|
|
assert.equal(err.message, '[[error:no-privileges]]');
|
2013-11-15 16:16:50 -05:00
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2014-11-11 23:12:37 -05:00
|
|
|
|
|
|
|
|
it('should fail to create new topic with empty title', function(done) {
|
|
|
|
|
topics.post({uid: topic.userId, title: '', content: topic.content, cid: topic.categoryId}, function(err, result) {
|
2014-11-12 01:19:40 -05:00
|
|
|
assert.ok(err);
|
2014-11-11 23:12:37 -05:00
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should fail to create new topic with empty content', function(done) {
|
|
|
|
|
topics.post({uid: topic.userId, title: topic.title, content: '', cid: topic.categoryId}, function(err, result) {
|
2014-11-12 01:19:40 -05:00
|
|
|
assert.ok(err);
|
2014-11-11 23:12:37 -05:00
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should fail to create new topic with non-existant category id', function(done) {
|
|
|
|
|
topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: 99}, function(err, result) {
|
2014-11-12 01:19:40 -05:00
|
|
|
assert.equal(err, '[[error:no-category]]', 'received no error');
|
2014-11-11 23:12:37 -05:00
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2013-11-15 16:16:50 -05:00
|
|
|
});
|
|
|
|
|
|
2013-11-17 23:50:19 +02:00
|
|
|
describe('Get methods', function() {
|
|
|
|
|
var newTopic;
|
|
|
|
|
var newPost;
|
|
|
|
|
|
2014-03-06 14:51:43 -05:00
|
|
|
beforeEach(function(done) {
|
|
|
|
|
topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId}, function(err, result) {
|
2013-11-17 23:50:19 +02:00
|
|
|
newTopic = result.topicData;
|
|
|
|
|
newPost = result.postData;
|
|
|
|
|
done();
|
2013-11-15 16:16:50 -05:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2013-11-17 23:50:19 +02:00
|
|
|
describe('.getTopicData', function() {
|
2013-11-18 00:00:22 +02:00
|
|
|
it('should not receive errors', function(done) {
|
2014-03-06 14:51:43 -05:00
|
|
|
topics.getTopicData(newTopic.tid, done);
|
2013-11-17 23:50:19 +02:00
|
|
|
});
|
|
|
|
|
});
|
2013-11-15 16:16:50 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
after(function() {
|
2013-12-06 13:21:21 -05:00
|
|
|
db.flushdb();
|
2013-11-15 16:16:50 -05:00
|
|
|
});
|
2014-04-10 20:31:57 +01:00
|
|
|
});
|