@fincity/kirun-js 1.6.13 → 1.6.15

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.
@@ -20,7 +20,7 @@ test('Array to Array of objects', async () => {
20
20
  .getResult()
21
21
  .get('result');
22
22
 
23
- expect(result).toMatchObject([{ value: 1 }, { value: 2 }, { value: 3 }]);
23
+ expect(result).toStrictEqual([{ value: 1 }, { value: 2 }, { value: 3 }]);
24
24
 
25
25
  result = (
26
26
  await fun.execute(
@@ -39,7 +39,7 @@ test('Array to Array of objects', async () => {
39
39
  .getResult()
40
40
  .get('result');
41
41
 
42
- expect(result).toMatchObject([{ number: 1 }, { number: 2 }, { number: 3 }]);
42
+ expect(result).toStrictEqual([{ number: 1 }, { number: 2 }, { number: 3 }]);
43
43
 
44
44
  result = (
45
45
  await fun.execute(
@@ -53,7 +53,7 @@ test('Array to Array of objects', async () => {
53
53
  .getResult()
54
54
  .get('result');
55
55
 
56
- expect(result).toMatchObject([
56
+ expect(result).toStrictEqual([
57
57
  { value: { number: 1 } },
58
58
  { value: { number: 2 } },
59
59
  { value: { number: 3 } },
@@ -82,7 +82,7 @@ test('Array to Array of objects', async () => {
82
82
  .getResult()
83
83
  .get('result');
84
84
 
85
- expect(result).toMatchObject([
85
+ expect(result).toStrictEqual([
86
86
  { value1: 'a', value2: 1 },
87
87
  { value1: 'b', value2: 2 },
88
88
  { value1: 'c', value2: '3' },
@@ -112,10 +112,10 @@ test('Array to Array of objects', async () => {
112
112
  .getResult()
113
113
  .get('result');
114
114
 
115
- expect(result).toMatchObject([
116
- { key: 'a', value: 1 },
117
- { key: 'b', value: 2 },
118
- { key: 'c', value: '3' },
115
+ expect(result).toStrictEqual([
116
+ { key: 'a', value: 1, other: undefined },
117
+ { key: 'b', value: 2, other: undefined },
118
+ { key: 'c', value: '3', other: undefined },
119
119
  ]);
120
120
 
121
121
  result = (
@@ -142,5 +142,118 @@ test('Array to Array of objects', async () => {
142
142
  .getResult()
143
143
  .get('result');
144
144
 
145
- expect(result).toMatchObject([{ maKey: 'a' }, { maKey: 'b' }, { maKey: 'c' }]);
145
+ expect(result).toStrictEqual([{ maKey: 'a' }, { maKey: 'b' }, { maKey: 'c' }]);
146
+ });
147
+
148
+ test('Array with nested object and mixed', async () => {
149
+ let fun = new ArrayToArrayOfObjects();
150
+
151
+ let result = (
152
+ await fun.execute(
153
+ new FunctionExecutionParameters(
154
+ new KIRunFunctionRepository(),
155
+ new KIRunSchemaRepository(),
156
+ ).setArguments(
157
+ new Map([
158
+ ['source', [true, 1, 2, ['a', 'b', 'c']]],
159
+ ['keyName', ['akey', 'bkey', 'ckey']],
160
+ ]),
161
+ ),
162
+ )
163
+ )
164
+ .allResults()[0]
165
+ .getResult()
166
+ .get('result');
167
+
168
+ expect(result).toMatchObject([
169
+ { akey: true },
170
+ { akey: 1 },
171
+ { akey: 2 },
172
+ { akey: 'a', bkey: 'b', ckey: 'c' },
173
+ ]);
174
+ });
175
+
176
+ test('Array with nested array object and mixed without key', async () => {
177
+ let fun = new ArrayToArrayOfObjects();
178
+
179
+ let result = (
180
+ await fun.execute(
181
+ new FunctionExecutionParameters(
182
+ new KIRunFunctionRepository(),
183
+ new KIRunSchemaRepository(),
184
+ ).setArguments(new Map([['source', [true, 1, 2, ['a', 'b', 'c']]]])),
185
+ )
186
+ )
187
+ .allResults()[0]
188
+ .getResult()
189
+ .get('result');
190
+
191
+ expect(result).toStrictEqual([
192
+ { value: true },
193
+ { value: 1 },
194
+ { value: 2 },
195
+ { value1: 'a', value2: 'b', value3: 'c' },
196
+ ]);
197
+ });
198
+
199
+ test('Array with nested array object and mixed without key', async () => {
200
+ let fun = new ArrayToArrayOfObjects();
201
+
202
+ let result = (
203
+ await fun.execute(
204
+ new FunctionExecutionParameters(
205
+ new KIRunFunctionRepository(),
206
+ new KIRunSchemaRepository(),
207
+ ).setArguments(
208
+ new Map([['source', [true, 1, 2, ['a', 'b', 'c', ['d', 'e'], { obj1: 'val1' }]]]]),
209
+ ),
210
+ )
211
+ )
212
+ .allResults()[0]
213
+ .getResult()
214
+ .get('result');
215
+
216
+ expect(result).toStrictEqual([
217
+ { value: true },
218
+ { value: 1 },
219
+ { value: 2 },
220
+ {
221
+ value1: 'a',
222
+ value2: 'b',
223
+ value3: 'c',
224
+ value4: ['d', 'e'],
225
+ value5: {
226
+ obj1: 'val1',
227
+ },
228
+ },
229
+ ]);
230
+ });
231
+
232
+ test('Array with nested array object and mixed with key arrays', async () => {
233
+ let fun = new ArrayToArrayOfObjects();
234
+
235
+ let result = (
236
+ await fun.execute(
237
+ new FunctionExecutionParameters(
238
+ new KIRunFunctionRepository(),
239
+ new KIRunSchemaRepository(),
240
+ ).setArguments(
241
+ new Map([
242
+ ['source', [[true, false], [1, 'surendhar'], ['satya']]],
243
+ ['keyName', ['valueA', 'valueB', 'valueC', 'valueD']],
244
+ ]),
245
+ ),
246
+ )
247
+ )
248
+ .allResults()[0]
249
+ .getResult()
250
+ .get('result');
251
+
252
+ console.log(result);
253
+
254
+ expect(result).toStrictEqual([
255
+ { valueA: true, valueB: false, valueC: undefined, valueD: undefined },
256
+ { valueA: 1, valueB: 'surendhar', valueC: undefined, valueD: undefined },
257
+ { valueA: 'satya', valueB: undefined, valueC: undefined, valueD: undefined },
258
+ ]);
146
259
  });
@@ -26,6 +26,14 @@ class Print extends AbstractFunction {
26
26
  new Map([
27
27
  Parameter.ofEntry(Print.VALUES, Schema.ofAny(Print.VALUES), true),
28
28
  Parameter.ofEntry(Print.VALUE, Schema.ofAny(Print.VALUE)),
29
+ Parameter.ofEntry(
30
+ Print.VALUE + 'Pick1',
31
+ Schema.ofBoolean(Print.VALUE + 'Pick1').setDefaultValue(false),
32
+ ),
33
+ Parameter.ofEntry(
34
+ Print.VALUE + 'Pick2',
35
+ Schema.ofString(Print.VALUE + 'Pick2').setDefaultValue(''),
36
+ ),
29
37
  ]),
30
38
  );
31
39
 
@@ -36,14 +44,20 @@ class Print extends AbstractFunction {
36
44
  protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
37
45
  let values = context.getArguments()?.get(Print.VALUES);
38
46
  let value = context.getArguments()?.get(Print.VALUE);
47
+ let valuePick1 = context.getArguments()?.get(Print.VALUE + 'Pick1');
48
+ let valuePick2 = context.getArguments()?.get(Print.VALUE + 'Pick2');
39
49
 
40
50
  console?.log('Values', ...values);
41
51
  console?.log('Value', value);
52
+ console?.log('ValuePick1', valuePick1);
53
+ console?.log('ValuePick2', valuePick2);
42
54
 
43
55
  return new FunctionOutput([EventResult.outputOf(new Map())]);
44
56
  }
45
57
  }
46
58
 
59
+ const mock = jest.spyOn(global.console, 'log').mockImplementation();
60
+
47
61
  test('KIRuntime With Definition no values passed ', async () => {
48
62
  var def = {
49
63
  name: 'Make an error',
@@ -80,7 +94,7 @@ test('KIRuntime With Definition no values passed ', async () => {
80
94
  new KIRunSchemaRepository(),
81
95
  ).setArguments(new Map()),
82
96
  );
83
- console.log(fo);
97
+ expect(mock).toBeCalledTimes(4);
84
98
  } catch (e: any) {
85
99
  console.error(e);
86
100
  }
@@ -122,7 +136,7 @@ test('KIRuntime With Definition with no value passed', async () => {
122
136
  new KIRunSchemaRepository(),
123
137
  ).setArguments(new Map()),
124
138
  );
125
- console.log(fo);
139
+ expect(mock).toBeCalledTimes(8);
126
140
  } catch (e: any) {
127
141
  console.error(e);
128
142
  }
@@ -165,7 +179,7 @@ test('KIRuntime With Definition with no value and values passed', async () => {
165
179
  new KIRunSchemaRepository(),
166
180
  ).setArguments(new Map()),
167
181
  );
168
- console.log(fo);
182
+ expect(mock).toBeCalledTimes(12);
169
183
  } catch (e: any) {
170
184
  console.error(e);
171
185
  }
@@ -1,25 +1,9 @@
1
- import { KIRuntime } from '../../../src/engine/runtime/KIRuntime';
2
- import { EventResult } from '../../../src/engine/model/EventResult';
3
- import { Event } from '../../../src/engine/model/Event';
4
1
  import { FunctionDefinition } from '../../../src/engine/model/FunctionDefinition';
5
- import { Parameter } from '../../../src/engine/model/Parameter';
6
- import { FunctionExecutionParameters } from '../../../src/engine/runtime/FunctionExecutionParameters';
7
- import { Create } from '../../../src/engine/function/system/context/Create';
8
- import { SetFunction } from '../../../src/engine/function/system/context/SetFunction';
9
- import { GenerateEvent } from '../../../src/engine/function/system/GenerateEvent';
10
- import { If } from '../../../src/engine/function/system/If';
11
- import { RangeLoop } from '../../../src/engine/function/system/loop/RangeLoop';
12
- import { Statement } from '../../../src/engine/model/Statement';
13
- import { ParameterReference } from '../../../src/engine/model/ParameterReference';
14
- import { Schema } from '../../../src/engine/json/schema/Schema';
2
+ import { Namespaces } from '../../../src/engine/namespaces/Namespaces';
15
3
  import { KIRunFunctionRepository } from '../../../src/engine/repository/KIRunFunctionRepository';
16
4
  import { KIRunSchemaRepository } from '../../../src/engine/repository/KIRunSchemaRepository';
17
- import { Namespaces } from '../../../src/engine/namespaces/Namespaces';
18
- import { FunctionSignature } from '../../../src/engine/model/FunctionSignature';
19
- import { AbstractFunction } from '../../../src/engine/function/AbstractFunction';
20
- import { FunctionOutput } from '../../../src/engine/model/FunctionOutput';
21
- import { HybridRepository } from '../../../src/engine/HybridRepository';
22
- import { Function } from '../../../src/engine/function/Function';
5
+ import { FunctionExecutionParameters } from '../../../src/engine/runtime/FunctionExecutionParameters';
6
+ import { KIRuntime } from '../../../src/engine/runtime/KIRuntime';
23
7
 
24
8
  test('KIRuntime With Definition 1', async () => {
25
9
  var def = {
@@ -42,3 +42,13 @@ test('OutputMapTokenValueExtractor Test', () => {
42
42
  expect(omtv.getValue('Steps.step1.output.zero')).toBe(0);
43
43
  expect(omtv.getValue('Steps.step1.output.obj.address.phone.phone2')).toBe('5678');
44
44
  });
45
+
46
+ test('OutputMapTokenValueExtractor Test 2', () => {
47
+ let output: Map<string, Map<string, Map<string, any>>> = new Map([
48
+ ['step1', new Map([['output', new Map([['arr', ['a', 'b', 'c']]])]])],
49
+ ]);
50
+
51
+ var omtv = new OutputMapTokenValueExtractor(output);
52
+ expect(omtv.getValue('Steps.step1.output.arr[1]')).toBe('b');
53
+ expect(omtv.getValue('Steps.step1.output.arr1[1]')).toBeUndefined();
54
+ });