1313 * See the License for the specific language governing permissions and
1414 * limitations under the License.
1515 */
16- import { describe , it , vi , expect } from 'vitest' ;
16+ import { beforeEach , afterEach , describe , it , vi , expect } from 'vitest' ;
1717
1818import AudienceEvaluator , { createAudienceEvaluator } from './index' ;
1919import * as conditionTreeEvaluator from '../condition_tree_evaluator' ;
2020import * as customAttributeConditionEvaluator from '../custom_attribute_condition_evaluator' ;
2121import { AUDIENCE_EVALUATION_RESULT , EVALUATING_AUDIENCE } from '../../message/log_message' ;
22- import { getMockRequestHandler } from '../../tests/mock/mock_request_handler' ;
2322import { getMockLogger } from '../../tests/mock/mock_logger' ;
24- import { OptimizelyDecideOption , OptimizelyDecision } from '../../shared_types' ;
23+ import { Audience , OptimizelyDecideOption , OptimizelyDecision } from '../../shared_types' ;
2524import { IOptimizelyUserContext } from '../../optimizely_user_context' ;
2625
2726let mockLogger = getMockLogger ( ) ;
@@ -45,6 +44,8 @@ const getMockUserContext = (attributes?: unknown, segments?: string[]): IOptimiz
4544} ) as IOptimizelyUserContext ;
4645
4746const chromeUserAudience = {
47+ id : '0' ,
48+ name : 'chromeUserAudience' ,
4849 conditions : [
4950 'and' ,
5051 {
@@ -55,6 +56,8 @@ const chromeUserAudience = {
5556 ] ,
5657} ;
5758const iphoneUserAudience = {
59+ id : '1' ,
60+ name : 'iphoneUserAudience' ,
5861 conditions : [
5962 'and' ,
6063 {
@@ -65,6 +68,8 @@ const iphoneUserAudience = {
6568 ] ,
6669} ;
6770const specialConditionTypeAudience = {
71+ id : '3' ,
72+ name : 'specialConditionTypeAudience' ,
6873 conditions : [
6974 'and' ,
7075 {
@@ -83,24 +88,11 @@ const conditionsPassingWithNoAttrs = [
8388 } ,
8489] ;
8590const conditionsPassingWithNoAttrsAudience = {
91+ id : '2' ,
92+ name : 'conditionsPassingWithNoAttrsAudience' ,
8693 conditions : conditionsPassingWithNoAttrs ,
8794} ;
8895
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-
10496const audiencesById : {
10597[ id : string ] : Audience ;
10698} = {
@@ -384,7 +376,7 @@ describe('lib/core/audience_evaluator', () => {
384376 } ) ;
385377 } ) ;
386378
387- context ( 'with additional custom condition evaluator' , ( ) => {
379+ describe ( 'with additional custom condition evaluator' , ( ) => {
388380 describe ( 'when passing a valid additional evaluator' , ( ) => {
389381 beforeEach ( ( ) => {
390382 const mockEnvironment = {
@@ -435,9 +427,11 @@ describe('lib/core/audience_evaluator', () => {
435427 } ) ;
436428 } ) ;
437429
438- context ( 'with odp segment evaluator' , ( ) => {
430+ describe ( 'with odp segment evaluator' , ( ) => {
439431 describe ( 'Single ODP Audience' , ( ) => {
440432 const singleAudience = {
433+ id : '0' ,
434+ name : 'singleAudience' ,
441435 conditions : [
442436 'and' ,
443437 {
@@ -451,7 +445,7 @@ describe('lib/core/audience_evaluator', () => {
451445 const audiencesById = {
452446 0 : singleAudience ,
453447 } ;
454- const audience = new AudienceEvaluator ( ) ;
448+ const audience = new AudienceEvaluator ( { } ) ;
455449
456450 it ( 'should evaluate to true if segment is found' , ( ) => {
457451 expect ( audience . evaluate ( [ 'or' , '0' ] , audiencesById , getMockUserContext ( { } , [ 'odp-segment-1' ] ) ) ) . toBe ( true ) ;
@@ -468,6 +462,8 @@ describe('lib/core/audience_evaluator', () => {
468462
469463 describe ( 'Multiple ODP conditions in one Audience' , ( ) => {
470464 const singleAudience = {
465+ id : '0' ,
466+ name : 'singleAudience' ,
471467 conditions : [
472468 'and' ,
473469 {
@@ -502,7 +498,7 @@ describe('lib/core/audience_evaluator', () => {
502498 const audiencesById = {
503499 0 : singleAudience ,
504500 } ;
505- const audience = new AudienceEvaluator ( ) ;
501+ const audience = new AudienceEvaluator ( { } ) ;
506502
507503 it ( 'should evaluate correctly based on the given segments' , ( ) => {
508504 expect (
@@ -545,6 +541,8 @@ describe('lib/core/audience_evaluator', () => {
545541
546542 describe ( 'Multiple ODP conditions in multiple Audience' , ( ) => {
547543 const audience1And2 = {
544+ id : '0' ,
545+ name : 'audience1And2' ,
548546 conditions : [
549547 'and' ,
550548 {
@@ -563,6 +561,8 @@ describe('lib/core/audience_evaluator', () => {
563561 } ;
564562
565563 const audience3And4 = {
564+ id : '1' ,
565+ name : 'audience3And4' ,
566566 conditions : [
567567 'and' ,
568568 {
@@ -581,6 +581,8 @@ describe('lib/core/audience_evaluator', () => {
581581 } ;
582582
583583 const audience5And6 = {
584+ id : '2' ,
585+ name : 'audience5And6' ,
584586 conditions : [
585587 'or' ,
586588 {
@@ -602,7 +604,7 @@ describe('lib/core/audience_evaluator', () => {
602604 1 : audience3And4 ,
603605 2 : audience5And6 ,
604606 } ;
605- const audience = new AudienceEvaluator ( ) ;
607+ const audience = new AudienceEvaluator ( { } ) ;
606608
607609 it ( 'should evaluate correctly based on the given segments' , ( ) => {
608610 expect (
@@ -643,8 +645,10 @@ describe('lib/core/audience_evaluator', () => {
643645 } ) ;
644646 } ) ;
645647
646- context ( 'with multiple types of evaluators' , ( ) => {
648+ it ( 'with multiple types of evaluators' , ( ) => {
647649 const audience1And2 = {
650+ id : '0' ,
651+ name : 'audience1And2' ,
648652 conditions : [
649653 'and' ,
650654 {
@@ -662,6 +666,8 @@ describe('lib/core/audience_evaluator', () => {
662666 ] ,
663667 } ;
664668 const audience3Or4 = {
669+ id : '' ,
670+ name : 'audience3And4' ,
665671 conditions : [
666672 'or' ,
667673 {
@@ -685,7 +691,7 @@ describe('lib/core/audience_evaluator', () => {
685691 2 : chromeUserAudience ,
686692 } ;
687693
688- const audience = new AudienceEvaluator ( ) ;
694+ const audience = new AudienceEvaluator ( { } ) ;
689695
690696 it ( 'should evaluate correctly based on the given segments' , ( ) => {
691697 expect (
0 commit comments