From b94963d830f16bfbedc43f4ff6156d7a179fec23 Mon Sep 17 00:00:00 2001 From: Claudio Costa Date: Thu, 24 Oct 2024 07:38:22 -0700 Subject: [PATCH] Revert breaking change in registerSlashCommandWillBePostedHook (#28914) --- .../channels/src/actions/views/create_comment.test.jsx | 10 ++++++++++ webapp/channels/src/actions/views/create_comment.tsx | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/webapp/channels/src/actions/views/create_comment.test.jsx b/webapp/channels/src/actions/views/create_comment.test.jsx index c52c1808c6..948b4ff475 100644 --- a/webapp/channels/src/actions/views/create_comment.test.jsx +++ b/webapp/channels/src/actions/views/create_comment.test.jsx @@ -243,6 +243,16 @@ describe('rhs view actions', () => { expect(executeCommand).not.toHaveBeenCalled(); }); + test('it should not error in case of an empty response', async () => { + HookActions.runSlashCommandWillBePostedHooks.mockImplementation(() => () => ({data: {}})); + + const res = await store.dispatch(submitCommand(channelId, rootId, draft)); + expect(res).toStrictEqual({}); + + expect(HookActions.runSlashCommandWillBePostedHooks).toHaveBeenCalled(); + expect(executeCommand).not.toHaveBeenCalled(); + }); + test('it calls submitPost on error.sendMessage', async () => { jest.mock('actions/channel_actions', () => ({ executeCommand: jest.fn((message, _args, resolve, reject) => reject({sendMessage: 'test'})), diff --git a/webapp/channels/src/actions/views/create_comment.tsx b/webapp/channels/src/actions/views/create_comment.tsx index 5bf9585d32..b988340e68 100644 --- a/webapp/channels/src/actions/views/create_comment.tsx +++ b/webapp/channels/src/actions/views/create_comment.tsx @@ -110,7 +110,10 @@ export function submitCommand(channelId: string, rootId: string, draft: PostDraf return {error: hookResult.error}; } else if (!hookResult.data!.message && !hookResult.data!.args) { // do nothing with an empty return from a hook - return {error: new Error('command not submitted due to plugin hook')}; + // this is allowed by the registerSlashCommandWillBePostedHook API in case + // a plugin intercepts and handles the command on the client side + // but doesn't require it to be sent to the server. (e.g., /call start). + return {}; } message = hookResult.data!.message;