test(Cron Node): Add workflow test to Cron node (no-changelog) (#12383)

This commit is contained in:
Dana 2025-01-02 08:01:45 +01:00 committed by GitHub
parent 4e9f2b3b9a
commit a484ea160b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -0,0 +1,46 @@
import { get } from 'lodash';
import {
type ITriggerFunctions,
type IDataObject,
type IGetNodeParameterOptions,
} from 'n8n-workflow';
import { Cron } from '../Cron.node';
describe('Cron Node', () => {
const node = new Cron();
const createMockExecuteFunction = (nodeParameters: IDataObject) => {
const fakeExecuteFunction = {
getNodeParameter(
parameterName: string,
fallbackValue?: IDataObject | undefined,
options?: IGetNodeParameterOptions | undefined,
) {
const parameter = options?.extractValue ? `${parameterName}.value` : parameterName;
const parameterValue = get(nodeParameters, parameter, fallbackValue);
return parameterValue;
},
} as unknown as ITriggerFunctions;
return fakeExecuteFunction;
};
const triggerFunctions = createMockExecuteFunction({
triggerTimes: {
item: [],
},
});
afterAll(() => {
jest.resetAllMocks();
});
it('should return a function to trigger', async () => {
expect(await node.trigger.call(triggerFunctions)).toEqual({
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
manualTriggerFunction: expect.any(Function),
});
});
});