Files
NodeBB/tests/categories.js

96 lines
2.2 KiB
JavaScript
Raw Normal View History

2015-01-03 20:07:09 -05:00
'use strict';
/*global require, process, after*/
2014-01-24 00:42:34 -05:00
var winston = require('winston');
process.on('uncaughtException', function (err) {
winston.error('Encountered error while running test suite: ' + err.message);
});
var assert = require('assert'),
2014-09-24 13:52:49 -04:00
db = require('./mocks/databasemock');
var Categories = require('../src/categories');
describe('Categories', function() {
var categoryObj;
describe('.create', function() {
it('should create a new category', function(done) {
Categories.create({
name: 'Test Category',
description: 'Test category created by testing script',
2013-11-26 14:25:46 -05:00
icon: 'fa-check',
blockclass: 'category-blue',
order: '5'
}, function(err, category) {
categoryObj = category;
done.apply(this, arguments);
});
});
});
describe('.getCategoryById', function() {
it('should retrieve a newly created category by its ID', function(done) {
Categories.getCategoryById({
cid: categoryObj.cid,
2015-01-08 13:47:15 -05:00
set: 'cid:' + categoryObj.cid + ':tids',
reverse: true,
start: 0,
end: -1,
uid: 0
}, function(err, categoryData) {
assert(categoryData);
2014-02-26 16:43:21 -05:00
assert.equal(categoryObj.name, categoryData.name);
assert.equal(categoryObj.description, categoryData.description);
done();
});
});
});
describe('.getCategoryTopics', function() {
it('should return a list of topics', function(done) {
Categories.getCategoryTopics({
cid: categoryObj.cid,
2015-01-08 13:47:15 -05:00
set: 'cid:' + categoryObj.cid + ':tids',
reverse: true,
start: 0,
stop: 10,
uid: 0
}, function(err, result) {
2014-01-26 17:17:34 -05:00
assert(Array.isArray(result.topics));
assert(result.topics.every(function(topic) {
return topic instanceof Object;
}));
done();
});
});
it('should return a list of topics by a specific user', function(done) {
Categories.getCategoryTopics({
cid: categoryObj.cid,
2015-01-08 13:47:15 -05:00
set: 'cid:' + categoryObj.cid + ':uid:' + 1 + ':tids',
reverse: true,
start: 0,
stop: 10,
uid: 0,
targetUid: 1
}, function(err, result) {
assert(Array.isArray(result.topics));
assert(result.topics.every(function(topic) {
return topic instanceof Object && topic.uid === '1';
}));
done();
});
});
});
after(function() {
db.flushdb();
});
2014-01-24 00:42:34 -05:00
});