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.
nodebb/tests/topics.js

80 lines
1.9 KiB
JavaScript

11 years ago
'use strict';
11 years ago
var assert = require('assert'),
11 years ago
db = require('../mocks/databasemock'),
topics = require('../src/topics'),
categories = require('../src/categories');
11 years ago
describe('Topic\'s', function() {
11 years ago
var topic,
categoryObj;
before(function(done) {
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: 1,
categoryId: categoryObj.cid,
title: 'Test Topic Title',
content: 'The content of test topic'
};
done();
});
});
11 years ago
describe('.post', function() {
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();
});
});
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();
});
});
});
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) {
newTopic = result.topicData;
newPost = result.postData;
done();
11 years ago
});
});
describe('.getTopicData', function() {
it('should not receive errors', function(done) {
11 years ago
topics.getTopicData(newTopic.tid, done);
});
});
11 years ago
describe('.getTopicDataWithUser', function() {
it('should not receive errors', function(done) {
11 years ago
topics.getTopicDataWithUser(newTopic.tid, done);
11 years ago
});
});
});
after(function() {
db.flushdb();
11 years ago
});
});