v1.18.x
Barış Soner Uşaklı 5 years ago
parent 526b3cd9ec
commit 81e33b9391

@ -52,6 +52,14 @@ module.exports = function (Topics) {
await Topics.updateLastPostTime(tid, Date.now());
await Promise.all([
Topics.setTopicFields(tid, {
upvotes: postData.upvotes,
downvotes: postData.downvotes,
}),
db.sortedSetsAdd(['topics:votes', 'cid:' + cid + ':tids:votes'], postData.votes, tid),
]);
plugins.fireHook('action:topic.fork', { tid: tid, fromTid: fromTid, uid: uid });
return await Topics.getTopicData(tid);

@ -906,6 +906,22 @@ describe('Topic\'s', function () {
},
], done);
});
it('should properly update topic vote count after forking', async () => {
const result = await topics.post({ uid: fooUid, cid: categoryObj.cid, title: 'fork vote test', content: 'main post' });
const reply1 = await topics.reply({ tid: result.topicData.tid, uid: fooUid, content: 'test reply 1' });
const reply2 = await topics.reply({ tid: result.topicData.tid, uid: fooUid, content: 'test reply 2' });
const reply3 = await topics.reply({ tid: result.topicData.tid, uid: fooUid, content: 'test reply 3' });
await posts.upvote(result.postData.pid, adminUid);
await posts.upvote(reply1.pid, adminUid);
assert.strictEqual(await db.sortedSetScore('topics:votes', result.topicData.tid), 1);
assert.strictEqual(await db.sortedSetScore('cid:' + categoryObj.cid + ':tids:votes', result.topicData.tid), 1);
const newTopic = await topics.createTopicFromPosts(adminUid, 'Fork test, vote update', [reply1.pid, reply2.pid], result.topicData.tid);
assert.strictEqual(await db.sortedSetScore('topics:votes', newTopic.tid), 1);
assert.strictEqual(await db.sortedSetScore('cid:' + categoryObj.cid + ':tids:votes', newTopic.tid), 1);
assert.strictEqual(await topics.getTopicField(newTopic.tid, 'upvotes'), 1);
});
});
describe('controller', function () {

Loading…
Cancel
Save