fix: handle start=0 stop=0 for topics.getTopicPosts

add more tests
This commit is contained in:
Barış Soner Uşaklı
2021-12-06 16:36:30 -05:00
parent 621c142f8e
commit 906dc5675e
4 changed files with 42 additions and 5 deletions

View File

@@ -507,6 +507,42 @@ describe('Topic\'s', () => {
const posts = await topics.getTopicPosts(null, `tid:${tid}:posts`, 0, 9, topic.userId, true);
assert.deepStrictEqual(posts, []);
});
it('should only return main post', async () => {
const topicData = await topics.getTopicData(tid);
const postsData = await topics.getTopicPosts(topicData, `tid:${tid}:posts`, 0, 0, topic.userId, false);
assert.strictEqual(postsData.length, 1);
assert.strictEqual(postsData[0].content, 'main post');
});
it('should only return first reply', async () => {
const topicData = await topics.getTopicData(tid);
const postsData = await topics.getTopicPosts(topicData, `tid:${tid}:posts`, 1, 1, topic.userId, false);
assert.strictEqual(postsData.length, 1);
assert.strictEqual(postsData[0].content, 'topic reply 1');
});
it('should return main post and first reply', async () => {
const topicData = await topics.getTopicData(tid);
const postsData = await topics.getTopicPosts(topicData, `tid:${tid}:posts`, 0, 1, topic.userId, false);
assert.strictEqual(postsData.length, 2);
assert.strictEqual(postsData[0].content, 'main post');
assert.strictEqual(postsData[1].content, 'topic reply 1');
});
it('should return posts in correct order', async () => {
const data = await socketTopics.loadMore({ uid: topic.userId }, { tid: tid, after: 20, direction: 1 });
assert.strictEqual(data.posts.length, 11);
assert.strictEqual(data.posts[0].content, 'topic reply 20');
assert.strictEqual(data.posts[1].content, 'topic reply 21');
});
it('should return posts in correct order in reverse direction', async () => {
const data = await socketTopics.loadMore({ uid: topic.userId }, { tid: tid, after: 25, direction: -1 });
assert.strictEqual(data.posts.length, 20);
assert.strictEqual(data.posts[0].content, 'topic reply 5');
assert.strictEqual(data.posts[1].content, 'topic reply 6');
});
});
});