fix(Onfleet Trigger Node): Fix content type issue (#24767)

This commit is contained in:
Shireen Missi
2026-01-26 14:13:51 +00:00
committed by GitHub
parent 4293b748c8
commit bfec0685f7
2 changed files with 76 additions and 1 deletions
@@ -138,7 +138,7 @@ export class OnfleetTrigger implements INodeType {
/* Validation request */
/* -------------------------------------------------------------------------- */
const res = this.getResponseObject();
res.status(200).send(req.query.check);
res.status(200).type('text/plain').send(req.query.check);
return { noWebhookResponse: true };
}
@@ -0,0 +1,75 @@
import type { IWebhookFunctions } from 'n8n-workflow';
import { OnfleetTrigger } from '../OnfleetTrigger.node';
describe('Onfleet Trigger Node', () => {
let node: OnfleetTrigger;
let mockWebhookFunctions: IWebhookFunctions;
beforeEach(() => {
node = new OnfleetTrigger();
mockWebhookFunctions = {
getWebhookName: jest.fn(),
getRequestObject: jest.fn(),
getResponseObject: jest.fn(),
getBodyData: jest.fn(),
helpers: {
returnJsonArray: jest.fn().mockImplementation((data) => [{ json: data }]),
},
} as unknown as IWebhookFunctions;
});
describe('webhook', () => {
describe('setup webhook validation', () => {
it('should respond with text/plain content type and check query parameter', async () => {
const mockRequest = {
query: {
check: 'validation-token-123',
},
};
const mockResponse = {
status: jest.fn().mockReturnThis(),
type: jest.fn().mockReturnThis(),
send: jest.fn().mockReturnThis(),
};
(mockWebhookFunctions.getWebhookName as jest.Mock).mockReturnValue('setup');
(mockWebhookFunctions.getRequestObject as jest.Mock).mockReturnValue(mockRequest);
(mockWebhookFunctions.getResponseObject as jest.Mock).mockReturnValue(mockResponse);
const result = await node.webhook.call(mockWebhookFunctions);
expect(mockResponse.status).toHaveBeenCalledWith(200);
expect(mockResponse.type).toHaveBeenCalledWith('text/plain');
expect(mockResponse.send).toHaveBeenCalledWith('validation-token-123');
expect(result).toEqual({ noWebhookResponse: true });
});
});
describe('default webhook', () => {
it('should process incoming webhook data', async () => {
const mockRequestData = {
taskId: 'task123',
workerId: 'worker456',
actionContext: 'COMPLETE',
};
const mockRequest = {
query: {},
};
(mockWebhookFunctions.getWebhookName as jest.Mock).mockReturnValue('default');
(mockWebhookFunctions.getRequestObject as jest.Mock).mockReturnValue(mockRequest);
(mockWebhookFunctions.getBodyData as jest.Mock).mockReturnValue(mockRequestData);
const result = await node.webhook.call(mockWebhookFunctions);
expect(result).toEqual({
workflowData: [[{ json: mockRequestData }]],
});
expect(mockWebhookFunctions.helpers.returnJsonArray).toHaveBeenCalledWith(mockRequestData);
});
});
});
});