@@ -4,6 +4,7 @@ import * as td from 'testdouble';
4
4
5
5
import {
6
6
ASSIGNMENT_TEST_DATA_DIR ,
7
+ AssignmentVariationValue ,
7
8
getTestAssignments ,
8
9
IAssignmentTestCase ,
9
10
MOCK_UFC_RESPONSE_FILE ,
@@ -28,7 +29,11 @@ import { Flag, ObfuscatedFlag, VariationType, FormatEnum, Variation } from '../i
28
29
import { getMD5Hash } from '../obfuscation' ;
29
30
import { AttributeType } from '../types' ;
30
31
31
- import EppoClient , { checkTypeMatch , FlagConfigurationRequestParameters } from './eppo-client' ;
32
+ import EppoClient , {
33
+ checkTypeMatch ,
34
+ FlagConfigurationRequestParameters ,
35
+ IAssignmentDetails ,
36
+ } from './eppo-client' ;
32
37
import { initConfiguration } from './test-utils' ;
33
38
34
39
// Use a known salt to produce deterministic hashes
@@ -317,50 +322,66 @@ describe('EppoClient E2E test', () => {
317
322
} ) ;
318
323
} ) ;
319
324
320
- describe ( ' UFC Shared Test Cases', ( ) => {
325
+ describe . each ( [ 'Not Obfuscated' , 'Obfuscated' ] ) ( ' UFC Shared Test Cases %s ', ( obfuscationType ) => {
321
326
const testCases = testCasesByFileName < IAssignmentTestCase > ( ASSIGNMENT_TEST_DATA_DIR ) ;
327
+ const isObfuscated = obfuscationType === 'Obfuscated' ;
322
328
323
- describe ( 'Not obfuscated' , ( ) => {
324
- beforeAll ( async ( ) => {
325
- global . fetch = jest . fn ( ( ) => {
326
- return Promise . resolve ( {
327
- ok : true ,
328
- status : 200 ,
329
- json : ( ) => Promise . resolve ( readMockUFCResponse ( MOCK_UFC_RESPONSE_FILE ) ) ,
330
- } ) ;
331
- } ) as jest . Mock ;
329
+ beforeAll ( async ( ) => {
330
+ global . fetch = jest . fn ( ( ) => {
331
+ return Promise . resolve ( {
332
+ ok : true ,
333
+ status : 200 ,
334
+ json : ( ) =>
335
+ Promise . resolve (
336
+ readMockUFCResponse (
337
+ isObfuscated ? OBFUSCATED_MOCK_UFC_RESPONSE_FILE : MOCK_UFC_RESPONSE_FILE ,
338
+ ) ,
339
+ ) ,
340
+ } ) ;
341
+ } ) as jest . Mock ;
332
342
333
- await initConfiguration ( storage ) ;
334
- } ) ;
343
+ await initConfiguration ( storage ) ;
344
+ } ) ;
335
345
336
- afterAll ( ( ) => {
337
- jest . restoreAllMocks ( ) ;
338
- } ) ;
346
+ afterAll ( ( ) => {
347
+ jest . restoreAllMocks ( ) ;
348
+ } ) ;
349
+
350
+ describe . each ( [ 'Scalar' , 'With Details' ] ) ( '%s' , ( assignmentType ) => {
351
+ const assignmentWithDetails = assignmentType === 'With Details' ;
339
352
340
353
it . each ( Object . keys ( testCases ) ) ( 'test variation assignment splits - %s' , async ( fileName ) => {
341
354
const { flag, variationType, defaultValue, subjects } = testCases [ fileName ] ;
342
- const client = new EppoClient ( { flagConfigurationStore : storage } ) ;
355
+ const client = new EppoClient ( { flagConfigurationStore : storage , isObfuscated } ) ;
343
356
client . setIsGracefulFailureMode ( false ) ;
344
357
345
358
let assignments : {
346
359
subject : SubjectTestCase ;
347
- assignment : string | boolean | number | null | object ;
360
+ assignment : AssignmentVariationValue ;
348
361
} [ ] = [ ] ;
349
362
350
- const typeAssignmentFunctions = {
351
- [ VariationType . BOOLEAN ] : client . getBooleanAssignment . bind ( client ) ,
352
- [ VariationType . NUMERIC ] : client . getNumericAssignment . bind ( client ) ,
353
- [ VariationType . INTEGER ] : client . getIntegerAssignment . bind ( client ) ,
354
- [ VariationType . STRING ] : client . getStringAssignment . bind ( client ) ,
355
- [ VariationType . JSON ] : client . getJSONAssignment . bind ( client ) ,
356
- } ;
363
+ const typeAssignmentFunctions = assignmentWithDetails
364
+ ? {
365
+ [ VariationType . BOOLEAN ] : client . getBooleanAssignmentDetails . bind ( client ) ,
366
+ [ VariationType . NUMERIC ] : client . getNumericAssignmentDetails . bind ( client ) ,
367
+ [ VariationType . INTEGER ] : client . getIntegerAssignmentDetails . bind ( client ) ,
368
+ [ VariationType . STRING ] : client . getStringAssignmentDetails . bind ( client ) ,
369
+ [ VariationType . JSON ] : client . getJSONAssignmentDetails . bind ( client ) ,
370
+ }
371
+ : {
372
+ [ VariationType . BOOLEAN ] : client . getBooleanAssignment . bind ( client ) ,
373
+ [ VariationType . NUMERIC ] : client . getNumericAssignment . bind ( client ) ,
374
+ [ VariationType . INTEGER ] : client . getIntegerAssignment . bind ( client ) ,
375
+ [ VariationType . STRING ] : client . getStringAssignment . bind ( client ) ,
376
+ [ VariationType . JSON ] : client . getJSONAssignment . bind ( client ) ,
377
+ } ;
357
378
358
379
const assignmentFn = typeAssignmentFunctions [ variationType ] as (
359
380
flagKey : string ,
360
381
subjectKey : string ,
361
382
subjectAttributes : Record < string , AttributeType > ,
362
- defaultValue : boolean | string | number | object ,
363
- ) => never ;
383
+ defaultValue : AssignmentVariationValue ,
384
+ ) => AssignmentVariationValue | IAssignmentDetails < AssignmentVariationValue > ;
364
385
if ( ! assignmentFn ) {
365
386
throw new Error ( `Unknown variation type: ${ variationType } ` ) ;
366
387
}
@@ -370,56 +391,7 @@ describe('EppoClient E2E test', () => {
370
391
assignmentFn ,
371
392
) ;
372
393
373
- validateTestAssignments ( assignments , flag ) ;
374
- } ) ;
375
- } ) ;
376
-
377
- describe ( 'Obfuscated' , ( ) => {
378
- beforeAll ( async ( ) => {
379
- global . fetch = jest . fn ( ( ) => {
380
- return Promise . resolve ( {
381
- ok : true ,
382
- status : 200 ,
383
- json : ( ) => Promise . resolve ( readMockUFCResponse ( OBFUSCATED_MOCK_UFC_RESPONSE_FILE ) ) ,
384
- } ) ;
385
- } ) as jest . Mock ;
386
-
387
- await initConfiguration ( storage ) ;
388
- } ) ;
389
-
390
- afterAll ( ( ) => {
391
- jest . restoreAllMocks ( ) ;
392
- } ) ;
393
-
394
- it . each ( Object . keys ( testCases ) ) ( 'test variation assignment splits - %s' , async ( fileName ) => {
395
- const { flag, variationType, defaultValue, subjects } = testCases [ fileName ] ;
396
- const client = new EppoClient ( { flagConfigurationStore : storage , isObfuscated : true } ) ;
397
- client . setIsGracefulFailureMode ( false ) ;
398
-
399
- const typeAssignmentFunctions = {
400
- [ VariationType . BOOLEAN ] : client . getBooleanAssignment . bind ( client ) ,
401
- [ VariationType . NUMERIC ] : client . getNumericAssignment . bind ( client ) ,
402
- [ VariationType . INTEGER ] : client . getIntegerAssignment . bind ( client ) ,
403
- [ VariationType . STRING ] : client . getStringAssignment . bind ( client ) ,
404
- [ VariationType . JSON ] : client . getJSONAssignment . bind ( client ) ,
405
- } ;
406
-
407
- const assignmentFn = typeAssignmentFunctions [ variationType ] as (
408
- flagKey : string ,
409
- subjectKey : string ,
410
- subjectAttributes : Record < string , AttributeType > ,
411
- defaultValue : boolean | string | number | object ,
412
- ) => never ;
413
- if ( ! assignmentFn ) {
414
- throw new Error ( `Unknown variation type: ${ variationType } ` ) ;
415
- }
416
-
417
- const assignments = getTestAssignments (
418
- { flag, variationType, defaultValue, subjects } ,
419
- assignmentFn ,
420
- ) ;
421
-
422
- validateTestAssignments ( assignments , flag ) ;
394
+ validateTestAssignments ( assignments , flag , assignmentWithDetails , isObfuscated ) ;
423
395
} ) ;
424
396
} ) ;
425
397
} ) ;
0 commit comments