You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.2 KiB
JavaScript
92 lines
2.2 KiB
JavaScript
11 years ago
|
'use strict';
|
||
11 years ago
|
|
||
|
var assert = require('assert'),
|
||
10 years ago
|
db = require('./mocks/databasemock'),
|
||
11 years ago
|
topics = require('../src/topics'),
|
||
11 years ago
|
categories = require('../src/categories'),
|
||
|
User = require('../src/user');
|
||
11 years ago
|
|
||
11 years ago
|
describe('Topic\'s', function() {
|
||
11 years ago
|
var topic,
|
||
|
categoryObj;
|
||
|
|
||
|
before(function(done) {
|
||
11 years ago
|
var userData = {
|
||
|
username: 'John Smith',
|
||
|
password: 'swordfish',
|
||
|
email: '[email protected]',
|
||
|
callback: undefined
|
||
11 years ago
|
};
|
||
11 years ago
|
|
||
|
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();
|
||
|
});
|
||
11 years ago
|
});
|
||
11 years ago
|
|
||
|
|
||
11 years ago
|
});
|
||
11 years ago
|
|
||
|
describe('.post', function() {
|
||
|
|
||
11 years ago
|
it('should create a new topic with proper parameters', function(done) {
|
||
11 years ago
|
topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId}, function(err, result) {
|
||
11 years ago
|
assert.equal(err, null, 'was created with error');
|
||
|
assert.ok(result);
|
||
|
|
||
|
done();
|
||
|
});
|
||
|
});
|
||
|
|
||
11 years ago
|
it('should fail to create new topic with wrong parameters', function(done) {
|
||
11 years ago
|
topics.post({uid: null, title: topic.title, content: topic.content, cid: topic.categoryId}, function(err, result) {
|
||
11 years ago
|
assert.equal(err.message, '[[error:no-user]]');
|
||
11 years ago
|
done();
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
|
||
11 years ago
|
describe('Get methods', function() {
|
||
|
var newTopic;
|
||
|
var newPost;
|
||
|
|
||
11 years ago
|
beforeEach(function(done) {
|
||
|
topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId}, function(err, result) {
|
||
11 years ago
|
newTopic = result.topicData;
|
||
|
newPost = result.postData;
|
||
|
done();
|
||
11 years ago
|
});
|
||
|
});
|
||
|
|
||
11 years ago
|
describe('.getTopicData', function() {
|
||
11 years ago
|
it('should not receive errors', function(done) {
|
||
11 years ago
|
topics.getTopicData(newTopic.tid, done);
|
||
11 years ago
|
});
|
||
|
});
|
||
11 years ago
|
|
||
11 years ago
|
describe('.getTopicDataWithUser', function() {
|
||
11 years ago
|
it('should not receive errors', function(done) {
|
||
11 years ago
|
topics.getTopicDataWithUser(newTopic.tid, done);
|
||
11 years ago
|
});
|
||
|
});
|
||
|
});
|
||
|
|
||
|
after(function() {
|
||
11 years ago
|
db.flushdb();
|
||
11 years ago
|
});
|
||
11 years ago
|
});
|