mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 18:46:01 +01:00
suggested topics test
This commit is contained in:
@@ -1,13 +1,11 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async'),
|
var async = require('async');
|
||||||
_ = require('underscore'),
|
var _ = require('underscore');
|
||||||
|
|
||||||
categories = require('../categories'),
|
|
||||||
search = require('../search'),
|
|
||||||
db = require('../database');
|
|
||||||
|
|
||||||
|
var categories = require('../categories');
|
||||||
|
var search = require('../search');
|
||||||
|
|
||||||
module.exports = function (Topics) {
|
module.exports = function (Topics) {
|
||||||
|
|
||||||
@@ -29,7 +27,13 @@ module.exports = function (Topics) {
|
|||||||
var tids = results.tagTids.concat(results.searchTids).concat(results.categoryTids);
|
var tids = results.tagTids.concat(results.searchTids).concat(results.categoryTids);
|
||||||
tids = tids.filter(function (_tid, index, array) {
|
tids = tids.filter(function (_tid, index, array) {
|
||||||
return parseInt(_tid, 10) !== parseInt(tid, 10) && array.indexOf(_tid) === index;
|
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);
|
Topics.getTopics(tids, uid, callback);
|
||||||
});
|
});
|
||||||
@@ -63,12 +67,14 @@ module.exports = function (Topics) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getCategoryTids(tid, callback) {
|
function getCategoryTids(tid, callback) {
|
||||||
Topics.getTopicField(tid, 'cid', function (err, cid) {
|
async.waterfall([
|
||||||
if (err || !cid) {
|
function (next) {
|
||||||
return callback(err, []);
|
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);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -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) {
|
after(function (done) {
|
||||||
|
|||||||
Reference in New Issue
Block a user