fix(Wait Node): Allow wait node to accept 0 waiting time input (#19159)

Co-authored-by: Elias Meire <elias@meire.dev>
This commit is contained in:
Antoine Bellion
2025-09-04 21:49:26 +02:00
committed by GitHub
parent 63672ad797
commit 59684039ee
3 changed files with 23 additions and 8 deletions

View File

@@ -503,7 +503,7 @@ export class Wait extends Webhook {
if (!validateWaitAmount(waitAmount)) { if (!validateWaitAmount(waitAmount)) {
throw new NodeOperationError( throw new NodeOperationError(
context.getNode(), context.getNode(),
'Invalid wait amount. It must be a positive number.', 'Invalid wait amount. Please enter a number that is 0 or greater.',
); );
} }

View File

@@ -90,10 +90,16 @@ describe('Execute Wait Node', () => {
amount: 10, amount: 10,
expectedWaitTill: () => DateTime.now().plus({ days: 10 }).toJSDate(), expectedWaitTill: () => DateTime.now().plus({ days: 10 }).toJSDate(),
}, },
{
unit: 'seconds',
amount: 0,
mode: 'timeout',
expectedWaitTill: () => DateTime.now().toJSDate(),
},
{ {
unit: 'seconds', unit: 'seconds',
amount: -10, 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', unit: 'years',
@@ -103,13 +109,14 @@ describe('Execute Wait Node', () => {
{ {
unit: 'minutes', unit: 'minutes',
amount: 'test', 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', 'Validate wait unit: $unit, amount: $amount',
async ({ unit, amount, expectedWaitTill, error }) => { async ({ unit, amount, expectedWaitTill, error, mode }) => {
const putExecutionToWaitSpy = jest.fn(); const putExecutionToWaitSpy = jest.fn();
const waitNode = new Wait(); const waitNode = new Wait();
const inputData = [{ json: { inputData: true } }];
const executeFunctionsMock = mock<IExecuteFunctions>({ const executeFunctionsMock = mock<IExecuteFunctions>({
getNodeParameter: jest.fn().mockImplementation((paramName: string) => { getNodeParameter: jest.fn().mockImplementation((paramName: string) => {
if (paramName === 'resume') return 'timeInterval'; if (paramName === 'resume') return 'timeInterval';
@@ -118,13 +125,21 @@ describe('Execute Wait Node', () => {
}), }),
getTimezone: jest.fn().mockReturnValue('UTC'), getTimezone: jest.fn().mockReturnValue('UTC'),
putExecutionToWait: putExecutionToWaitSpy, putExecutionToWait: putExecutionToWaitSpy,
getInputData: jest.fn(), getInputData: jest.fn(() => inputData),
getNode: jest.fn(), getNode: jest.fn(),
}); });
if (!error) { if (!error) {
await expect(waitNode.execute(executeFunctionsMock)).resolves.not.toThrow(); if (mode === 'timeout') {
expect(putExecutionToWaitSpy).toHaveBeenCalledWith(expectedWaitTill?.()); // 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 { } else {
await expect(waitNode.execute(executeFunctionsMock)).rejects.toThrowError(error); await expect(waitNode.execute(executeFunctionsMock)).rejects.toThrowError(error);
} }

View File

@@ -1,5 +1,5 @@
export function validateWaitAmount(amount: unknown): amount is number { 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'; export type WaitUnit = 'seconds' | 'minutes' | 'hours' | 'days';