forked from NodeBB/NodeBB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcategories.js
61 lines (49 loc) · 1.56 KB
/
categories.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var winston = require('winston');
process.on('uncaughtException', function (err) {
winston.error('Encountered error while running test suite: ' + err.message);
});
var assert = require('assert'),
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',
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(categoryObj.cid, 0, -1, 0, function(err, categoryData) {
assert(categoryData);
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(categoryObj.cid, 0, 10, 0, function(err, result) {
assert(Array.isArray(result.topics));
assert(result.topics.every(function(topic) {
return topic instanceof Object;
}));
done();
});
});
});
after(function() {
db.delete('category:' + categoryObj.cid);
db.sortedSetRemove('categories:cid', categoryObj.cid);
});
});