diff --git a/packages/nodes-base/nodes/Wait/Wait.node.ts b/packages/nodes-base/nodes/Wait/Wait.node.ts index 56ca638141..166de8aea2 100644 --- a/packages/nodes-base/nodes/Wait/Wait.node.ts +++ b/packages/nodes-base/nodes/Wait/Wait.node.ts @@ -503,7 +503,7 @@ export class Wait extends Webhook { if (!validateWaitAmount(waitAmount)) { throw new NodeOperationError( context.getNode(), - 'Invalid wait amount. It must be a positive number.', + 'Invalid wait amount. Please enter a number that is 0 or greater.', ); } diff --git a/packages/nodes-base/nodes/Wait/test/Wait.node.test.ts b/packages/nodes-base/nodes/Wait/test/Wait.node.test.ts index 49a41e9700..86423af4b6 100644 --- a/packages/nodes-base/nodes/Wait/test/Wait.node.test.ts +++ b/packages/nodes-base/nodes/Wait/test/Wait.node.test.ts @@ -90,10 +90,16 @@ describe('Execute Wait Node', () => { amount: 10, expectedWaitTill: () => DateTime.now().plus({ days: 10 }).toJSDate(), }, + { + unit: 'seconds', + amount: 0, + mode: 'timeout', + expectedWaitTill: () => DateTime.now().toJSDate(), + }, { unit: 'seconds', amount: -10, - error: 'Invalid wait amount. It must be a positive number.', + error: 'Invalid wait amount. Please enter a number that is 0 or greater.', }, { unit: 'years', @@ -103,13 +109,14 @@ describe('Execute Wait Node', () => { { unit: 'minutes', amount: 'test', - error: 'Invalid wait amount. It must be a positive number.', + error: 'Invalid wait amount. Please enter a number that is 0 or greater.', }, ])( 'Validate wait unit: $unit, amount: $amount', - async ({ unit, amount, expectedWaitTill, error }) => { + async ({ unit, amount, expectedWaitTill, error, mode }) => { const putExecutionToWaitSpy = jest.fn(); const waitNode = new Wait(); + const inputData = [{ json: { inputData: true } }]; const executeFunctionsMock = mock({ getNodeParameter: jest.fn().mockImplementation((paramName: string) => { if (paramName === 'resume') return 'timeInterval'; @@ -118,13 +125,21 @@ describe('Execute Wait Node', () => { }), getTimezone: jest.fn().mockReturnValue('UTC'), putExecutionToWait: putExecutionToWaitSpy, - getInputData: jest.fn(), + getInputData: jest.fn(() => inputData), getNode: jest.fn(), }); if (!error) { - await expect(waitNode.execute(executeFunctionsMock)).resolves.not.toThrow(); - expect(putExecutionToWaitSpy).toHaveBeenCalledWith(expectedWaitTill?.()); + if (mode === 'timeout') { + // for short wait times (<65s) a simple timeout is used + const resultPromise = waitNode.execute(executeFunctionsMock); + jest.runAllTimers(); + await expect(resultPromise).resolves.toEqual([inputData]); + } else { + // for longer wait times (>=65s) the execution is put to wait + await expect(waitNode.execute(executeFunctionsMock)).resolves.not.toThrow(); + expect(putExecutionToWaitSpy).toHaveBeenCalledWith(expectedWaitTill?.()); + } } else { await expect(waitNode.execute(executeFunctionsMock)).rejects.toThrowError(error); } diff --git a/packages/nodes-base/nodes/Wait/validation.ts b/packages/nodes-base/nodes/Wait/validation.ts index 860da48ee7..fee090c90f 100644 --- a/packages/nodes-base/nodes/Wait/validation.ts +++ b/packages/nodes-base/nodes/Wait/validation.ts @@ -1,5 +1,5 @@ export function validateWaitAmount(amount: unknown): amount is number { - return typeof amount === 'number' && amount > 0; + return typeof amount === 'number' && amount >= 0; } export type WaitUnit = 'seconds' | 'minutes' | 'hours' | 'days';