@@ -43,13 +43,13 @@ const mockErrorResponse = (statusCode: number) => Promise.resolve({
43
43
const assertRequest = (
44
44
call : number ,
45
45
mockRequestHandler : MockInstance < RequestHandler [ 'makeRequest' ] > ,
46
- experimentId : string ,
46
+ ruleId : string ,
47
47
userId : string ,
48
48
attributes : Record < string , any > ,
49
49
cmabUuid : string ,
50
50
) => {
51
51
const [ requestUrl , headers , method , data ] = mockRequestHandler . mock . calls [ call ] ;
52
- expect ( requestUrl ) . toBe ( `https://prediction.cmab.optimizely.com/predict/${ experimentId } ` ) ;
52
+ expect ( requestUrl ) . toBe ( `https://prediction.cmab.optimizely.com/predict/${ ruleId } ` ) ;
53
53
expect ( method ) . toBe ( 'POST' ) ;
54
54
expect ( headers ) . toEqual ( {
55
55
'Content-Type' : 'application/json' ,
@@ -59,7 +59,7 @@ const assertRequest = (
59
59
expect ( parsedData . instances ) . toEqual ( [
60
60
{
61
61
visitorId : userId ,
62
- experimentId,
62
+ experimentId : ruleId ,
63
63
attributes : Object . keys ( attributes ) . map ( ( key ) => ( {
64
64
id : key ,
65
65
value : attributes [ key ] ,
@@ -81,18 +81,18 @@ describe('DefaultCmabClient', () => {
81
81
requestHandler,
82
82
} ) ;
83
83
84
- const experimentId = '123' ;
84
+ const ruleId = '123' ;
85
85
const userId = 'user123' ;
86
86
const attributes = {
87
87
browser : 'chrome' ,
88
88
isMobile : true ,
89
89
} ;
90
90
const cmabUuid = 'uuid123' ;
91
91
92
- const variation = await cmabClient . fetchVariation ( experimentId , userId , attributes , cmabUuid ) ;
92
+ const variation = await cmabClient . fetchDecision ( ruleId , userId , attributes , cmabUuid ) ;
93
93
94
94
expect ( variation ) . toBe ( 'var123' ) ;
95
- assertRequest ( 0 , mockMakeRequest , experimentId , userId , attributes , cmabUuid ) ;
95
+ assertRequest ( 0 , mockMakeRequest , ruleId , userId , attributes , cmabUuid ) ;
96
96
} ) ;
97
97
98
98
it ( 'should retry fetch if retryConfig is provided' , async ( ) => {
@@ -110,20 +110,20 @@ describe('DefaultCmabClient', () => {
110
110
} ,
111
111
} ) ;
112
112
113
- const experimentId = '123' ;
113
+ const ruleId = '123' ;
114
114
const userId = 'user123' ;
115
115
const attributes = {
116
116
browser : 'chrome' ,
117
117
isMobile : true ,
118
118
} ;
119
119
const cmabUuid = 'uuid123' ;
120
120
121
- const variation = await cmabClient . fetchVariation ( experimentId , userId , attributes , cmabUuid ) ;
121
+ const variation = await cmabClient . fetchDecision ( ruleId , userId , attributes , cmabUuid ) ;
122
122
123
123
expect ( variation ) . toBe ( 'var123' ) ;
124
124
expect ( mockMakeRequest . mock . calls . length ) . toBe ( 3 ) ;
125
125
for ( let i = 0 ; i < 3 ; i ++ ) {
126
- assertRequest ( i , mockMakeRequest , experimentId , userId , attributes , cmabUuid ) ;
126
+ assertRequest ( i , mockMakeRequest , ruleId , userId , attributes , cmabUuid ) ;
127
127
}
128
128
} ) ;
129
129
@@ -157,15 +157,15 @@ describe('DefaultCmabClient', () => {
157
157
} ,
158
158
} ) ;
159
159
160
- const experimentId = '123' ;
160
+ const ruleId = '123' ;
161
161
const userId = 'user123' ;
162
162
const attributes = {
163
163
browser : 'chrome' ,
164
164
isMobile : true ,
165
165
} ;
166
166
const cmabUuid = 'uuid123' ;
167
167
168
- const fetchPromise = cmabClient . fetchVariation ( experimentId , userId , attributes , cmabUuid ) ;
168
+ const fetchPromise = cmabClient . fetchDecision ( ruleId , userId , attributes , cmabUuid ) ;
169
169
170
170
await exhaustMicrotasks ( ) ;
171
171
expect ( mockMakeRequest . mock . calls . length ) . toBe ( 1 ) ;
@@ -205,7 +205,7 @@ describe('DefaultCmabClient', () => {
205
205
expect ( variation ) . toBe ( 'var123' ) ;
206
206
expect ( mockMakeRequest . mock . calls . length ) . toBe ( 4 ) ;
207
207
for ( let i = 0 ; i < 4 ; i ++ ) {
208
- assertRequest ( i , mockMakeRequest , experimentId , userId , attributes , cmabUuid ) ;
208
+ assertRequest ( i , mockMakeRequest , ruleId , userId , attributes , cmabUuid ) ;
209
209
}
210
210
vi . useRealTimers ( ) ;
211
211
} ) ;
@@ -223,15 +223,15 @@ describe('DefaultCmabClient', () => {
223
223
} ,
224
224
} ) ;
225
225
226
- const experimentId = '123' ;
226
+ const ruleId = '123' ;
227
227
const userId = 'user123' ;
228
228
const attributes = {
229
229
browser : 'chrome' ,
230
230
isMobile : true ,
231
231
} ;
232
232
const cmabUuid = 'uuid123' ;
233
233
234
- await expect ( cmabClient . fetchVariation ( experimentId , userId , attributes , cmabUuid ) ) . rejects . toThrow ( ) ;
234
+ await expect ( cmabClient . fetchDecision ( ruleId , userId , attributes , cmabUuid ) ) . rejects . toThrow ( ) ;
235
235
expect ( mockMakeRequest . mock . calls . length ) . toBe ( 6 ) ;
236
236
} ) ;
237
237
@@ -248,15 +248,15 @@ describe('DefaultCmabClient', () => {
248
248
} ,
249
249
} ) ;
250
250
251
- const experimentId = '123' ;
251
+ const ruleId = '123' ;
252
252
const userId = 'user123' ;
253
253
const attributes = {
254
254
browser : 'chrome' ,
255
255
isMobile : true ,
256
256
} ;
257
257
const cmabUuid = 'uuid123' ;
258
258
259
- await expect ( cmabClient . fetchVariation ( experimentId , userId , attributes , cmabUuid ) ) . rejects . toThrow ( ) ;
259
+ await expect ( cmabClient . fetchDecision ( ruleId , userId , attributes , cmabUuid ) ) . rejects . toThrow ( ) ;
260
260
expect ( mockMakeRequest . mock . calls . length ) . toBe ( 6 ) ;
261
261
} ) ;
262
262
@@ -270,15 +270,15 @@ describe('DefaultCmabClient', () => {
270
270
requestHandler,
271
271
} ) ;
272
272
273
- const experimentId = '123' ;
273
+ const ruleId = '123' ;
274
274
const userId = 'user123' ;
275
275
const attributes = {
276
276
browser : 'chrome' ,
277
277
isMobile : true ,
278
278
} ;
279
279
const cmabUuid = 'uuid123' ;
280
280
281
- await expect ( cmabClient . fetchVariation ( experimentId , userId , attributes , cmabUuid ) ) . rejects . toThrow ( ) ;
281
+ await expect ( cmabClient . fetchDecision ( ruleId , userId , attributes , cmabUuid ) ) . rejects . toThrow ( ) ;
282
282
expect ( mockMakeRequest . mock . calls . length ) . toBe ( 1 ) ;
283
283
} ) ;
284
284
@@ -292,15 +292,15 @@ describe('DefaultCmabClient', () => {
292
292
requestHandler,
293
293
} ) ;
294
294
295
- const experimentId = '123' ;
295
+ const ruleId = '123' ;
296
296
const userId = 'user123' ;
297
297
const attributes = {
298
298
browser : 'chrome' ,
299
299
isMobile : true ,
300
300
} ;
301
301
const cmabUuid = 'uuid123' ;
302
302
303
- await expect ( cmabClient . fetchVariation ( experimentId , userId , attributes , cmabUuid ) ) . rejects . toMatchObject (
303
+ await expect ( cmabClient . fetchDecision ( ruleId , userId , attributes , cmabUuid ) ) . rejects . toMatchObject (
304
304
new OptimizelyError ( 'CMAB_FETCH_FAILED' , 500 ) ,
305
305
) ;
306
306
} ) ;
@@ -321,15 +321,15 @@ describe('DefaultCmabClient', () => {
321
321
requestHandler,
322
322
} ) ;
323
323
324
- const experimentId = '123' ;
324
+ const ruleId = '123' ;
325
325
const userId = 'user123' ;
326
326
const attributes = {
327
327
browser : 'chrome' ,
328
328
isMobile : true ,
329
329
} ;
330
330
const cmabUuid = 'uuid123' ;
331
331
332
- await expect ( cmabClient . fetchVariation ( experimentId , userId , attributes , cmabUuid ) ) . rejects . toMatchObject (
332
+ await expect ( cmabClient . fetchDecision ( ruleId , userId , attributes , cmabUuid ) ) . rejects . toMatchObject (
333
333
new OptimizelyError ( 'INVALID_CMAB_RESPONSE' ) ,
334
334
) ;
335
335
} ) ;
@@ -344,14 +344,14 @@ describe('DefaultCmabClient', () => {
344
344
requestHandler,
345
345
} ) ;
346
346
347
- const experimentId = '123' ;
347
+ const ruleId = '123' ;
348
348
const userId = 'user123' ;
349
349
const attributes = {
350
350
browser : 'chrome' ,
351
351
isMobile : true ,
352
352
} ;
353
353
const cmabUuid = 'uuid123' ;
354
354
355
- await expect ( cmabClient . fetchVariation ( experimentId , userId , attributes , cmabUuid ) ) . rejects . toThrow ( 'error' ) ;
355
+ await expect ( cmabClient . fetchDecision ( ruleId , userId , attributes , cmabUuid ) ) . rejects . toThrow ( 'error' ) ;
356
356
} ) ;
357
357
} ) ;
0 commit comments