@@ -31,23 +31,23 @@ import { getTestProjectConfig } from '../../tests/test_data';
31
31
var buildLogMessageFromArgs = args => sprintf ( args [ 1 ] , ...args . splice ( 2 ) ) ;
32
32
var testData = getTestProjectConfig ( ) ;
33
33
34
- describe ( 'lib/core/bucketer' , function ( ) {
35
- describe ( 'APIs' , function ( ) {
36
- describe ( 'bucket' , function ( ) {
34
+ describe ( 'lib/core/bucketer' , function ( ) {
35
+ describe ( 'APIs' , function ( ) {
36
+ describe ( 'bucket' , function ( ) {
37
37
var configObj ;
38
38
var createdLogger = createLogger ( { logLevel : LOG_LEVEL . INFO } ) ;
39
39
var bucketerParams ;
40
40
41
- beforeEach ( function ( ) {
41
+ beforeEach ( function ( ) {
42
42
sinon . stub ( createdLogger , 'log' ) ;
43
43
} ) ;
44
44
45
- afterEach ( function ( ) {
45
+ afterEach ( function ( ) {
46
46
createdLogger . log . restore ( ) ;
47
47
} ) ;
48
48
49
- describe ( 'return values for bucketing (excluding groups)' , function ( ) {
50
- beforeEach ( function ( ) {
49
+ describe ( 'return values for bucketing (excluding groups)' , function ( ) {
50
+ beforeEach ( function ( ) {
51
51
configObj = projectConfig . createProjectConfig ( cloneDeep ( testData ) ) ;
52
52
bucketerParams = {
53
53
experimentId : configObj . experiments [ 0 ] . id ,
@@ -66,11 +66,11 @@ describe('lib/core/bucketer', function() {
66
66
. returns ( 50000 ) ;
67
67
} ) ;
68
68
69
- afterEach ( function ( ) {
69
+ afterEach ( function ( ) {
70
70
bucketer . _generateBucketValue . restore ( ) ;
71
71
} ) ;
72
72
73
- it ( 'should return decision response with correct variation ID when provided bucket value' , function ( ) {
73
+ it ( 'should return decision response with correct variation ID when provided bucket value' , function ( ) {
74
74
var bucketerParamsTest1 = cloneDeep ( bucketerParams ) ;
75
75
bucketerParamsTest1 . userId = 'ppid1' ;
76
76
var decisionResponse = bucketer . bucket ( bucketerParamsTest1 ) ;
@@ -93,9 +93,9 @@ describe('lib/core/bucketer', function() {
93
93
} ) ;
94
94
} ) ;
95
95
96
- describe ( 'return values for bucketing (including groups)' , function ( ) {
96
+ describe ( 'return values for bucketing (including groups)' , function ( ) {
97
97
var bucketerStub ;
98
- beforeEach ( function ( ) {
98
+ beforeEach ( function ( ) {
99
99
configObj = projectConfig . createProjectConfig ( cloneDeep ( testData ) ) ;
100
100
bucketerParams = {
101
101
experimentId : configObj . experiments [ 0 ] . id ,
@@ -109,13 +109,13 @@ describe('lib/core/bucketer', function() {
109
109
bucketerStub = sinon . stub ( bucketer , '_generateBucketValue' ) ;
110
110
} ) ;
111
111
112
- afterEach ( function ( ) {
112
+ afterEach ( function ( ) {
113
113
bucketer . _generateBucketValue . restore ( ) ;
114
114
} ) ;
115
115
116
- describe ( 'random groups' , function ( ) {
116
+ describe ( 'random groups' , function ( ) {
117
117
bucketerParams = { } ;
118
- beforeEach ( function ( ) {
118
+ beforeEach ( function ( ) {
119
119
bucketerParams = {
120
120
experimentId : configObj . experiments [ 4 ] . id ,
121
121
experimentKey : configObj . experiments [ 4 ] . key ,
@@ -128,7 +128,7 @@ describe('lib/core/bucketer', function() {
128
128
} ;
129
129
} ) ;
130
130
131
- it ( 'should return decision response with the proper variation for a user in a grouped experiment' , function ( ) {
131
+ it ( 'should return decision response with the proper variation for a user in a grouped experiment' , function ( ) {
132
132
bucketerStub . onFirstCall ( ) . returns ( 50 ) ;
133
133
bucketerStub . onSecondCall ( ) . returns ( 50 ) ;
134
134
@@ -160,7 +160,7 @@ describe('lib/core/bucketer', function() {
160
160
) ;
161
161
} ) ;
162
162
163
- it ( 'should return decision response with variation null when a user is bucketed into a different grouped experiment than the one speicfied' , function ( ) {
163
+ it ( 'should return decision response with variation null when a user is bucketed into a different grouped experiment than the one speicfied' , function ( ) {
164
164
bucketerStub . returns ( 5000 ) ;
165
165
166
166
var decisionResponse = bucketer . bucket ( bucketerParams ) ;
@@ -185,7 +185,7 @@ describe('lib/core/bucketer', function() {
185
185
) ;
186
186
} ) ;
187
187
188
- it ( 'should return decision response with variation null when a user is not bucketed into any experiments in the random group' , function ( ) {
188
+ it ( 'should return decision response with variation null when a user is not bucketed into any experiments in the random group' , function ( ) {
189
189
bucketerStub . returns ( 50000 ) ;
190
190
191
191
var decisionResponse = bucketer . bucket ( bucketerParams ) ;
@@ -202,7 +202,7 @@ describe('lib/core/bucketer', function() {
202
202
expect ( log2 ) . to . equal ( sprintf ( LOG_MESSAGES . USER_NOT_IN_ANY_EXPERIMENT , 'BUCKETER' , 'testUser' , '666' ) ) ;
203
203
} ) ;
204
204
205
- it ( 'should return decision response with variation null when a user is bucketed into traffic space of deleted experiment within a random group' , function ( ) {
205
+ it ( 'should return decision response with variation null when a user is bucketed into traffic space of deleted experiment within a random group' , function ( ) {
206
206
bucketerStub . returns ( 9000 ) ;
207
207
208
208
var decisionResponse = bucketer . bucket ( bucketerParams ) ;
@@ -219,19 +219,19 @@ describe('lib/core/bucketer', function() {
219
219
expect ( log2 ) . to . equal ( sprintf ( LOG_MESSAGES . USER_NOT_IN_ANY_EXPERIMENT , 'BUCKETER' , 'testUser' , '666' ) ) ;
220
220
} ) ;
221
221
222
- it ( 'should throw an error if group ID is not in the datafile' , function ( ) {
222
+ it ( 'should throw an error if group ID is not in the datafile' , function ( ) {
223
223
var bucketerParamsWithInvalidGroupId = cloneDeep ( bucketerParams ) ;
224
224
bucketerParamsWithInvalidGroupId . experimentIdMap [ configObj . experiments [ 4 ] . id ] . groupId = '6969' ;
225
225
226
- assert . throws ( function ( ) {
226
+ assert . throws ( function ( ) {
227
227
bucketer . bucket ( bucketerParamsWithInvalidGroupId ) ;
228
228
} , sprintf ( ERROR_MESSAGES . INVALID_GROUP_ID , 'BUCKETER' , '6969' ) ) ;
229
229
} ) ;
230
230
} ) ;
231
231
232
- describe ( 'overlapping groups' , function ( ) {
232
+ describe ( 'overlapping groups' , function ( ) {
233
233
bucketerParams = { } ;
234
- beforeEach ( function ( ) {
234
+ beforeEach ( function ( ) {
235
235
bucketerParams = {
236
236
experimentId : configObj . experiments [ 6 ] . id ,
237
237
experimentKey : configObj . experiments [ 6 ] . key ,
@@ -244,7 +244,7 @@ describe('lib/core/bucketer', function() {
244
244
} ;
245
245
} ) ;
246
246
247
- it ( 'should return decision response with variation when a user falls into an experiment within an overlapping group' , function ( ) {
247
+ it ( 'should return decision response with variation when a user falls into an experiment within an overlapping group' , function ( ) {
248
248
bucketerStub . returns ( 0 ) ;
249
249
250
250
var decisionResponse = bucketer . bucket ( bucketerParams ) ;
@@ -257,7 +257,7 @@ describe('lib/core/bucketer', function() {
257
257
expect ( log1 ) . to . equal ( sprintf ( LOG_MESSAGES . USER_ASSIGNED_TO_EXPERIMENT_BUCKET , 'BUCKETER' , '0' , 'testUser' ) ) ;
258
258
} ) ;
259
259
260
- it ( 'should return decision response with variation null when a user does not fall into an experiment within an overlapping group' , function ( ) {
260
+ it ( 'should return decision response with variation null when a user does not fall into an experiment within an overlapping group' , function ( ) {
261
261
bucketerStub . returns ( 3000 ) ;
262
262
263
263
var decisionResponse = bucketer . bucket ( bucketerParams ) ;
@@ -266,8 +266,8 @@ describe('lib/core/bucketer', function() {
266
266
} ) ;
267
267
} ) ;
268
268
269
- describe ( 'when the bucket value falls into empty traffic allocation ranges' , function ( ) {
270
- beforeEach ( function ( ) {
269
+ describe ( 'when the bucket value falls into empty traffic allocation ranges' , function ( ) {
270
+ beforeEach ( function ( ) {
271
271
configObj = projectConfig . createProjectConfig ( cloneDeep ( testData ) ) ;
272
272
bucketerParams = {
273
273
experimentId : configObj . experiments [ 0 ] . id ,
@@ -289,14 +289,14 @@ describe('lib/core/bucketer', function() {
289
289
} ;
290
290
} ) ;
291
291
292
- it ( 'should return decision response with variation null' , function ( ) {
292
+ it ( 'should return decision response with variation null' , function ( ) {
293
293
var bucketerParamsTest1 = cloneDeep ( bucketerParams ) ;
294
294
bucketerParamsTest1 . userId = 'ppid1' ;
295
295
var decisionResponse = bucketer . bucket ( bucketerParamsTest1 ) ;
296
296
expect ( decisionResponse . result ) . to . equal ( null ) ;
297
297
} ) ;
298
298
299
- it ( 'should not log an invalid variation ID warning' , function ( ) {
299
+ it ( 'should not log an invalid variation ID warning' , function ( ) {
300
300
bucketer . bucket ( bucketerParams )
301
301
const foundInvalidVariationWarning = createdLogger . log . getCalls ( ) . some ( ( call ) => {
302
302
const message = call . args [ 1 ] ;
@@ -306,8 +306,8 @@ describe('lib/core/bucketer', function() {
306
306
} ) ;
307
307
} ) ;
308
308
309
- describe ( 'when the traffic allocation has invalid variation ids' , function ( ) {
310
- beforeEach ( function ( ) {
309
+ describe ( 'when the traffic allocation has invalid variation ids' , function ( ) {
310
+ beforeEach ( function ( ) {
311
311
configObj = projectConfig . createProjectConfig ( cloneDeep ( testData ) ) ;
312
312
bucketerParams = {
313
313
experimentId : configObj . experiments [ 0 ] . id ,
@@ -329,7 +329,7 @@ describe('lib/core/bucketer', function() {
329
329
} ;
330
330
} ) ;
331
331
332
- it ( 'should return decision response with variation null' , function ( ) {
332
+ it ( 'should return decision response with variation null' , function ( ) {
333
333
var bucketerParamsTest1 = cloneDeep ( bucketerParams ) ;
334
334
bucketerParamsTest1 . userId = 'ppid1' ;
335
335
var decisionResponse = bucketer . bucket ( bucketerParamsTest1 ) ;
@@ -338,8 +338,8 @@ describe('lib/core/bucketer', function() {
338
338
} ) ;
339
339
} ) ;
340
340
341
- describe ( '_generateBucketValue' , function ( ) {
342
- it ( 'should return a bucket value for different inputs' , function ( ) {
341
+ describe ( '_generateBucketValue' , function ( ) {
342
+ it ( 'should return a bucket value for different inputs' , function ( ) {
343
343
var experimentId = 1886780721 ;
344
344
var bucketingKey1 = sprintf ( '%s%s' , 'ppid1' , experimentId ) ;
345
345
var bucketingKey2 = sprintf ( '%s%s' , 'ppid2' , experimentId ) ;
@@ -352,21 +352,21 @@ describe('lib/core/bucketer', function() {
352
352
expect ( bucketer . _generateBucketValue ( bucketingKey4 ) ) . to . equal ( 5439 ) ;
353
353
} ) ;
354
354
355
- it ( 'should return an error if it cannot generate the hash value' , function ( ) {
356
- assert . throws ( function ( ) {
355
+ it ( 'should return an error if it cannot generate the hash value' , function ( ) {
356
+ assert . throws ( function ( ) {
357
357
bucketer . _generateBucketValue ( null ) ;
358
358
} , sprintf ( ERROR_MESSAGES . INVALID_BUCKETING_ID , 'BUCKETER' , null , "Cannot read property 'length' of null" ) ) ;
359
359
} ) ;
360
360
} ) ;
361
361
362
- describe ( 'testBucketWithBucketingId' , function ( ) {
362
+ describe ( 'testBucketWithBucketingId' , function ( ) {
363
363
var bucketerParams ;
364
364
var createdLogger = createLogger ( {
365
365
logLevel : LOG_LEVEL . INFO ,
366
366
logToConsole : false ,
367
367
} ) ;
368
368
369
- beforeEach ( function ( ) {
369
+ beforeEach ( function ( ) {
370
370
var configObj = projectConfig . createProjectConfig ( cloneDeep ( testData ) ) ;
371
371
bucketerParams = {
372
372
trafficAllocationConfig : configObj . experiments [ 0 ] . trafficAllocation ,
@@ -377,7 +377,7 @@ describe('lib/core/bucketer', function() {
377
377
} ;
378
378
} ) ;
379
379
380
- it ( 'check that a non null bucketingId buckets a variation different than the one expected with userId' , function ( ) {
380
+ it ( 'check that a non null bucketingId buckets a variation different than the one expected with userId' , function ( ) {
381
381
var bucketerParams1 = cloneDeep ( bucketerParams ) ;
382
382
bucketerParams1 [ 'userId' ] = 'testBucketingIdControl' ;
383
383
bucketerParams1 [ 'bucketingId' ] = '123456789' ;
@@ -386,7 +386,7 @@ describe('lib/core/bucketer', function() {
386
386
expect ( bucketer . bucket ( bucketerParams1 ) . result ) . to . equal ( '111129' ) ;
387
387
} ) ;
388
388
389
- it ( 'check that a null bucketing ID defaults to bucketing with the userId' , function ( ) {
389
+ it ( 'check that a null bucketing ID defaults to bucketing with the userId' , function ( ) {
390
390
var bucketerParams2 = cloneDeep ( bucketerParams ) ;
391
391
bucketerParams2 [ 'userId' ] = 'testBucketingIdControl' ;
392
392
bucketerParams2 [ 'bucketingId' ] = null ;
@@ -395,7 +395,7 @@ describe('lib/core/bucketer', function() {
395
395
expect ( bucketer . bucket ( bucketerParams2 ) . result ) . to . equal ( '111128' ) ;
396
396
} ) ;
397
397
398
- it ( 'check that bucketing works with an experiment in group' , function ( ) {
398
+ it ( 'check that bucketing works with an experiment in group' , function ( ) {
399
399
var bucketerParams4 = cloneDeep ( bucketerParams ) ;
400
400
bucketerParams4 [ 'userId' ] = 'testBucketingIdControl' ;
401
401
bucketerParams4 [ 'bucketingId' ] = '123456789' ;
0 commit comments