@@ -4,6 +4,7 @@ import * as td from 'testdouble';
44
55import {
66 ASSIGNMENT_TEST_DATA_DIR ,
7+ AssignmentVariationValue ,
78 getTestAssignments ,
89 IAssignmentTestCase ,
910 MOCK_UFC_RESPONSE_FILE ,
@@ -28,7 +29,11 @@ import { Flag, ObfuscatedFlag, VariationType, FormatEnum, Variation } from '../i
2829import { getMD5Hash } from '../obfuscation' ;
2930import { AttributeType } from '../types' ;
3031
31- import EppoClient , { checkTypeMatch , FlagConfigurationRequestParameters } from './eppo-client' ;
32+ import EppoClient , {
33+ checkTypeMatch ,
34+ FlagConfigurationRequestParameters ,
35+ IAssignmentDetails ,
36+ } from './eppo-client' ;
3237import { initConfiguration } from './test-utils' ;
3338
3439// Use a known salt to produce deterministic hashes
@@ -317,50 +322,66 @@ describe('EppoClient E2E test', () => {
317322 } ) ;
318323 } ) ;
319324
320- describe ( ' UFC Shared Test Cases', ( ) => {
325+ describe . each ( [ 'Not Obfuscated' , 'Obfuscated' ] ) ( ' UFC Shared Test Cases %s ', ( obfuscationType ) => {
321326 const testCases = testCasesByFileName < IAssignmentTestCase > ( ASSIGNMENT_TEST_DATA_DIR ) ;
327+ const isObfuscated = obfuscationType === 'Obfuscated' ;
322328
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 ;
332342
333- await initConfiguration ( storage ) ;
334- } ) ;
343+ await initConfiguration ( storage ) ;
344+ } ) ;
335345
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' ;
339352
340353 it . each ( Object . keys ( testCases ) ) ( 'test variation assignment splits - %s' , async ( fileName ) => {
341354 const { flag, variationType, defaultValue, subjects } = testCases [ fileName ] ;
342- const client = new EppoClient ( { flagConfigurationStore : storage } ) ;
355+ const client = new EppoClient ( { flagConfigurationStore : storage , isObfuscated } ) ;
343356 client . setIsGracefulFailureMode ( false ) ;
344357
345358 let assignments : {
346359 subject : SubjectTestCase ;
347- assignment : string | boolean | number | null | object ;
360+ assignment : AssignmentVariationValue ;
348361 } [ ] = [ ] ;
349362
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+ } ;
357378
358379 const assignmentFn = typeAssignmentFunctions [ variationType ] as (
359380 flagKey : string ,
360381 subjectKey : string ,
361382 subjectAttributes : Record < string , AttributeType > ,
362- defaultValue : boolean | string | number | object ,
363- ) => never ;
383+ defaultValue : AssignmentVariationValue ,
384+ ) => AssignmentVariationValue | IAssignmentDetails < AssignmentVariationValue > ;
364385 if ( ! assignmentFn ) {
365386 throw new Error ( `Unknown variation type: ${ variationType } ` ) ;
366387 }
@@ -370,56 +391,7 @@ describe('EppoClient E2E test', () => {
370391 assignmentFn ,
371392 ) ;
372393
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 ) ;
423395 } ) ;
424396 } ) ;
425397 } ) ;
0 commit comments