Skip to content

Commit

Permalink
suggested topics test
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Nov 22, 2016
1 parent 069a90e commit 584cfd0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/topics/suggested.js
Original file line number Diff line number Diff line change
@@ -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) {

Expand All @@ -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);
});
Expand Down Expand Up @@ -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);
}

};
28 changes: 28 additions & 0 deletions test/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 584cfd0

Please sign in to comment.