@featurevisor/core 2.5.0 → 2.6.7

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.
Files changed (91) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/LICENSE +1 -1
  3. package/coverage/clover.xml +444 -78
  4. package/coverage/coverage-final.json +9 -3
  5. package/coverage/lcov-report/index.html +42 -42
  6. package/coverage/lcov-report/lib/builder/allocator.js.html +1 -1
  7. package/coverage/lcov-report/lib/builder/buildScopedConditions.js.html +373 -0
  8. package/coverage/lcov-report/lib/builder/buildScopedDatafile.js.html +403 -0
  9. package/coverage/lcov-report/lib/builder/buildScopedSegments.js.html +379 -0
  10. package/coverage/lcov-report/lib/builder/index.html +53 -8
  11. package/coverage/lcov-report/lib/builder/revision.js.html +1 -1
  12. package/coverage/lcov-report/lib/builder/traffic.js.html +1 -1
  13. package/coverage/lcov-report/lib/list/index.html +14 -14
  14. package/coverage/lcov-report/lib/list/matrix.js.html +23 -8
  15. package/coverage/lcov-report/lib/tester/helpers.js.html +1 -1
  16. package/coverage/lcov-report/lib/tester/index.html +1 -1
  17. package/coverage/lcov-report/src/builder/allocator.ts.html +1 -1
  18. package/coverage/lcov-report/src/builder/buildScopedConditions.ts.html +487 -0
  19. package/coverage/lcov-report/src/builder/buildScopedDatafile.ts.html +604 -0
  20. package/coverage/lcov-report/src/builder/buildScopedSegments.ts.html +544 -0
  21. package/coverage/lcov-report/src/builder/index.html +55 -10
  22. package/coverage/lcov-report/src/builder/revision.ts.html +1 -1
  23. package/coverage/lcov-report/src/builder/traffic.ts.html +3 -3
  24. package/coverage/lcov-report/src/list/index.html +14 -14
  25. package/coverage/lcov-report/src/list/matrix.ts.html +33 -12
  26. package/coverage/lcov-report/src/tester/helpers.ts.html +1 -1
  27. package/coverage/lcov-report/src/tester/index.html +1 -1
  28. package/coverage/lcov.info +810 -129
  29. package/jest.config.js +8 -0
  30. package/lib/builder/buildDatafile.d.ts +10 -0
  31. package/lib/builder/buildDatafile.js +27 -0
  32. package/lib/builder/buildDatafile.js.map +1 -1
  33. package/lib/builder/buildProject.d.ts +2 -0
  34. package/lib/builder/buildProject.js +38 -4
  35. package/lib/builder/buildProject.js.map +1 -1
  36. package/lib/builder/buildScopedConditions.d.ts +5 -0
  37. package/lib/builder/buildScopedConditions.js +97 -0
  38. package/lib/builder/buildScopedConditions.js.map +1 -0
  39. package/lib/builder/buildScopedConditions.spec.d.ts +1 -0
  40. package/lib/builder/buildScopedConditions.spec.js +2167 -0
  41. package/lib/builder/buildScopedConditions.spec.js.map +1 -0
  42. package/lib/builder/buildScopedDatafile.d.ts +2 -0
  43. package/lib/builder/buildScopedDatafile.js +107 -0
  44. package/lib/builder/buildScopedDatafile.js.map +1 -0
  45. package/lib/builder/buildScopedDatafile.spec.d.ts +1 -0
  46. package/lib/builder/buildScopedDatafile.spec.js +1988 -0
  47. package/lib/builder/buildScopedDatafile.spec.js.map +1 -0
  48. package/lib/builder/buildScopedSegments.d.ts +5 -0
  49. package/lib/builder/buildScopedSegments.js +99 -0
  50. package/lib/builder/buildScopedSegments.js.map +1 -0
  51. package/lib/builder/buildScopedSegments.spec.d.ts +1 -0
  52. package/lib/builder/buildScopedSegments.spec.js +1062 -0
  53. package/lib/builder/buildScopedSegments.spec.js.map +1 -0
  54. package/lib/builder/index.d.ts +1 -0
  55. package/lib/builder/index.js +1 -0
  56. package/lib/builder/index.js.map +1 -1
  57. package/lib/config/projectConfig.d.ts +9 -1
  58. package/lib/config/projectConfig.js +1 -0
  59. package/lib/config/projectConfig.js.map +1 -1
  60. package/lib/datasource/adapter.d.ts +3 -1
  61. package/lib/datasource/adapter.js.map +1 -1
  62. package/lib/datasource/filesystemAdapter.js +3 -1
  63. package/lib/datasource/filesystemAdapter.js.map +1 -1
  64. package/lib/linter/testSchema.d.ts +5 -0
  65. package/lib/linter/testSchema.js +8 -0
  66. package/lib/linter/testSchema.js.map +1 -1
  67. package/lib/list/matrix.js +5 -0
  68. package/lib/list/matrix.js.map +1 -1
  69. package/lib/tester/testFeature.d.ts +5 -3
  70. package/lib/tester/testFeature.js +34 -9
  71. package/lib/tester/testFeature.js.map +1 -1
  72. package/lib/tester/testProject.d.ts +3 -2
  73. package/lib/tester/testProject.js +40 -6
  74. package/lib/tester/testProject.js.map +1 -1
  75. package/package.json +5 -5
  76. package/src/builder/buildDatafile.ts +47 -0
  77. package/src/builder/buildProject.ts +58 -3
  78. package/src/builder/buildScopedConditions.spec.ts +2659 -0
  79. package/src/builder/buildScopedConditions.ts +134 -0
  80. package/src/builder/buildScopedDatafile.spec.ts +2236 -0
  81. package/src/builder/buildScopedDatafile.ts +173 -0
  82. package/src/builder/buildScopedSegments.spec.ts +1573 -0
  83. package/src/builder/buildScopedSegments.ts +153 -0
  84. package/src/builder/index.ts +1 -0
  85. package/src/config/projectConfig.ts +11 -1
  86. package/src/datasource/adapter.ts +4 -1
  87. package/src/datasource/filesystemAdapter.ts +4 -1
  88. package/src/linter/testSchema.ts +12 -0
  89. package/src/list/matrix.ts +7 -0
  90. package/src/tester/testFeature.ts +50 -16
  91. package/src/tester/testProject.ts +68 -8
