Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): Add more unit tests for Workflow.ts (no-changelog) #9868

Merged
merged 4 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 23 additions & 24 deletions packages/workflow/src/Workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ function dedupe<T>(arr: T[]): T[] {
return [...new Set(arr)];
}

export interface WorkflowParameters {
id?: string;
name?: string;
nodes: INode[];
connections: IConnections;
active: boolean;
nodeTypes: INodeTypes;
staticData?: IDataObject;
settings?: IWorkflowSettings;
pinData?: IPinData;
}

export class Workflow {
id: string;

Expand Down Expand Up @@ -90,18 +102,7 @@ export class Workflow {

pinData?: IPinData;

// constructor(id: string | undefined, nodes: INode[], connections: IConnections, active: boolean, nodeTypes: INodeTypes, staticData?: IDataObject, settings?: IWorkflowSettings) {
constructor(parameters: {
id?: string;
name?: string;
nodes: INode[];
connections: IConnections;
active: boolean;
nodeTypes: INodeTypes;
staticData?: IDataObject;
settings?: IWorkflowSettings;
pinData?: IPinData;
}) {
constructor(parameters: WorkflowParameters) {
this.id = parameters.id as string; // @tech_debt Ensure this is not optional
this.name = parameters.name;
this.nodeTypes = parameters.nodeTypes;
Expand Down Expand Up @@ -251,16 +252,14 @@ export class Workflow {
* is fine. If there are issues it returns the issues
* which have been found for the different nodes.
* TODO: Does currently not check for credential issues!
*
*/
checkReadyForExecution(inputData: {
startNode?: string;
destinationNode?: string;
pinDataNodeNames?: string[];
}): IWorkflowIssues | null {
let node: INode;
let nodeType: INodeType | undefined;
let nodeIssues: INodeIssues | null = null;
checkReadyForExecution(
inputData: {
startNode?: string;
destinationNode?: string;
pinDataNodeNames?: string[];
} = {},
): IWorkflowIssues | null {
const workflowIssues: IWorkflowIssues = {};

let checkNodes: string[] = [];
Expand All @@ -277,14 +276,14 @@ export class Workflow {
}

for (const nodeName of checkNodes) {
nodeIssues = null;
node = this.nodes[nodeName];
let nodeIssues: INodeIssues | null = null;
const node = this.nodes[nodeName];

if (node.disabled === true) {
continue;
}

nodeType = this.nodeTypes.getByNameAndVersion(node.type, node.typeVersion);
const nodeType = this.nodeTypes.getByNameAndVersion(node.type, node.typeVersion);

if (nodeType === undefined) {
// Node type is not known
Expand Down
Loading
Loading