@fincity/kirun-js 3.4.0 → 3.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,84 @@
1
+ import {
2
+ ExpressionEvaluator,
3
+ KIRunSchemaRepository,
4
+ FunctionExecutionParameters,
5
+ KIRunFunctionRepository,
6
+ } from '../../../../src';
7
+
8
+ // Reproduces the sitezump buyTokens status-filter chip label expression.
9
+ //
10
+ // Kirun's equality operator is '=' (Operation.EQUAL = new Operation('=')),
11
+ // NOT '=='. Writing '==' makes the lexer read two consecutive '=' tokens,
12
+ // which leaves a dangling operator and throws "Extra operator ... found."
13
+ // This is exactly the error reported on the chip label.
14
+
15
+ let inMap: Map<string, any> = new Map();
16
+ inMap.set('status', 'PAID'); // Page.invoiceQuery.status equivalent (active)
17
+ inMap.set('emptyStatus', ''); // Page.invoiceQuery.status when "All" (inactive)
18
+ inMap.set('value', 'PAID'); // Parent.value equivalent
19
+ inMap.set('label', 'Paid'); // Parent.label equivalent
20
+
21
+ let output: Map<string, Map<string, Map<string, any>>> = new Map([
22
+ ['step1', new Map([['output', inMap]])],
23
+ ]);
24
+
25
+ let parameters: FunctionExecutionParameters = new FunctionExecutionParameters(
26
+ new KIRunFunctionRepository(),
27
+ new KIRunSchemaRepository(),
28
+ )
29
+ .setArguments(new Map())
30
+ .setSteps(output);
31
+
32
+ test('Double-equals (==) is not a valid Kirun operator and throws', () => {
33
+ const expr = new ExpressionEvaluator(
34
+ "((Steps.step1.output.status ?? '') == Steps.step1.output.value ? '● ' : '') + Steps.step1.output.label",
35
+ );
36
+ expect(() => expr.evaluate(parameters.getValuesMap())).toThrow();
37
+ });
38
+
39
+ test('Single-equals (=) evaluates the chip label correctly', () => {
40
+ // active chip: status = value -> prefixed with the bullet
41
+ let expr = new ExpressionEvaluator(
42
+ "((Steps.step1.output.status ?? '') = Steps.step1.output.value ? '● ' : '') + Steps.step1.output.label",
43
+ );
44
+ expect(expr.evaluate(parameters.getValuesMap())).toBe('● Paid');
45
+
46
+ // inactive chip: emptyStatus (All) != value -> no prefix
47
+ expr = new ExpressionEvaluator(
48
+ "((Steps.step1.output.emptyStatus ?? '') = Steps.step1.output.value ? '● ' : '') + Steps.step1.output.label",
49
+ );
50
+ expect(expr.evaluate(parameters.getValuesMap())).toBe('Paid');
51
+ });
52
+
53
+ // Investigating Kiran's hypothesis: does an expression that ENDS with a string
54
+ // literal (like the original chip label that ended in '') need a trailing space?
55
+ test('Expression ending in a string literal: trailing space should not matter', () => {
56
+ // exact shape Kiran quoted, ending in '' — no trailing space
57
+ let noTrail = new ExpressionEvaluator(
58
+ "(Steps.step1.output.status ?? '') = Steps.step1.output.value ? '● ' : ''",
59
+ );
60
+ expect(noTrail.evaluate(parameters.getValuesMap())).toBe('● ');
61
+
62
+ // same, WITH a trailing space
63
+ let withTrail = new ExpressionEvaluator(
64
+ "(Steps.step1.output.status ?? '') = Steps.step1.output.value ? '● ' : '' ",
65
+ );
66
+ expect(withTrail.evaluate(parameters.getValuesMap())).toBe('● ');
67
+ });
68
+
69
+ test('Bare string literals at end of expression, with/without trailing space', () => {
70
+ expect(new ExpressionEvaluator("'hello'").evaluate(parameters.getValuesMap())).toBe('hello');
71
+ expect(new ExpressionEvaluator("'hello' ").evaluate(parameters.getValuesMap())).toBe('hello');
72
+ expect(new ExpressionEvaluator("''").evaluate(parameters.getValuesMap())).toBe('');
73
+ expect(new ExpressionEvaluator("'' ").evaluate(parameters.getValuesMap())).toBe('');
74
+ });
75
+
76
+ // Kiran's platform example: a {{ }} template that expands to a bare quoted string
77
+ // literal followed by trailing spaces. Before the fix this evaluated to undefined,
78
+ // which would have made e.g. a FetchData url resolve to undefined.
79
+ test('Template expanding to a quoted literal with trailing spaces resolves (not undefined)', () => {
80
+ const expr = new ExpressionEvaluator(
81
+ '"api/ui/personalization/{{Steps.step1.output.label}}/{{Steps.step1.output.value}}" ',
82
+ );
83
+ expect(expr.evaluate(parameters.getValuesMap())).toBe('api/ui/personalization/Paid/PAID');
84
+ });