Revert breaking change in registerSlashCommandWillBePostedHook (#28914)

Этот коммит содержится в:
Claudio Costa
2024-10-24 07:38:22 -07:00
коммит произвёл GitHub
родитель 108efac918
Коммит b94963d830
2 изменённых файлов: 14 добавлений и 1 удалений

Просмотреть файл

@@ -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'})),

Просмотреть файл

@@ -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;