mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
fix(Stripe Trigger Node): Adds API version specification (#16232)
This commit is contained in:
@@ -7,6 +7,7 @@ import type {
|
||||
INodeTypeDescription,
|
||||
IWebhookResponseData,
|
||||
JsonObject,
|
||||
NodeParameterValue,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeApiError, NodeConnectionTypes } from 'n8n-workflow';
|
||||
|
||||
@@ -827,6 +828,15 @@ export class StripeTrigger implements INodeType {
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'API Version',
|
||||
name: 'apiVersion',
|
||||
type: 'string',
|
||||
placeholder: '2025-05-28.basil',
|
||||
default: '',
|
||||
description:
|
||||
'The API version to use for requests. It controls the format and structure of the incoming event payloads that Stripe sends to your webhook. If empty, Stripe will use the default API version set in your account at the time, which may lead to event processing issues if the API version changes in the future.',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -871,12 +881,25 @@ export class StripeTrigger implements INodeType {
|
||||
|
||||
const endpoint = '/webhook_endpoints';
|
||||
|
||||
const body = {
|
||||
interface StripeWebhookBody {
|
||||
url: string | undefined;
|
||||
description: string;
|
||||
enabled_events: object | NodeParameterValue;
|
||||
api_version?: string;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
const body: StripeWebhookBody = {
|
||||
url: webhookUrl,
|
||||
description: webhookDescription,
|
||||
enabled_events: events,
|
||||
};
|
||||
|
||||
const apiVersion = this.getNodeParameter('apiVersion', '');
|
||||
if (apiVersion && apiVersion !== '') {
|
||||
body.api_version = apiVersion as string;
|
||||
}
|
||||
|
||||
const responseData = await stripeApiRequest.call(this, 'POST', endpoint, body);
|
||||
|
||||
if (
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
import type { IHookFunctions } from 'n8n-workflow';
|
||||
|
||||
import { stripeApiRequest } from '../helpers';
|
||||
import { StripeTrigger } from '../StripeTrigger.node';
|
||||
|
||||
jest.mock('../helpers', () => ({
|
||||
stripeApiRequest: jest.fn(),
|
||||
}));
|
||||
|
||||
const mockedStripeApiRequest = jest.mocked(stripeApiRequest);
|
||||
|
||||
describe('Stripe Trigger Node', () => {
|
||||
let node: StripeTrigger;
|
||||
let mockNodeFunctions: IHookFunctions;
|
||||
|
||||
beforeEach(() => {
|
||||
node = new StripeTrigger();
|
||||
|
||||
mockNodeFunctions = {
|
||||
getNodeWebhookUrl: jest.fn().mockReturnValue('https://webhook.url/test'),
|
||||
getWorkflow: jest.fn().mockReturnValue({ id: 'test-workflow-id' }),
|
||||
getNodeParameter: jest.fn(),
|
||||
getCredentials: jest.fn(),
|
||||
getWorkflowStaticData: jest.fn().mockReturnValue({}),
|
||||
getNode: jest.fn().mockReturnValue({ name: 'StripeTrigger' }),
|
||||
getWebhookName: jest.fn().mockReturnValue('default'),
|
||||
getContext: jest.fn(),
|
||||
getActivationMode: jest.fn(),
|
||||
getMode: jest.fn(),
|
||||
getNodeExecutionData: jest.fn(),
|
||||
getRestApiUrl: jest.fn(),
|
||||
getTimezone: jest.fn(),
|
||||
helpers: {} as any,
|
||||
} as unknown as IHookFunctions;
|
||||
|
||||
// (mockNodeFunctions.getCredentials as jest.Mock).mockResolvedValue({
|
||||
// secretKey: 'sk_test_123',
|
||||
// });
|
||||
|
||||
mockedStripeApiRequest.mockResolvedValue({
|
||||
id: 'we_test123',
|
||||
secret: 'whsec_test123',
|
||||
status: 'enabled',
|
||||
enabled_events: ['*'],
|
||||
});
|
||||
|
||||
mockedStripeApiRequest.mockClear();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should not send API version in body if not specified', async () => {
|
||||
(mockNodeFunctions.getNodeParameter as jest.Mock).mockImplementation((param) => {
|
||||
if (param === 'events') return ['*'];
|
||||
return undefined;
|
||||
});
|
||||
|
||||
const expectedRequestBody = {
|
||||
url: 'https://webhook.url/test',
|
||||
description: 'Created by n8n for workflow ID: test-workflow-id',
|
||||
enabled_events: ['*'],
|
||||
};
|
||||
|
||||
const endpoint = '/webhook_endpoints';
|
||||
|
||||
await node.webhookMethods.default.create.call(mockNodeFunctions);
|
||||
expect(mockedStripeApiRequest).toHaveBeenCalledWith('POST', endpoint, expectedRequestBody);
|
||||
|
||||
const callArgs = mockedStripeApiRequest.mock.calls[0];
|
||||
const requestBody = callArgs[2];
|
||||
expect(requestBody).not.toHaveProperty('api_version');
|
||||
});
|
||||
|
||||
it('should send API version in body if specified in node parameters', async () => {
|
||||
(mockNodeFunctions.getNodeParameter as jest.Mock).mockImplementation((param) => {
|
||||
if (param === 'apiVersion') return '2025-05-28.basil';
|
||||
if (param === 'events') return ['*'];
|
||||
return undefined;
|
||||
});
|
||||
|
||||
const expectedRequestBody = {
|
||||
url: 'https://webhook.url/test',
|
||||
description: 'Created by n8n for workflow ID: test-workflow-id',
|
||||
enabled_events: ['*'],
|
||||
api_version: '2025-05-28.basil',
|
||||
};
|
||||
|
||||
const endpoint = '/webhook_endpoints';
|
||||
|
||||
await node.webhookMethods.default.create.call(mockNodeFunctions);
|
||||
expect(mockedStripeApiRequest).toHaveBeenCalledWith('POST', endpoint, expectedRequestBody);
|
||||
|
||||
const callArgs = mockedStripeApiRequest.mock.calls[0];
|
||||
const requestBody = callArgs[2];
|
||||
expect(requestBody).toHaveProperty('api_version', '2025-05-28.basil');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user