UNPKG

auto-builder-sdk

Version:

SDK for building Auto Builder workflow plugins

48 lines (47 loc) 1.37 kB
/** * Create a minimal stub INode for unit testing nodes. * Allows overriding any field via the `overrides` parameter. */ export const makeStubNode = (type, overrides = {}) => ({ id: overrides.id ?? 'node1', name: overrides.name ?? `${type} Node`, type, typeVersion: overrides.typeVersion ?? 1, position: overrides.position ?? [0, 0], parameters: overrides.parameters ?? {}, ...overrides, }); /** * Create a minimal stub IExecutionContext for unit testing. * Only the commonly-accessed fields are populated; the rest are filled * with reasonable defaults. You can override any part through the * `overrides` argument. */ export const makeStubContext = (overrides = {}) => { const now = new Date(); return { workflowId: 'wf1', workflow: { id: 'wf1', name: 'Test Workflow', nodes: [], connections: {}, active: true, deleted: false, createdAt: now, updatedAt: now, settings: {}, description: '', ...overrides.workflow, }, executionId: 'exec1', mode: 'manual', node: overrides.node ?? makeStubNode('stub'), inputData: [], runIndex: 0, itemIndex: 0, timezone: 'UTC', variables: {}, ...overrides, }; };