@usertour/helpers 0.0.33 → 0.0.34
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.
- package/dist/__tests__/attribute.test.cjs +242 -11
- package/dist/__tests__/attribute.test.js +232 -2
- package/dist/__tests__/condition.test.cjs +11 -10
- package/dist/__tests__/condition.test.js +2 -2
- package/dist/{chunk-E2APTIR7.js → chunk-7JXEY4A2.js} +11 -10
- package/dist/{chunk-YZQBWYCU.js → chunk-A4KMGXB3.js} +1 -1
- package/dist/conditions/attribute.cjs +11 -10
- package/dist/conditions/attribute.js +1 -1
- package/dist/conditions/condition.cjs +11 -10
- package/dist/conditions/condition.js +2 -2
- package/dist/conditions/index.cjs +11 -10
- package/dist/conditions/index.js +2 -2
- package/dist/index.cjs +11 -10
- package/dist/index.js +2 -2
- package/package.json +1 -1
|
@@ -110,26 +110,27 @@ function evaluateStringCondition(logic, actualValue, expectedValue) {
|
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
function evaluateNumberCondition(logic, actualValue, expectedValue, expectedValue2) {
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
|
|
113
|
+
const numActualValue = Number(actualValue);
|
|
114
|
+
const numExpectedValue = Number(expectedValue);
|
|
115
|
+
const numExpectedValue2 = Number(expectedValue2);
|
|
116
|
+
if (Number.isNaN(numActualValue)) {
|
|
116
117
|
return false;
|
|
117
118
|
}
|
|
118
119
|
switch (logic) {
|
|
119
120
|
case "is":
|
|
120
|
-
return
|
|
121
|
+
return numActualValue === numExpectedValue;
|
|
121
122
|
case "not":
|
|
122
|
-
return
|
|
123
|
+
return numActualValue !== numExpectedValue;
|
|
123
124
|
case "isLessThan":
|
|
124
|
-
return
|
|
125
|
+
return numActualValue < numExpectedValue;
|
|
125
126
|
case "isLessThanOrEqualTo":
|
|
126
|
-
return
|
|
127
|
+
return numActualValue <= numExpectedValue;
|
|
127
128
|
case "isGreaterThan":
|
|
128
|
-
return
|
|
129
|
+
return numActualValue > numExpectedValue;
|
|
129
130
|
case "isGreaterThanOrEqualTo":
|
|
130
|
-
return
|
|
131
|
+
return numActualValue >= numExpectedValue;
|
|
131
132
|
case "between":
|
|
132
|
-
return
|
|
133
|
+
return numActualValue >= numExpectedValue && numActualValue <= numExpectedValue2;
|
|
133
134
|
case "empty":
|
|
134
135
|
return actualValue === null || actualValue === void 0 || actualValue === "";
|
|
135
136
|
case "any":
|
|
@@ -289,6 +290,12 @@ var testAttributes = [
|
|
|
289
290
|
dataType: import_types2.BizAttributeTypes.Number,
|
|
290
291
|
bizType: import_types2.AttributeBizTypes.User
|
|
291
292
|
},
|
|
293
|
+
{
|
|
294
|
+
id: "sdsdd-attr",
|
|
295
|
+
codeName: "sdsdd",
|
|
296
|
+
dataType: import_types2.BizAttributeTypes.Number,
|
|
297
|
+
bizType: import_types2.AttributeBizTypes.User
|
|
298
|
+
},
|
|
292
299
|
// Company attributes
|
|
293
300
|
{
|
|
294
301
|
id: "company-name-attr",
|
|
@@ -323,7 +330,8 @@ var testUserAttributes = {
|
|
|
323
330
|
roles: ["admin", "user"],
|
|
324
331
|
tags: [123, 456],
|
|
325
332
|
signUpDate: "2024-01-15T10:30:00Z",
|
|
326
|
-
score: 85.5
|
|
333
|
+
score: 85.5,
|
|
334
|
+
sdsdd: 101
|
|
327
335
|
};
|
|
328
336
|
var testCompanyAttributes = {
|
|
329
337
|
companyName: "Example Corp",
|
|
@@ -596,6 +604,229 @@ describe("Attribute Filter - Complete Test Suite", () => {
|
|
|
596
604
|
expect(evaluateFilterConditions(condition, defaultOptions)).toBe(true);
|
|
597
605
|
});
|
|
598
606
|
});
|
|
607
|
+
describe("Number conditions with string values", () => {
|
|
608
|
+
test('should evaluate "is" condition when actualValue is number and expectedValue is string', () => {
|
|
609
|
+
const condition = [
|
|
610
|
+
{
|
|
611
|
+
id: "number-string-condition-1",
|
|
612
|
+
type: "condition",
|
|
613
|
+
operators: "and",
|
|
614
|
+
data: {
|
|
615
|
+
logic: "is",
|
|
616
|
+
value: "101",
|
|
617
|
+
attrId: "sdsdd-attr"
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
];
|
|
621
|
+
expect(evaluateFilterConditions(condition, defaultOptions)).toBe(true);
|
|
622
|
+
});
|
|
623
|
+
test('should evaluate "is" condition when actualValue is string and expectedValue is number', () => {
|
|
624
|
+
const userAttributesWithStringNumber = {
|
|
625
|
+
...testUserAttributes,
|
|
626
|
+
sdsdd: "101"
|
|
627
|
+
};
|
|
628
|
+
const condition = [
|
|
629
|
+
{
|
|
630
|
+
id: "number-string-condition-2",
|
|
631
|
+
type: "condition",
|
|
632
|
+
operators: "and",
|
|
633
|
+
data: {
|
|
634
|
+
logic: "is",
|
|
635
|
+
value: 101,
|
|
636
|
+
attrId: "sdsdd-attr"
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
];
|
|
640
|
+
expect(
|
|
641
|
+
evaluateFilterConditions(condition, {
|
|
642
|
+
...defaultOptions,
|
|
643
|
+
userAttributes: userAttributesWithStringNumber
|
|
644
|
+
})
|
|
645
|
+
).toBe(true);
|
|
646
|
+
});
|
|
647
|
+
test('should evaluate "is" condition when both actualValue and expectedValue are strings', () => {
|
|
648
|
+
const userAttributesWithStringNumber = {
|
|
649
|
+
...testUserAttributes,
|
|
650
|
+
sdsdd: "101"
|
|
651
|
+
};
|
|
652
|
+
const condition = [
|
|
653
|
+
{
|
|
654
|
+
id: "number-string-condition-3",
|
|
655
|
+
type: "condition",
|
|
656
|
+
operators: "and",
|
|
657
|
+
data: {
|
|
658
|
+
logic: "is",
|
|
659
|
+
value: "101",
|
|
660
|
+
attrId: "sdsdd-attr"
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
];
|
|
664
|
+
expect(
|
|
665
|
+
evaluateFilterConditions(condition, {
|
|
666
|
+
...defaultOptions,
|
|
667
|
+
userAttributes: userAttributesWithStringNumber
|
|
668
|
+
})
|
|
669
|
+
).toBe(true);
|
|
670
|
+
});
|
|
671
|
+
test('should evaluate "not" condition when actualValue is number and expectedValue is string', () => {
|
|
672
|
+
const condition = [
|
|
673
|
+
{
|
|
674
|
+
id: "number-string-condition-4",
|
|
675
|
+
type: "condition",
|
|
676
|
+
operators: "and",
|
|
677
|
+
data: {
|
|
678
|
+
logic: "not",
|
|
679
|
+
value: "102",
|
|
680
|
+
attrId: "sdsdd-attr"
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
];
|
|
684
|
+
expect(evaluateFilterConditions(condition, defaultOptions)).toBe(true);
|
|
685
|
+
});
|
|
686
|
+
test('should evaluate "isLessThan" condition when expectedValue is string', () => {
|
|
687
|
+
const condition = [
|
|
688
|
+
{
|
|
689
|
+
id: "number-string-condition-5",
|
|
690
|
+
type: "condition",
|
|
691
|
+
operators: "and",
|
|
692
|
+
data: {
|
|
693
|
+
logic: "isLessThan",
|
|
694
|
+
value: "102",
|
|
695
|
+
attrId: "sdsdd-attr"
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
];
|
|
699
|
+
expect(evaluateFilterConditions(condition, defaultOptions)).toBe(true);
|
|
700
|
+
});
|
|
701
|
+
test('should evaluate "isGreaterThan" condition when expectedValue is string', () => {
|
|
702
|
+
const condition = [
|
|
703
|
+
{
|
|
704
|
+
id: "number-string-condition-6",
|
|
705
|
+
type: "condition",
|
|
706
|
+
operators: "and",
|
|
707
|
+
data: {
|
|
708
|
+
logic: "isGreaterThan",
|
|
709
|
+
value: "100",
|
|
710
|
+
attrId: "sdsdd-attr"
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
];
|
|
714
|
+
expect(evaluateFilterConditions(condition, defaultOptions)).toBe(true);
|
|
715
|
+
});
|
|
716
|
+
test('should evaluate "between" condition when value and value2 are strings', () => {
|
|
717
|
+
const condition = [
|
|
718
|
+
{
|
|
719
|
+
id: "number-string-condition-7",
|
|
720
|
+
type: "condition",
|
|
721
|
+
operators: "and",
|
|
722
|
+
data: {
|
|
723
|
+
logic: "between",
|
|
724
|
+
value: "100",
|
|
725
|
+
value2: "103",
|
|
726
|
+
attrId: "sdsdd-attr"
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
];
|
|
730
|
+
expect(evaluateFilterConditions(condition, defaultOptions)).toBe(true);
|
|
731
|
+
});
|
|
732
|
+
test('should evaluate "between" condition when actualValue is string and values are strings', () => {
|
|
733
|
+
const userAttributesWithStringNumber = {
|
|
734
|
+
...testUserAttributes,
|
|
735
|
+
sdsdd: "101"
|
|
736
|
+
};
|
|
737
|
+
const condition = [
|
|
738
|
+
{
|
|
739
|
+
id: "number-string-condition-8",
|
|
740
|
+
type: "condition",
|
|
741
|
+
operators: "and",
|
|
742
|
+
data: {
|
|
743
|
+
logic: "between",
|
|
744
|
+
value: "100",
|
|
745
|
+
value2: "103",
|
|
746
|
+
attrId: "sdsdd-attr"
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
];
|
|
750
|
+
expect(
|
|
751
|
+
evaluateFilterConditions(condition, {
|
|
752
|
+
...defaultOptions,
|
|
753
|
+
userAttributes: userAttributesWithStringNumber
|
|
754
|
+
})
|
|
755
|
+
).toBe(true);
|
|
756
|
+
});
|
|
757
|
+
test("should return false when actualValue is NaN", () => {
|
|
758
|
+
const userAttributesWithNaN = {
|
|
759
|
+
...testUserAttributes,
|
|
760
|
+
sdsdd: "not-a-number"
|
|
761
|
+
};
|
|
762
|
+
const condition = [
|
|
763
|
+
{
|
|
764
|
+
id: "number-string-condition-9",
|
|
765
|
+
type: "condition",
|
|
766
|
+
operators: "and",
|
|
767
|
+
data: {
|
|
768
|
+
logic: "is",
|
|
769
|
+
value: 101,
|
|
770
|
+
attrId: "sdsdd-attr"
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
];
|
|
774
|
+
expect(
|
|
775
|
+
evaluateFilterConditions(condition, {
|
|
776
|
+
...defaultOptions,
|
|
777
|
+
userAttributes: userAttributesWithNaN
|
|
778
|
+
})
|
|
779
|
+
).toBe(false);
|
|
780
|
+
});
|
|
781
|
+
test("should handle decimal string values correctly", () => {
|
|
782
|
+
const userAttributesWithDecimal = {
|
|
783
|
+
...testUserAttributes,
|
|
784
|
+
score: "85.5"
|
|
785
|
+
};
|
|
786
|
+
const condition = [
|
|
787
|
+
{
|
|
788
|
+
id: "number-string-condition-10",
|
|
789
|
+
type: "condition",
|
|
790
|
+
operators: "and",
|
|
791
|
+
data: {
|
|
792
|
+
logic: "is",
|
|
793
|
+
value: "85.5",
|
|
794
|
+
attrId: "score-attr"
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
];
|
|
798
|
+
expect(
|
|
799
|
+
evaluateFilterConditions(condition, {
|
|
800
|
+
...defaultOptions,
|
|
801
|
+
userAttributes: userAttributesWithDecimal
|
|
802
|
+
})
|
|
803
|
+
).toBe(true);
|
|
804
|
+
});
|
|
805
|
+
test("should handle negative string values correctly", () => {
|
|
806
|
+
const userAttributesWithNegative = {
|
|
807
|
+
...testUserAttributes,
|
|
808
|
+
sdsdd: "-50"
|
|
809
|
+
};
|
|
810
|
+
const condition = [
|
|
811
|
+
{
|
|
812
|
+
id: "number-string-condition-11",
|
|
813
|
+
type: "condition",
|
|
814
|
+
operators: "and",
|
|
815
|
+
data: {
|
|
816
|
+
logic: "isLessThan",
|
|
817
|
+
value: "0",
|
|
818
|
+
attrId: "sdsdd-attr"
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
];
|
|
822
|
+
expect(
|
|
823
|
+
evaluateFilterConditions(condition, {
|
|
824
|
+
...defaultOptions,
|
|
825
|
+
userAttributes: userAttributesWithNegative
|
|
826
|
+
})
|
|
827
|
+
).toBe(true);
|
|
828
|
+
});
|
|
829
|
+
});
|
|
599
830
|
describe("Boolean conditions (4 cases)", () => {
|
|
600
831
|
test('should evaluate "true" condition correctly', () => {
|
|
601
832
|
const condition = [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
evaluateAttributeCondition,
|
|
3
3
|
evaluateFilterConditions
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-7JXEY4A2.js";
|
|
5
5
|
import "../chunk-XEO3YXBM.js";
|
|
6
6
|
|
|
7
7
|
// src/__tests__/attribute.test.ts
|
|
@@ -52,6 +52,12 @@ var testAttributes = [
|
|
|
52
52
|
dataType: BizAttributeTypes.Number,
|
|
53
53
|
bizType: AttributeBizTypes.User
|
|
54
54
|
},
|
|
55
|
+
{
|
|
56
|
+
id: "sdsdd-attr",
|
|
57
|
+
codeName: "sdsdd",
|
|
58
|
+
dataType: BizAttributeTypes.Number,
|
|
59
|
+
bizType: AttributeBizTypes.User
|
|
60
|
+
},
|
|
55
61
|
// Company attributes
|
|
56
62
|
{
|
|
57
63
|
id: "company-name-attr",
|
|
@@ -86,7 +92,8 @@ var testUserAttributes = {
|
|
|
86
92
|
roles: ["admin", "user"],
|
|
87
93
|
tags: [123, 456],
|
|
88
94
|
signUpDate: "2024-01-15T10:30:00Z",
|
|
89
|
-
score: 85.5
|
|
95
|
+
score: 85.5,
|
|
96
|
+
sdsdd: 101
|
|
90
97
|
};
|
|
91
98
|
var testCompanyAttributes = {
|
|
92
99
|
companyName: "Example Corp",
|
|
@@ -359,6 +366,229 @@ describe("Attribute Filter - Complete Test Suite", () => {
|
|
|
359
366
|
expect(evaluateFilterConditions(condition, defaultOptions)).toBe(true);
|
|
360
367
|
});
|
|
361
368
|
});
|
|
369
|
+
describe("Number conditions with string values", () => {
|
|
370
|
+
test('should evaluate "is" condition when actualValue is number and expectedValue is string', () => {
|
|
371
|
+
const condition = [
|
|
372
|
+
{
|
|
373
|
+
id: "number-string-condition-1",
|
|
374
|
+
type: "condition",
|
|
375
|
+
operators: "and",
|
|
376
|
+
data: {
|
|
377
|
+
logic: "is",
|
|
378
|
+
value: "101",
|
|
379
|
+
attrId: "sdsdd-attr"
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
];
|
|
383
|
+
expect(evaluateFilterConditions(condition, defaultOptions)).toBe(true);
|
|
384
|
+
});
|
|
385
|
+
test('should evaluate "is" condition when actualValue is string and expectedValue is number', () => {
|
|
386
|
+
const userAttributesWithStringNumber = {
|
|
387
|
+
...testUserAttributes,
|
|
388
|
+
sdsdd: "101"
|
|
389
|
+
};
|
|
390
|
+
const condition = [
|
|
391
|
+
{
|
|
392
|
+
id: "number-string-condition-2",
|
|
393
|
+
type: "condition",
|
|
394
|
+
operators: "and",
|
|
395
|
+
data: {
|
|
396
|
+
logic: "is",
|
|
397
|
+
value: 101,
|
|
398
|
+
attrId: "sdsdd-attr"
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
];
|
|
402
|
+
expect(
|
|
403
|
+
evaluateFilterConditions(condition, {
|
|
404
|
+
...defaultOptions,
|
|
405
|
+
userAttributes: userAttributesWithStringNumber
|
|
406
|
+
})
|
|
407
|
+
).toBe(true);
|
|
408
|
+
});
|
|
409
|
+
test('should evaluate "is" condition when both actualValue and expectedValue are strings', () => {
|
|
410
|
+
const userAttributesWithStringNumber = {
|
|
411
|
+
...testUserAttributes,
|
|
412
|
+
sdsdd: "101"
|
|
413
|
+
};
|
|
414
|
+
const condition = [
|
|
415
|
+
{
|
|
416
|
+
id: "number-string-condition-3",
|
|
417
|
+
type: "condition",
|
|
418
|
+
operators: "and",
|
|
419
|
+
data: {
|
|
420
|
+
logic: "is",
|
|
421
|
+
value: "101",
|
|
422
|
+
attrId: "sdsdd-attr"
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
];
|
|
426
|
+
expect(
|
|
427
|
+
evaluateFilterConditions(condition, {
|
|
428
|
+
...defaultOptions,
|
|
429
|
+
userAttributes: userAttributesWithStringNumber
|
|
430
|
+
})
|
|
431
|
+
).toBe(true);
|
|
432
|
+
});
|
|
433
|
+
test('should evaluate "not" condition when actualValue is number and expectedValue is string', () => {
|
|
434
|
+
const condition = [
|
|
435
|
+
{
|
|
436
|
+
id: "number-string-condition-4",
|
|
437
|
+
type: "condition",
|
|
438
|
+
operators: "and",
|
|
439
|
+
data: {
|
|
440
|
+
logic: "not",
|
|
441
|
+
value: "102",
|
|
442
|
+
attrId: "sdsdd-attr"
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
];
|
|
446
|
+
expect(evaluateFilterConditions(condition, defaultOptions)).toBe(true);
|
|
447
|
+
});
|
|
448
|
+
test('should evaluate "isLessThan" condition when expectedValue is string', () => {
|
|
449
|
+
const condition = [
|
|
450
|
+
{
|
|
451
|
+
id: "number-string-condition-5",
|
|
452
|
+
type: "condition",
|
|
453
|
+
operators: "and",
|
|
454
|
+
data: {
|
|
455
|
+
logic: "isLessThan",
|
|
456
|
+
value: "102",
|
|
457
|
+
attrId: "sdsdd-attr"
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
];
|
|
461
|
+
expect(evaluateFilterConditions(condition, defaultOptions)).toBe(true);
|
|
462
|
+
});
|
|
463
|
+
test('should evaluate "isGreaterThan" condition when expectedValue is string', () => {
|
|
464
|
+
const condition = [
|
|
465
|
+
{
|
|
466
|
+
id: "number-string-condition-6",
|
|
467
|
+
type: "condition",
|
|
468
|
+
operators: "and",
|
|
469
|
+
data: {
|
|
470
|
+
logic: "isGreaterThan",
|
|
471
|
+
value: "100",
|
|
472
|
+
attrId: "sdsdd-attr"
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
];
|
|
476
|
+
expect(evaluateFilterConditions(condition, defaultOptions)).toBe(true);
|
|
477
|
+
});
|
|
478
|
+
test('should evaluate "between" condition when value and value2 are strings', () => {
|
|
479
|
+
const condition = [
|
|
480
|
+
{
|
|
481
|
+
id: "number-string-condition-7",
|
|
482
|
+
type: "condition",
|
|
483
|
+
operators: "and",
|
|
484
|
+
data: {
|
|
485
|
+
logic: "between",
|
|
486
|
+
value: "100",
|
|
487
|
+
value2: "103",
|
|
488
|
+
attrId: "sdsdd-attr"
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
];
|
|
492
|
+
expect(evaluateFilterConditions(condition, defaultOptions)).toBe(true);
|
|
493
|
+
});
|
|
494
|
+
test('should evaluate "between" condition when actualValue is string and values are strings', () => {
|
|
495
|
+
const userAttributesWithStringNumber = {
|
|
496
|
+
...testUserAttributes,
|
|
497
|
+
sdsdd: "101"
|
|
498
|
+
};
|
|
499
|
+
const condition = [
|
|
500
|
+
{
|
|
501
|
+
id: "number-string-condition-8",
|
|
502
|
+
type: "condition",
|
|
503
|
+
operators: "and",
|
|
504
|
+
data: {
|
|
505
|
+
logic: "between",
|
|
506
|
+
value: "100",
|
|
507
|
+
value2: "103",
|
|
508
|
+
attrId: "sdsdd-attr"
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
];
|
|
512
|
+
expect(
|
|
513
|
+
evaluateFilterConditions(condition, {
|
|
514
|
+
...defaultOptions,
|
|
515
|
+
userAttributes: userAttributesWithStringNumber
|
|
516
|
+
})
|
|
517
|
+
).toBe(true);
|
|
518
|
+
});
|
|
519
|
+
test("should return false when actualValue is NaN", () => {
|
|
520
|
+
const userAttributesWithNaN = {
|
|
521
|
+
...testUserAttributes,
|
|
522
|
+
sdsdd: "not-a-number"
|
|
523
|
+
};
|
|
524
|
+
const condition = [
|
|
525
|
+
{
|
|
526
|
+
id: "number-string-condition-9",
|
|
527
|
+
type: "condition",
|
|
528
|
+
operators: "and",
|
|
529
|
+
data: {
|
|
530
|
+
logic: "is",
|
|
531
|
+
value: 101,
|
|
532
|
+
attrId: "sdsdd-attr"
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
];
|
|
536
|
+
expect(
|
|
537
|
+
evaluateFilterConditions(condition, {
|
|
538
|
+
...defaultOptions,
|
|
539
|
+
userAttributes: userAttributesWithNaN
|
|
540
|
+
})
|
|
541
|
+
).toBe(false);
|
|
542
|
+
});
|
|
543
|
+
test("should handle decimal string values correctly", () => {
|
|
544
|
+
const userAttributesWithDecimal = {
|
|
545
|
+
...testUserAttributes,
|
|
546
|
+
score: "85.5"
|
|
547
|
+
};
|
|
548
|
+
const condition = [
|
|
549
|
+
{
|
|
550
|
+
id: "number-string-condition-10",
|
|
551
|
+
type: "condition",
|
|
552
|
+
operators: "and",
|
|
553
|
+
data: {
|
|
554
|
+
logic: "is",
|
|
555
|
+
value: "85.5",
|
|
556
|
+
attrId: "score-attr"
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
];
|
|
560
|
+
expect(
|
|
561
|
+
evaluateFilterConditions(condition, {
|
|
562
|
+
...defaultOptions,
|
|
563
|
+
userAttributes: userAttributesWithDecimal
|
|
564
|
+
})
|
|
565
|
+
).toBe(true);
|
|
566
|
+
});
|
|
567
|
+
test("should handle negative string values correctly", () => {
|
|
568
|
+
const userAttributesWithNegative = {
|
|
569
|
+
...testUserAttributes,
|
|
570
|
+
sdsdd: "-50"
|
|
571
|
+
};
|
|
572
|
+
const condition = [
|
|
573
|
+
{
|
|
574
|
+
id: "number-string-condition-11",
|
|
575
|
+
type: "condition",
|
|
576
|
+
operators: "and",
|
|
577
|
+
data: {
|
|
578
|
+
logic: "isLessThan",
|
|
579
|
+
value: "0",
|
|
580
|
+
attrId: "sdsdd-attr"
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
];
|
|
584
|
+
expect(
|
|
585
|
+
evaluateFilterConditions(condition, {
|
|
586
|
+
...defaultOptions,
|
|
587
|
+
userAttributes: userAttributesWithNegative
|
|
588
|
+
})
|
|
589
|
+
).toBe(true);
|
|
590
|
+
});
|
|
591
|
+
});
|
|
362
592
|
describe("Boolean conditions (4 cases)", () => {
|
|
363
593
|
test('should evaluate "true" condition correctly', () => {
|
|
364
594
|
const condition = [
|
|
@@ -210,26 +210,27 @@ function evaluateStringCondition(logic, actualValue, expectedValue) {
|
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
function evaluateNumberCondition(logic, actualValue, expectedValue, expectedValue2) {
|
|
213
|
-
const
|
|
214
|
-
const
|
|
215
|
-
|
|
213
|
+
const numActualValue = Number(actualValue);
|
|
214
|
+
const numExpectedValue = Number(expectedValue);
|
|
215
|
+
const numExpectedValue2 = Number(expectedValue2);
|
|
216
|
+
if (Number.isNaN(numActualValue)) {
|
|
216
217
|
return false;
|
|
217
218
|
}
|
|
218
219
|
switch (logic) {
|
|
219
220
|
case "is":
|
|
220
|
-
return
|
|
221
|
+
return numActualValue === numExpectedValue;
|
|
221
222
|
case "not":
|
|
222
|
-
return
|
|
223
|
+
return numActualValue !== numExpectedValue;
|
|
223
224
|
case "isLessThan":
|
|
224
|
-
return
|
|
225
|
+
return numActualValue < numExpectedValue;
|
|
225
226
|
case "isLessThanOrEqualTo":
|
|
226
|
-
return
|
|
227
|
+
return numActualValue <= numExpectedValue;
|
|
227
228
|
case "isGreaterThan":
|
|
228
|
-
return
|
|
229
|
+
return numActualValue > numExpectedValue;
|
|
229
230
|
case "isGreaterThanOrEqualTo":
|
|
230
|
-
return
|
|
231
|
+
return numActualValue >= numExpectedValue;
|
|
231
232
|
case "between":
|
|
232
|
-
return
|
|
233
|
+
return numActualValue >= numExpectedValue && numActualValue <= numExpectedValue2;
|
|
233
234
|
case "empty":
|
|
234
235
|
return actualValue === null || actualValue === void 0 || actualValue === "";
|
|
235
236
|
case "any":
|
|
@@ -2,10 +2,10 @@ import {
|
|
|
2
2
|
evaluateRulesConditions,
|
|
3
3
|
filterConditionsByType,
|
|
4
4
|
isConditionsActived
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-A4KMGXB3.js";
|
|
6
6
|
import "../chunk-YYIGUZNZ.js";
|
|
7
7
|
import "../chunk-PAESAL23.js";
|
|
8
|
-
import "../chunk-
|
|
8
|
+
import "../chunk-7JXEY4A2.js";
|
|
9
9
|
import "../chunk-CEK3SCQO.js";
|
|
10
10
|
import "../chunk-3KG2HTZ3.js";
|
|
11
11
|
import "../chunk-XEO3YXBM.js";
|
|
@@ -108,26 +108,27 @@ function evaluateStringCondition(logic, actualValue, expectedValue) {
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
function evaluateNumberCondition(logic, actualValue, expectedValue, expectedValue2) {
|
|
111
|
-
const
|
|
112
|
-
const
|
|
113
|
-
|
|
111
|
+
const numActualValue = Number(actualValue);
|
|
112
|
+
const numExpectedValue = Number(expectedValue);
|
|
113
|
+
const numExpectedValue2 = Number(expectedValue2);
|
|
114
|
+
if (Number.isNaN(numActualValue)) {
|
|
114
115
|
return false;
|
|
115
116
|
}
|
|
116
117
|
switch (logic) {
|
|
117
118
|
case "is":
|
|
118
|
-
return
|
|
119
|
+
return numActualValue === numExpectedValue;
|
|
119
120
|
case "not":
|
|
120
|
-
return
|
|
121
|
+
return numActualValue !== numExpectedValue;
|
|
121
122
|
case "isLessThan":
|
|
122
|
-
return
|
|
123
|
+
return numActualValue < numExpectedValue;
|
|
123
124
|
case "isLessThanOrEqualTo":
|
|
124
|
-
return
|
|
125
|
+
return numActualValue <= numExpectedValue;
|
|
125
126
|
case "isGreaterThan":
|
|
126
|
-
return
|
|
127
|
+
return numActualValue > numExpectedValue;
|
|
127
128
|
case "isGreaterThanOrEqualTo":
|
|
128
|
-
return
|
|
129
|
+
return numActualValue >= numExpectedValue;
|
|
129
130
|
case "between":
|
|
130
|
-
return
|
|
131
|
+
return numActualValue >= numExpectedValue && numActualValue <= numExpectedValue2;
|
|
131
132
|
case "empty":
|
|
132
133
|
return actualValue === null || actualValue === void 0 || actualValue === "";
|
|
133
134
|
case "any":
|
|
@@ -130,26 +130,27 @@ function evaluateStringCondition(logic, actualValue, expectedValue) {
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
function evaluateNumberCondition(logic, actualValue, expectedValue, expectedValue2) {
|
|
133
|
-
const
|
|
134
|
-
const
|
|
135
|
-
|
|
133
|
+
const numActualValue = Number(actualValue);
|
|
134
|
+
const numExpectedValue = Number(expectedValue);
|
|
135
|
+
const numExpectedValue2 = Number(expectedValue2);
|
|
136
|
+
if (Number.isNaN(numActualValue)) {
|
|
136
137
|
return false;
|
|
137
138
|
}
|
|
138
139
|
switch (logic) {
|
|
139
140
|
case "is":
|
|
140
|
-
return
|
|
141
|
+
return numActualValue === numExpectedValue;
|
|
141
142
|
case "not":
|
|
142
|
-
return
|
|
143
|
+
return numActualValue !== numExpectedValue;
|
|
143
144
|
case "isLessThan":
|
|
144
|
-
return
|
|
145
|
+
return numActualValue < numExpectedValue;
|
|
145
146
|
case "isLessThanOrEqualTo":
|
|
146
|
-
return
|
|
147
|
+
return numActualValue <= numExpectedValue;
|
|
147
148
|
case "isGreaterThan":
|
|
148
|
-
return
|
|
149
|
+
return numActualValue > numExpectedValue;
|
|
149
150
|
case "isGreaterThanOrEqualTo":
|
|
150
|
-
return
|
|
151
|
+
return numActualValue >= numExpectedValue;
|
|
151
152
|
case "between":
|
|
152
|
-
return
|
|
153
|
+
return numActualValue >= numExpectedValue && numActualValue <= numExpectedValue2;
|
|
153
154
|
case "empty":
|
|
154
155
|
return actualValue === null || actualValue === void 0 || actualValue === "";
|
|
155
156
|
case "any":
|
|
@@ -225,26 +225,27 @@ function evaluateStringCondition(logic, actualValue, expectedValue) {
|
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
function evaluateNumberCondition(logic, actualValue, expectedValue, expectedValue2) {
|
|
228
|
-
const
|
|
229
|
-
const
|
|
230
|
-
|
|
228
|
+
const numActualValue = Number(actualValue);
|
|
229
|
+
const numExpectedValue = Number(expectedValue);
|
|
230
|
+
const numExpectedValue2 = Number(expectedValue2);
|
|
231
|
+
if (Number.isNaN(numActualValue)) {
|
|
231
232
|
return false;
|
|
232
233
|
}
|
|
233
234
|
switch (logic) {
|
|
234
235
|
case "is":
|
|
235
|
-
return
|
|
236
|
+
return numActualValue === numExpectedValue;
|
|
236
237
|
case "not":
|
|
237
|
-
return
|
|
238
|
+
return numActualValue !== numExpectedValue;
|
|
238
239
|
case "isLessThan":
|
|
239
|
-
return
|
|
240
|
+
return numActualValue < numExpectedValue;
|
|
240
241
|
case "isLessThanOrEqualTo":
|
|
241
|
-
return
|
|
242
|
+
return numActualValue <= numExpectedValue;
|
|
242
243
|
case "isGreaterThan":
|
|
243
|
-
return
|
|
244
|
+
return numActualValue > numExpectedValue;
|
|
244
245
|
case "isGreaterThanOrEqualTo":
|
|
245
|
-
return
|
|
246
|
+
return numActualValue >= numExpectedValue;
|
|
246
247
|
case "between":
|
|
247
|
-
return
|
|
248
|
+
return numActualValue >= numExpectedValue && numActualValue <= numExpectedValue2;
|
|
248
249
|
case "empty":
|
|
249
250
|
return actualValue === null || actualValue === void 0 || actualValue === "";
|
|
250
251
|
case "any":
|
|
@@ -8,10 +8,10 @@ import {
|
|
|
8
8
|
isConditionsActived,
|
|
9
9
|
isEqual,
|
|
10
10
|
regenerateConditionIds
|
|
11
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-A4KMGXB3.js";
|
|
12
12
|
import "../chunk-YYIGUZNZ.js";
|
|
13
13
|
import "../chunk-PAESAL23.js";
|
|
14
|
-
import "../chunk-
|
|
14
|
+
import "../chunk-7JXEY4A2.js";
|
|
15
15
|
import "../chunk-CEK3SCQO.js";
|
|
16
16
|
import "../chunk-3KG2HTZ3.js";
|
|
17
17
|
import "../chunk-XEO3YXBM.js";
|
|
@@ -231,26 +231,27 @@ function evaluateStringCondition(logic, actualValue, expectedValue) {
|
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
233
|
function evaluateNumberCondition(logic, actualValue, expectedValue, expectedValue2) {
|
|
234
|
-
const
|
|
235
|
-
const
|
|
236
|
-
|
|
234
|
+
const numActualValue = Number(actualValue);
|
|
235
|
+
const numExpectedValue = Number(expectedValue);
|
|
236
|
+
const numExpectedValue2 = Number(expectedValue2);
|
|
237
|
+
if (Number.isNaN(numActualValue)) {
|
|
237
238
|
return false;
|
|
238
239
|
}
|
|
239
240
|
switch (logic) {
|
|
240
241
|
case "is":
|
|
241
|
-
return
|
|
242
|
+
return numActualValue === numExpectedValue;
|
|
242
243
|
case "not":
|
|
243
|
-
return
|
|
244
|
+
return numActualValue !== numExpectedValue;
|
|
244
245
|
case "isLessThan":
|
|
245
|
-
return
|
|
246
|
+
return numActualValue < numExpectedValue;
|
|
246
247
|
case "isLessThanOrEqualTo":
|
|
247
|
-
return
|
|
248
|
+
return numActualValue <= numExpectedValue;
|
|
248
249
|
case "isGreaterThan":
|
|
249
|
-
return
|
|
250
|
+
return numActualValue > numExpectedValue;
|
|
250
251
|
case "isGreaterThanOrEqualTo":
|
|
251
|
-
return
|
|
252
|
+
return numActualValue >= numExpectedValue;
|
|
252
253
|
case "between":
|
|
253
|
-
return
|
|
254
|
+
return numActualValue >= numExpectedValue && numActualValue <= numExpectedValue2;
|
|
254
255
|
case "empty":
|
|
255
256
|
return actualValue === null || actualValue === void 0 || actualValue === "";
|
|
256
257
|
case "any":
|
package/dist/conditions/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
isConditionsActived,
|
|
10
10
|
isEqual,
|
|
11
11
|
regenerateConditionIds
|
|
12
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-A4KMGXB3.js";
|
|
13
13
|
import {
|
|
14
14
|
evaluateUrlCondition,
|
|
15
15
|
isMatchUrlPattern
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
import "../chunk-PAESAL23.js";
|
|
18
18
|
import {
|
|
19
19
|
evaluateAttributeCondition
|
|
20
|
-
} from "../chunk-
|
|
20
|
+
} from "../chunk-7JXEY4A2.js";
|
|
21
21
|
import {
|
|
22
22
|
evaluateTimeCondition
|
|
23
23
|
} from "../chunk-CEK3SCQO.js";
|
package/dist/index.cjs
CHANGED
|
@@ -1196,26 +1196,27 @@ function evaluateStringCondition(logic, actualValue, expectedValue) {
|
|
|
1196
1196
|
}
|
|
1197
1197
|
}
|
|
1198
1198
|
function evaluateNumberCondition(logic, actualValue, expectedValue, expectedValue2) {
|
|
1199
|
-
const
|
|
1200
|
-
const
|
|
1201
|
-
|
|
1199
|
+
const numActualValue = Number(actualValue);
|
|
1200
|
+
const numExpectedValue = Number(expectedValue);
|
|
1201
|
+
const numExpectedValue2 = Number(expectedValue2);
|
|
1202
|
+
if (Number.isNaN(numActualValue)) {
|
|
1202
1203
|
return false;
|
|
1203
1204
|
}
|
|
1204
1205
|
switch (logic) {
|
|
1205
1206
|
case "is":
|
|
1206
|
-
return
|
|
1207
|
+
return numActualValue === numExpectedValue;
|
|
1207
1208
|
case "not":
|
|
1208
|
-
return
|
|
1209
|
+
return numActualValue !== numExpectedValue;
|
|
1209
1210
|
case "isLessThan":
|
|
1210
|
-
return
|
|
1211
|
+
return numActualValue < numExpectedValue;
|
|
1211
1212
|
case "isLessThanOrEqualTo":
|
|
1212
|
-
return
|
|
1213
|
+
return numActualValue <= numExpectedValue;
|
|
1213
1214
|
case "isGreaterThan":
|
|
1214
|
-
return
|
|
1215
|
+
return numActualValue > numExpectedValue;
|
|
1215
1216
|
case "isGreaterThanOrEqualTo":
|
|
1216
|
-
return
|
|
1217
|
+
return numActualValue >= numExpectedValue;
|
|
1217
1218
|
case "between":
|
|
1218
|
-
return
|
|
1219
|
+
return numActualValue >= numExpectedValue && numActualValue <= numExpectedValue2;
|
|
1219
1220
|
case "empty":
|
|
1220
1221
|
return actualValue === null || actualValue === void 0 || actualValue === "";
|
|
1221
1222
|
case "any":
|
package/dist/index.js
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
isConditionsActived,
|
|
21
21
|
isEqual,
|
|
22
22
|
regenerateConditionIds
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-A4KMGXB3.js";
|
|
24
24
|
import {
|
|
25
25
|
evaluateUrlCondition,
|
|
26
26
|
isMatchUrlPattern
|
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
import "./chunk-PAESAL23.js";
|
|
29
29
|
import {
|
|
30
30
|
evaluateAttributeCondition
|
|
31
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-7JXEY4A2.js";
|
|
32
32
|
import {
|
|
33
33
|
evaluateTimeCondition
|
|
34
34
|
} from "./chunk-CEK3SCQO.js";
|