Node.js based forum software built for the modern web
test: add a test for user.deleteCount and counters
Barış Soner Uşaklı130aadd0f29b
diff --git a/test/user.js b/test/user.jsindex bc423942da..d8d9540531 100644--- a/test/user.js+++ b/test/user.js@@ -546,6 +546,42 @@ describe('User', () => {await User.delete(1, uid1);assert.strictEqual(await User.exists(uid1), false);});++ it('should properly update global post counters after user account deletion with a topic that has replies from other users', async () => {+ const global = await db.getObject('global');++ const uid1 = await User.create({ username: 'chatuserdelete1' });+ const uid2 = await User.create({ username: 'chatuserdelete2' });+ const uid3 = await User.create({ username: 'chatuserdelete3' });+ const topic = await Topics.post({+ uid: uid1,+ title: 'topic with replies',+ content: 'initial post content',+ cid: testCid,+ });++ await Topics.reply({+ uid: uid2,+ tid: topic.topicData.tid,+ content: 'reply content',+ });+ await Topics.reply({+ uid: uid3,+ tid: topic.topicData.tid,+ content: 'reply content 2',+ });+ const afterPosting = await db.getObject('global');++ assert.strictEqual(afterPosting.postCount, global.postCount + 3); // initial post + 2 replies+ assert.strictEqual(afterPosting.topicCount, global.topicCount + 1); // just one new topic++ await User.deleteContent(uid1, uid1);++ const afterUserDelete = await db.getObject('global');++ assert.strictEqual(afterUserDelete.postCount, global.postCount); // back to original postcount+ assert.strictEqual(afterUserDelete.topicCount, global.topicCount); // back to original topic count+ });});describe('hash methods', () => {