mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat: Add timeout options to sendAndWait operations (#12753)
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import { type MockProxy, mock } from 'jest-mock-extended';
|
||||
import type { IExecuteFunctions, INodeProperties, IWebhookFunctions } from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
import { NodeOperationError, WAIT_INDEFINITELY } from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
getSendAndWaitProperties,
|
||||
getSendAndWaitConfig,
|
||||
createEmail,
|
||||
sendAndWaitWebhook,
|
||||
configureWaitTillDate,
|
||||
} from '../utils';
|
||||
|
||||
describe('Send and Wait utils tests', () => {
|
||||
@@ -369,3 +370,100 @@ describe('Send and Wait utils tests', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('configureWaitTillDate', () => {
|
||||
let mockExecuteFunctions: MockProxy<IExecuteFunctions>;
|
||||
|
||||
beforeEach(() => {
|
||||
mockExecuteFunctions = mock<IExecuteFunctions>();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should return WAIT_INDEFINITELY if limitWaitTime is empty', () => {
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({});
|
||||
const result = configureWaitTillDate(mockExecuteFunctions);
|
||||
expect(result).toBe(WAIT_INDEFINITELY);
|
||||
});
|
||||
|
||||
it('should calculate future date correctly for afterTimeInterval with minutes', () => {
|
||||
const resumeAmount = 5;
|
||||
const resumeUnit = 'minutes';
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({
|
||||
limitType: 'afterTimeInterval',
|
||||
resumeAmount,
|
||||
resumeUnit,
|
||||
});
|
||||
|
||||
const result = configureWaitTillDate(mockExecuteFunctions);
|
||||
const expectedDate = new Date(new Date().getTime() + 5 * 60 * 1000);
|
||||
expect(result.getTime()).toBeCloseTo(expectedDate.getTime(), -2); // Allowing 100ms difference
|
||||
});
|
||||
|
||||
it('should calculate future date correctly for afterTimeInterval with hours', () => {
|
||||
const resumeAmount = 2;
|
||||
const resumeUnit = 'hours';
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({
|
||||
limitType: 'afterTimeInterval',
|
||||
resumeAmount,
|
||||
resumeUnit,
|
||||
});
|
||||
|
||||
const result = configureWaitTillDate(mockExecuteFunctions);
|
||||
const expectedDate = new Date(new Date().getTime() + 2 * 60 * 60 * 1000);
|
||||
expect(result.getTime()).toBeCloseTo(expectedDate.getTime(), -2);
|
||||
});
|
||||
|
||||
it('should calculate future date correctly for afterTimeInterval with days', () => {
|
||||
const resumeAmount = 1;
|
||||
const resumeUnit = 'days';
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({
|
||||
limitType: 'afterTimeInterval',
|
||||
resumeAmount,
|
||||
resumeUnit,
|
||||
});
|
||||
|
||||
const result = configureWaitTillDate(mockExecuteFunctions);
|
||||
const expectedDate = new Date(new Date().getTime() + 1 * 24 * 60 * 60 * 1000);
|
||||
expect(result.getTime()).toBeCloseTo(expectedDate.getTime(), -2);
|
||||
});
|
||||
|
||||
it('should return the specified maxDateAndTime for maxDateAndTime limitType', () => {
|
||||
const maxDateAndTime = '2023-12-31T23:59:59Z';
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({
|
||||
limitType: 'maxDateAndTime',
|
||||
maxDateAndTime,
|
||||
});
|
||||
|
||||
const result = configureWaitTillDate(mockExecuteFunctions);
|
||||
expect(result).toEqual(new Date(maxDateAndTime));
|
||||
});
|
||||
|
||||
it('should throw NodeOperationError for invalid maxDateAndTime format', () => {
|
||||
const invalidMaxDateAndTime = 'invalid-date';
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValue({
|
||||
limitType: 'maxDateAndTime',
|
||||
maxDateAndTime: invalidMaxDateAndTime,
|
||||
});
|
||||
|
||||
expect(() => configureWaitTillDate(mockExecuteFunctions)).toThrow(NodeOperationError);
|
||||
expect(() => configureWaitTillDate(mockExecuteFunctions)).toThrow(
|
||||
'Could not configure Limit Wait Time',
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw NodeOperationError for invalid resumeAmount or resumeUnit', () => {
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValue({
|
||||
limitType: 'afterTimeInterval',
|
||||
resumeAmount: 'invalid',
|
||||
resumeUnit: 'minutes',
|
||||
});
|
||||
|
||||
expect(() => configureWaitTillDate(mockExecuteFunctions)).toThrow(NodeOperationError);
|
||||
expect(() => configureWaitTillDate(mockExecuteFunctions)).toThrow(
|
||||
'Could not configure Limit Wait Time',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user