From a391d01d3042cdbcf2518aece57d8b3f2285a243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 10 Mar 2026 09:49:23 -0400 Subject: [PATCH] fix: closes #14073, fix teasers from child categories add a test --- src/categories/recentreplies.js | 9 +++++---- test/categories.js | 26 ++++++++++++++++++-------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/categories/recentreplies.js b/src/categories/recentreplies.js index d5f4c99764..8e21647c70 100644 --- a/src/categories/recentreplies.js +++ b/src/categories/recentreplies.js @@ -99,7 +99,7 @@ module.exports = function (Categories) { const [topicData, crossposts] = await Promise.all([ topics.getTopicsFields( tids, - ['tid', 'mainPid', 'slug', 'title', 'teaserPid', 'cid', 'postcount'] + ['tid', 'uid', 'mainPid', 'slug', 'title', 'teaserPid', 'cid', 'postcount'] ), topics.crossposts.get(tids), ]); @@ -137,11 +137,12 @@ module.exports = function (Categories) { function assignTopicsToCategories(categories, topics) { categories.forEach((category) => { if (category) { + const categoryCid = String(category.cid); category.posts = topics.filter(t => t.cid && - (t.cid === category.cid || - (t.parentCids && t.parentCids.includes(category.cid)) || - (t.crossposts.some(({ cid }) => parseInt(cid, 10) === category.cid)) + (String(t.cid) === categoryCid || + (t.parentCids && t.parentCids.includes(categoryCid)) || + (t.crossposts.some(({ cid }) => String(cid) === categoryCid)) )) .sort((a, b) => b.timestamp - a.timestamp) .slice(0, parseInt(category.numRecentReplies, 10)); diff --git a/test/categories.js b/test/categories.js index 9f666af5dd..40c3039310 100644 --- a/test/categories.js +++ b/test/categories.js @@ -85,21 +85,31 @@ describe('Categories', () => { }); describe('Categories.getRecentTopicReplies', () => { - it('should not throw', (done) => { - Categories.getCategoryById({ + it('should not throw', async () => { + const categoryData = await Categories.getCategoryById({ cid: categoryObj.cid, set: `cid:${categoryObj.cid}:tids`, reverse: true, start: 0, stop: -1, uid: 0, - }, (err, categoryData) => { - assert.ifError(err); - Categories.getRecentTopicReplies(categoryData, 0, {}, (err) => { - assert.ifError(err); - done(); - }); }); + + await Categories.getRecentTopicReplies([categoryData], 0, {}); + }); + + it('should return posts in child category as teaser on parent category' , async () => { + const { cid: parentCid } = await Categories.create({ name: 'theparent' }); + const { cid: childCid } = await Categories.create({ name: 'thechild', parentCid }); + await Topics.post({ uid: posterUid, title: 'inparent', content: 'post in parent', cid: parentCid }); + await Topics.post({ uid: posterUid, title: 'inchild', content: 'post in child', cid: childCid }); + const categoryData = await Categories.getCategories([parentCid, childCid]); + Categories.getTree(categoryData, 0); + + await Categories.getRecentTopicReplies(categoryData, 0, {}), + assert.strictEqual(String(categoryData[0].cid), String(parentCid)); + assert.strictEqual(categoryData[0].posts[0].uid, posterUid); + assert.strictEqual(categoryData[0].posts[0].content, 'post in child'); }); });