mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-05 05:25:49 +01:00
test: added tests for new logic paths (toPid validation on post creation)
re: #12025
This commit is contained in:
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user