From 3e52557689ecac28a8773fe9325939690b3c68ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Fri, 17 Jan 2020 11:16:23 -0500 Subject: [PATCH] fix: change owner missing await --- src/posts/user.js | 2 +- test/posts.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/posts/user.js b/src/posts/user.js index 02c0c694ea..49706ec59b 100644 --- a/src/posts/user.js +++ b/src/posts/user.js @@ -123,7 +123,7 @@ module.exports = function (Posts) { }; Posts.changeOwner = async function (pids, toUid) { - const exists = user.exists(toUid); + const exists = await user.exists(toUid); if (!exists) { throw new Error('[[error:no-user]]'); } diff --git a/test/posts.js b/test/posts.js index 48e9df4200..adcc4a7ec2 100644 --- a/test/posts.js +++ b/test/posts.js @@ -134,6 +134,14 @@ describe('Post\'s', function () { assert.strictEqual(await topics.isOwner(postResult.topicData.tid, newUid), true); }); + it('should fail to change owner if new owner does not exist', async function () { + try { + await posts.changeOwner([1], '9999999'); + } catch (err) { + assert.strictEqual(err.message, '[[error:no-user]]'); + } + }); + it('should return falsy if post does not exist', function (done) { posts.getPostData(9999, function (err, postData) { assert.ifError(err);