2024-06-19 04:33:57 -07:00
|
|
|
import { nanoid } from 'nanoid';
|
2024-06-10 06:49:50 -07:00
|
|
|
import type { IDataObject, IPinData, ITaskData, ITaskDataConnections } from 'n8n-workflow';
|
2023-11-29 03:13:55 -08:00
|
|
|
import { clickExecuteWorkflowButton } from '../composables/workflow';
|
|
|
|
|
|
|
|
export function createMockNodeExecutionData(
|
|
|
|
name: string,
|
|
|
|
{
|
|
|
|
data,
|
|
|
|
inputOverride,
|
|
|
|
executionStatus = 'success',
|
|
|
|
jsonData,
|
|
|
|
...rest
|
2024-06-10 06:49:50 -07:00
|
|
|
}: Partial<ITaskData> & { jsonData?: Record<string, IDataObject> },
|
2023-11-29 03:13:55 -08:00
|
|
|
): Record<string, ITaskData> {
|
|
|
|
return {
|
|
|
|
[name]: {
|
|
|
|
startTime: new Date().getTime(),
|
|
|
|
executionTime: 0,
|
|
|
|
executionStatus,
|
|
|
|
data: jsonData
|
|
|
|
? Object.keys(jsonData).reduce((acc, key) => {
|
|
|
|
acc[key] = [
|
|
|
|
[
|
|
|
|
{
|
|
|
|
json: jsonData[key],
|
|
|
|
pairedItem: { item: 0 },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
return acc;
|
2024-06-10 06:49:50 -07:00
|
|
|
}, {} as ITaskDataConnections)
|
2023-11-29 03:13:55 -08:00
|
|
|
: data,
|
|
|
|
source: [null],
|
|
|
|
...rest,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function createMockWorkflowExecutionData({
|
|
|
|
executionId,
|
|
|
|
runData,
|
|
|
|
pinData = {},
|
|
|
|
lastNodeExecuted,
|
|
|
|
}: {
|
|
|
|
executionId: string;
|
|
|
|
runData: Record<string, ITaskData | ITaskData[]>;
|
|
|
|
pinData?: IPinData;
|
|
|
|
lastNodeExecuted: string;
|
|
|
|
}) {
|
|
|
|
return {
|
|
|
|
executionId,
|
|
|
|
data: {
|
|
|
|
data: {
|
|
|
|
startData: {},
|
|
|
|
resultData: {
|
|
|
|
runData,
|
|
|
|
pinData,
|
|
|
|
lastNodeExecuted,
|
|
|
|
},
|
|
|
|
executionData: {
|
|
|
|
contextData: {},
|
|
|
|
nodeExecutionStack: [],
|
|
|
|
metadata: {},
|
|
|
|
waitingExecution: {},
|
|
|
|
waitingExecutionSource: {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
mode: 'manual',
|
|
|
|
startedAt: new Date().toISOString(),
|
|
|
|
stoppedAt: new Date().toISOString(),
|
|
|
|
status: 'success',
|
|
|
|
finished: true,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-06-10 06:49:50 -07:00
|
|
|
export function runMockWorkflowExecution({
|
2023-11-29 03:13:55 -08:00
|
|
|
trigger,
|
|
|
|
lastNodeExecuted,
|
|
|
|
runData,
|
|
|
|
workflowExecutionData,
|
|
|
|
}: {
|
|
|
|
trigger?: () => void;
|
|
|
|
lastNodeExecuted: string;
|
|
|
|
runData: Array<ReturnType<typeof createMockNodeExecutionData>>;
|
|
|
|
workflowExecutionData?: ReturnType<typeof createMockWorkflowExecutionData>;
|
|
|
|
}) {
|
2024-06-19 04:33:57 -07:00
|
|
|
const executionId = nanoid(8);
|
2023-11-29 03:13:55 -08:00
|
|
|
|
2024-05-17 01:53:15 -07:00
|
|
|
cy.intercept('POST', '/rest/workflows/**/run', {
|
2023-11-29 03:13:55 -08:00
|
|
|
statusCode: 201,
|
|
|
|
body: {
|
|
|
|
data: {
|
|
|
|
executionId,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).as('runWorkflow');
|
|
|
|
|
|
|
|
if (trigger) {
|
|
|
|
trigger();
|
|
|
|
} else {
|
|
|
|
clickExecuteWorkflowButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
cy.wait('@runWorkflow');
|
|
|
|
|
2024-06-10 06:49:50 -07:00
|
|
|
const resolvedRunData: Record<string, ITaskData> = {};
|
2023-11-29 03:13:55 -08:00
|
|
|
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',
|
|
|
|
createMockWorkflowExecutionData({
|
|
|
|
executionId,
|
|
|
|
lastNodeExecuted,
|
|
|
|
runData: resolvedRunData,
|
|
|
|
...workflowExecutionData,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|