16
16
import sinon from 'sinon' ;
17
17
import { assert } from 'chai' ;
18
18
import { getLogger } from '@optimizely/js-sdk-logging' ;
19
+ import { sprintf } from '@optimizely/js-sdk-utils' ;
19
20
20
21
import { createAudienceEvaluator } from './index' ;
21
22
import * as conditionTreeEvaluator from '../condition_tree_evaluator' ;
22
23
import * as customAttributeConditionEvaluator from '../custom_attribute_condition_evaluator' ;
23
24
25
+ var buildLogMessageFromArgs = args => sprintf ( args [ 1 ] , ...args . splice ( 2 ) ) ;
24
26
var mockLogger = getLogger ( ) ;
25
27
26
28
var chromeUserAudience = {
@@ -233,10 +235,10 @@ describe('lib/core/audience_evaluator', function() {
233
235
assert . isFalse ( result ) ;
234
236
assert . strictEqual ( 2 , mockLogger . log . callCount ) ;
235
237
assert . strictEqual (
236
- mockLogger . log . args [ 0 ] [ 1 ] ,
238
+ buildLogMessageFromArgs ( mockLogger . log . args [ 0 ] ) ,
237
239
'AUDIENCE_EVALUATOR: Starting to evaluate audience "1" with conditions: ["and",{"name":"device_model","value":"iphone","type":"custom_attribute"}].'
238
240
) ;
239
- assert . strictEqual ( mockLogger . log . args [ 1 ] [ 1 ] , 'AUDIENCE_EVALUATOR: Audience "1" evaluated to UNKNOWN.' ) ;
241
+ assert . strictEqual ( buildLogMessageFromArgs ( mockLogger . log . args [ 1 ] ) , 'AUDIENCE_EVALUATOR: Audience "1" evaluated to UNKNOWN.' ) ;
240
242
} ) ;
241
243
242
244
it ( 'logs correctly when conditionTreeEvaluator.evaluate returns true' , function ( ) {
@@ -255,10 +257,10 @@ describe('lib/core/audience_evaluator', function() {
255
257
assert . isTrue ( result ) ;
256
258
assert . strictEqual ( 2 , mockLogger . log . callCount ) ;
257
259
assert . strictEqual (
258
- mockLogger . log . args [ 0 ] [ 1 ] ,
260
+ buildLogMessageFromArgs ( mockLogger . log . args [ 0 ] ) ,
259
261
'AUDIENCE_EVALUATOR: Starting to evaluate audience "1" with conditions: ["and",{"name":"device_model","value":"iphone","type":"custom_attribute"}].'
260
262
) ;
261
- assert . strictEqual ( mockLogger . log . args [ 1 ] [ 1 ] , 'AUDIENCE_EVALUATOR: Audience "1" evaluated to TRUE.' ) ;
263
+ assert . strictEqual ( buildLogMessageFromArgs ( mockLogger . log . args [ 1 ] ) , 'AUDIENCE_EVALUATOR: Audience "1" evaluated to TRUE.' ) ;
262
264
} ) ;
263
265
264
266
it ( 'logs correctly when conditionTreeEvaluator.evaluate returns false' , function ( ) {
@@ -277,10 +279,10 @@ describe('lib/core/audience_evaluator', function() {
277
279
assert . isFalse ( result ) ;
278
280
assert . strictEqual ( 2 , mockLogger . log . callCount ) ;
279
281
assert . strictEqual (
280
- mockLogger . log . args [ 0 ] [ 1 ] ,
282
+ buildLogMessageFromArgs ( mockLogger . log . args [ 0 ] ) ,
281
283
'AUDIENCE_EVALUATOR: Starting to evaluate audience "1" with conditions: ["and",{"name":"device_model","value":"iphone","type":"custom_attribute"}].'
282
284
) ;
283
- assert . strictEqual ( mockLogger . log . args [ 1 ] [ 1 ] , 'AUDIENCE_EVALUATOR: Audience "1" evaluated to FALSE.' ) ;
285
+ assert . strictEqual ( buildLogMessageFromArgs ( mockLogger . log . args [ 1 ] ) , 'AUDIENCE_EVALUATOR: Audience "1" evaluated to FALSE.' ) ;
284
286
} ) ;
285
287
} ) ;
286
288
} ) ;
0 commit comments