Skip to content

Commit 0bc1ba9

Browse files
authored
Merge pull request #24 from Exabyte-io/fix/SOF-6389-1
SOF-6389-1: change subworkflow.addUnit signature without head parameter
2 parents dc1b5bb + d648a61 commit 0bc1ba9

File tree

2 files changed

+69
-11
lines changed

2 files changed

+69
-11
lines changed

src/subworkflows/subworkflow.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -206,22 +206,14 @@ export class Subworkflow extends BaseSubworkflow {
206206
* @param head {Boolean}
207207
* @param index {Number}
208208
*/
209-
addUnit(unit, head = false, index = -1) {
209+
addUnit(unit, index = -1) {
210210
const { units } = this;
211211
if (units.length === 0) {
212212
unit.head = true;
213213
this.setUnits([unit]);
214214
} else {
215-
if (head) {
216-
const first = lodash.first(units);
217-
unit.next = first.flowchartId;
218-
units.unshift(unit);
219-
} else {
220-
const last = lodash.last(units);
221-
last.next = unit.flowchartId;
222-
if (index >= 0) units.splice(index, 0, unit);
223-
else units.push(unit);
224-
}
215+
if (index >= 0) units.splice(index, 0, unit);
216+
else units.push(unit);
225217
this.setUnits(setNextLinks(setUnitsHead(units)));
226218
}
227219
}

tests/subworkflow.test.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
import { expect } from "chai";
22

33
import { createSubworkflowByName } from "../src/subworkflows";
4+
import { AssignmentUnit, ConditionUnit } from "../src/units";
5+
6+
const assignmentUnitData = {
7+
type: "assignment",
8+
application: { name: "espresso", version: "5.4.0" },
9+
};
10+
11+
const conditionUnitData = {
12+
type: "condition",
13+
application: { name: "espresso", version: "5.4.0" },
14+
};
415

516
describe("subworkflows", () => {
617
it("have updateContext function", () => {
@@ -19,4 +30,59 @@ describe("subworkflows", () => {
1930
subworkflow.updateContext(newContext);
2031
expect(subworkflow.context).to.include(newContext);
2132
});
33+
it("add unit to list end", () => {
34+
const subworkflow = createSubworkflowByName({
35+
appName: "espresso",
36+
swfName: "total_energy",
37+
});
38+
39+
expect(subworkflow.units.length).to.be.equal(1);
40+
expect(subworkflow.units[0]._json.type).to.be.equal("execution");
41+
42+
const assignementUnit = new AssignmentUnit(assignmentUnitData);
43+
subworkflow.addUnit(assignementUnit, -1);
44+
45+
expect(subworkflow.units.length).to.be.equal(2);
46+
expect(subworkflow.units[0]._json.type).to.be.equal("execution");
47+
expect(subworkflow.units[1]._json.type).to.be.equal("assignment");
48+
});
49+
it("add unit to list head", () => {
50+
const subworkflow = createSubworkflowByName({
51+
appName: "espresso",
52+
swfName: "total_energy",
53+
});
54+
55+
expect(subworkflow.units.length).to.be.equal(1);
56+
expect(subworkflow.units[0]._json.type).to.be.equal("execution");
57+
58+
const assignementUnit = new AssignmentUnit(assignmentUnitData);
59+
subworkflow.addUnit(assignementUnit, 0);
60+
61+
expect(subworkflow.units.length).to.be.equal(2);
62+
expect(subworkflow.units[0]._json.type).to.be.equal("assignment");
63+
expect(subworkflow.units[1]._json.type).to.be.equal("execution");
64+
});
65+
it("add unit in the middle list of two", () => {
66+
const subworkflow = createSubworkflowByName({
67+
appName: "espresso",
68+
swfName: "total_energy",
69+
});
70+
expect(subworkflow.units.length).to.be.equal(1);
71+
expect(subworkflow.units[0]._json.type).to.be.equal("execution");
72+
73+
const assignementUnit = new AssignmentUnit(assignmentUnitData);
74+
const conditionUnit = new ConditionUnit(conditionUnitData);
75+
subworkflow.addUnit(assignementUnit, -1);
76+
77+
expect(subworkflow.units.length).to.be.equal(2);
78+
expect(subworkflow.units[0]._json.type).to.be.equal("execution");
79+
expect(subworkflow.units[1]._json.type).to.be.equal("assignment");
80+
81+
subworkflow.addUnit(conditionUnit, 1);
82+
83+
expect(subworkflow.units.length).to.be.equal(3);
84+
expect(subworkflow.units[0]._json.type).to.be.equal("execution");
85+
expect(subworkflow.units[1]._json.type).to.be.equal("condition");
86+
expect(subworkflow.units[2]._json.type).to.be.equal("assignment");
87+
});
2288
});

0 commit comments

Comments
 (0)