@fincity/kirun-js 1.4.14 → 1.5.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.
@@ -0,0 +1,214 @@
1
+ import { KIRuntime } from '../../../src/engine/runtime/KIRuntime';
2
+ import { FunctionDefinition } from '../../../src/engine/model/FunctionDefinition';
3
+ import { FunctionExecutionParameters } from '../../../src/engine/runtime/FunctionExecutionParameters';
4
+ import { KIRunFunctionRepository } from '../../../src/engine/repository/KIRunFunctionRepository';
5
+ import { KIRunSchemaRepository } from '../../../src/engine/repository/KIRunSchemaRepository';
6
+ import { Namespaces } from '../../../src/engine/namespaces/Namespaces';
7
+
8
+ test('KIRuntime Without Gen Event Definition 1', async () => {
9
+ var def = {
10
+ name: 'getAppData',
11
+ namespace: 'UIApp',
12
+ parameters: {
13
+ a: { parameterName: 'a', schema: { name: 'INTEGER', type: 'INTEGER' } },
14
+ b: { parameterName: 'b', schema: { name: 'INTEGER', type: 'INTEGER' } },
15
+ c: { parameterName: 'c', schema: { name: 'INTEGER', type: 'INTEGER' } },
16
+ },
17
+ steps: {
18
+ add: {
19
+ statementName: 'add',
20
+ namespace: Namespaces.MATH,
21
+ name: 'Add',
22
+ parameterMap: {
23
+ value: {
24
+ one: { key: 'one', type: 'EXPRESSION', expression: 'Arguments.a' },
25
+ two: { key: 'two', type: 'EXPRESSION', expression: '10 + 1' },
26
+ three: { key: 'three', type: 'EXPRESSION', expression: 'Arguments.c' },
27
+ },
28
+ },
29
+ },
30
+ print: {
31
+ statementName: 'print',
32
+ namespace: Namespaces.SYSTEM,
33
+ name: 'Print',
34
+ parameterMap: {
35
+ values: {
36
+ one: {
37
+ key: 'one',
38
+ type: 'EXPRESSION',
39
+ expression: 'Steps.add.output.value',
40
+ order: 2,
41
+ },
42
+ abc: {
43
+ key: 'abc',
44
+ type: 'VALUE',
45
+ value: 'Nothing muchh....',
46
+ order: 1,
47
+ },
48
+ },
49
+ },
50
+ },
51
+ },
52
+ };
53
+
54
+ const fd = FunctionDefinition.from(def);
55
+
56
+ const test = (console.log = jest.fn().mockImplementation(() => {}));
57
+
58
+ await new KIRuntime(fd, false).execute(
59
+ new FunctionExecutionParameters(
60
+ new KIRunFunctionRepository(),
61
+ new KIRunSchemaRepository(),
62
+ ).setArguments(
63
+ new Map([
64
+ ['a', 7],
65
+ ['b', 11],
66
+ ['c', 13],
67
+ ]),
68
+ ),
69
+ );
70
+ expect(test.mock.calls[0][0]).toBe('Nothing muchh....');
71
+ expect(test.mock.calls[0][1]).toBe(31);
72
+ });
73
+
74
+ test('KIRuntime Without Gen Event Definition 2', async () => {
75
+ var def = {
76
+ name: 'getAppData',
77
+ namespace: 'UIApp',
78
+ parameters: {
79
+ a: { parameterName: 'a', schema: { name: 'INTEGER', type: 'INTEGER' } },
80
+ b: { parameterName: 'b', schema: { name: 'INTEGER', type: 'INTEGER' } },
81
+ c: { parameterName: 'c', schema: { name: 'INTEGER', type: 'INTEGER' } },
82
+ },
83
+ events: {
84
+ output: {
85
+ name: 'output',
86
+ parameters: {},
87
+ },
88
+ },
89
+ steps: {
90
+ add: {
91
+ statementName: 'add',
92
+ namespace: Namespaces.MATH,
93
+ name: 'Add',
94
+ parameterMap: {
95
+ value: {
96
+ one: { key: 'one', type: 'EXPRESSION', expression: 'Arguments.a' },
97
+ two: { key: 'two', type: 'EXPRESSION', expression: '10 + 1' },
98
+ three: { key: 'three', type: 'EXPRESSION', expression: 'Arguments.c' },
99
+ },
100
+ },
101
+ },
102
+ print: {
103
+ statementName: 'print',
104
+ namespace: Namespaces.SYSTEM,
105
+ name: 'Print',
106
+ parameterMap: {
107
+ values: {
108
+ one: {
109
+ key: 'one',
110
+ type: 'EXPRESSION',
111
+ expression: 'Steps.add.output.value',
112
+ order: 2,
113
+ },
114
+ abc: {
115
+ key: 'abc',
116
+ type: 'VALUE',
117
+ value: 'Something muchh....',
118
+ order: 1,
119
+ },
120
+ },
121
+ },
122
+ },
123
+ },
124
+ };
125
+
126
+ const fd = FunctionDefinition.from(def);
127
+
128
+ const test = (console.log = jest.fn().mockImplementation(() => {}));
129
+
130
+ await new KIRuntime(fd, false).execute(
131
+ new FunctionExecutionParameters(
132
+ new KIRunFunctionRepository(),
133
+ new KIRunSchemaRepository(),
134
+ ).setArguments(
135
+ new Map([
136
+ ['a', 7],
137
+ ['b', 11],
138
+ ['c', 13],
139
+ ]),
140
+ ),
141
+ );
142
+ expect(test.mock.calls[0][0]).toBe('Something muchh....');
143
+ expect(test.mock.calls[0][1]).toBe(31);
144
+ });
145
+
146
+ test('KIRuntime With Definition 1', async () => {
147
+ var def = {
148
+ name: 'getAppData',
149
+ namespace: 'UIApp',
150
+ parameters: {
151
+ a: { parameterName: 'a', schema: { name: 'INTEGER', type: 'INTEGER' } },
152
+ b: { parameterName: 'b', schema: { name: 'INTEGER', type: 'INTEGER' } },
153
+ c: { parameterName: 'c', schema: { name: 'INTEGER', type: 'INTEGER' } },
154
+ },
155
+ events: {
156
+ output: {
157
+ name: 'output',
158
+ parameters: { additionResult: { name: 'additionResult', type: 'INTEGER' } },
159
+ },
160
+ },
161
+ steps: {
162
+ add: {
163
+ statementName: 'add',
164
+ namespace: Namespaces.MATH,
165
+ name: 'Add',
166
+ parameterMap: {
167
+ value: {
168
+ one: { key: 'one', type: 'EXPRESSION', expression: 'Arguments.a' },
169
+ two: { key: 'two', type: 'EXPRESSION', expression: '10 + 1' },
170
+ three: { key: 'three', type: 'EXPRESSION', expression: 'Arguments.c' },
171
+ },
172
+ },
173
+ },
174
+ print: {
175
+ statementName: 'print',
176
+ namespace: Namespaces.SYSTEM,
177
+ name: 'Print',
178
+ parameterMap: {
179
+ values: {
180
+ one: {
181
+ key: 'one',
182
+ type: 'EXPRESSION',
183
+ expression: 'Steps.add.output.value',
184
+ order: 2,
185
+ },
186
+ abc: {
187
+ key: 'abc',
188
+ type: 'VALUE',
189
+ value: 'Something muchh....',
190
+ order: 1,
191
+ },
192
+ },
193
+ },
194
+ },
195
+ },
196
+ };
197
+
198
+ const fd = FunctionDefinition.from(def);
199
+
200
+ const fep = new FunctionExecutionParameters(
201
+ new KIRunFunctionRepository(),
202
+ new KIRunSchemaRepository(),
203
+ ).setArguments(
204
+ new Map([
205
+ ['a', 7],
206
+ ['b', 11],
207
+ ['c', 13],
208
+ ]),
209
+ );
210
+
211
+ const runtime = new KIRuntime(fd, false);
212
+
213
+ await expect(() => runtime.execute(fep)).rejects.toThrowError();
214
+ });