add tests for top topics

fix popular page displaying 18 topics per page
v1.18.x
Barış Soner Uşaklı 7 years ago
parent 956aa55253
commit 2fd2accf8c

@ -57,7 +57,7 @@ module.exports = function (Categories) {
function (results, next) {
var totalPinnedCount = results.pinnedTids.length;
pinnedTids = results.pinnedTids.slice(data.start, data.stop === -1 ? undefined : data.stop + 1);
pinnedTids = results.pinnedTids.slice(data.start, data.stop !== -1 ? data.stop + 1 : undefined);
var pinnedCount = pinnedTids.length;

@ -53,7 +53,7 @@ module.exports = function (Topics) {
function (topics, next) {
tids = topics.filter(function (topic) {
return topic && parseInt(topic.deleted, 10) !== 1;
}).sort(sortPopular).slice(start, stop !== -1 ? stop - 1 : undefined).map(function (topic) {
}).sort(sortPopular).slice(start, stop !== -1 ? stop + 1 : undefined).map(function (topic) {
return topic.tid;
});
privileges.topics.filterTids('read', tids, uid, next);

@ -41,7 +41,7 @@ module.exports = function (Topics) {
},
function (tids, next) {
recentTopics.topicCount = tids.length;
tids = tids.slice(start, stop + 1);
tids = tids.slice(start, stop !== -1 ? stop + 1 : undefined);
Topics.getTopicsByTids(tids, uid, next);
},
function (topicData, next) {

@ -35,13 +35,7 @@ module.exports = function (Topics) {
}
},
function (categoryTids, next) {
tids = _.uniq(tids.concat(categoryTids));
if (stop === -1) {
tids = tids.slice(start);
} else {
tids = tids.slice(start, stop + 1);
}
tids = _.uniq(tids.concat(categoryTids)).slice(start, stop !== -1 ? stop + 1 : undefined);
Topics.getTopicsByTids(tids, uid, next);
},
], callback);

@ -33,7 +33,7 @@ module.exports = function (Topics) {
},
function (tids, next) {
topTopics.topicCount = tids.length;
tids = tids.slice(start, stop + 1);
tids = tids.slice(start, stop !== -1 ? stop + 1 : undefined);
Topics.getTopicsByTids(tids, uid, next);
},
function (topicData, next) {

@ -42,11 +42,7 @@ module.exports = function (Topics) {
return next(null, []);
}
if (params.stop === -1) {
tids = tids.slice(params.start);
} else {
tids = tids.slice(params.start, params.stop + 1);
}
tids = tids.slice(params.start, params.stop !== -1 ? params.stop + 1 : undefined);
Topics.getTopicsByTids(tids, params.uid, next);
},

@ -1823,4 +1823,20 @@ describe('Topic\'s', function () {
], done);
});
});
describe('top topics', function () {
it('should get top topics in category', function (done) {
var filters = ['', 'watched', 'unreplied', 'new'];
async.map(filters, function (filter, next) {
topics.getTopTopics(topic.categoryId, topic.userId, 0, -1, filter, next);
}, function (err, data) {
assert.ifError(err);
assert(data);
data.forEach(function (filterTopics) {
assert(Array.isArray(filterTopics.topics));
});
done();
});
});
});
});

Loading…
Cancel
Save