Files
alighasami 3d5eaf9445
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
first commit
2026-03-17 16:22:57 +03:30

76 lines
2.3 KiB
TypeScript

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