Skip to content

Commit

Permalink
test: added tests for new logic paths (toPid validation on post creat…
Browse files Browse the repository at this point in the history
…ion)

re: #12025
  • Loading branch information
julianlam committed Sep 25, 2023
1 parent fe42fd4 commit ce74030
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/topics.js
Expand Up @@ -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');
Expand Down Expand Up @@ -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 });
Expand Down

0 comments on commit ce74030

Please sign in to comment.