13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
- import { describe , it , vi , expect } from 'vitest' ;
16
+ import { beforeEach , afterEach , describe , it , vi , expect } from 'vitest' ;
17
17
18
18
import AudienceEvaluator , { createAudienceEvaluator } from './index' ;
19
19
import * as conditionTreeEvaluator from '../condition_tree_evaluator' ;
20
20
import * as customAttributeConditionEvaluator from '../custom_attribute_condition_evaluator' ;
21
21
import { AUDIENCE_EVALUATION_RESULT , EVALUATING_AUDIENCE } from '../../message/log_message' ;
22
- import { getMockRequestHandler } from '../../tests/mock/mock_request_handler' ;
23
22
import { getMockLogger } from '../../tests/mock/mock_logger' ;
24
- import { OptimizelyDecideOption , OptimizelyDecision } from '../../shared_types' ;
23
+ import { Audience , OptimizelyDecideOption , OptimizelyDecision } from '../../shared_types' ;
25
24
import { IOptimizelyUserContext } from '../../optimizely_user_context' ;
26
25
27
26
let mockLogger = getMockLogger ( ) ;
@@ -45,6 +44,8 @@ const getMockUserContext = (attributes?: unknown, segments?: string[]): IOptimiz
45
44
} ) as IOptimizelyUserContext ;
46
45
47
46
const chromeUserAudience = {
47
+ id : '0' ,
48
+ name : 'chromeUserAudience' ,
48
49
conditions : [
49
50
'and' ,
50
51
{
@@ -55,6 +56,8 @@ const chromeUserAudience = {
55
56
] ,
56
57
} ;
57
58
const iphoneUserAudience = {
59
+ id : '1' ,
60
+ name : 'iphoneUserAudience' ,
58
61
conditions : [
59
62
'and' ,
60
63
{
@@ -65,6 +68,8 @@ const iphoneUserAudience = {
65
68
] ,
66
69
} ;
67
70
const specialConditionTypeAudience = {
71
+ id : '3' ,
72
+ name : 'specialConditionTypeAudience' ,
68
73
conditions : [
69
74
'and' ,
70
75
{
@@ -83,24 +88,11 @@ const conditionsPassingWithNoAttrs = [
83
88
} ,
84
89
] ;
85
90
const conditionsPassingWithNoAttrsAudience = {
91
+ id : '2' ,
92
+ name : 'conditionsPassingWithNoAttrsAudience' ,
86
93
conditions : conditionsPassingWithNoAttrs ,
87
94
} ;
88
95
89
- type Condition =
90
- | string
91
- | {
92
- match ?: string ;
93
- value ?: string ;
94
- type ?: string ;
95
- name ?: string ;
96
- } ;
97
-
98
- type Audience = {
99
- id ?: string ,
100
- name ?: string ,
101
- conditions : Condition [ ] ;
102
- } ;
103
-
104
96
const audiencesById : {
105
97
[ id : string ] : Audience ;
106
98
} = {
@@ -384,7 +376,7 @@ describe('lib/core/audience_evaluator', () => {
384
376
} ) ;
385
377
} ) ;
386
378
387
- context ( 'with additional custom condition evaluator' , ( ) => {
379
+ describe ( 'with additional custom condition evaluator' , ( ) => {
388
380
describe ( 'when passing a valid additional evaluator' , ( ) => {
389
381
beforeEach ( ( ) => {
390
382
const mockEnvironment = {
@@ -435,9 +427,11 @@ describe('lib/core/audience_evaluator', () => {
435
427
} ) ;
436
428
} ) ;
437
429
438
- context ( 'with odp segment evaluator' , ( ) => {
430
+ describe ( 'with odp segment evaluator' , ( ) => {
439
431
describe ( 'Single ODP Audience' , ( ) => {
440
432
const singleAudience = {
433
+ id : '0' ,
434
+ name : 'singleAudience' ,
441
435
conditions : [
442
436
'and' ,
443
437
{
@@ -451,7 +445,7 @@ describe('lib/core/audience_evaluator', () => {
451
445
const audiencesById = {
452
446
0 : singleAudience ,
453
447
} ;
454
- const audience = new AudienceEvaluator ( ) ;
448
+ const audience = new AudienceEvaluator ( { } ) ;
455
449
456
450
it ( 'should evaluate to true if segment is found' , ( ) => {
457
451
expect ( audience . evaluate ( [ 'or' , '0' ] , audiencesById , getMockUserContext ( { } , [ 'odp-segment-1' ] ) ) ) . toBe ( true ) ;
@@ -468,6 +462,8 @@ describe('lib/core/audience_evaluator', () => {
468
462
469
463
describe ( 'Multiple ODP conditions in one Audience' , ( ) => {
470
464
const singleAudience = {
465
+ id : '0' ,
466
+ name : 'singleAudience' ,
471
467
conditions : [
472
468
'and' ,
473
469
{
@@ -502,7 +498,7 @@ describe('lib/core/audience_evaluator', () => {
502
498
const audiencesById = {
503
499
0 : singleAudience ,
504
500
} ;
505
- const audience = new AudienceEvaluator ( ) ;
501
+ const audience = new AudienceEvaluator ( { } ) ;
506
502
507
503
it ( 'should evaluate correctly based on the given segments' , ( ) => {
508
504
expect (
@@ -545,6 +541,8 @@ describe('lib/core/audience_evaluator', () => {
545
541
546
542
describe ( 'Multiple ODP conditions in multiple Audience' , ( ) => {
547
543
const audience1And2 = {
544
+ id : '0' ,
545
+ name : 'audience1And2' ,
548
546
conditions : [
549
547
'and' ,
550
548
{
@@ -563,6 +561,8 @@ describe('lib/core/audience_evaluator', () => {
563
561
} ;
564
562
565
563
const audience3And4 = {
564
+ id : '1' ,
565
+ name : 'audience3And4' ,
566
566
conditions : [
567
567
'and' ,
568
568
{
@@ -581,6 +581,8 @@ describe('lib/core/audience_evaluator', () => {
581
581
} ;
582
582
583
583
const audience5And6 = {
584
+ id : '2' ,
585
+ name : 'audience5And6' ,
584
586
conditions : [
585
587
'or' ,
586
588
{
@@ -602,7 +604,7 @@ describe('lib/core/audience_evaluator', () => {
602
604
1 : audience3And4 ,
603
605
2 : audience5And6 ,
604
606
} ;
605
- const audience = new AudienceEvaluator ( ) ;
607
+ const audience = new AudienceEvaluator ( { } ) ;
606
608
607
609
it ( 'should evaluate correctly based on the given segments' , ( ) => {
608
610
expect (
@@ -643,8 +645,10 @@ describe('lib/core/audience_evaluator', () => {
643
645
} ) ;
644
646
} ) ;
645
647
646
- context ( 'with multiple types of evaluators' , ( ) => {
648
+ it ( 'with multiple types of evaluators' , ( ) => {
647
649
const audience1And2 = {
650
+ id : '0' ,
651
+ name : 'audience1And2' ,
648
652
conditions : [
649
653
'and' ,
650
654
{
@@ -662,6 +666,8 @@ describe('lib/core/audience_evaluator', () => {
662
666
] ,
663
667
} ;
664
668
const audience3Or4 = {
669
+ id : '' ,
670
+ name : 'audience3And4' ,
665
671
conditions : [
666
672
'or' ,
667
673
{
@@ -685,7 +691,7 @@ describe('lib/core/audience_evaluator', () => {
685
691
2 : chromeUserAudience ,
686
692
} ;
687
693
688
- const audience = new AudienceEvaluator ( ) ;
694
+ const audience = new AudienceEvaluator ( { } ) ;
689
695
690
696
it ( 'should evaluate correctly based on the given segments' , ( ) => {
691
697
expect (
0 commit comments