fix(Respond to Webhook Node): Return headers in response (#6921)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2023-08-14 12:38:17 +02:00 committed by GitHub
parent 139e08a549
commit a82107fb05
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View file

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

View file

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