mirror of
https://github.com/n8n-io/n8n.git
synced 2026-05-27 23:07:12 +02:00
71 lines
1.9 KiB
TypeScript
71 lines
1.9 KiB
TypeScript
import type { IExecuteFunctions, INodeTypeBaseDescription } from 'n8n-workflow';
|
|
|
|
import { HttpRequestV1 } from '../../V1/HttpRequestV1.node';
|
|
|
|
describe('HttpRequestV1', () => {
|
|
let node: HttpRequestV1;
|
|
let executeFunctions: IExecuteFunctions;
|
|
|
|
beforeEach(() => {
|
|
const baseDescription: INodeTypeBaseDescription = {
|
|
displayName: 'HTTP Request',
|
|
name: 'httpRequest',
|
|
description: 'Makes an HTTP request and returns the response data',
|
|
group: [],
|
|
};
|
|
node = new HttpRequestV1(baseDescription);
|
|
executeFunctions = {
|
|
getInputData: jest.fn(() => [{ json: {} }]),
|
|
getNodeParameter: jest.fn(),
|
|
getNode: jest.fn(() => ({
|
|
type: 'n8n-nodes-base.httpRequest',
|
|
typeVersion: 1,
|
|
})),
|
|
getCredentials: jest.fn(),
|
|
helpers: {
|
|
request: jest.fn(),
|
|
requestOAuth1: jest.fn(),
|
|
requestOAuth2: jest.fn(),
|
|
assertBinaryData: jest.fn(),
|
|
getBinaryStream: jest.fn(),
|
|
getBinaryMetadata: jest.fn(),
|
|
binaryToString: jest.fn(),
|
|
prepareBinaryData: jest.fn(),
|
|
},
|
|
getContext: jest.fn(),
|
|
sendMessageToUI: jest.fn(),
|
|
continueOnFail: jest.fn(),
|
|
getMode: jest.fn(),
|
|
} as unknown as IExecuteFunctions;
|
|
});
|
|
|
|
describe('URL Parameter Validation', () => {
|
|
it.each([
|
|
{ url: undefined, expectedType: 'undefined' },
|
|
{ url: null, expectedType: 'null' },
|
|
{ url: 42, expectedType: 'number' },
|
|
])('should throw error when URL is $expectedType', async ({ url, expectedType }) => {
|
|
(executeFunctions.getNodeParameter as jest.Mock).mockImplementation((paramName: string) => {
|
|
switch (paramName) {
|
|
case 'responseFormat':
|
|
return 'json';
|
|
case 'requestMethod':
|
|
return 'GET';
|
|
case 'jsonParameters':
|
|
return false;
|
|
case 'options':
|
|
return {};
|
|
case 'url':
|
|
return url;
|
|
default:
|
|
return undefined;
|
|
}
|
|
});
|
|
|
|
await expect(node.execute.call(executeFunctions)).rejects.toThrow(
|
|
`URL parameter must be a string, got ${expectedType}`,
|
|
);
|
|
});
|
|
});
|
|
});
|