@@ -0,0 +1,2167 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const buildScopedConditions_1 = require("./buildScopedConditions");
4
+ const sdk_1 = require("@featurevisor/sdk");
5
+ describe("core: buildScopedConditions", function () {
6
+ const emptyDatafile = {
7
+ schemaVersion: "2",
8
+ revision: "unknown",
9
+ segments: {},
10
+ features: {},
11
+ };
12
+ const datafileReader = new sdk_1.DatafileReader({
13
+ datafile: emptyDatafile,
14
+ logger: (0, sdk_1.createLogger)({ level: "fatal" }),
15
+ });
16
+ describe("buildScopedConditions (plural)", function () {
17
+ test("buildScopedConditions is a function", function () {
18
+ expect(buildScopedConditions_1.buildScopedConditions).toBeInstanceOf(Function);
19
+ });
20
+ test("simple cases", function () {
21
+ // "*" remains "*"
22
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, "*", {})).toEqual("*");
23
+ // Plain condition that matches
24
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, {
25
+ attribute: "platform",
26
+ operator: "equals",
27
+ value: "web",
28
+ }, {
29
+ platform: "web",
30
+ })).toEqual("*");
31
+ // Plain condition that doesn't match
32
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, {
33
+ attribute: "platform",
34
+ operator: "equals",
35
+ value: "web",
36
+ }, {
37
+ platform: "mobile",
38
+ })).toEqual({
39
+ attribute: "platform",
40
+ operator: "equals",
41
+ value: "web",
42
+ });
43
+ // Array of conditions - partial match (redundant "*" removed)
44
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, [
45
+ {
46
+ attribute: "platform",
47
+ operator: "equals",
48
+ value: "web",
49
+ },
50
+ {
51
+ attribute: "browser",
52
+ operator: "equals",
53
+ value: "chrome",
54
+ },
55
+ ], {
56
+ platform: "web",
57
+ })).toEqual([
58
+ {
59
+ attribute: "browser",
60
+ operator: "equals",
61
+ value: "chrome",
62
+ },
63
+ ]);
64
+ // Array of conditions - full match (all "*" becomes "*")
65
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, [
66
+ {
67
+ attribute: "platform",
68
+ operator: "equals",
69
+ value: "web",
70
+ },
71
+ {
72
+ attribute: "browser",
73
+ operator: "equals",
74
+ value: "chrome",
75
+ },
76
+ ], {
77
+ platform: "web",
78
+ browser: "chrome",
79
+ })).toEqual("*");
80
+ // Array of conditions - no match
81
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, [
82
+ {
83
+ attribute: "platform",
84
+ operator: "equals",
85
+ value: "web",
86
+ },
87
+ {
88
+ attribute: "browser",
89
+ operator: "equals",
90
+ value: "chrome",
91
+ },
92
+ ], {
93
+ platform: "mobile",
94
+ browser: "safari",
95
+ })).toEqual([
96
+ {
97
+ attribute: "platform",
98
+ operator: "equals",
99
+ value: "web",
100
+ },
101
+ {
102
+ attribute: "browser",
103
+ operator: "equals",
104
+ value: "chrome",
105
+ },
106
+ ]);
107
+ });
108
+ test("AND conditions", function () {
109
+ // AND with all matching conditions (all "*" becomes "*")
110
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, {
111
+ and: [
112
+ {
113
+ attribute: "platform",
114
+ operator: "equals",
115
+ value: "web",
116
+ },
117
+ {
118
+ attribute: "browser",
119
+ operator: "equals",
120
+ value: "chrome",
121
+ },
122
+ ],
123
+ }, {
124
+ platform: "web",
125
+ browser: "chrome",
126
+ })).toEqual("*");
127
+ // AND with partial match (redundant "*" removed)
128
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, {
129
+ and: [
130
+ {
131
+ attribute: "platform",
132
+ operator: "equals",
133
+ value: "web",
134
+ },
135
+ {
136
+ attribute: "browser",
137
+ operator: "equals",
138
+ value: "chrome",
139
+ },
140
+ ],
141
+ }, {
142
+ platform: "web",
143
+ })).toEqual({
144
+ and: [
145
+ {
146
+ attribute: "browser",
147
+ operator: "equals",
148
+ value: "chrome",
149
+ },
150
+ ],
151
+ });
152
+ // AND with no matches
153
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, {
154
+ and: [
155
+ {
156
+ attribute: "platform",
157
+ operator: "equals",
158
+ value: "web",
159
+ },
160
+ {
161
+ attribute: "browser",
162
+ operator: "equals",
163
+ value: "chrome",
164
+ },
165
+ ],
166
+ }, {
167
+ platform: "mobile",
168
+ browser: "safari",
169
+ })).toEqual({
170
+ and: [
171
+ {
172
+ attribute: "platform",
173
+ operator: "equals",
174
+ value: "web",
175
+ },
176
+ {
177
+ attribute: "browser",
178
+ operator: "equals",
179
+ value: "chrome",
180
+ },
181
+ ],
182
+ });
183
+ // AND with "*" in it (all "*" becomes "*")
184
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, {
185
+ and: [
186
+ "*",
187
+ {
188
+ attribute: "platform",
189
+ operator: "equals",
190
+ value: "web",
191
+ },
192
+ ],
193
+ }, {
194
+ platform: "web",
195
+ })).toEqual("*");
196
+ });
197
+ test("OR conditions", function () {
198
+ // OR with all matching conditions (all "*" becomes "*")
199
+ // Note: This would require both conditions to match, which isn't possible with same attribute
200
+ // So testing with different attributes that both match
201
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, {
202
+ or: [
203
+ {
204
+ attribute: "platform",
205
+ operator: "equals",
206
+ value: "web",
207
+ },
208
+ {
209
+ attribute: "browser",
210
+ operator: "equals",
211
+ value: "chrome",
212
+ },
213
+ ],
214
+ }, {
215
+ platform: "web",
216
+ browser: "chrome",
217
+ })).toEqual("*");
218
+ // OR with partial match (redundant "*" removed, but OR structure remains)
219
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, {
220
+ or: [
221
+ {
222
+ attribute: "platform",
223
+ operator: "equals",
224
+ value: "web",
225
+ },
226
+ {
227
+ attribute: "browser",
228
+ operator: "equals",
229
+ value: "chrome",
230
+ },
231
+ ],
232
+ }, {
233
+ platform: "web",
234
+ })).toEqual({
235
+ or: [
236
+ {
237
+ attribute: "browser",
238
+ operator: "equals",
239
+ value: "chrome",
240
+ },
241
+ ],
242
+ });
243
+ // OR with no matches
244
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, {
245
+ or: [
246
+ {
247
+ attribute: "platform",
248
+ operator: "equals",
249
+ value: "web",
250
+ },
251
+ {
252
+ attribute: "platform",
253
+ operator: "equals",
254
+ value: "mobile",
255
+ },
256
+ ],
257
+ }, {
258
+ platform: "desktop",
259
+ })).toEqual({
260
+ or: [
261
+ {
262
+ attribute: "platform",
263
+ operator: "equals",
264
+ value: "web",
265
+ },
266
+ {
267
+ attribute: "platform",
268
+ operator: "equals",
269
+ value: "mobile",
270
+ },
271
+ ],
272
+ });
273
+ });
274
+ test("NOT conditions", function () {
275
+ // NOT with matching condition (all "*" becomes "*")
276
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, {
277
+ not: [
278
+ {
279
+ attribute: "platform",
280
+ operator: "equals",
281
+ value: "web",
282
+ },
283
+ ],
284
+ }, {
285
+ platform: "web",
286
+ })).toEqual("*");
287
+ // NOT with non-matching condition
288
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, {
289
+ not: [
290
+ {
291
+ attribute: "platform",
292
+ operator: "equals",
293
+ value: "web",
294
+ },
295
+ ],
296
+ }, {
297
+ platform: "mobile",
298
+ })).toEqual({
299
+ not: [
300
+ {
301
+ attribute: "platform",
302
+ operator: "equals",
303
+ value: "web",
304
+ },
305
+ ],
306
+ });
307
+ // NOT with multiple conditions (all "*" becomes "*")
308
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, {
309
+ not: [
310
+ {
311
+ attribute: "platform",
312
+ operator: "equals",
313
+ value: "web",
314
+ },
315
+ {
316
+ attribute: "browser",
317
+ operator: "equals",
318
+ value: "chrome",
319
+ },
320
+ ],
321
+ }, {
322
+ platform: "web",
323
+ browser: "chrome",
324
+ })).toEqual("*");
325
+ });
326
+ test("nested AND conditions", function () {
327
+ // Nested AND with all matching (all "*" becomes "*")
328
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, {
329
+ and: [
330
+ {
331
+ attribute: "platform",
332
+ operator: "equals",
333
+ value: "web",
334
+ },
335
+ {
336
+ and: [
337
+ {
338
+ attribute: "browser",
339
+ operator: "equals",
340
+ value: "chrome",
341
+ },
342
+ {
343
+ attribute: "version",
344
+ operator: "equals",
345
+ value: "1.0",
346
+ },
347
+ ],
348
+ },
349
+ ],
350
+ }, {
351
+ platform: "web",
352
+ browser: "chrome",
353
+ version: "1.0",
354
+ })).toEqual("*");
355
+ // Nested AND with partial match (redundant "*" removed)
356
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, {
357
+ and: [
358
+ {
359
+ attribute: "platform",
360
+ operator: "equals",
361
+ value: "web",
362
+ },
363
+ {
364
+ and: [
365
+ {
366
+ attribute: "browser",
367
+ operator: "equals",
368
+ value: "chrome",
369
+ },
370
+ {
371
+ attribute: "version",
372
+ operator: "equals",
373
+ value: "1.0",
374
+ },
375
+ ],
376
+ },
377
+ ],
378
+ }, {
379
+ platform: "web",
380
+ browser: "chrome",
381
+ })).toEqual({
382
+ and: [
383
+ {
384
+ and: [
385
+ {
386
+ attribute: "version",
387
+ operator: "equals",
388
+ value: "1.0",
389
+ },
390
+ ],
391
+ },
392
+ ],
393
+ });
394
+ });
395
+ test("nested OR conditions", function () {
396
+ // Nested OR with outer match (redundant "*" removed, but inner OR remains)
397
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, {
398
+ or: [
399
+ {
400
+ attribute: "platform",
401
+ operator: "equals",
402
+ value: "web",
403
+ },
404
+ {
405
+ or: [
406
+ {
407
+ attribute: "platform",
408
+ operator: "equals",
409
+ value: "mobile",
410
+ },
411
+ {
412
+ attribute: "platform",
413
+ operator: "equals",
414
+ value: "desktop",
415
+ },
416
+ ],
417
+ },
418
+ ],
419
+ }, {
420
+ platform: "web",
421
+ })).toEqual({
422
+ or: [
423
+ {
424
+ or: [
425
+ {
426
+ attribute: "platform",
427
+ operator: "equals",
428
+ value: "mobile",
429
+ },
430
+ {
431
+ attribute: "platform",
432
+ operator: "equals",
433
+ value: "desktop",
434
+ },
435
+ ],
436
+ },
437
+ ],
438
+ });
439
+ // Nested OR with inner match (redundant "*" removed, but outer OR remains)
440
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, {
441
+ or: [
442
+ {
443
+ attribute: "platform",
444
+ operator: "equals",
445
+ value: "web",
446
+ },
447
+ {
448
+ or: [
449
+ {
450
+ attribute: "platform",
451
+ operator: "equals",
452
+ value: "mobile",
453
+ },
454
+ {
455
+ attribute: "platform",
456
+ operator: "equals",
457
+ value: "desktop",
458
+ },
459
+ ],
460
+ },
461
+ ],
462
+ }, {
463
+ platform: "mobile",
464
+ })).toEqual({
465
+ or: [
466
+ {
467
+ attribute: "platform",
468
+ operator: "equals",
469
+ value: "web",
470
+ },
471
+ {
472
+ or: [
473
+ {
474
+ attribute: "platform",
475
+ operator: "equals",
476
+ value: "desktop",
477
+ },
478
+ ],
479
+ },
480
+ ],
481
+ });
482
+ });
483
+ test("nested NOT conditions", function () {
484
+ // Nested NOT (all "*" becomes "*")
485
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, {
486
+ not: [
487
+ {
488
+ attribute: "platform",
489
+ operator: "equals",
490
+ value: "web",
491
+ },
492
+ {
493
+ not: [
494
+ {
495
+ attribute: "browser",
496
+ operator: "equals",
497
+ value: "chrome",
498
+ },
499
+ ],
500
+ },
501
+ ],
502
+ }, {
503
+ platform: "web",
504
+ browser: "chrome",
505
+ })).toEqual("*");
506
+ });
507
+ test("mixed nested conditions", function () {
508
+ // AND with nested OR (redundant "*" removed, but OR structure remains if not all match)
509
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, {
510
+ and: [
511
+ {
512
+ attribute: "platform",
513
+ operator: "equals",
514
+ value: "web",
515
+ },
516
+ {
517
+ or: [
518
+ {
519
+ attribute: "browser",
520
+ operator: "equals",
521
+ value: "chrome",
522
+ },
523
+ {
524
+ attribute: "browser",
525
+ operator: "equals",
526
+ value: "firefox",
527
+ },
528
+ ],
529
+ },
530
+ ],
531
+ }, {
532
+ platform: "web",
533
+ browser: "chrome",
534
+ })).toEqual({
535
+ and: [
536
+ {
537
+ or: [
538
+ {
539
+ attribute: "browser",
540
+ operator: "equals",
541
+ value: "firefox",
542
+ },
543
+ ],
544
+ },
545
+ ],
546
+ });
547
+ // OR with nested AND (redundant "*" removed, but OR structure remains if not all match)
548
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, {
549
+ or: [
550
+ {
551
+ attribute: "platform",
552
+ operator: "equals",
553
+ value: "web",
554
+ },
555
+ {
556
+ and: [
557
+ {
558
+ attribute: "platform",
559
+ operator: "equals",
560
+ value: "mobile",
561
+ },
562
+ {
563
+ attribute: "browser",
564
+ operator: "equals",
565
+ value: "chrome",
566
+ },
567
+ ],
568
+ },
569
+ ],
570
+ }, {
571
+ platform: "mobile",
572
+ browser: "chrome",
573
+ })).toEqual({
574
+ or: [
575
+ {
576
+ attribute: "platform",
577
+ operator: "equals",
578
+ value: "web",
579
+ },
580
+ ],
581
+ });
582
+ // AND with nested NOT (redundant "*" removed)
583
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, {
584
+ and: [
585
+ {
586
+ attribute: "platform",
587
+ operator: "equals",
588
+ value: "web",
589
+ },
590
+ {
591
+ not: [
592
+ {
593
+ attribute: "browser",
594
+ operator: "equals",
595
+ value: "safari",
596
+ },
597
+ ],
598
+ },
599
+ ],
600
+ }, {
601
+ platform: "web",
602
+ browser: "chrome",
603
+ })).toEqual({
604
+ and: [
605
+ {
606
+ not: [
607
+ {
608
+ attribute: "browser",
609
+ operator: "equals",
610
+ value: "safari",
611
+ },
612
+ ],
613
+ },
614
+ ],
615
+ });
616
+ // Complex nested structure (redundant "*" removed)
617
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, {
618
+ and: [
619
+ {
620
+ attribute: "platform",
621
+ operator: "equals",
622
+ value: "web",
623
+ },
624
+ {
625
+ or: [
626
+ {
627
+ and: [
628
+ {
629
+ attribute: "browser",
630
+ operator: "equals",
631
+ value: "chrome",
632
+ },
633
+ {
634
+ attribute: "version",
635
+ operator: "equals",
636
+ value: "1.0",
637
+ },
638
+ ],
639
+ },
640
+ {
641
+ attribute: "browser",
642
+ operator: "equals",
643
+ value: "firefox",
644
+ },
645
+ ],
646
+ },
647
+ ],
648
+ }, {
649
+ platform: "web",
650
+ browser: "chrome",
651
+ version: "1.0",
652
+ })).toEqual({
653
+ and: [
654
+ {
655
+ or: [
656
+ {
657
+ attribute: "browser",
658
+ operator: "equals",
659
+ value: "firefox",
660
+ },
661
+ ],
662
+ },
663
+ ],
664
+ });
665
+ });
666
+ test("arrays with nested conditions", function () {
667
+ // Array with AND condition (redundant "*" removed)
668
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, [
669
+ {
670
+ attribute: "platform",
671
+ operator: "equals",
672
+ value: "web",
673
+ },
674
+ {
675
+ and: [
676
+ {
677
+ attribute: "browser",
678
+ operator: "equals",
679
+ value: "chrome",
680
+ },
681
+ {
682
+ attribute: "version",
683
+ operator: "equals",
684
+ value: "1.0",
685
+ },
686
+ ],
687
+ },
688
+ ], {
689
+ platform: "web",
690
+ browser: "chrome",
691
+ version: "1.0",
692
+ })).toEqual("*");
693
+ // Array with OR condition (redundant "*" removed, but OR structure remains if not all match)
694
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, [
695
+ {
696
+ attribute: "platform",
697
+ operator: "equals",
698
+ value: "web",
699
+ },
700
+ {
701
+ or: [
702
+ {
703
+ attribute: "browser",
704
+ operator: "equals",
705
+ value: "chrome",
706
+ },
707
+ {
708
+ attribute: "browser",
709
+ operator: "equals",
710
+ value: "firefox",
711
+ },
712
+ ],
713
+ },
714
+ ], {
715
+ platform: "web",
716
+ browser: "chrome",
717
+ })).toEqual([
718
+ {
719
+ or: [
720
+ {
721
+ attribute: "browser",
722
+ operator: "equals",
723
+ value: "firefox",
724
+ },
725
+ ],
726
+ },
727
+ ]);
728
+ });
729
+ test("edge cases", function () {
730
+ // Empty context
731
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, {
732
+ attribute: "platform",
733
+ operator: "equals",
734
+ value: "web",
735
+ }, {})).toEqual({
736
+ attribute: "platform",
737
+ operator: "equals",
738
+ value: "web",
739
+ });
740
+ // Empty array (all "*" becomes "*")
741
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, [], {})).toEqual("*");
742
+ // "*" in array with matching condition (all "*" becomes "*")
743
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, [
744
+ "*",
745
+ {
746
+ attribute: "platform",
747
+ operator: "equals",
748
+ value: "web",
749
+ },
750
+ ], {
751
+ platform: "web",
752
+ })).toEqual("*");
753
+ // AND with empty array (all "*" becomes "*")
754
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, {
755
+ and: [],
756
+ }, {})).toEqual("*");
757
+ // OR with empty array (all "*" becomes "*")
758
+ expect((0, buildScopedConditions_1.buildScopedConditions)(datafileReader, {
759
+ or: [],
760
+ }, {})).toEqual("*");
761
+ });
762
+ });
763
+ describe("buildScopedCondition (singular)", function () {
764
+ test("buildScopedCondition is a function", function () {
765
+ expect(buildScopedConditions_1.buildScopedCondition).toBeInstanceOf(Function);
766
+ });
767
+ test("simple cases", function () {
768
+ // "*" remains "*"
769
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, "*", {})).toEqual("*");
770
+ // Plain condition that matches
771
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, {
772
+ attribute: "platform",
773
+ operator: "equals",
774
+ value: "web",
775
+ }, {
776
+ platform: "web",
777
+ })).toEqual("*");
778
+ // Plain condition that doesn't match
779
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, {
780
+ attribute: "platform",
781
+ operator: "equals",
782
+ value: "web",
783
+ }, {
784
+ platform: "mobile",
785
+ })).toEqual({
786
+ attribute: "platform",
787
+ operator: "equals",
788
+ value: "web",
789
+ });
790
+ // Array of conditions
791
+ const originalConditions = [
792
+ {
793
+ attribute: "platform",
794
+ operator: "equals",
795
+ value: "web",
796
+ },
797
+ {
798
+ attribute: "browser",
799
+ operator: "equals",
800
+ value: "chrome",
801
+ },
802
+ ];
803
+ // Partial match
804
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, originalConditions, {
805
+ platform: "web",
806
+ })).toEqual([
807
+ "*",
808
+ {
809
+ attribute: "browser",
810
+ operator: "equals",
811
+ value: "chrome",
812
+ },
813
+ ]);
814
+ // Full match
815
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, originalConditions, {
816
+ platform: "web",
817
+ browser: "chrome",
818
+ })).toEqual(["*", "*"]);
819
+ // No match
820
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, originalConditions, {
821
+ platform: "mobile",
822
+ browser: "safari",
823
+ })).toEqual([
824
+ {
825
+ attribute: "platform",
826
+ operator: "equals",
827
+ value: "web",
828
+ },
829
+ {
830
+ attribute: "browser",
831
+ operator: "equals",
832
+ value: "chrome",
833
+ },
834
+ ]);
835
+ });
836
+ test("AND conditions", function () {
837
+ // AND with all matching conditions
838
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, {
839
+ and: [
840
+ {
841
+ attribute: "platform",
842
+ operator: "equals",
843
+ value: "web",
844
+ },
845
+ {
846
+ attribute: "browser",
847
+ operator: "equals",
848
+ value: "chrome",
849
+ },
850
+ ],
851
+ }, {
852
+ platform: "web",
853
+ browser: "chrome",
854
+ })).toEqual({
855
+ and: ["*", "*"],
856
+ });
857
+ // AND with partial match
858
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, {
859
+ and: [
860
+ {
861
+ attribute: "platform",
862
+ operator: "equals",
863
+ value: "web",
864
+ },
865
+ {
866
+ attribute: "browser",
867
+ operator: "equals",
868
+ value: "chrome",
869
+ },
870
+ ],
871
+ }, {
872
+ platform: "web",
873
+ })).toEqual({
874
+ and: [
875
+ "*",
876
+ {
877
+ attribute: "browser",
878
+ operator: "equals",
879
+ value: "chrome",
880
+ },
881
+ ],
882
+ });
883
+ // AND with no matches
884
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, {
885
+ and: [
886
+ {
887
+ attribute: "platform",
888
+ operator: "equals",
889
+ value: "web",
890
+ },
891
+ {
892
+ attribute: "browser",
893
+ operator: "equals",
894
+ value: "chrome",
895
+ },
896
+ ],
897
+ }, {
898
+ platform: "mobile",
899
+ browser: "safari",
900
+ })).toEqual({
901
+ and: [
902
+ {
903
+ attribute: "platform",
904
+ operator: "equals",
905
+ value: "web",
906
+ },
907
+ {
908
+ attribute: "browser",
909
+ operator: "equals",
910
+ value: "chrome",
911
+ },
912
+ ],
913
+ });
914
+ // AND with "*" in it
915
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, {
916
+ and: [
917
+ "*",
918
+ {
919
+ attribute: "platform",
920
+ operator: "equals",
921
+ value: "web",
922
+ },
923
+ ],
924
+ }, {
925
+ platform: "web",
926
+ })).toEqual({
927
+ and: ["*", "*"],
928
+ });
929
+ });
930
+ test("OR conditions", function () {
931
+ // OR with all matching conditions
932
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, {
933
+ or: [
934
+ {
935
+ attribute: "platform",
936
+ operator: "equals",
937
+ value: "web",
938
+ },
939
+ {
940
+ attribute: "platform",
941
+ operator: "equals",
942
+ value: "mobile",
943
+ },
944
+ ],
945
+ }, {
946
+ platform: "web",
947
+ })).toEqual({
948
+ or: ["*", { attribute: "platform", operator: "equals", value: "mobile" }],
949
+ });
950
+ // OR with partial match (first matches)
951
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, {
952
+ or: [
953
+ {
954
+ attribute: "platform",
955
+ operator: "equals",
956
+ value: "web",
957
+ },
958
+ {
959
+ attribute: "browser",
960
+ operator: "equals",
961
+ value: "chrome",
962
+ },
963
+ ],
964
+ }, {
965
+ platform: "web",
966
+ })).toEqual({
967
+ or: [
968
+ "*",
969
+ {
970
+ attribute: "browser",
971
+ operator: "equals",
972
+ value: "chrome",
973
+ },
974
+ ],
975
+ });
976
+ // OR with no matches
977
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, {
978
+ or: [
979
+ {
980
+ attribute: "platform",
981
+ operator: "equals",
982
+ value: "web",
983
+ },
984
+ {
985
+ attribute: "platform",
986
+ operator: "equals",
987
+ value: "mobile",
988
+ },
989
+ ],
990
+ }, {
991
+ platform: "desktop",
992
+ })).toEqual({
993
+ or: [
994
+ {
995
+ attribute: "platform",
996
+ operator: "equals",
997
+ value: "web",
998
+ },
999
+ {
1000
+ attribute: "platform",
1001
+ operator: "equals",
1002
+ value: "mobile",
1003
+ },
1004
+ ],
1005
+ });
1006
+ });
1007
+ test("NOT conditions", function () {
1008
+ // NOT with matching condition (should not match)
1009
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, {
1010
+ not: [
1011
+ {
1012
+ attribute: "platform",
1013
+ operator: "equals",
1014
+ value: "web",
1015
+ },
1016
+ ],
1017
+ }, {
1018
+ platform: "web",
1019
+ })).toEqual({
1020
+ not: ["*"],
1021
+ });
1022
+ // NOT with non-matching condition
1023
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, {
1024
+ not: [
1025
+ {
1026
+ attribute: "platform",
1027
+ operator: "equals",
1028
+ value: "web",
1029
+ },
1030
+ ],
1031
+ }, {
1032
+ platform: "mobile",
1033
+ })).toEqual({
1034
+ not: [
1035
+ {
1036
+ attribute: "platform",
1037
+ operator: "equals",
1038
+ value: "web",
1039
+ },
1040
+ ],
1041
+ });
1042
+ // NOT with multiple conditions
1043
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, {
1044
+ not: [
1045
+ {
1046
+ attribute: "platform",
1047
+ operator: "equals",
1048
+ value: "web",
1049
+ },
1050
+ {
1051
+ attribute: "browser",
1052
+ operator: "equals",
1053
+ value: "chrome",
1054
+ },
1055
+ ],
1056
+ }, {
1057
+ platform: "web",
1058
+ browser: "chrome",
1059
+ })).toEqual({
1060
+ not: ["*", "*"],
1061
+ });
1062
+ });
1063
+ test("nested AND conditions", function () {
1064
+ // Nested AND with all matching
1065
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, {
1066
+ and: [
1067
+ {
1068
+ attribute: "platform",
1069
+ operator: "equals",
1070
+ value: "web",
1071
+ },
1072
+ {
1073
+ and: [
1074
+ {
1075
+ attribute: "browser",
1076
+ operator: "equals",
1077
+ value: "chrome",
1078
+ },
1079
+ {
1080
+ attribute: "version",
1081
+ operator: "equals",
1082
+ value: "1.0",
1083
+ },
1084
+ ],
1085
+ },
1086
+ ],
1087
+ }, {
1088
+ platform: "web",
1089
+ browser: "chrome",
1090
+ version: "1.0",
1091
+ })).toEqual({
1092
+ and: [
1093
+ "*",
1094
+ {
1095
+ and: ["*", "*"],
1096
+ },
1097
+ ],
1098
+ });
1099
+ // Nested AND with partial match
1100
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, {
1101
+ and: [
1102
+ {
1103
+ attribute: "platform",
1104
+ operator: "equals",
1105
+ value: "web",
1106
+ },
1107
+ {
1108
+ and: [
1109
+ {
1110
+ attribute: "browser",
1111
+ operator: "equals",
1112
+ value: "chrome",
1113
+ },
1114
+ {
1115
+ attribute: "version",
1116
+ operator: "equals",
1117
+ value: "1.0",
1118
+ },
1119
+ ],
1120
+ },
1121
+ ],
1122
+ }, {
1123
+ platform: "web",
1124
+ browser: "chrome",
1125
+ })).toEqual({
1126
+ and: [
1127
+ "*",
1128
+ {
1129
+ and: [
1130
+ "*",
1131
+ {
1132
+ attribute: "version",
1133
+ operator: "equals",
1134
+ value: "1.0",
1135
+ },
1136
+ ],
1137
+ },
1138
+ ],
1139
+ });
1140
+ });
1141
+ test("nested OR conditions", function () {
1142
+ // Nested OR with matching
1143
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, {
1144
+ or: [
1145
+ {
1146
+ attribute: "platform",
1147
+ operator: "equals",
1148
+ value: "web",
1149
+ },
1150
+ {
1151
+ or: [
1152
+ {
1153
+ attribute: "platform",
1154
+ operator: "equals",
1155
+ value: "mobile",
1156
+ },
1157
+ {
1158
+ attribute: "platform",
1159
+ operator: "equals",
1160
+ value: "desktop",
1161
+ },
1162
+ ],
1163
+ },
1164
+ ],
1165
+ }, {
1166
+ platform: "web",
1167
+ })).toEqual({
1168
+ or: [
1169
+ "*",
1170
+ {
1171
+ or: [
1172
+ {
1173
+ attribute: "platform",
1174
+ operator: "equals",
1175
+ value: "mobile",
1176
+ },
1177
+ {
1178
+ attribute: "platform",
1179
+ operator: "equals",
1180
+ value: "desktop",
1181
+ },
1182
+ ],
1183
+ },
1184
+ ],
1185
+ });
1186
+ // Nested OR with inner match
1187
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, {
1188
+ or: [
1189
+ {
1190
+ attribute: "platform",
1191
+ operator: "equals",
1192
+ value: "web",
1193
+ },
1194
+ {
1195
+ or: [
1196
+ {
1197
+ attribute: "platform",
1198
+ operator: "equals",
1199
+ value: "mobile",
1200
+ },
1201
+ {
1202
+ attribute: "platform",
1203
+ operator: "equals",
1204
+ value: "desktop",
1205
+ },
1206
+ ],
1207
+ },
1208
+ ],
1209
+ }, {
1210
+ platform: "mobile",
1211
+ })).toEqual({
1212
+ or: [
1213
+ {
1214
+ attribute: "platform",
1215
+ operator: "equals",
1216
+ value: "web",
1217
+ },
1218
+ {
1219
+ or: [
1220
+ "*",
1221
+ {
1222
+ attribute: "platform",
1223
+ operator: "equals",
1224
+ value: "desktop",
1225
+ },
1226
+ ],
1227
+ },
1228
+ ],
1229
+ });
1230
+ });
1231
+ test("nested NOT conditions", function () {
1232
+ // Nested NOT
1233
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, {
1234
+ not: [
1235
+ {
1236
+ attribute: "platform",
1237
+ operator: "equals",
1238
+ value: "web",
1239
+ },
1240
+ {
1241
+ not: [
1242
+ {
1243
+ attribute: "browser",
1244
+ operator: "equals",
1245
+ value: "chrome",
1246
+ },
1247
+ ],
1248
+ },
1249
+ ],
1250
+ }, {
1251
+ platform: "web",
1252
+ browser: "chrome",
1253
+ })).toEqual({
1254
+ not: [
1255
+ "*",
1256
+ {
1257
+ not: ["*"],
1258
+ },
1259
+ ],
1260
+ });
1261
+ });
1262
+ test("mixed nested conditions", function () {
1263
+ // AND with nested OR
1264
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, {
1265
+ and: [
1266
+ {
1267
+ attribute: "platform",
1268
+ operator: "equals",
1269
+ value: "web",
1270
+ },
1271
+ {
1272
+ or: [
1273
+ {
1274
+ attribute: "browser",
1275
+ operator: "equals",
1276
+ value: "chrome",
1277
+ },
1278
+ {
1279
+ attribute: "browser",
1280
+ operator: "equals",
1281
+ value: "firefox",
1282
+ },
1283
+ ],
1284
+ },
1285
+ ],
1286
+ }, {
1287
+ platform: "web",
1288
+ browser: "chrome",
1289
+ })).toEqual({
1290
+ and: [
1291
+ "*",
1292
+ {
1293
+ or: [
1294
+ "*",
1295
+ {
1296
+ attribute: "browser",
1297
+ operator: "equals",
1298
+ value: "firefox",
1299
+ },
1300
+ ],
1301
+ },
1302
+ ],
1303
+ });
1304
+ // OR with nested AND
1305
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, {
1306
+ or: [
1307
+ {
1308
+ attribute: "platform",
1309
+ operator: "equals",
1310
+ value: "web",
1311
+ },
1312
+ {
1313
+ and: [
1314
+ {
1315
+ attribute: "platform",
1316
+ operator: "equals",
1317
+ value: "mobile",
1318
+ },
1319
+ {
1320
+ attribute: "browser",
1321
+ operator: "equals",
1322
+ value: "chrome",
1323
+ },
1324
+ ],
1325
+ },
1326
+ ],
1327
+ }, {
1328
+ platform: "mobile",
1329
+ browser: "chrome",
1330
+ })).toEqual({
1331
+ or: [
1332
+ {
1333
+ attribute: "platform",
1334
+ operator: "equals",
1335
+ value: "web",
1336
+ },
1337
+ {
1338
+ and: ["*", "*"],
1339
+ },
1340
+ ],
1341
+ });
1342
+ // AND with nested NOT
1343
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, {
1344
+ and: [
1345
+ {
1346
+ attribute: "platform",
1347
+ operator: "equals",
1348
+ value: "web",
1349
+ },
1350
+ {
1351
+ not: [
1352
+ {
1353
+ attribute: "browser",
1354
+ operator: "equals",
1355
+ value: "safari",
1356
+ },
1357
+ ],
1358
+ },
1359
+ ],
1360
+ }, {
1361
+ platform: "web",
1362
+ browser: "chrome",
1363
+ })).toEqual({
1364
+ and: [
1365
+ "*",
1366
+ {
1367
+ not: [
1368
+ {
1369
+ attribute: "browser",
1370
+ operator: "equals",
1371
+ value: "safari",
1372
+ },
1373
+ ],
1374
+ },
1375
+ ],
1376
+ });
1377
+ // Complex nested structure
1378
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, {
1379
+ and: [
1380
+ {
1381
+ attribute: "platform",
1382
+ operator: "equals",
1383
+ value: "web",
1384
+ },
1385
+ {
1386
+ or: [
1387
+ {
1388
+ and: [
1389
+ {
1390
+ attribute: "browser",
1391
+ operator: "equals",
1392
+ value: "chrome",
1393
+ },
1394
+ {
1395
+ attribute: "version",
1396
+ operator: "equals",
1397
+ value: "1.0",
1398
+ },
1399
+ ],
1400
+ },
1401
+ {
1402
+ attribute: "browser",
1403
+ operator: "equals",
1404
+ value: "firefox",
1405
+ },
1406
+ ],
1407
+ },
1408
+ ],
1409
+ }, {
1410
+ platform: "web",
1411
+ browser: "chrome",
1412
+ version: "1.0",
1413
+ })).toEqual({
1414
+ and: [
1415
+ "*",
1416
+ {
1417
+ or: [
1418
+ {
1419
+ and: ["*", "*"],
1420
+ },
1421
+ {
1422
+ attribute: "browser",
1423
+ operator: "equals",
1424
+ value: "firefox",
1425
+ },
1426
+ ],
1427
+ },
1428
+ ],
1429
+ });
1430
+ });
1431
+ test("arrays with nested conditions", function () {
1432
+ // Array with AND condition
1433
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, [
1434
+ {
1435
+ attribute: "platform",
1436
+ operator: "equals",
1437
+ value: "web",
1438
+ },
1439
+ {
1440
+ and: [
1441
+ {
1442
+ attribute: "browser",
1443
+ operator: "equals",
1444
+ value: "chrome",
1445
+ },
1446
+ {
1447
+ attribute: "version",
1448
+ operator: "equals",
1449
+ value: "1.0",
1450
+ },
1451
+ ],
1452
+ },
1453
+ ], {
1454
+ platform: "web",
1455
+ browser: "chrome",
1456
+ version: "1.0",
1457
+ })).toEqual([
1458
+ "*",
1459
+ {
1460
+ and: ["*", "*"],
1461
+ },
1462
+ ]);
1463
+ // Array with OR condition
1464
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, [
1465
+ {
1466
+ attribute: "platform",
1467
+ operator: "equals",
1468
+ value: "web",
1469
+ },
1470
+ {
1471
+ or: [
1472
+ {
1473
+ attribute: "browser",
1474
+ operator: "equals",
1475
+ value: "chrome",
1476
+ },
1477
+ {
1478
+ attribute: "browser",
1479
+ operator: "equals",
1480
+ value: "firefox",
1481
+ },
1482
+ ],
1483
+ },
1484
+ ], {
1485
+ platform: "web",
1486
+ browser: "chrome",
1487
+ })).toEqual([
1488
+ "*",
1489
+ {
1490
+ or: [
1491
+ "*",
1492
+ {
1493
+ attribute: "browser",
1494
+ operator: "equals",
1495
+ value: "firefox",
1496
+ },
1497
+ ],
1498
+ },
1499
+ ]);
1500
+ });
1501
+ test("edge cases", function () {
1502
+ // Empty context
1503
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, {
1504
+ attribute: "platform",
1505
+ operator: "equals",
1506
+ value: "web",
1507
+ }, {})).toEqual({
1508
+ attribute: "platform",
1509
+ operator: "equals",
1510
+ value: "web",
1511
+ });
1512
+ // Empty array
1513
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, [], {})).toEqual([]);
1514
+ // "*" in array
1515
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, [
1516
+ "*",
1517
+ {
1518
+ attribute: "platform",
1519
+ operator: "equals",
1520
+ value: "web",
1521
+ },
1522
+ ], {
1523
+ platform: "web",
1524
+ })).toEqual(["*", "*"]);
1525
+ // AND with empty array
1526
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, {
1527
+ and: [],
1528
+ }, {})).toEqual({
1529
+ and: [],
1530
+ });
1531
+ // OR with empty array
1532
+ expect((0, buildScopedConditions_1.buildScopedCondition)(datafileReader, {
1533
+ or: [],
1534
+ }, {})).toEqual({
1535
+ or: [],
1536
+ });
1537
+ });
1538
+ });
1539
+ describe("removeRedundantConditions", function () {
1540
+ test("removeRedundantConditions is a function", function () {
1541
+ expect(buildScopedConditions_1.removeRedundantConditions).toBeInstanceOf(Function);
1542
+ });
1543
+ test("simple cases", function () {
1544
+ // * is *
1545
+ expect((0, buildScopedConditions_1.removeRedundantConditions)("*")).toEqual("*");
1546
+ // [*, *, *] is "*"
1547
+ expect((0, buildScopedConditions_1.removeRedundantConditions)(["*", "*", "*"])).toEqual("*");
1548
+ // Array with mixed conditions
1549
+ expect((0, buildScopedConditions_1.removeRedundantConditions)([
1550
+ "*",
1551
+ {
1552
+ attribute: "platform",
1553
+ operator: "equals",
1554
+ value: "web",
1555
+ },
1556
+ "*",
1557
+ {
1558
+ attribute: "browser",
1559
+ operator: "equals",
1560
+ value: "chrome",
1561
+ },
1562
+ ])).toEqual([
1563
+ {
1564
+ attribute: "platform",
1565
+ operator: "equals",
1566
+ value: "web",
1567
+ },
1568
+ {
1569
+ attribute: "browser",
1570
+ operator: "equals",
1571
+ value: "chrome",
1572
+ },
1573
+ ]);
1574
+ });
1575
+ test("AND conditions", function () {
1576
+ // All "*" in AND
1577
+ expect((0, buildScopedConditions_1.removeRedundantConditions)({ and: ["*", "*", "*"] })).toEqual("*");
1578
+ // Mixed with "*" in AND
1579
+ expect((0, buildScopedConditions_1.removeRedundantConditions)({
1580
+ and: [
1581
+ "*",
1582
+ {
1583
+ attribute: "platform",
1584
+ operator: "equals",
1585
+ value: "web",
1586
+ },
1587
+ "*",
1588
+ ],
1589
+ })).toEqual({
1590
+ and: [
1591
+ {
1592
+ attribute: "platform",
1593
+ operator: "equals",
1594
+ value: "web",
1595
+ },
1596
+ ],
1597
+ });
1598
+ // Multiple non-* conditions in AND
1599
+ expect((0, buildScopedConditions_1.removeRedundantConditions)({
1600
+ and: [
1601
+ "*",
1602
+ {
1603
+ attribute: "platform",
1604
+ operator: "equals",
1605
+ value: "web",
1606
+ },
1607
+ "*",
1608
+ {
1609
+ attribute: "browser",
1610
+ operator: "equals",
1611
+ value: "chrome",
1612
+ },
1613
+ "*",
1614
+ ],
1615
+ })).toEqual({
1616
+ and: [
1617
+ {
1618
+ attribute: "platform",
1619
+ operator: "equals",
1620
+ value: "web",
1621
+ },
1622
+ {
1623
+ attribute: "browser",
1624
+ operator: "equals",
1625
+ value: "chrome",
1626
+ },
1627
+ ],
1628
+ });
1629
+ });
1630
+ test("OR conditions", function () {
1631
+ // All "*" in OR
1632
+ expect((0, buildScopedConditions_1.removeRedundantConditions)({ or: ["*", "*", "*"] })).toEqual("*");
1633
+ // Mixed with "*" in OR
1634
+ expect((0, buildScopedConditions_1.removeRedundantConditions)({
1635
+ or: [
1636
+ "*",
1637
+ {
1638
+ attribute: "platform",
1639
+ operator: "equals",
1640
+ value: "web",
1641
+ },
1642
+ "*",
1643
+ ],
1644
+ })).toEqual({
1645
+ or: [
1646
+ {
1647
+ attribute: "platform",
1648
+ operator: "equals",
1649
+ value: "web",
1650
+ },
1651
+ ],
1652
+ });
1653
+ // Multiple non-* conditions in OR
1654
+ expect((0, buildScopedConditions_1.removeRedundantConditions)({
1655
+ or: [
1656
+ "*",
1657
+ {
1658
+ attribute: "platform",
1659
+ operator: "equals",
1660
+ value: "web",
1661
+ },
1662
+ "*",
1663
+ {
1664
+ attribute: "platform",
1665
+ operator: "equals",
1666
+ value: "mobile",
1667
+ },
1668
+ "*",
1669
+ ],
1670
+ })).toEqual({
1671
+ or: [
1672
+ {
1673
+ attribute: "platform",
1674
+ operator: "equals",
1675
+ value: "web",
1676
+ },
1677
+ {
1678
+ attribute: "platform",
1679
+ operator: "equals",
1680
+ value: "mobile",
1681
+ },
1682
+ ],
1683
+ });
1684
+ });
1685
+ test("NOT conditions", function () {
1686
+ // All "*" in NOT
1687
+ expect((0, buildScopedConditions_1.removeRedundantConditions)({ not: ["*", "*", "*"] })).toEqual("*");
1688
+ // Mixed with "*" in NOT
1689
+ expect((0, buildScopedConditions_1.removeRedundantConditions)({
1690
+ not: [
1691
+ "*",
1692
+ {
1693
+ attribute: "platform",
1694
+ operator: "equals",
1695
+ value: "web",
1696
+ },
1697
+ "*",
1698
+ ],
1699
+ })).toEqual({
1700
+ not: [
1701
+ {
1702
+ attribute: "platform",
1703
+ operator: "equals",
1704
+ value: "web",
1705
+ },
1706
+ ],
1707
+ });
1708
+ });
1709
+ test("nested AND conditions", function () {
1710
+ // Nested AND with all "*"
1711
+ expect((0, buildScopedConditions_1.removeRedundantConditions)({
1712
+ and: [
1713
+ "*",
1714
+ {
1715
+ and: ["*", "*", "*"],
1716
+ },
1717
+ "*",
1718
+ ],
1719
+ })).toEqual("*");
1720
+ // Nested AND with mixed conditions
1721
+ expect((0, buildScopedConditions_1.removeRedundantConditions)({
1722
+ and: [
1723
+ "*",
1724
+ {
1725
+ attribute: "platform",
1726
+ operator: "equals",
1727
+ value: "web",
1728
+ },
1729
+ {
1730
+ and: [
1731
+ "*",
1732
+ {
1733
+ attribute: "browser",
1734
+ operator: "equals",
1735
+ value: "chrome",
1736
+ },
1737
+ "*",
1738
+ ],
1739
+ },
1740
+ "*",
1741
+ ],
1742
+ })).toEqual({
1743
+ and: [
1744
+ {
1745
+ attribute: "platform",
1746
+ operator: "equals",
1747
+ value: "web",
1748
+ },
1749
+ {
1750
+ and: [
1751
+ {
1752
+ attribute: "browser",
1753
+ operator: "equals",
1754
+ value: "chrome",
1755
+ },
1756
+ ],
1757
+ },
1758
+ ],
1759
+ });
1760
+ // Deeply nested AND
1761
+ expect((0, buildScopedConditions_1.removeRedundantConditions)({
1762
+ and: [
1763
+ "*",
1764
+ {
1765
+ and: [
1766
+ "*",
1767
+ {
1768
+ and: ["*", "*", "*"],
1769
+ },
1770
+ "*",
1771
+ ],
1772
+ },
1773
+ "*",
1774
+ ],
1775
+ })).toEqual("*");
1776
+ });
1777
+ test("nested OR conditions", function () {
1778
+ // Nested OR with all "*"
1779
+ expect((0, buildScopedConditions_1.removeRedundantConditions)({
1780
+ or: [
1781
+ "*",
1782
+ {
1783
+ or: ["*", "*", "*"],
1784
+ },
1785
+ "*",
1786
+ ],
1787
+ })).toEqual("*");
1788
+ // Nested OR with mixed conditions
1789
+ expect((0, buildScopedConditions_1.removeRedundantConditions)({
1790
+ or: [
1791
+ "*",
1792
+ {
1793
+ attribute: "platform",
1794
+ operator: "equals",
1795
+ value: "web",
1796
+ },
1797
+ {
1798
+ or: [
1799
+ "*",
1800
+ {
1801
+ attribute: "platform",
1802
+ operator: "equals",
1803
+ value: "mobile",
1804
+ },
1805
+ "*",
1806
+ ],
1807
+ },
1808
+ "*",
1809
+ ],
1810
+ })).toEqual({
1811
+ or: [
1812
+ {
1813
+ attribute: "platform",
1814
+ operator: "equals",
1815
+ value: "web",
1816
+ },
1817
+ {
1818
+ or: [
1819
+ {
1820
+ attribute: "platform",
1821
+ operator: "equals",
1822
+ value: "mobile",
1823
+ },
1824
+ ],
1825
+ },
1826
+ ],
1827
+ });
1828
+ });
1829
+ test("nested NOT conditions", function () {
1830
+ // Nested NOT with all "*"
1831
+ expect((0, buildScopedConditions_1.removeRedundantConditions)({
1832
+ not: [
1833
+ "*",
1834
+ {
1835
+ not: ["*", "*", "*"],
1836
+ },
1837
+ "*",
1838
+ ],
1839
+ })).toEqual("*");
1840
+ // Nested NOT with mixed conditions
1841
+ expect((0, buildScopedConditions_1.removeRedundantConditions)({
1842
+ not: [
1843
+ "*",
1844
+ {
1845
+ attribute: "platform",
1846
+ operator: "equals",
1847
+ value: "web",
1848
+ },
1849
+ {
1850
+ not: [
1851
+ "*",
1852
+ {
1853
+ attribute: "browser",
1854
+ operator: "equals",
1855
+ value: "chrome",
1856
+ },
1857
+ "*",
1858
+ ],
1859
+ },
1860
+ "*",
1861
+ ],
1862
+ })).toEqual({
1863
+ not: [
1864
+ {
1865
+ attribute: "platform",
1866
+ operator: "equals",
1867
+ value: "web",
1868
+ },
1869
+ {
1870
+ not: [
1871
+ {
1872
+ attribute: "browser",
1873
+ operator: "equals",
1874
+ value: "chrome",
1875
+ },
1876
+ ],
1877
+ },
1878
+ ],
1879
+ });
1880
+ });
1881
+ test("mixed nested conditions", function () {
1882
+ // AND with nested OR
1883
+ expect((0, buildScopedConditions_1.removeRedundantConditions)({
1884
+ and: [
1885
+ "*",
1886
+ {
1887
+ attribute: "platform",
1888
+ operator: "equals",
1889
+ value: "web",
1890
+ },
1891
+ {
1892
+ or: [
1893
+ "*",
1894
+ {
1895
+ attribute: "browser",
1896
+ operator: "equals",
1897
+ value: "chrome",
1898
+ },
1899
+ "*",
1900
+ ],
1901
+ },
1902
+ "*",
1903
+ ],
1904
+ })).toEqual({
1905
+ and: [
1906
+ {
1907
+ attribute: "platform",
1908
+ operator: "equals",
1909
+ value: "web",
1910
+ },
1911
+ {
1912
+ or: [
1913
+ {
1914
+ attribute: "browser",
1915
+ operator: "equals",
1916
+ value: "chrome",
1917
+ },
1918
+ ],
1919
+ },
1920
+ ],
1921
+ });
1922
+ // OR with nested AND
1923
+ expect((0, buildScopedConditions_1.removeRedundantConditions)({
1924
+ or: [
1925
+ "*",
1926
+ {
1927
+ attribute: "platform",
1928
+ operator: "equals",
1929
+ value: "web",
1930
+ },
1931
+ {
1932
+ and: [
1933
+ "*",
1934
+ {
1935
+ attribute: "browser",
1936
+ operator: "equals",
1937
+ value: "chrome",
1938
+ },
1939
+ "*",
1940
+ ],
1941
+ },
1942
+ "*",
1943
+ ],
1944
+ })).toEqual({
1945
+ or: [
1946
+ {
1947
+ attribute: "platform",
1948
+ operator: "equals",
1949
+ value: "web",
1950
+ },
1951
+ {
1952
+ and: [
1953
+ {
1954
+ attribute: "browser",
1955
+ operator: "equals",
1956
+ value: "chrome",
1957
+ },
1958
+ ],
1959
+ },
1960
+ ],
1961
+ });
1962
+ // AND with nested NOT
1963
+ expect((0, buildScopedConditions_1.removeRedundantConditions)({
1964
+ and: [
1965
+ "*",
1966
+ {
1967
+ attribute: "platform",
1968
+ operator: "equals",
1969
+ value: "web",
1970
+ },
1971
+ {
1972
+ not: [
1973
+ "*",
1974
+ {
1975
+ attribute: "browser",
1976
+ operator: "equals",
1977
+ value: "safari",
1978
+ },
1979
+ "*",
1980
+ ],
1981
+ },
1982
+ "*",
1983
+ ],
1984
+ })).toEqual({
1985
+ and: [
1986
+ {
1987
+ attribute: "platform",
1988
+ operator: "equals",
1989
+ value: "web",
1990
+ },
1991
+ {
1992
+ not: [
1993
+ {
1994
+ attribute: "browser",
1995
+ operator: "equals",
1996
+ value: "safari",
1997
+ },
1998
+ ],
1999
+ },
2000
+ ],
2001
+ });
2002
+ // Complex nested structure
2003
+ expect((0, buildScopedConditions_1.removeRedundantConditions)({
2004
+ and: [
2005
+ "*",
2006
+ {
2007
+ attribute: "platform",
2008
+ operator: "equals",
2009
+ value: "web",
2010
+ },
2011
+ {
2012
+ or: [
2013
+ "*",
2014
+ {
2015
+ and: [
2016
+ "*",
2017
+ {
2018
+ attribute: "browser",
2019
+ operator: "equals",
2020
+ value: "chrome",
2021
+ },
2022
+ "*",
2023
+ ],
2024
+ },
2025
+ "*",
2026
+ ],
2027
+ },
2028
+ "*",
2029
+ ],
2030
+ })).toEqual({
2031
+ and: [
2032
+ {
2033
+ attribute: "platform",
2034
+ operator: "equals",
2035
+ value: "web",
2036
+ },
2037
+ {
2038
+ or: [
2039
+ {
2040
+ and: [
2041
+ {
2042
+ attribute: "browser",
2043
+ operator: "equals",
2044
+ value: "chrome",
2045
+ },
2046
+ ],
2047
+ },
2048
+ ],
2049
+ },
2050
+ ],
2051
+ });
2052
+ });
2053
+ test("arrays with nested conditions", function () {
2054
+ // Array with nested AND
2055
+ expect((0, buildScopedConditions_1.removeRedundantConditions)([
2056
+ "*",
2057
+ {
2058
+ and: [
2059
+ "*",
2060
+ {
2061
+ attribute: "platform",
2062
+ operator: "equals",
2063
+ value: "web",
2064
+ },
2065
+ "*",
2066
+ ],
2067
+ },
2068
+ "*",
2069
+ ])).toEqual([
2070
+ {
2071
+ and: [
2072
+ {
2073
+ attribute: "platform",
2074
+ operator: "equals",
2075
+ value: "web",
2076
+ },
2077
+ ],
2078
+ },
2079
+ ]);
2080
+ // Array with multiple nested conditions
2081
+ expect((0, buildScopedConditions_1.removeRedundantConditions)([
2082
+ "*",
2083
+ {
2084
+ attribute: "platform",
2085
+ operator: "equals",
2086
+ value: "web",
2087
+ },
2088
+ {
2089
+ or: [
2090
+ "*",
2091
+ {
2092
+ attribute: "browser",
2093
+ operator: "equals",
2094
+ value: "chrome",
2095
+ },
2096
+ "*",
2097
+ ],
2098
+ },
2099
+ "*",
2100
+ ])).toEqual([
2101
+ {
2102
+ attribute: "platform",
2103
+ operator: "equals",
2104
+ value: "web",
2105
+ },
2106
+ {
2107
+ or: [
2108
+ {
2109
+ attribute: "browser",
2110
+ operator: "equals",
2111
+ value: "chrome",
2112
+ },
2113
+ ],
2114
+ },
2115
+ ]);
2116
+ });
2117
+ test("edge cases", function () {
2118
+ // Single condition after filtering
2119
+ expect((0, buildScopedConditions_1.removeRedundantConditions)({
2120
+ and: [
2121
+ "*",
2122
+ {
2123
+ attribute: "platform",
2124
+ operator: "equals",
2125
+ value: "web",
2126
+ },
2127
+ "*",
2128
+ ],
2129
+ })).toEqual({
2130
+ and: [
2131
+ {
2132
+ attribute: "platform",
2133
+ operator: "equals",
2134
+ value: "web",
2135
+ },
2136
+ ],
2137
+ });
2138
+ // Plain condition object (no change)
2139
+ expect((0, buildScopedConditions_1.removeRedundantConditions)({
2140
+ attribute: "platform",
2141
+ operator: "equals",
2142
+ value: "web",
2143
+ })).toEqual({
2144
+ attribute: "platform",
2145
+ operator: "equals",
2146
+ value: "web",
2147
+ });
2148
+ // Array with single non-* condition
2149
+ expect((0, buildScopedConditions_1.removeRedundantConditions)([
2150
+ "*",
2151
+ {
2152
+ attribute: "platform",
2153
+ operator: "equals",
2154
+ value: "web",
2155
+ },
2156
+ "*",
2157
+ ])).toEqual([
2158
+ {
2159
+ attribute: "platform",
2160
+ operator: "equals",
2161
+ value: "web",
2162
+ },
2163
+ ]);
2164
+ });
2165
+ });
2166
+ });
2167
+ //# sourceMappingURL=buildScopedConditions.spec.js.map