Files
n8n/packages/nodes-base/nodes/Github/__tests__/node/Github.webhook.test.ts
T
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

65 lines
1.5 KiB
TypeScript

import type { IWebhookFunctions } from 'n8n-workflow';
import { Github } from '../../Github.node';
describe('Github Node - Webhook Method', () => {
let githubNode: Github;
let mockWebhookFunctions: IWebhookFunctions;
beforeEach(() => {
githubNode = new Github();
mockWebhookFunctions = {
getRequestObject: jest.fn(),
getResponseObject: jest.fn(),
getNodeParameter: jest.fn(),
getNode: jest.fn(),
helpers: {
returnJsonArray: jest.fn(),
},
} as unknown as IWebhookFunctions;
});
it('should process webhook request and return workflowData', async () => {
const sampleWebhookBody = {
action: 'opened',
issue: {
number: 123,
title: 'Test Issue',
body: 'This is a test issue',
user: {
login: 'testuser',
},
},
repository: {
name: 'test-repo',
owner: {
login: 'test-owner',
},
},
};
const mockRequestObject = {
body: sampleWebhookBody,
headers: {
'x-github-event': 'issues',
'x-github-delivery': '72d3162e-cc78-11e3-81ab-4c9367dc0958',
},
};
(mockWebhookFunctions.getRequestObject as jest.Mock).mockReturnValue(mockRequestObject);
(mockWebhookFunctions.helpers.returnJsonArray as jest.Mock).mockReturnValue([
sampleWebhookBody,
]);
const result = await githubNode.webhook.call(mockWebhookFunctions);
expect(result).toEqual({
workflowData: [[sampleWebhookBody]],
});
expect(mockWebhookFunctions.getRequestObject).toHaveBeenCalled();
expect(mockWebhookFunctions.helpers.returnJsonArray).toHaveBeenCalledWith(sampleWebhookBody);
});
});