feat(GitHub Node): GitHub Node Overhaul implementation #12271 (#13238)

This commit is contained in:
Stanimira Rikova
2025-04-04 21:03:45 +03:00
committed by GitHub
parent 2f0b5e488e
commit 33e265aaa8
14 changed files with 1797 additions and 189 deletions

View File

@@ -0,0 +1,64 @@
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);
});
});