@fincity/kirun-js 1.6.1 → 1.6.3

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,142 @@
1
+ import { KIRunSchemaRepository, SchemaValidator } from '../../../../../src';
2
+ import { Schema } from '../../../../../src/engine/json/schema/Schema';
3
+
4
+ const repo = new KIRunSchemaRepository();
5
+ test('schemaArray With Single Test', () => {
6
+ let schema = Schema.from({
7
+ type: 'ARRAY',
8
+ items: {
9
+ singleSchema: {
10
+ type: 'OBJECT',
11
+ properties: { name: { type: 'STRING' }, age: { type: 'INTEGER' } },
12
+ },
13
+ },
14
+ additionalItems: false,
15
+ });
16
+
17
+ let obj = [
18
+ {
19
+ name: 'amigo1',
20
+ },
21
+ {
22
+ age: 24,
23
+ },
24
+ false,
25
+ 'exampleString',
26
+ ];
27
+
28
+ expect(() => SchemaValidator.validate([], schema, repo, obj)).toThrow();
29
+ });
30
+
31
+ test('schemaArray With out Single fail Test', () => {
32
+ let schema = Schema.from({
33
+ type: 'ARRAY',
34
+ items: {
35
+ type: 'OBJECT',
36
+ properties: { name: { type: 'STRING' }, age: { type: 'INTEGER' } },
37
+ },
38
+
39
+ additionalItems: false,
40
+ });
41
+
42
+ let obj = [
43
+ {
44
+ name: 'amigo1',
45
+ },
46
+ {
47
+ age: 24,
48
+ },
49
+ false,
50
+ 'exampleString',
51
+ ];
52
+
53
+ expect(() => SchemaValidator.validate([], schema, repo, obj)).toThrow();
54
+ });
55
+
56
+ test('schemaArrayWithSingle pass Test', () => {
57
+ let schema = Schema.from({
58
+ type: 'ARRAY',
59
+ items: {
60
+ singleSchema: {
61
+ type: 'OBJECT',
62
+ properties: { name: { type: 'STRING' }, age: { type: 'INTEGER' } },
63
+ },
64
+ },
65
+
66
+ additionalItems: false,
67
+ });
68
+
69
+ let obj = [
70
+ {
71
+ name: 'amigo1',
72
+ },
73
+ {
74
+ age: 24,
75
+ },
76
+ ];
77
+
78
+ expect(SchemaValidator.validate([], schema, repo, obj)).toBe(obj);
79
+ });
80
+
81
+ test('schemaArray With Tuple Test ', () => {
82
+ let schema = Schema.from({
83
+ type: 'ARRAY',
84
+ items: {
85
+ tupleSchema: [
86
+ {
87
+ type: 'OBJECT',
88
+ properties: { name: { type: 'STRING' }, age: { type: 'INTEGER' } },
89
+ required: ['age'],
90
+ },
91
+ { type: 'STRING', minLength: 2 },
92
+ { type: 'INTEGER', minimum: 10 },
93
+ ],
94
+ },
95
+ additionalItems: true,
96
+ });
97
+
98
+ let obj = [
99
+ {
100
+ name: 'amigo1',
101
+ age: 24,
102
+ },
103
+ 'string type',
104
+
105
+ 11,
106
+ false,
107
+ 12.34,
108
+ 'mla',
109
+ ];
110
+ console.log(JSON.stringify(schema, undefined, 2));
111
+
112
+ expect(SchemaValidator.validate([], schema, repo, obj)).toBe(obj);
113
+ });
114
+
115
+ test('schemaArray With out Tuple Test ', () => {
116
+ let schema = Schema.from({
117
+ type: 'ARRAY',
118
+ items: [
119
+ {
120
+ type: 'OBJECT',
121
+ properties: { name: { type: 'STRING' }, age: { type: 'INTEGER' } },
122
+ required: ['age'],
123
+ },
124
+ { type: 'STRING', minLength: 2 },
125
+ { type: 'ARRAY', items: { type: 'INTEGER' }, additionalItems: false },
126
+ ],
127
+ additionalItems: true,
128
+ });
129
+
130
+ let obj = [
131
+ {
132
+ name: 'amigo1',
133
+ age: 21,
134
+ },
135
+ 'second string',
136
+ [1, 2, 31231],
137
+ 'additional items was added here with true and false',
138
+ true,
139
+ false,
140
+ ];
141
+ expect(SchemaValidator.validate([], schema, repo, obj)).toBe(obj);
142
+ });
@@ -9,112 +9,112 @@ import {
9
9
 
10
10
  const repo = new KIRunSchemaRepository();
11
11
 
12
- // test('schema array validator tuple schema test for additional items with boolean different datatype', () => {
13
- // let schema = Schema.from({
14
- // type: 'ARRAY',
15
- // items: [
16
- // {
17
- // type: 'INTEGER',
18
- // },
19
- // {
20
- // type: 'STRING',
21
- // },
22
- // {
23
- // type: 'BOOLEAN',
24
- // },
25
- // {
26
- // type: 'OBJECT',
27
- // },
28
- // ],
29
- // additionalItems: {
30
- // schemaValue: {
31
- // type: 'OBJECT',
32
- // },
33
- // },
34
- // });
35
-
36
- // let obj = [1, 'asd', { val: 'stringtype' }, 'stringOnemore'];
37
-
38
- // expect(() => SchemaValidator.validate([], schema, repo, obj)).toThrowError();
39
- // });
40
-
41
- // test('schema array validator tuple schema test for additional items with boolean true datatype', () => {
42
- // let schema = Schema.from({
43
- // type: 'ARRAY',
44
- // items: [
45
- // {
46
- // type: 'STRING',
47
- // },
48
- // {
49
- // type: 'BOOLEAN',
50
- // },
51
- // ],
52
- // additionalItems: {
53
- // schemaValue: {
54
- // type: 'OBJECT',
55
- // },
56
- // },
57
- // });
58
-
59
- // let obj = ['asd', true, { a: 'b' }];
60
-
61
- // expect(SchemaValidator.validate([], schema, repo, obj)).toStrictEqual(obj);
62
- // });
63
-
64
- // test('schema array validator test for additional items with boolean false different datatype', () => {
65
- // let schema = Schema.from({
66
- // type: 'ARRAY',
67
- // items: { type: 'INTEGER' },
68
- // additionalItems: { booleanValue: false },
69
- // });
70
- // let obj = [1, 2, 3, 4, 'stringtype', true];
71
-
72
- // expect(() => SchemaValidator.validate([], schema, repo, obj)).toThrowError();
73
- // });
74
-
75
- // test('schema array validator test for additional items with boolean true different datatype', () => {
76
- // let schema = Schema.from({
77
- // type: 'ARRAY',
78
- // items: {
79
- // type: 'INTEGER',
80
- // },
81
- // additionalItems: {
82
- // schemaValue: {
83
- // type: 'STRING',
84
- // },
85
- // },
86
- // });
87
-
88
- // let obj = [1, 2, 3, 'stringtype', true];
89
-
90
- // expect(() => SchemaValidator.validate([], schema, repo, obj)).toThrowError();
91
- // });
92
-
93
- // test('schema array validator tuple schema test for additional items with boolean different datatype', () => {
94
- // let schema = Schema.from({
95
- // type: 'ARRAY',
96
- // items: [
97
- // {
98
- // type: 'INTEGER',
99
- // },
100
- // {
101
- // type: 'STRING',
102
- // },
103
- // {
104
- // type: 'BOOLEAN',
105
- // },
106
- // ],
107
- // additionalItems: {
108
- // schemaValue: {
109
- // type: 'OBJECT',
110
- // },
111
- // },
112
- // });
113
-
114
- // let obj = [1, 'asd', { val: 'stringtype' }, 'stringOnemore'];
115
-
116
- // expect(() => SchemaValidator.validate([], schema, repo, obj)).toThrowError();
117
- // });
12
+ test('schema array validator tuple schema test for additional items with boolean different datatype', () => {
13
+ let schema = Schema.from({
14
+ type: 'ARRAY',
15
+ items: [
16
+ {
17
+ type: 'INTEGER',
18
+ },
19
+ {
20
+ type: 'STRING',
21
+ },
22
+ {
23
+ type: 'BOOLEAN',
24
+ },
25
+ {
26
+ type: 'OBJECT',
27
+ },
28
+ ],
29
+ additionalItems: {
30
+ schemaValue: {
31
+ type: 'OBJECT',
32
+ },
33
+ },
34
+ });
35
+
36
+ let obj = [1, 'asd', { val: 'stringtype' }, 'stringOnemore'];
37
+
38
+ expect(() => SchemaValidator.validate([], schema, repo, obj)).toThrowError();
39
+ });
40
+
41
+ test('schema array validator tuple schema test for additional items with boolean true datatype', () => {
42
+ let schema = Schema.from({
43
+ type: 'ARRAY',
44
+ items: [
45
+ {
46
+ type: 'STRING',
47
+ },
48
+ {
49
+ type: 'BOOLEAN',
50
+ },
51
+ ],
52
+ additionalItems: {
53
+ schemaValue: {
54
+ type: 'OBJECT',
55
+ },
56
+ },
57
+ });
58
+
59
+ let obj = ['asd', true, { a: 'b' }];
60
+
61
+ expect(SchemaValidator.validate([], schema, repo, obj)).toStrictEqual(obj);
62
+ });
63
+
64
+ test('schema array validator test for additional items with boolean false different datatype', () => {
65
+ let schema = Schema.from({
66
+ type: 'ARRAY',
67
+ items: { type: 'INTEGER' },
68
+ additionalItems: { booleanValue: false },
69
+ });
70
+ let obj = [1, 2, 3, 4, 'stringtype', true];
71
+
72
+ expect(() => SchemaValidator.validate([], schema, repo, obj)).toThrowError();
73
+ });
74
+
75
+ test('schema array validator test for additional items with boolean true different datatype', () => {
76
+ let schema = Schema.from({
77
+ type: 'ARRAY',
78
+ items: {
79
+ type: 'INTEGER',
80
+ },
81
+ additionalItems: {
82
+ schemaValue: {
83
+ type: 'STRING',
84
+ },
85
+ },
86
+ });
87
+
88
+ let obj = [1, 2, 3, 'stringtype', true];
89
+
90
+ expect(() => SchemaValidator.validate([], schema, repo, obj)).toThrowError();
91
+ });
92
+
93
+ test('schema array validator tuple schema test for additional items with boolean different datatype', () => {
94
+ let schema = Schema.from({
95
+ type: 'ARRAY',
96
+ items: [
97
+ {
98
+ type: 'INTEGER',
99
+ },
100
+ {
101
+ type: 'STRING',
102
+ },
103
+ {
104
+ type: 'BOOLEAN',
105
+ },
106
+ ],
107
+ additionalItems: {
108
+ schemaValue: {
109
+ type: 'OBJECT',
110
+ },
111
+ },
112
+ });
113
+
114
+ let obj = [1, 'asd', { val: 'stringtype' }, 'stringOnemore'];
115
+
116
+ expect(() => SchemaValidator.validate([], schema, repo, obj)).toThrowError();
117
+ });
118
118
 
119
119
  test('multi level validation inner object pollution test', () => {
120
120
  let schema = Schema.from({
@@ -0,0 +1,179 @@
1
+ import {
2
+ FunctionDefinition,
3
+ FunctionExecutionParameters,
4
+ KIRunFunctionRepository,
5
+ KIRunSchemaRepository,
6
+ KIRuntime,
7
+ Namespaces,
8
+ } from '../../../src';
9
+
10
+ test('Messages Test 1', async () => {
11
+ const func = {
12
+ name: 'loginFunction',
13
+ steps: {
14
+ messageStep: {
15
+ statementName: 'messageStep',
16
+ namespace: 'UIEngine',
17
+ name: 'Message',
18
+ parameterMap: {
19
+ msg: {
20
+ value1: {
21
+ key: 'value1',
22
+ type: 'EXPRESSION',
23
+ expression: 'Steps.loginStep.error.data',
24
+ },
25
+ },
26
+ },
27
+ position: {
28
+ left: 198,
29
+ top: 245,
30
+ },
31
+ },
32
+ genOutput: {
33
+ statementName: 'genOutput',
34
+ namespace: 'System',
35
+ name: 'GenerateEvent',
36
+ dependentStatements: {
37
+ 'Steps.loginStep.output': true,
38
+ },
39
+ position: {
40
+ left: 482,
41
+ top: 172,
42
+ },
43
+ },
44
+ loginStep1: {
45
+ name: 'Login',
46
+ namespace: 'UIEngine',
47
+ statementName: 'loginStep1',
48
+ parameterMap: {
49
+ userName: {
50
+ value1: {
51
+ key: 'value1',
52
+ type: 'EXPRESSION',
53
+ expression: 'Page.user.userName',
54
+ },
55
+ },
56
+ password: {
57
+ value1: {
58
+ key: 'value1',
59
+ type: 'EXPRESSION',
60
+ expression: 'Page.user.password',
61
+ },
62
+ },
63
+ rememberMe: {
64
+ value1: {
65
+ key: 'value1',
66
+ type: 'EXPRESSION',
67
+ expression: 'Page.user.rememberMe',
68
+ },
69
+ },
70
+ },
71
+ position: {
72
+ left: 472,
73
+ top: 333,
74
+ },
75
+ },
76
+ },
77
+ };
78
+
79
+ const fd = FunctionDefinition.from(func);
80
+
81
+ const graph = await new KIRuntime(fd, false).getExecutionPlan(
82
+ new KIRunFunctionRepository(),
83
+ new KIRunSchemaRepository(),
84
+ );
85
+
86
+ const messages = Array.from(graph.getNodeMap().values()).flatMap((node) => {
87
+ return node
88
+ .getData()
89
+ .getMessages()
90
+ .map((e) => e.getMessage());
91
+ });
92
+
93
+ expect(messages).toStrictEqual([
94
+ 'UIEngine.Message is not available',
95
+ 'Unable to find the step with name loginStep',
96
+ 'UIEngine.Login is not available',
97
+ ]);
98
+ });
99
+
100
+ test('Messages Test 2', async () => {
101
+ var def = {
102
+ name: 'getAppData',
103
+ namespace: 'UIApp',
104
+ parameters: {
105
+ a: { parameterName: 'a', schema: { name: 'INTEGER', type: 'INTEGER' } },
106
+ b: { parameterName: 'b', schema: { name: 'INTEGER', type: 'INTEGER' } },
107
+ c: { parameterName: 'c', schema: { name: 'INTEGER', type: 'INTEGER' } },
108
+ },
109
+ events: {
110
+ output: {
111
+ name: 'output',
112
+ parameters: { additionResult: { name: 'additionResult', type: 'INTEGER' } },
113
+ },
114
+ },
115
+ steps: {
116
+ add1: {
117
+ statementName: 'add1',
118
+ namespace: Namespaces.MATH,
119
+ name: 'Add',
120
+ parameterMap: {
121
+ value: {
122
+ one: { key: 'one', type: 'EXPRESSION', expression: 'Arguments.a' },
123
+ two: { key: 'two', type: 'EXPRESSION', expression: '10 + 1' },
124
+ three: { key: 'three', type: 'EXPRESSION', expression: 'Arguments.c' },
125
+ },
126
+ },
127
+ },
128
+ genOutput: {
129
+ statementName: 'genOutput',
130
+ namespace: Namespaces.SYSTEM,
131
+ name: 'GenerateEvent',
132
+ parameterMap: {
133
+ eventName: { one: { key: 'one', type: 'VALUE', value: 'output' } },
134
+ results: {
135
+ one: {
136
+ key: 'one',
137
+ type: 'VALUE',
138
+ value: {
139
+ name: 'additionResult',
140
+ value: { isExpression: true, value: 'Steps.add.output.value' },
141
+ },
142
+ },
143
+ },
144
+ },
145
+ },
146
+ },
147
+ };
148
+
149
+ const fd = FunctionDefinition.from(def);
150
+
151
+ const graph = await new KIRuntime(fd, false).getExecutionPlan(
152
+ new KIRunFunctionRepository(),
153
+ new KIRunSchemaRepository(),
154
+ );
155
+
156
+ const messages = Array.from(graph.getNodeMap().values()).flatMap((node) => {
157
+ return node
158
+ .getData()
159
+ .getMessages()
160
+ .map((e) => e.getMessage());
161
+ });
162
+
163
+ expect(messages).toStrictEqual(['Unable to find the step with name add']);
164
+
165
+ await expect(
166
+ new KIRuntime(fd, false).execute(
167
+ new FunctionExecutionParameters(
168
+ new KIRunFunctionRepository(),
169
+ new KIRunSchemaRepository(),
170
+ ).setArguments(
171
+ new Map([
172
+ ['a', 7],
173
+ ['b', 11],
174
+ ['c', 13],
175
+ ]),
176
+ ),
177
+ ),
178
+ ).rejects.toThrow('Unable to find the step with name add');
179
+ });