@blokjs/if-else 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/dist/test/index.test.d.ts +0 -7
- package/dist/test/index.test.js +0 -171
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blokjs/if-else",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"files": ["dist"],
|
|
5
5
|
"description": "blok if-else",
|
|
6
6
|
"type": "module",
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"vitest": "^4.0.18"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@blokjs/helper": "^2.
|
|
30
|
-
"@blokjs/runner": "^2.
|
|
31
|
-
"@blokjs/shared": "^2.
|
|
29
|
+
"@blokjs/helper": "^2.1.0",
|
|
30
|
+
"@blokjs/runner": "^2.1.0",
|
|
31
|
+
"@blokjs/shared": "^2.1.0",
|
|
32
32
|
"lodash": "^4.17.21",
|
|
33
33
|
"zod": "^3.24.2"
|
|
34
34
|
},
|
package/dist/test/index.test.js
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* If-Else Node Tests - Updated for Function-First Implementation
|
|
3
|
-
*
|
|
4
|
-
* Tests migrated from class-based to function-first pattern.
|
|
5
|
-
* All existing behavior is preserved.
|
|
6
|
-
*/
|
|
7
|
-
import { describe, expect, it, vi } from "vitest";
|
|
8
|
-
import IfElseNode from "../index.js";
|
|
9
|
-
describe("IfElse Node - Function-First", () => {
|
|
10
|
-
const mockContext = {
|
|
11
|
-
response: {
|
|
12
|
-
data: null,
|
|
13
|
-
error: null,
|
|
14
|
-
success: true,
|
|
15
|
-
},
|
|
16
|
-
request: {
|
|
17
|
-
body: {},
|
|
18
|
-
headers: {},
|
|
19
|
-
params: {},
|
|
20
|
-
query: {},
|
|
21
|
-
method: "GET",
|
|
22
|
-
},
|
|
23
|
-
config: {
|
|
24
|
-
"if-else": {},
|
|
25
|
-
},
|
|
26
|
-
id: "test-id",
|
|
27
|
-
workflow_name: "test-workflow",
|
|
28
|
-
workflow_path: "/test",
|
|
29
|
-
error: {
|
|
30
|
-
message: [],
|
|
31
|
-
},
|
|
32
|
-
logger: {
|
|
33
|
-
log: vi.fn(),
|
|
34
|
-
info: vi.fn(),
|
|
35
|
-
error: vi.fn(),
|
|
36
|
-
warn: vi.fn(),
|
|
37
|
-
debug: vi.fn(),
|
|
38
|
-
},
|
|
39
|
-
vars: {},
|
|
40
|
-
env: {},
|
|
41
|
-
eventLogger: null,
|
|
42
|
-
_PRIVATE_: null,
|
|
43
|
-
};
|
|
44
|
-
const step = {
|
|
45
|
-
name: "node1",
|
|
46
|
-
run: async (ctx, data) => ({}),
|
|
47
|
-
};
|
|
48
|
-
it("should execute the correct steps when if condition is true", async () => {
|
|
49
|
-
const conditions = [
|
|
50
|
-
{
|
|
51
|
-
type: "if",
|
|
52
|
-
condition: "ctx.request.method === 'GET'",
|
|
53
|
-
steps: [
|
|
54
|
-
(() => {
|
|
55
|
-
step.name = "step1";
|
|
56
|
-
return step;
|
|
57
|
-
})(),
|
|
58
|
-
],
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
type: "else",
|
|
62
|
-
steps: [step],
|
|
63
|
-
condition: "",
|
|
64
|
-
},
|
|
65
|
-
];
|
|
66
|
-
mockContext.request.method = "GET";
|
|
67
|
-
// Flow nodes (definition.flow === true) return their sub-steps as
|
|
68
|
-
// an array directly — no BlokResponse wrap. The runner's
|
|
69
|
-
// processFlow() reads the array straight off `result`.
|
|
70
|
-
const steps = (await IfElseNode.handle(mockContext, conditions));
|
|
71
|
-
expect(steps[0].name).toEqual("step1");
|
|
72
|
-
});
|
|
73
|
-
it("should execute the else step when if condition is false", async () => {
|
|
74
|
-
const conditions = [
|
|
75
|
-
{
|
|
76
|
-
type: "if",
|
|
77
|
-
condition: "ctx.request.method === 'POST'",
|
|
78
|
-
steps: [step],
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
type: "else",
|
|
82
|
-
steps: [
|
|
83
|
-
(() => {
|
|
84
|
-
step.name = "step2";
|
|
85
|
-
return step;
|
|
86
|
-
})(),
|
|
87
|
-
],
|
|
88
|
-
condition: "",
|
|
89
|
-
},
|
|
90
|
-
];
|
|
91
|
-
const steps = (await IfElseNode.handle(mockContext, conditions));
|
|
92
|
-
expect(steps[0].name).toEqual("step2");
|
|
93
|
-
});
|
|
94
|
-
it("should throw an error if the first condition is not 'if'", async () => {
|
|
95
|
-
const conditions = [
|
|
96
|
-
{
|
|
97
|
-
type: "else",
|
|
98
|
-
steps: [step],
|
|
99
|
-
condition: "",
|
|
100
|
-
},
|
|
101
|
-
];
|
|
102
|
-
const result = (await IfElseNode.handle(mockContext, conditions));
|
|
103
|
-
expect(result.success).toBe(false);
|
|
104
|
-
expect(result.error).toBeDefined();
|
|
105
|
-
});
|
|
106
|
-
it("should throw an error if the last condition is not 'else'", async () => {
|
|
107
|
-
const conditions = [
|
|
108
|
-
{
|
|
109
|
-
type: "if",
|
|
110
|
-
condition: "ctx.request.method === 'GET'",
|
|
111
|
-
steps: [step],
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
type: "if",
|
|
115
|
-
condition: "ctx.request.method === 'POST'",
|
|
116
|
-
steps: [step],
|
|
117
|
-
},
|
|
118
|
-
];
|
|
119
|
-
const result = (await IfElseNode.handle(mockContext, conditions));
|
|
120
|
-
expect(result.success).toBe(false);
|
|
121
|
-
expect(result.error).toBeDefined();
|
|
122
|
-
});
|
|
123
|
-
it("should execute the first matching condition", async () => {
|
|
124
|
-
const conditions = [
|
|
125
|
-
{
|
|
126
|
-
type: "if",
|
|
127
|
-
condition: "ctx.request.method === 'POST'",
|
|
128
|
-
steps: [step],
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
type: "if",
|
|
132
|
-
condition: "ctx.request.method === 'GET'",
|
|
133
|
-
steps: [
|
|
134
|
-
(() => {
|
|
135
|
-
step.name = "step2";
|
|
136
|
-
return step;
|
|
137
|
-
})(),
|
|
138
|
-
],
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
type: "else",
|
|
142
|
-
steps: [step],
|
|
143
|
-
condition: "",
|
|
144
|
-
},
|
|
145
|
-
];
|
|
146
|
-
mockContext.request.method = "GET";
|
|
147
|
-
const steps = (await IfElseNode.handle(mockContext, conditions));
|
|
148
|
-
expect(steps[0].name).toEqual("step2");
|
|
149
|
-
});
|
|
150
|
-
it("should execute the else condition if none match", async () => {
|
|
151
|
-
const conditions = [
|
|
152
|
-
{
|
|
153
|
-
type: "if",
|
|
154
|
-
condition: "ctx.request.method === 'POST'",
|
|
155
|
-
steps: [step],
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
type: "else",
|
|
159
|
-
steps: [
|
|
160
|
-
(() => {
|
|
161
|
-
step.name = "step2";
|
|
162
|
-
return step;
|
|
163
|
-
})(),
|
|
164
|
-
],
|
|
165
|
-
condition: "",
|
|
166
|
-
},
|
|
167
|
-
];
|
|
168
|
-
const steps = (await IfElseNode.handle(mockContext, conditions));
|
|
169
|
-
expect(steps[0].name).toEqual("step2");
|
|
170
|
-
});
|
|
171
|
-
});
|