Files
n8n/packages/nodes-base/nodes/HighLevel/v2/test/TaskUpdatePreSendAction.test.ts
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

127 lines
3.1 KiB
TypeScript

import type { IExecuteSingleFunctions, IHttpRequestOptions } from 'n8n-workflow';
import { taskUpdatePreSendAction } from '../GenericFunctions';
describe('taskUpdatePreSendAction', () => {
let mockThis: Partial<IExecuteSingleFunctions>;
beforeEach(() => {
mockThis = {
getNodeParameter: jest.fn(),
helpers: {
httpRequestWithAuthentication: jest.fn(),
} as any,
};
});
it('should not modify requestOptions if title and dueDate are provided', async () => {
const requestOptions: IHttpRequestOptions = {
url: 'https://api.example.com',
body: {
title: 'Task Title',
dueDate: '2024-12-25T00:00:00Z',
},
};
const result = await taskUpdatePreSendAction.call(
mockThis as IExecuteSingleFunctions,
requestOptions,
);
expect(result).toEqual(requestOptions);
});
it('should fetch missing title and dueDate from the API', async () => {
(mockThis.getNodeParameter as jest.Mock).mockReturnValueOnce('123').mockReturnValueOnce('456');
const mockApiResponse = {
title: 'Fetched Task Title',
dueDate: '2024-12-25T02:00:00+02:00',
};
(mockThis.helpers?.httpRequestWithAuthentication as jest.Mock).mockResolvedValue(
mockApiResponse,
);
const requestOptions: IHttpRequestOptions = {
url: 'https://api.example.com',
body: {
title: undefined,
dueDate: undefined,
},
};
const result = await taskUpdatePreSendAction.call(
mockThis as IExecuteSingleFunctions,
requestOptions,
);
expect(result.body).toEqual({
title: 'Fetched Task Title',
dueDate: '2024-12-25T00:00:00+00:00',
});
});
it('should only fetch title if dueDate is provided', async () => {
(mockThis.getNodeParameter as jest.Mock).mockReturnValueOnce('123').mockReturnValueOnce('456');
const mockApiResponse = {
title: 'Fetched Task Title',
dueDate: '2024-12-25T02:00:00+02:00',
};
(mockThis.helpers?.httpRequestWithAuthentication as jest.Mock).mockResolvedValue(
mockApiResponse,
);
const requestOptions: IHttpRequestOptions = {
url: 'https://api.example.com',
body: {
title: undefined,
dueDate: '2024-12-24T00:00:00Z',
},
};
const result = await taskUpdatePreSendAction.call(
mockThis as IExecuteSingleFunctions,
requestOptions,
);
expect(result.body).toEqual({
title: 'Fetched Task Title',
dueDate: '2024-12-24T00:00:00Z',
});
});
it('should only fetch dueDate if title is provided', async () => {
(mockThis.getNodeParameter as jest.Mock).mockReturnValueOnce('123').mockReturnValueOnce('456');
const mockApiResponse = {
title: 'Fetched Task Title',
dueDate: '2024-12-25T02:00:00+02:00',
};
(mockThis.helpers?.httpRequestWithAuthentication as jest.Mock).mockResolvedValue(
mockApiResponse,
);
const requestOptions: IHttpRequestOptions = {
url: 'https://api.example.com',
body: {
title: 'Existing Task Title',
dueDate: undefined,
},
};
const result = await taskUpdatePreSendAction.call(
mockThis as IExecuteSingleFunctions,
requestOptions,
);
expect(result.body).toEqual({
title: 'Existing Task Title',
dueDate: '2024-12-25T00:00:00+00:00',
});
});
});