@fincity/kirun-js 1.5.0 → 1.5.2

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,226 @@
1
+ import { AdditionalPropertiesType, ArraySchemaType, HybridRepository } from '../../../../../src';
2
+ import { Schema } from '../../../../../src/engine/json/schema/Schema';
3
+ import { SchemaType } from '../../../../../src/engine/json/schema/type/SchemaType';
4
+ import { TypeUtil } from '../../../../../src/engine/json/schema/type/TypeUtil';
5
+ import { SchemaValidationException } from '../../../../../src/engine/json/schema/validator/exception/SchemaValidationException';
6
+ import { SchemaValidator } from '../../../../../src/engine/json/schema/validator/SchemaValidator';
7
+ import { KIRunSchemaRepository } from '../../../../../src/engine/repository/KIRunSchemaRepository';
8
+
9
+ test('filter condition with ref schema', () => {
10
+ let filterOperator: Schema = Schema.ofString('filterOperator')
11
+ .setNamespace('Test')
12
+ .setEnums(['EQUALS', 'LESS_THAN', 'GREATER_THAN', 'LESS_THAN_EQUAL']);
13
+
14
+ let filterCondition: Schema = Schema.ofObject('filterCondition')
15
+ .setNamespace('Test')
16
+ .setProperties(
17
+ new Map<string, Schema>([
18
+ ['negate', Schema.ofBoolean('negate')],
19
+ ['filterConditionOperator', Schema.ofRef('Test.filterOperator')],
20
+ ['field', Schema.ofString('field')],
21
+ ['value', Schema.ofAny('value')],
22
+ ['toValue', Schema.ofAny('toValue')],
23
+ [
24
+ 'multiValue',
25
+ Schema.ofArray('multiValue').setItems(
26
+ new ArraySchemaType().setSingleSchema(Schema.ofAny('singleType')),
27
+ ),
28
+ ],
29
+ ['isValue', Schema.ofBoolean('isValue')],
30
+ ['isToValue', Schema.ofBoolean('isToValue')],
31
+ ]),
32
+ );
33
+
34
+ var schemaMap = new Map<string, Schema>([
35
+ ['filterOperator', filterOperator],
36
+ ['filterCondition', filterCondition],
37
+ ]);
38
+
39
+ const repo = new HybridRepository<Schema>(
40
+ {
41
+ find(namespace: string, name: string): Schema | undefined {
42
+ if (namespace !== 'Test') return undefined;
43
+ return schemaMap.get(name);
44
+ },
45
+ },
46
+ new KIRunSchemaRepository(),
47
+ );
48
+
49
+ var tempOb = {
50
+ field: 'a.b.c.d',
51
+ value: 'surendhar',
52
+ filterConditionOperator: 'LESS_THAN',
53
+ negate: true,
54
+ isValue: false,
55
+ };
56
+
57
+ expect(SchemaValidator.validate([], filterCondition, repo, tempOb)).toBe(tempOb);
58
+ });
59
+
60
+ test('complex condition with ref schema', () => {
61
+ let complexOperator: Schema = Schema.ofString('complexOperator')
62
+ .setNamespace('Test')
63
+ .setEnums(['AND', 'OR']);
64
+
65
+ // let arraySchema: Schema = Schema.ofArray('conditions', Schema.ofRef('#'));
66
+ let arraySchema: Schema = Schema.ofArray('conditions', Schema.ofRef('Test.complexCondition'));
67
+
68
+ let complexCondition: Schema = Schema.ofObject('complexCondition')
69
+ .setNamespace('Test')
70
+ .setProperties(
71
+ new Map<string, Schema>([
72
+ ['negate', Schema.ofBoolean('negate')],
73
+ ['complexConditionOperator', Schema.ofRef('Test.complexOperator')],
74
+ ['conditions', arraySchema],
75
+ ]),
76
+ );
77
+
78
+ var schemaMap = new Map<string, Schema>([
79
+ ['complexOperator', complexOperator],
80
+ ['complexCondition', complexCondition],
81
+ ]);
82
+
83
+ const repo = new HybridRepository<Schema>(
84
+ {
85
+ find(namespace: string, name: string): Schema | undefined {
86
+ if (namespace !== 'Test') return undefined;
87
+ return schemaMap.get(name);
88
+ },
89
+ },
90
+ new KIRunSchemaRepository(),
91
+ );
92
+
93
+ let ja: any[] = [];
94
+
95
+ let mjob = {
96
+ conditions: [...ja],
97
+ negate: true,
98
+ complexConditionOperator: 'AND',
99
+ };
100
+
101
+ let njob = {
102
+ conditions: [...ja],
103
+ negate: true,
104
+ complexConditionOperator: 'OR',
105
+ };
106
+
107
+ ja.push(mjob);
108
+ ja.push(njob);
109
+
110
+ let bjob = {
111
+ conditions: [...ja],
112
+ negate: true,
113
+ complexConditionOperator: 'AND',
114
+ };
115
+
116
+ expect(SchemaValidator.validate([], complexCondition, repo, bjob)).toBe(bjob);
117
+ });
118
+
119
+ test('filter complex condition with ref schema', () => {
120
+ let filterOperator: Schema = Schema.ofString('filterOperator')
121
+ .setNamespace('Test')
122
+ .setEnums(['EQUALS', 'LESS_THAN', 'GREATER_THAN', 'LESS_THAN_EQUAL', 'IN'])
123
+ .setDefaultValue('EQUALS');
124
+
125
+ let filterCondition: Schema = Schema.ofObject('filterCondition')
126
+ .setNamespace('Test')
127
+ .setProperties(
128
+ new Map<string, Schema>([
129
+ ['negate', Schema.ofBoolean('negate').setDefaultValue(false)],
130
+ ['operator', Schema.ofRef('Test.filterOperator')],
131
+ ['field', Schema.ofString('field')],
132
+ ['value', Schema.ofAny('value')],
133
+ ['toValue', Schema.ofAny('toValue')],
134
+ [
135
+ 'multiValue',
136
+ Schema.ofArray('multiValue').setItems(
137
+ new ArraySchemaType().setSingleSchema(Schema.ofAny('singleType')),
138
+ ),
139
+ ],
140
+ ['isValue', Schema.ofBoolean('isValue').setDefaultValue(false)],
141
+ ['isToValue', Schema.ofBoolean('isToValue').setDefaultValue(false)],
142
+ ]),
143
+ )
144
+ .setRequired(['operator', 'field'])
145
+ .setAdditionalProperties(new AdditionalPropertiesType().setBooleanValue(false));
146
+
147
+ let complexOperator: Schema = Schema.ofString('complexOperator')
148
+ .setNamespace('Test')
149
+ .setEnums(['AND', 'OR']);
150
+
151
+ let arraySchema: Schema = Schema.ofArray(
152
+ 'conditions',
153
+ new Schema().setAnyOf([Schema.ofRef('#'), Schema.ofRef('Test.FilterCondition')]),
154
+ );
155
+
156
+ let complexCondition: Schema = Schema.ofObject('complexCondition')
157
+ .setNamespace('Test')
158
+ .setProperties(
159
+ new Map<string, Schema>([
160
+ ['conditions', arraySchema],
161
+ ['negate', Schema.ofBoolean('negate').setDefaultValue(false)],
162
+ ['operator', Schema.ofRef('Test.complexOperator')],
163
+ ]),
164
+ )
165
+ .setRequired(['conditions', 'operator'])
166
+ .setAdditionalProperties(new AdditionalPropertiesType().setBooleanValue(false));
167
+
168
+ var schemaMap = new Map<string, Schema>([
169
+ ['filterOperator', filterOperator],
170
+ ['filterCondition', filterCondition],
171
+ ['complexOperator', complexOperator],
172
+ ['complexCondition', complexCondition],
173
+ ]);
174
+
175
+ const repo = new HybridRepository<Schema>(
176
+ {
177
+ find(namespace: string, name: string): Schema | undefined {
178
+ if (namespace !== 'Test') return undefined;
179
+ return schemaMap.get(name);
180
+ },
181
+ },
182
+ new KIRunSchemaRepository(),
183
+ );
184
+
185
+ var tempOb = {
186
+ field: 'a.b.c.d',
187
+ value: 'surendhar',
188
+ operator: 'LESS_THAN',
189
+ negate: true,
190
+ isValue: false,
191
+ };
192
+
193
+ var tempOb1 = {
194
+ ...tempOb,
195
+ operator: 'GREATER_THAN',
196
+ isValue: true,
197
+ };
198
+
199
+ var tempOb2 = {
200
+ field: 'k.lm.mno',
201
+ operator: 'IN',
202
+ multiValue: [1, 2, 3, 4, 5, 5, 6, 7],
203
+ negate: true,
204
+ };
205
+ var ja: any[] = [];
206
+
207
+ ja.push(tempOb);
208
+ ja.push(tempOb1);
209
+ ja.push(tempOb2);
210
+
211
+ var mjob = {
212
+ conditions: [],
213
+ negate: false,
214
+ operator: 'AND',
215
+ };
216
+
217
+ var bjob = {
218
+ conditions: [mjob],
219
+ negate: true,
220
+ operator: 'OR',
221
+ };
222
+
223
+ var res = SchemaValidator.validate([], complexCondition, repo, bjob);
224
+
225
+ expect(res).toBe(bjob);
226
+ });