first commit
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
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
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
import type { IExecuteSingleFunctions, IHttpRequestOptions } from 'n8n-workflow';
|
||||
|
||||
import { dateTimeToEpochPreSendAction } from '../GenericFunctions';
|
||||
|
||||
describe('dateTimeToEpochPreSendAction', () => {
|
||||
let mockThis: Partial<IExecuteSingleFunctions>;
|
||||
|
||||
beforeEach(() => {
|
||||
mockThis = {};
|
||||
});
|
||||
|
||||
it('should convert startDate and endDate to epoch time', async () => {
|
||||
const requestOptions: IHttpRequestOptions = {
|
||||
url: 'https://example.com/api',
|
||||
qs: {
|
||||
startDate: '2024-12-25T00:00:00Z',
|
||||
endDate: '2024-12-26T00:00:00Z',
|
||||
},
|
||||
};
|
||||
|
||||
const result = await dateTimeToEpochPreSendAction.call(
|
||||
mockThis as IExecuteSingleFunctions,
|
||||
requestOptions,
|
||||
);
|
||||
|
||||
expect(result.qs).toEqual({
|
||||
startDate: new Date('2024-12-25T00:00:00Z').getTime(),
|
||||
endDate: new Date('2024-12-26T00:00:00Z').getTime(),
|
||||
});
|
||||
});
|
||||
|
||||
it('should convert only startDate if endDate is not provided', async () => {
|
||||
const requestOptions: IHttpRequestOptions = {
|
||||
url: 'https://example.com/api',
|
||||
qs: {
|
||||
startDate: '2024-12-25T00:00:00Z',
|
||||
},
|
||||
};
|
||||
|
||||
const result = await dateTimeToEpochPreSendAction.call(
|
||||
mockThis as IExecuteSingleFunctions,
|
||||
requestOptions,
|
||||
);
|
||||
|
||||
expect(result.qs).toEqual({
|
||||
startDate: new Date('2024-12-25T00:00:00Z').getTime(),
|
||||
});
|
||||
});
|
||||
|
||||
it('should convert only endDate if startDate is not provided', async () => {
|
||||
const requestOptions: IHttpRequestOptions = {
|
||||
url: 'https://example.com/api',
|
||||
qs: {
|
||||
endDate: '2024-12-26T00:00:00Z',
|
||||
},
|
||||
};
|
||||
|
||||
const result = await dateTimeToEpochPreSendAction.call(
|
||||
mockThis as IExecuteSingleFunctions,
|
||||
requestOptions,
|
||||
);
|
||||
|
||||
expect(result.qs).toEqual({
|
||||
endDate: new Date('2024-12-26T00:00:00Z').getTime(),
|
||||
});
|
||||
});
|
||||
|
||||
it('should not modify requestOptions if neither startDate nor endDate are provided', async () => {
|
||||
const requestOptions: IHttpRequestOptions = {
|
||||
url: 'https://example.com/api',
|
||||
qs: {},
|
||||
};
|
||||
|
||||
const result = await dateTimeToEpochPreSendAction.call(
|
||||
mockThis as IExecuteSingleFunctions,
|
||||
requestOptions,
|
||||
);
|
||||
|
||||
expect(result).toEqual(requestOptions);
|
||||
});
|
||||
|
||||
it('should not modify requestOptions if qs is undefined', async () => {
|
||||
const requestOptions: IHttpRequestOptions = {
|
||||
url: 'https://example.com/api',
|
||||
qs: undefined,
|
||||
};
|
||||
|
||||
const result = await dateTimeToEpochPreSendAction.call(
|
||||
mockThis as IExecuteSingleFunctions,
|
||||
requestOptions,
|
||||
);
|
||||
|
||||
expect(result).toEqual(requestOptions);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user