diff --git a/src/topics/posts.js b/src/topics/posts.js index 97c3ebbb87..a561c1339c 100644 --- a/src/topics/posts.js +++ b/src/topics/posts.js @@ -22,7 +22,10 @@ module.exports = function (Topics) { }; Topics.getTopicPosts = async function (topicOrTid, set, start, stop, uid, reverse) { - if (topicOrTid && typeof topicOrTid !== 'object') { + if (!topicOrTid) { + return []; + } + if (typeof topicOrTid !== 'object') { // TODO: remove in 1.19.0 winston.warn('[deprecated] Topics.getTopicPosts(tid, ...) usage is deprecated, pass a topic object as first argument!'); topicOrTid = await Topics.getTopicData(topicOrTid); diff --git a/test/topics.js b/test/topics.js index 65ae549427..29452c7cd7 100644 --- a/test/topics.js +++ b/test/topics.js @@ -502,6 +502,11 @@ describe('Topic\'s', () => { assert.strictEqual(post.index, index); }); }); + + it('should return empty array if first param is falsy', async () => { + const posts = await topics.getTopicPosts(null, `tid:${tid}:posts`, 0, 9, topic.userId, true); + assert.deepStrictEqual(posts, []); + }); }); });