mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
test(Cron Node): Add workflow test to Cron node (no-changelog) (#12383)
This commit is contained in:
parent
4e9f2b3b9a
commit
a484ea160b
46
packages/nodes-base/nodes/Cron/test/Cron.node.test.ts
Normal file
46
packages/nodes-base/nodes/Cron/test/Cron.node.test.ts
Normal 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),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue