Skip to content

Commit

Permalink
Revert breaking change in registerSlashCommandWillBePostedHook (matte…
Browse files Browse the repository at this point in the history
  • Loading branch information
streamer45 authored Oct 24, 2024
1 parent 108efac commit b94963d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions webapp/channels/src/actions/views/create_comment.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'})),
Expand Down
5 changes: 4 additions & 1 deletion webapp/channels/src/actions/views/create_comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b94963d

Please sign in to comment.