Skip to content

Commit

Permalink
fix(Respond to Webhook Node): Return headers in response (#6921)
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed Aug 14, 2023
1 parent 174f191 commit 3787156
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 7 additions & 1 deletion packages/cli/src/WebhookHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,13 @@ export const webhookRequestHandler =

// Don't respond, if already responded
if (response.noWebhookResponse !== true) {
ResponseHelper.sendSuccessResponse(res, response.data, true, response.responseCode);
ResponseHelper.sendSuccessResponse(
res,
response.data,
true,
response.responseCode,
response.headers,
);
}
};

Expand Down
8 changes: 6 additions & 2 deletions packages/cli/test/unit/webhooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,24 @@ describe('WebhookServer', () => {
it('should handle regular requests', async () => {
const pathPrefix = config.getEnv(`endpoints.${key}`);
manager.getWebhookMethods.mockResolvedValueOnce(['GET']);
manager.executeWebhook.mockResolvedValueOnce(mockResponse({ test: true }));
manager.executeWebhook.mockResolvedValueOnce(
mockResponse({ test: true }, { key: 'value ' }),
);

const response = await agent.get(`/${pathPrefix}/abcd`).set('origin', corsOrigin);
expect(response.statusCode).toEqual(200);
expect(response.body).toEqual({ test: true });
expect(response.headers['access-control-allow-origin']).toEqual(corsOrigin);
expect(response.headers.key).toEqual('value');
});
});
}

const mockResponse = (data = {}, status = 200) => {
const mockResponse = (data = {}, headers = {}, status = 200) => {
const response = mock<IResponseCallbackData>();
response.responseCode = status;
response.data = data;
response.headers = headers;
return response;
};
});
Expand Down

0 comments on commit 3787156

Please sign in to comment.