@@ -7,6 +7,7 @@ import mock from 'xhr-mock';
7
7
8
8
import {
9
9
IAssignmentTestCase ,
10
+ ValueTestType ,
10
11
readAssignmentTestData ,
11
12
readMockRacResponse ,
12
13
} from '../../test/testHelpers' ;
@@ -15,6 +16,7 @@ import { IAssignmentLogger } from '../assignment-logger';
15
16
import { IConfigurationStore } from '../configuration-store' ;
16
17
import { MAX_EVENT_QUEUE_SIZE } from '../constants' ;
17
18
import { OperatorType } from '../dto/rule-dto' ;
19
+ import { EppoValue } from '../eppo_value' ;
18
20
import ExperimentConfigurationRequestor from '../experiment-configuration-requestor' ;
19
21
import HttpClient from '../http-client' ;
20
22
@@ -85,6 +87,7 @@ describe('EppoClient E2E test', () => {
85
87
enabled : true ,
86
88
subjectShards : 100 ,
87
89
overrides : { } ,
90
+ typedOverrides : { } ,
88
91
rules : [
89
92
{
90
93
allocationKey : 'allocation1' ,
@@ -98,6 +101,7 @@ describe('EppoClient E2E test', () => {
98
101
{
99
102
name : 'control' ,
100
103
value : 'control' ,
104
+ typedValue : 'control' ,
101
105
shardRange : {
102
106
start : 0 ,
103
107
end : 34 ,
@@ -106,6 +110,7 @@ describe('EppoClient E2E test', () => {
106
110
{
107
111
name : 'variant-1' ,
108
112
value : 'variant-1' ,
113
+ typedValue : 'variant-1' ,
109
114
shardRange : {
110
115
start : 34 ,
111
116
end : 67 ,
@@ -114,6 +119,7 @@ describe('EppoClient E2E test', () => {
114
119
{
115
120
name : 'variant-2' ,
116
121
value : 'variant-2' ,
122
+ typedValue : 'variant-2' ,
117
123
shardRange : {
118
124
start : 67 ,
119
125
end : 100 ,
@@ -172,17 +178,34 @@ describe('EppoClient E2E test', () => {
172
178
'test variation assignment splits' ,
173
179
async ( {
174
180
experiment,
181
+ valueType = ValueTestType . StringType ,
175
182
subjects,
176
183
subjectsWithAttributes,
177
184
expectedAssignments,
178
185
} : IAssignmentTestCase ) => {
179
186
`---- Test Case for ${ experiment } Experiment ----` ;
180
- const assignments = subjectsWithAttributes
181
- ? getAssignmentsWithSubjectAttributes ( subjectsWithAttributes , experiment )
182
- : getAssignments ( subjects , experiment ) ;
183
187
184
- // temporarily cast to string under dynamic configuration support is added
185
- expect ( assignments ) . toEqual ( expectedAssignments . map ( ( e ) => ( e ? e . toString ( ) : null ) ) ) ;
188
+ const assignments = subjectsWithAttributes
189
+ ? getAssignmentsWithSubjectAttributes ( subjectsWithAttributes , experiment , valueType )
190
+ : getAssignments ( subjects , experiment , valueType ) ;
191
+
192
+ switch ( valueType ) {
193
+ case ValueTestType . BoolType : {
194
+ const boolAssignments = assignments . map ( ( a ) => a ?. boolValue ?? null ) ;
195
+ expect ( boolAssignments ) . toEqual ( expectedAssignments ) ;
196
+ break ;
197
+ }
198
+ case ValueTestType . NumericType : {
199
+ const numericAssignments = assignments . map ( ( a ) => a ?. numericValue ?? null ) ;
200
+ expect ( numericAssignments ) . toEqual ( expectedAssignments ) ;
201
+ break ;
202
+ }
203
+ case ValueTestType . StringType : {
204
+ const stringAssignments = assignments . map ( ( a ) => a ?. stringValue ?? null ) ;
205
+ expect ( stringAssignments ) . toEqual ( expectedAssignments ) ;
206
+ break ;
207
+ }
208
+ }
186
209
} ,
187
210
) ;
188
211
} ) ;
@@ -198,7 +221,7 @@ describe('EppoClient E2E test', () => {
198
221
experimentName ,
199
222
JSON . stringify ( {
200
223
...mockExperimentConfig ,
201
- overrides : {
224
+ typedOverrides : {
202
225
'1b50f33aef8f681a13f623963da967ed' : 'control' ,
203
226
} ,
204
227
} ) ,
@@ -212,7 +235,7 @@ describe('EppoClient E2E test', () => {
212
235
const entry = {
213
236
...mockExperimentConfig ,
214
237
enabled : false ,
215
- overrides : {
238
+ typedOverrides : {
216
239
'1b50f33aef8f681a13f623963da967ed' : 'control' ,
217
240
} ,
218
241
} ;
@@ -281,9 +304,29 @@ describe('EppoClient E2E test', () => {
281
304
expect ( assignment ) . toEqual ( 'control' ) ;
282
305
} ) ;
283
306
284
- function getAssignments ( subjects : string [ ] , experiment : string ) : string [ ] {
307
+ function getAssignments (
308
+ subjects : string [ ] ,
309
+ experiment : string ,
310
+ valueTestType : ValueTestType = ValueTestType . StringType ,
311
+ ) : ( EppoValue | null ) [ ] {
285
312
return subjects . map ( ( subjectKey ) => {
286
- return globalClient . getAssignment ( subjectKey , experiment ) ;
313
+ switch ( valueTestType ) {
314
+ case ValueTestType . BoolType : {
315
+ const ba = globalClient . getBoolAssignment ( subjectKey , experiment ) ;
316
+ if ( ba === null ) return null ;
317
+ return EppoValue . Bool ( ba ) ;
318
+ }
319
+ case ValueTestType . NumericType : {
320
+ const na = globalClient . getNumericAssignment ( subjectKey , experiment ) ;
321
+ if ( na === null ) return null ;
322
+ return EppoValue . Numeric ( na ) ;
323
+ }
324
+ case ValueTestType . StringType : {
325
+ const sa = globalClient . getStringAssignment ( subjectKey , experiment ) ;
326
+ if ( sa === null ) return null ;
327
+ return EppoValue . String ( sa ) ;
328
+ }
329
+ }
287
330
} ) ;
288
331
}
289
332
@@ -294,9 +337,38 @@ describe('EppoClient E2E test', () => {
294
337
subjectAttributes : Record < string , any > ;
295
338
} [ ] ,
296
339
experiment : string ,
297
- ) : string [ ] {
340
+ valueTestType : ValueTestType = ValueTestType . StringType ,
341
+ ) : ( EppoValue | null ) [ ] {
298
342
return subjectsWithAttributes . map ( ( subject ) => {
299
- return globalClient . getAssignment ( subject . subjectKey , experiment , subject . subjectAttributes ) ;
343
+ switch ( valueTestType ) {
344
+ case ValueTestType . BoolType : {
345
+ const ba = globalClient . getBoolAssignment (
346
+ subject . subjectKey ,
347
+ experiment ,
348
+ subject . subjectAttributes ,
349
+ ) ;
350
+ if ( ba === null ) return null ;
351
+ return EppoValue . Bool ( ba ) ;
352
+ }
353
+ case ValueTestType . NumericType : {
354
+ const na = globalClient . getNumericAssignment (
355
+ subject . subjectKey ,
356
+ experiment ,
357
+ subject . subjectAttributes ,
358
+ ) ;
359
+ if ( na === null ) return null ;
360
+ return EppoValue . Numeric ( na ) ;
361
+ }
362
+ case ValueTestType . StringType : {
363
+ const sa = globalClient . getStringAssignment (
364
+ subject . subjectKey ,
365
+ experiment ,
366
+ subject . subjectAttributes ,
367
+ ) ;
368
+ if ( sa === null ) return null ;
369
+ return EppoValue . String ( sa ) ;
370
+ }
371
+ }
300
372
} ) ;
301
373
}
302
374
@@ -324,12 +396,16 @@ describe('EppoClient E2E test', () => {
324
396
{ } ,
325
397
{
326
398
// eslint-disable-next-line @typescript-eslint/no-unused-vars
327
- onPreAssignment ( experimentKey : string , subject : string ) : string {
328
- return 'my-overridden-variation' ;
399
+ onPreAssignment ( experimentKey : string , subject : string ) : EppoValue | null {
400
+ return EppoValue . String ( 'my-overridden-variation' ) ;
329
401
} ,
330
402
331
403
// eslint-disable-next-line @typescript-eslint/no-unused-vars
332
- onPostAssignment ( experimentKey : string , subject : string , variation : string ) : void {
404
+ onPostAssignment (
405
+ experimentKey : string ,
406
+ subject : string ,
407
+ variation : EppoValue | null ,
408
+ ) : void {
333
409
// no-op
334
410
} ,
335
411
} ,
@@ -345,12 +421,16 @@ describe('EppoClient E2E test', () => {
345
421
{ } ,
346
422
{
347
423
// eslint-disable-next-line @typescript-eslint/no-unused-vars
348
- onPreAssignment ( experimentKey : string , subject : string ) : string | null {
424
+ onPreAssignment ( experimentKey : string , subject : string ) : EppoValue | null {
349
425
return null ;
350
426
} ,
351
427
352
428
// eslint-disable-next-line @typescript-eslint/no-unused-vars
353
- onPostAssignment ( experimentKey : string , subject : string , variation : string ) : void {
429
+ onPostAssignment (
430
+ experimentKey : string ,
431
+ subject : string ,
432
+ variation : EppoValue | null ,
433
+ ) : void {
354
434
// no-op
355
435
} ,
356
436
} ,
@@ -369,7 +449,9 @@ describe('EppoClient E2E test', () => {
369
449
expect ( td . explain ( mockHooks . onPostAssignment ) . callCount ) . toEqual ( 1 ) ;
370
450
expect ( td . explain ( mockHooks . onPostAssignment ) . calls [ 0 ] . args [ 0 ] ) . toEqual ( experimentName ) ;
371
451
expect ( td . explain ( mockHooks . onPostAssignment ) . calls [ 0 ] . args [ 1 ] ) . toEqual ( subject ) ;
372
- expect ( td . explain ( mockHooks . onPostAssignment ) . calls [ 0 ] . args [ 2 ] ) . toEqual ( variation ) ;
452
+ expect ( td . explain ( mockHooks . onPostAssignment ) . calls [ 0 ] . args [ 2 ] ) . toEqual (
453
+ EppoValue . String ( variation ?? '' ) ,
454
+ ) ;
373
455
} ) ;
374
456
} ) ;
375
457
} ) ;
0 commit comments