n8n/cypress/utils/executions.ts
कारतोफ्फेलस्क्रिप्ट™ 03135702f1
Some checks failed
Test Master / install-and-build (push) Has been cancelled
Test Master / Unit tests (18.x) (push) Has been cancelled
Test Master / Unit tests (20.x) (push) Has been cancelled
Test Master / Unit tests (22.4) (push) Has been cancelled
Test Master / Lint (push) Has been cancelled
Test Master / Notify Slack on failure (push) Has been cancelled
fix(core): Bring back execution data on the executionFinished push message (#11821)
2024-11-22 19:09:48 +01:00

111 lines
2.2 KiB
TypeScript

import { stringify } from 'flatted';
import type { IDataObject, ITaskData, ITaskDataConnections } from 'n8n-workflow';
import { nanoid } from 'nanoid';
import { clickExecuteWorkflowButton } from '../composables/workflow';
export function createMockNodeExecutionData(
name: string,
{
data,
inputOverride,
executionStatus = 'success',
jsonData,
...rest
}: Partial<ITaskData> & { jsonData?: Record<string, IDataObject> },
): Record<string, ITaskData> {
return {
[name]: {
startTime: new Date().getTime(),
executionTime: 1,
executionStatus,
data: jsonData
? Object.keys(jsonData).reduce((acc, key) => {
acc[key] = [
[
{
json: jsonData[key],
pairedItem: { item: 0 },
},
],
];
return acc;
}, {} as ITaskDataConnections)
: data,
source: [null],
inputOverride,
...rest,
},
};
}
export function runMockWorkflowExecution({
trigger,
lastNodeExecuted,
runData,
}: {
trigger?: () => void;
lastNodeExecuted: string;
runData: Array<ReturnType<typeof createMockNodeExecutionData>>;
}) {
const workflowId = nanoid();
const executionId = Math.floor(Math.random() * 1_000_000).toString();
cy.intercept('POST', '/rest/workflows/**/run?**', {
statusCode: 201,
body: {
data: {
executionId,
},
},
}).as('runWorkflow');
if (trigger) {
trigger();
} else {
clickExecuteWorkflowButton();
}
cy.wait('@runWorkflow');
const resolvedRunData: Record<string, ITaskData> = {};
runData.forEach((nodeExecution) => {
const nodeName = Object.keys(nodeExecution)[0];
const nodeRunData = nodeExecution[nodeName];
cy.push('nodeExecuteBefore', {
executionId,
nodeName,
});
cy.push('nodeExecuteAfter', {
executionId,
nodeName,
data: nodeRunData,
});
resolvedRunData[nodeName] = nodeExecution[nodeName];
});
cy.push('executionFinished', {
executionId,
workflowId,
status: 'success',
rawData: stringify({
startData: {},
resultData: {
runData,
pinData: {},
lastNodeExecuted,
},
executionData: {
contextData: {},
nodeExecutionStack: [],
metadata: {},
waitingExecution: {},
waitingExecutionSource: {},
},
}),
});
}