mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
test: replace calls to getReplies socket call to api method
This commit is contained in:
@@ -24,6 +24,7 @@ const helpers = require('./helpers');
|
|||||||
const socketPosts = require('../src/socket.io/posts');
|
const socketPosts = require('../src/socket.io/posts');
|
||||||
const socketTopics = require('../src/socket.io/topics');
|
const socketTopics = require('../src/socket.io/topics');
|
||||||
const apiTopics = require('../src/api/topics');
|
const apiTopics = require('../src/api/topics');
|
||||||
|
const apiPosts = require('../src/api/posts');
|
||||||
|
|
||||||
const requestType = util.promisify((type, url, opts, cb) => {
|
const requestType = util.promisify((type, url, opts, cb) => {
|
||||||
request[type](url, opts, (err, res, body) => cb(err, { res: res, body: body }));
|
request[type](url, opts, (err, res, body) => cb(err, { res: res, body: body }));
|
||||||
@@ -274,29 +275,19 @@ describe('Topic\'s', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle direct replies', (done) => {
|
it('should handle direct replies', async () => {
|
||||||
topics.reply({ uid: topic.userId, content: 'test reply', tid: newTopic.tid, toPid: newPost.pid }, (err, result) => {
|
const result = await topics.reply({ uid: topic.userId, content: 'test reply', tid: newTopic.tid, toPid: newPost.pid });
|
||||||
assert.equal(err, null, 'was created with error');
|
assert.ok(result);
|
||||||
assert.ok(result);
|
|
||||||
|
|
||||||
socketPosts.getReplies({ uid: 0 }, newPost.pid, (err, postData) => {
|
const postData = await apiPosts.getReplies({ uid: 0 }, { pid: newPost.pid });
|
||||||
assert.ifError(err);
|
assert.ok(postData);
|
||||||
|
|
||||||
assert.ok(postData);
|
assert.equal(postData.length, 1, 'should have 1 result');
|
||||||
|
assert.equal(postData[0].pid, result.pid, 'result should be the reply we added');
|
||||||
assert.equal(postData.length, 1, 'should have 1 result');
|
|
||||||
assert.equal(postData[0].pid, result.pid, 'result should be the reply we added');
|
|
||||||
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should error if pid is not a number', (done) => {
|
it('should error if pid is not a number', async () => {
|
||||||
socketPosts.getReplies({ uid: 0 }, 'abc', (err) => {
|
assert.rejects(apiPosts.getReplies({ uid: 0 }, { pid: 'abc' }, '[[error:invalid-data]]'));
|
||||||
assert.equal(err.message, '[[error:invalid-data]]');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to create new reply with invalid user id', (done) => {
|
it('should fail to create new reply with invalid user id', (done) => {
|
||||||
@@ -331,14 +322,14 @@ describe('Topic\'s', () => {
|
|||||||
const result = await topics.post({ uid: fooUid, title: 'nested test', content: 'main post', cid: topic.categoryId });
|
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 });
|
const reply1 = await topics.reply({ uid: fooUid, content: 'reply post 1', tid: result.topicData.tid });
|
||||||
const reply2 = await topics.reply({ uid: fooUid, content: 'reply post 2', tid: result.topicData.tid, toPid: reply1.pid });
|
const reply2 = await topics.reply({ uid: fooUid, content: 'reply post 2', tid: result.topicData.tid, toPid: reply1.pid });
|
||||||
let replies = await socketPosts.getReplies({ uid: fooUid }, reply1.pid);
|
let replies = await apiPosts.getReplies({ uid: fooUid }, { pid: reply1.pid });
|
||||||
assert.strictEqual(replies.length, 1);
|
assert.strictEqual(replies.length, 1);
|
||||||
assert.strictEqual(replies[0].content, 'reply post 2');
|
assert.strictEqual(replies[0].content, 'reply post 2');
|
||||||
let toPid = await posts.getPostField(reply2.pid, 'toPid');
|
let toPid = await posts.getPostField(reply2.pid, 'toPid');
|
||||||
assert.strictEqual(parseInt(toPid, 10), parseInt(reply1.pid, 10));
|
assert.strictEqual(parseInt(toPid, 10), parseInt(reply1.pid, 10));
|
||||||
await posts.purge(reply1.pid, fooUid);
|
await posts.purge(reply1.pid, fooUid);
|
||||||
replies = await socketPosts.getReplies({ uid: fooUid }, reply1.pid);
|
replies = await apiPosts.getReplies({ uid: fooUid }, { pid: reply1.pid });
|
||||||
assert.strictEqual(replies.length, 0);
|
assert.strictEqual(replies, null);
|
||||||
toPid = await posts.getPostField(reply2.pid, 'toPid');
|
toPid = await posts.getPostField(reply2.pid, 'toPid');
|
||||||
assert.strictEqual(toPid, null);
|
assert.strictEqual(toPid, null);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user