Node.js based forum software built for the modern web
test: added tests for new logic paths (toPid validation on post creation)
Julian Lamce7403014a2a
diff --git a/test/topics.js b/test/topics.jsindex 07af567b25..f40925103a 100644--- a/test/topics.js+++ b/test/topics.js@@ -20,6 +20,7 @@ const privileges = require('../src/privileges');const meta = require('../src/meta');const User = require('../src/user');const groups = require('../src/groups');+const utils = require('../src/utils');const helpers = require('./helpers');const socketPosts = require('../src/socket.io/posts');const socketTopics = require('../src/socket.io/topics');@@ -324,6 +325,51 @@ describe('Topic\'s', () => {});});+ it('should fail to create new reply with toPid that has been purged', async () => {+ const { postData } = await topics.post({+ uid: topic.userId,+ cid: topic.categoryId,+ title: utils.generateUUID(),+ content: utils.generateUUID(),+ });+ await posts.purge(postData.pid, topic.userId);++ await assert.rejects(+ topics.reply({ uid: topic.userId, content: 'test post', tid: postData.topic.tid, toPid: postData.pid }),+ { message: '[[error:invalid-pid]]' }+ );+ });++ it('should fail to create a new reply with toPid that has been deleted (user cannot view_deleted)', async () => {+ const { postData } = await topics.post({+ uid: topic.userId,+ cid: topic.categoryId,+ title: utils.generateUUID(),+ content: utils.generateUUID(),+ });+ await posts.delete(postData.pid, topic.userId);+ const uid = await User.create({ username: utils.generateUUID().slice(0, 10) });++ await assert.rejects(+ topics.reply({ uid, content: 'test post', tid: postData.topic.tid, toPid: postData.pid }),+ { message: '[[error:invalid-pid]]' }+ );+ });++ it('should properly create a new reply with toPid that has been deleted (user\'s own deleted post)', async () => {+ const { postData } = await topics.post({+ uid: topic.userId,+ cid: topic.categoryId,+ title: utils.generateUUID(),+ content: utils.generateUUID(),+ });+ await posts.delete(postData.pid, topic.userId);+ const uid = await User.create({ username: utils.generateUUID().slice(0, 10) });++ const { pid } = await topics.reply({ uid: topic.userId, content: 'test post', tid: postData.topic.tid, toPid: postData.pid });+ assert(pid);+ });+it('should delete nested relies properly', async () => {const result = await topics.post({ uid: fooUid, title: 'nested test', content: 'main post', cid: topic.categoryId });const reply1 = await topics.reply({ uid: fooUid, content: 'reply post 1', tid: result.topicData.tid });