From 8117b7f22fd4c487b5b61d73b9ad8eb9862e262e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Sun, 28 Nov 2021 19:45:29 -0500 Subject: [PATCH] breaking: remove deprecated post diff socket calls --- src/socket.io/posts.js | 1 - src/socket.io/posts/diffs.js | 21 --------------------- test/posts.js | 35 ++++++++++++++++++----------------- 3 files changed, 18 insertions(+), 39 deletions(-) delete mode 100644 src/socket.io/posts/diffs.js diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js index 9fc33293cf..f63b7e3e27 100644 --- a/src/socket.io/posts.js +++ b/src/socket.io/posts.js @@ -22,7 +22,6 @@ require('./posts/move')(SocketPosts); require('./posts/votes')(SocketPosts); require('./posts/bookmarks')(SocketPosts); require('./posts/tools')(SocketPosts); -require('./posts/diffs')(SocketPosts); SocketPosts.reply = async function (socket, data) { sockets.warnDeprecated(socket, 'POST /api/v3/topics/:tid'); diff --git a/src/socket.io/posts/diffs.js b/src/socket.io/posts/diffs.js deleted file mode 100644 index a1e2043243..0000000000 --- a/src/socket.io/posts/diffs.js +++ /dev/null @@ -1,21 +0,0 @@ -'use strict'; - -const api = require('../../api'); -const websockets = require('..'); - -module.exports = function (SocketPosts) { - SocketPosts.getDiffs = async function (socket, data) { - websockets.warnDeprecated(socket, 'GET /api/v3/posts/:pid/diffs'); - return await api.posts.getDiffs(socket, data); - }; - - SocketPosts.showPostAt = async function (socket, data) { - websockets.warnDeprecated(socket, 'GET /api/v3/posts/:pid/diffs/:since'); - return await api.posts.loadDiff(socket, data); - }; - - SocketPosts.restoreDiff = async function (socket, data) { - websockets.warnDeprecated(socket, 'PUT /api/v3/posts/:pid/diffs/:since'); - return await api.posts.restoreDiff(socket, data); - }; -}; diff --git a/test/posts.js b/test/posts.js index 268082ffb0..7da93f16b8 100644 --- a/test/posts.js +++ b/test/posts.js @@ -18,6 +18,7 @@ const user = require('../src/user'); const groups = require('../src/groups'); const socketPosts = require('../src/socket.io/posts'); const socketTopics = require('../src/socket.io/topics'); +const apiPosts = require('../src/api/posts'); const meta = require('../src/meta'); const helpers = require('./helpers'); @@ -625,28 +626,28 @@ describe('Post\'s', () => { }); }); - it('should not allow guests to view diffs', (done) => { - socketPosts.getDiffs({ uid: 0 }, { pid: 1 }, (err) => { - assert.equal(err.message, '[[error:no-privileges]]'); - done(); - }); + it('should not allow guests to view diffs', async () => { + let err = {}; + try { + await apiPosts.getDiffs({ uid: 0 }, { pid: 1 }); + } catch (_err) { + err = _err; + } + assert.strictEqual(err.message, '[[error:no-privileges]]'); }); - it('should allow registered-users group to view diffs', (done) => { - socketPosts.getDiffs({ uid: 1 }, { pid: 1 }, (err, data) => { - assert.ifError(err); + it('should allow registered-users group to view diffs', async () => { + const data = await apiPosts.getDiffs({ uid: 1 }, { pid: 1 }); - assert.strictEqual('boolean', typeof data.editable); - assert.strictEqual(false, data.editable); + assert.strictEqual('boolean', typeof data.editable); + assert.strictEqual(false, data.editable); - assert.equal(true, Array.isArray(data.timestamps)); - assert.strictEqual(1, data.timestamps.length); + assert.equal(true, Array.isArray(data.timestamps)); + assert.strictEqual(1, data.timestamps.length); - assert.equal(true, Array.isArray(data.revisions)); - assert.strictEqual(data.timestamps.length, data.revisions.length); - ['timestamp', 'username'].every(prop => Object.keys(data.revisions[0]).includes(prop)); - done(); - }); + assert.equal(true, Array.isArray(data.revisions)); + assert.strictEqual(data.timestamps.length, data.revisions.length); + ['timestamp', 'username'].every(prop => Object.keys(data.revisions[0]).includes(prop)); }); it('should not delete first diff of a post', async () => {