1
1
import {
2
+ MOCK_PRECOMPUTED_WIRE_FILE ,
2
3
readMockConfigurationWireResponse ,
3
- MOCK_DEOBFUSCATED_PRECOMPUTED_RESPONSE_FILE ,
4
4
} from '../../test/testHelpers' ;
5
5
import ApiEndpoints from '../api-endpoints' ;
6
6
import { MemoryOnlyConfigurationStore } from '../configuration-store/memory.store' ;
7
7
import FetchHttpClient from '../http-client' ;
8
- import { PrecomputedFlag , IObfuscatedPrecomputedBandit } from '../interfaces' ;
8
+ import { IObfuscatedPrecomputedBandit , PrecomputedFlag } from '../interfaces' ;
9
9
import PrecomputedFlagRequestor from '../precomputed-requestor' ;
10
10
11
11
import EppoPrecomputedClient from './eppo-precomputed-client' ;
@@ -17,12 +17,10 @@ describe('EppoPrecomputedClient Bandits E2E test', () => {
17
17
const mockLogAssignment = jest . fn ( ) ;
18
18
const mockLogBanditAction = jest . fn ( ) ;
19
19
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 ;
24
22
25
- const testModes = [ 'offline' , 'online' ] as const ;
23
+ const testModes = [ 'offline' ] ;
26
24
27
25
testModes . forEach ( ( mode ) => {
28
26
describe ( `${ mode } mode` , ( ) => {
@@ -33,7 +31,7 @@ describe('EppoPrecomputedClient Bandits E2E test', () => {
33
31
return Promise . resolve ( {
34
32
ok : true ,
35
33
status : 200 ,
36
- json : ( ) => Promise . resolve ( parsedPrecomputedResponse ) ,
34
+ json : ( ) => Promise . resolve ( JSON . parse ( obfuscatedResponse ) ) ,
37
35
} ) ;
38
36
} ) as jest . Mock ;
39
37
@@ -62,13 +60,17 @@ describe('EppoPrecomputedClient Bandits E2E test', () => {
62
60
categoricalAttributes : { loyalty_tier : 'bronze' } ,
63
61
} ,
64
62
} ,
63
+ 'not-a-bandit-flag' : { } ,
65
64
} ,
66
65
) ;
67
66
await configurationRequestor . fetchAndStorePrecomputedFlags ( ) ;
68
67
} else if ( mode === 'offline' ) {
68
+ const parsed = JSON . parse ( obfuscatedResponse ) ;
69
69
// 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 ) ;
72
74
}
73
75
} ) ;
74
76
@@ -102,6 +104,21 @@ describe('EppoPrecomputedClient Bandits E2E test', () => {
102
104
const precomputedConfiguration = client . getBanditAction ( 'banner_bandit_flag' , 'nike' ) ;
103
105
expect ( precomputedConfiguration ) . toEqual ( { action : null , variation : 'nike' } ) ;
104
106
} ) ;
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
+ } ) ;
105
122
} ) ;
106
123
} ) ;
107
124
} ) ;
0 commit comments