@fincity/kirun-js 2.2.0 → 2.2.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.
@@ -1,4 +1,4 @@
1
- import { KIRunSchemaRepository, SchemaValidator } from '../../../../../src';
1
+ import { KIRunSchemaRepository, SchemaType, SchemaValidator } from '../../../../../src';
2
2
  import { Schema } from '../../../../../src/engine/json/schema/Schema';
3
3
 
4
4
  const repo = new KIRunSchemaRepository();
@@ -139,3 +139,28 @@ test('schemaArray With out Tuple Test ', async () => {
139
139
  ];
140
140
  expect(await SchemaValidator.validate([], schema, repo, obj)).toBe(obj);
141
141
  });
142
+
143
+ test('Regular JSON', async () => {
144
+ let schema = Schema.from({
145
+ type: 'object',
146
+ properties: {
147
+ productId: {
148
+ description: 'The unique identifier for a product',
149
+ type: 'integer',
150
+ },
151
+ },
152
+ });
153
+
154
+ expect(schema?.getType()?.contains(SchemaType.OBJECT)).toBe(true);
155
+ expect(schema?.getType()?.contains(SchemaType.INTEGER)).toBe(false);
156
+ expect(schema?.getProperties()?.get('productId')?.getType()?.contains(SchemaType.INTEGER)).toBe(
157
+ true,
158
+ );
159
+ });
160
+
161
+ test('Only Ref test', async () => {
162
+ let schema = Schema.from({ ref: 'System.any' });
163
+
164
+ expect(schema?.getType()).toBeUndefined();
165
+ expect(schema?.getRef()).toBe('System.any');
166
+ });
@@ -375,6 +375,25 @@ test('Expression with logical operators and all value types including object', (
375
375
  expect(ev.evaluate(valuesMap)).toBe(4);
376
376
  });
377
377
 
378
+ class TestTokenValueExtractor extends TokenValueExtractor {
379
+ private store: any;
380
+
381
+ constructor(store: any) {
382
+ super();
383
+ this.store = store;
384
+ }
385
+
386
+ protected getValueInternal(token: string): any {
387
+ return this.retrieveElementFrom(token, token.split('.'), 1, this.store);
388
+ }
389
+ public getPrefix(): string {
390
+ return 'Test.';
391
+ }
392
+ public getStore(): any {
393
+ return this.store;
394
+ }
395
+ }
396
+
378
397
  test('Full Store Test', () => {
379
398
  let atv: ArgumentsTokenValueExtractor = new ArgumentsTokenValueExtractor(
380
399
  new Map<string, any>([
@@ -404,25 +423,6 @@ test('Full Store Test', () => {
404
423
  loop: { iteration: { index: 2 } },
405
424
  });
406
425
 
407
- class TestTokenValueExtractor extends TokenValueExtractor {
408
- private store: any;
409
-
410
- constructor(store: any) {
411
- super();
412
- this.store = store;
413
- }
414
-
415
- protected getValueInternal(token: string): any {
416
- return this.retrieveElementFrom(token, token.split('.'), 1, this.store);
417
- }
418
- public getPrefix(): string {
419
- return 'Test.';
420
- }
421
- public getStore(): any {
422
- return this.store;
423
- }
424
- }
425
-
426
426
  let ttv: TestTokenValueExtractor = new TestTokenValueExtractor({
427
427
  a: 'kirun',
428
428
  b: 2,
@@ -441,3 +441,11 @@ test('Full Store Test', () => {
441
441
  ev = new ExpressionEvaluator('Test > 10');
442
442
  expect(ev.evaluate(MapUtil.of(ttv.getPrefix(), ttv))).toStrictEqual(true);
443
443
  });
444
+
445
+ test('Full Store Test when undefined', () => {
446
+ let ttv = new TestTokenValueExtractor(undefined);
447
+
448
+ let ev = new ExpressionEvaluator('Test');
449
+
450
+ expect(ev.evaluate(MapUtil.of(ttv.getPrefix(), ttv))).toBeUndefined();
451
+ });