Skip to content

Node.js based forum software built for the modern web

suggested topics test

barisusakli584cfd09ef1c
diff --git a/src/topics/suggested.js b/src/topics/suggested.js
index a7b1190bf1..aebef72683 100644
--- a/src/topics/suggested.js
+++ b/src/topics/suggested.js
@@ -1,13 +1,11 @@
'use strict';
-var async = require('async'),
- _ = require('underscore'),
-
- categories = require('../categories'),
- search = require('../search'),
- db = require('../database');
+var async = require('async');
+var _ = require('underscore');
+var categories = require('../categories');
+var search = require('../search');
module.exports = function (Topics) {
@@ -29,7 +27,13 @@ module.exports = function (Topics) {
var tids = results.tagTids.concat(results.searchTids).concat(results.categoryTids);
tids = tids.filter(function (_tid, index, array) {
return parseInt(_tid, 10) !== parseInt(tid, 10) && array.indexOf(_tid) === index;
- }).slice(start, stop + 1);
+ });
+
+ if (stop === -1) {
+ tids = tids.slice(start);
+ } else {
+ tids = tids.slice(start, stop + 1);
+ }
Topics.getTopics(tids, uid, callback);
});
@@ -63,12 +67,14 @@ module.exports = function (Topics) {
}
function getCategoryTids(tid, callback) {
- Topics.getTopicField(tid, 'cid', function (err, cid) {
- if (err || !cid) {
- return callback(err, []);
+ async.waterfall([
+ function (next) {
+ Topics.getTopicField(tid, 'cid', next);
+ },
+ function (cid, next) {
+ categories.getTopicIds('cid:' + cid + ':tids', true, 0, 9, next);
}
- categories.getTopicIds('cid:' + cid + ':tids', true, 0, 9, callback);
- });
+ ], callback);
}
};
\ No newline at end of file
diff --git a/test/topics.js b/test/topics.js
index 01ee3c0aeb..8dfc024f64 100644
--- a/test/topics.js
+++ b/test/topics.js
@@ -654,6 +654,34 @@ describe('Topic\'s', function () {
});
+ describe('suggested topics', function () {
+ var tid1;
+ var tid2;
+ before(function (done) {
+ async.parallel({
+ topic1: function (next) {
+ topics.post({uid: adminUid, tags: ['nodebb'], title: 'topic title 1', content: 'topic 1 content', cid: topic.categoryId}, next);
+ },
+ topic2: function (next) {
+ topics.post({uid: adminUid, tags: ['nodebb'], title: 'topic title 2', content: 'topic 2 content', cid: topic.categoryId}, next);
+ }
+ }, function (err, results) {
+ assert.ifError(err);
+ tid1 = results.topic1.topicData.tid;
+ tid2 = results.topic2.topicData.tid;
+ done();
+ });
+ });
+
+ it('should return suggested topics', function (done) {
+ topics.getSuggestedTopics(tid1, adminUid, 0, -1, function (err, topics) {
+ assert.ifError(err);
+ assert(Array.isArray(topics));
+ done();
+ });
+ });
+ });
+
after(function (done) {