11import {
2+ MOCK_PRECOMPUTED_WIRE_FILE ,
23 readMockConfigurationWireResponse ,
3- MOCK_DEOBFUSCATED_PRECOMPUTED_RESPONSE_FILE ,
44} from '../../test/testHelpers' ;
55import ApiEndpoints from '../api-endpoints' ;
66import { MemoryOnlyConfigurationStore } from '../configuration-store/memory.store' ;
77import FetchHttpClient from '../http-client' ;
8- import { PrecomputedFlag , IObfuscatedPrecomputedBandit } from '../interfaces' ;
8+ import { IObfuscatedPrecomputedBandit , PrecomputedFlag } from '../interfaces' ;
99import PrecomputedFlagRequestor from '../precomputed-requestor' ;
1010
1111import EppoPrecomputedClient from './eppo-precomputed-client' ;
@@ -17,12 +17,10 @@ describe('EppoPrecomputedClient Bandits E2E test', () => {
1717 const mockLogAssignment = jest . fn ( ) ;
1818 const mockLogBanditAction = jest . fn ( ) ;
1919
20- const precomputedConfigurationWire = readMockConfigurationWireResponse (
21- MOCK_DEOBFUSCATED_PRECOMPUTED_RESPONSE_FILE ,
22- ) ;
23- const parsedPrecomputedResponse = JSON . parse ( precomputedConfigurationWire ) . precomputed . response ;
20+ const obfuscatedConfigurationWire = readMockConfigurationWireResponse ( MOCK_PRECOMPUTED_WIRE_FILE ) ;
21+ const obfuscatedResponse = JSON . parse ( obfuscatedConfigurationWire ) . precomputed . response ;
2422
25- const testModes = [ 'offline' , 'online' ] as const ;
23+ const testModes = [ 'offline' ] ;
2624
2725 testModes . forEach ( ( mode ) => {
2826 describe ( `${ mode } mode` , ( ) => {
@@ -33,7 +31,7 @@ describe('EppoPrecomputedClient Bandits E2E test', () => {
3331 return Promise . resolve ( {
3432 ok : true ,
3533 status : 200 ,
36- json : ( ) => Promise . resolve ( parsedPrecomputedResponse ) ,
34+ json : ( ) => Promise . resolve ( JSON . parse ( obfuscatedResponse ) ) ,
3735 } ) ;
3836 } ) as jest . Mock ;
3937
@@ -62,13 +60,17 @@ describe('EppoPrecomputedClient Bandits E2E test', () => {
6260 categoricalAttributes : { loyalty_tier : 'bronze' } ,
6361 } ,
6462 } ,
63+ 'not-a-bandit-flag' : { } ,
6564 } ,
6665 ) ;
6766 await configurationRequestor . fetchAndStorePrecomputedFlags ( ) ;
6867 } else if ( mode === 'offline' ) {
68+ const parsed = JSON . parse ( obfuscatedResponse ) ;
6969 // Offline mode: directly populate stores with precomputed response
70- await precomputedFlagStore . setEntries ( parsedPrecomputedResponse . flags ) ;
71- await precomputedBanditStore . setEntries ( parsedPrecomputedResponse . bandits ) ;
70+ precomputedFlagStore . salt = parsed . salt ;
71+ precomputedBanditStore . salt = parsed . salt ;
72+ await precomputedFlagStore . setEntries ( parsed . flags ) ;
73+ await precomputedBanditStore . setEntries ( parsed . bandits ) ;
7274 }
7375 } ) ;
7476
@@ -102,6 +104,21 @@ describe('EppoPrecomputedClient Bandits E2E test', () => {
102104 const precomputedConfiguration = client . getBanditAction ( 'banner_bandit_flag' , 'nike' ) ;
103105 expect ( precomputedConfiguration ) . toEqual ( { action : null , variation : 'nike' } ) ;
104106 } ) ;
107+
108+ it ( 'should return the assigned variation if a flag is not a bandit' , ( ) => {
109+ const precomputedConfiguration = client . getBanditAction ( 'not-a-bandit-flag' , 'default' ) ;
110+ expect ( precomputedConfiguration ) . toEqual ( { action : null , variation : 'control' } ) ;
111+ expect ( mockLogBanditAction ) . not . toHaveBeenCalled ( ) ;
112+ } ) ;
113+
114+ it ( 'should return the bandit variation and action if a flag is a bandit' , ( ) => {
115+ const precomputedConfiguration = client . getBanditAction ( 'string-flag' , 'default' ) ;
116+ expect ( precomputedConfiguration ) . toEqual ( {
117+ action : 'show_red_button' ,
118+ variation : 'red' ,
119+ } ) ;
120+ expect ( mockLogBanditAction ) . toHaveBeenCalled ( ) ;
121+ } ) ;
105122 } ) ;
106123 } ) ;
107124} ) ;
0 commit comments