@@ -22,7 +22,15 @@ import projectConfig from './project_config';
22
22
import { FEATURE_VARIABLE_TYPES , LOG_LEVEL } from '../utils/enums' ;
23
23
import testDatafile from '../tests/test_data' ;
24
24
import configValidator from '../utils/config_validator' ;
25
- import { INVALID_EXPERIMENT_ID , INVALID_EXPERIMENT_KEY } from '../error_messages' ;
25
+ import {
26
+ INVALID_EXPERIMENT_ID ,
27
+ INVALID_EXPERIMENT_KEY ,
28
+ UNEXPECTED_RESERVED_ATTRIBUTE_PREFIX ,
29
+ UNRECOGNIZED_ATTRIBUTE ,
30
+ VARIABLE_KEY_NOT_IN_DATAFILE ,
31
+ FEATURE_NOT_IN_DATAFILE ,
32
+ UNABLE_TO_CAST_VALUE
33
+ } from '../error_messages' ;
26
34
27
35
var createLogger = ( ) => ( {
28
36
debug : ( ) => { } ,
@@ -289,11 +297,11 @@ describe('lib/core/project_config', function() {
289
297
290
298
beforeEach ( function ( ) {
291
299
configObj = projectConfig . createProjectConfig ( cloneDeep ( testData ) ) ;
292
- sinon . stub ( createdLogger , 'log ' ) ;
300
+ sinon . stub ( createdLogger , 'warn ' ) ;
293
301
} ) ;
294
302
295
303
afterEach ( function ( ) {
296
- createdLogger . log . restore ( ) ;
304
+ createdLogger . warn . restore ( ) ;
297
305
} ) ;
298
306
299
307
it ( 'should retrieve experiment ID for valid experiment key in getExperimentId' , function ( ) {
@@ -329,10 +337,8 @@ describe('lib/core/project_config', function() {
329
337
330
338
it ( 'should return null for invalid attribute key in getAttributeId' , function ( ) {
331
339
assert . isNull ( projectConfig . getAttributeId ( configObj , 'invalidAttributeKey' , createdLogger ) ) ;
332
- assert . strictEqual (
333
- buildLogMessageFromArgs ( createdLogger . log . lastCall . args ) ,
334
- 'PROJECT_CONFIG: Unrecognized attribute invalidAttributeKey provided. Pruning before sending event to Optimizely.'
335
- ) ;
340
+
341
+ assert . deepEqual ( createdLogger . warn . lastCall . args , [ UNRECOGNIZED_ATTRIBUTE , 'invalidAttributeKey' ] ) ;
336
342
} ) ;
337
343
338
344
it ( 'should return null for invalid attribute key in getAttributeId' , function ( ) {
@@ -342,10 +348,8 @@ describe('lib/core/project_config', function() {
342
348
key : '$opt_some_reserved_attribute' ,
343
349
} ;
344
350
assert . strictEqual ( projectConfig . getAttributeId ( configObj , '$opt_some_reserved_attribute' , createdLogger ) , '42' ) ;
345
- assert . strictEqual (
346
- buildLogMessageFromArgs ( createdLogger . log . lastCall . args ) ,
347
- 'Attribute $opt_some_reserved_attribute unexpectedly has reserved prefix $opt_; using attribute ID instead of reserved attribute name.'
348
- ) ;
351
+
352
+ assert . deepEqual ( createdLogger . warn . lastCall . args , [ UNEXPECTED_RESERVED_ATTRIBUTE_PREFIX , '$opt_some_reserved_attribute' , '$opt_' ] ) ;
349
353
} ) ;
350
354
351
355
it ( 'should retrieve event ID for valid event key in getEventId' , function ( ) {
@@ -439,11 +443,17 @@ describe('lib/core/project_config', function() {
439
443
var featureManagementLogger = createLogger ( { logLevel : LOG_LEVEL . INFO } ) ;
440
444
beforeEach ( function ( ) {
441
445
configObj = projectConfig . createProjectConfig ( testDatafile . getTestProjectConfigWithFeatures ( ) ) ;
442
- sinon . stub ( featureManagementLogger , 'log' ) ;
446
+ sinon . stub ( featureManagementLogger , 'warn' ) ;
447
+ sinon . stub ( featureManagementLogger , 'error' ) ;
448
+ sinon . stub ( featureManagementLogger , 'info' ) ;
449
+ sinon . stub ( featureManagementLogger , 'debug' ) ;
443
450
} ) ;
444
451
445
452
afterEach ( function ( ) {
446
- featureManagementLogger . log . restore ( ) ;
453
+ featureManagementLogger . warn . restore ( ) ;
454
+ featureManagementLogger . error . restore ( ) ;
455
+ featureManagementLogger . info . restore ( ) ;
456
+ featureManagementLogger . debug . restore ( ) ;
447
457
} ) ;
448
458
449
459
describe ( 'getVariableForFeature' , function ( ) {
@@ -464,35 +474,29 @@ describe('lib/core/project_config', function() {
464
474
var variableKey = 'notARealVariable____' ;
465
475
var result = projectConfig . getVariableForFeature ( configObj , featureKey , variableKey , featureManagementLogger ) ;
466
476
assert . strictEqual ( result , null ) ;
467
- sinon . assert . calledOnce ( featureManagementLogger . log ) ;
468
- assert . strictEqual (
469
- buildLogMessageFromArgs ( featureManagementLogger . log . lastCall . args ) ,
470
- 'PROJECT_CONFIG: Variable with key "notARealVariable____" associated with feature with key "test_feature_for_experiment" is not in datafile.'
471
- ) ;
477
+ sinon . assert . calledOnce ( featureManagementLogger . error ) ;
478
+
479
+ assert . deepEqual ( featureManagementLogger . error . lastCall . args , [ VARIABLE_KEY_NOT_IN_DATAFILE , 'notARealVariable____' , 'test_feature_for_experiment' ] ) ;
472
480
} ) ;
473
481
474
482
it ( 'should return null for an invalid feature key' , function ( ) {
475
483
var featureKey = 'notARealFeature_____' ;
476
484
var variableKey = 'num_buttons' ;
477
485
var result = projectConfig . getVariableForFeature ( configObj , featureKey , variableKey , featureManagementLogger ) ;
478
486
assert . strictEqual ( result , null ) ;
479
- sinon . assert . calledOnce ( featureManagementLogger . log ) ;
480
- assert . strictEqual (
481
- buildLogMessageFromArgs ( featureManagementLogger . log . lastCall . args ) ,
482
- 'PROJECT_CONFIG: Feature key notARealFeature_____ is not in datafile.'
483
- ) ;
487
+ sinon . assert . calledOnce ( featureManagementLogger . error ) ;
488
+
489
+ assert . deepEqual ( featureManagementLogger . error . lastCall . args , [ FEATURE_NOT_IN_DATAFILE , 'notARealFeature_____' ] ) ;
484
490
} ) ;
485
491
486
492
it ( 'should return null for an invalid variable key and an invalid feature key' , function ( ) {
487
493
var featureKey = 'notARealFeature_____' ;
488
494
var variableKey = 'notARealVariable____' ;
489
495
var result = projectConfig . getVariableForFeature ( configObj , featureKey , variableKey , featureManagementLogger ) ;
490
496
assert . strictEqual ( result , null ) ;
491
- sinon . assert . calledOnce ( featureManagementLogger . log ) ;
492
- assert . strictEqual (
493
- buildLogMessageFromArgs ( featureManagementLogger . log . lastCall . args ) ,
494
- 'PROJECT_CONFIG: Feature key notARealFeature_____ is not in datafile.'
495
- ) ;
497
+ sinon . assert . calledOnce ( featureManagementLogger . error ) ;
498
+
499
+ assert . deepEqual ( featureManagementLogger . error . lastCall . args , [ FEATURE_NOT_IN_DATAFILE , 'notARealFeature_____' ] ) ;
496
500
} ) ;
497
501
} ) ;
498
502
@@ -634,10 +638,8 @@ describe('lib/core/project_config', function() {
634
638
featureManagementLogger
635
639
) ;
636
640
assert . strictEqual ( result , null ) ;
637
- assert . strictEqual (
638
- buildLogMessageFromArgs ( featureManagementLogger . log . lastCall . args ) ,
639
- 'PROJECT_CONFIG: Unable to cast value notabool to type boolean, returning null.'
640
- ) ;
641
+
642
+ assert . deepEqual ( featureManagementLogger . error . lastCall . args , [ UNABLE_TO_CAST_VALUE , 'notabool' , 'boolean' ] ) ;
641
643
} ) ;
642
644
643
645
it ( 'returns null and logs an error for an invalid integer' , function ( ) {
@@ -647,10 +649,8 @@ describe('lib/core/project_config', function() {
647
649
featureManagementLogger
648
650
) ;
649
651
assert . strictEqual ( result , null ) ;
650
- assert . strictEqual (
651
- buildLogMessageFromArgs ( featureManagementLogger . log . lastCall . args ) ,
652
- 'PROJECT_CONFIG: Unable to cast value notanint to type integer, returning null.'
653
- ) ;
652
+
653
+ assert . deepEqual ( featureManagementLogger . error . lastCall . args , [ UNABLE_TO_CAST_VALUE , 'notanint' , 'integer' ] ) ;
654
654
} ) ;
655
655
656
656
it ( 'returns null and logs an error for an invalid double' , function ( ) {
@@ -660,10 +660,8 @@ describe('lib/core/project_config', function() {
660
660
featureManagementLogger
661
661
) ;
662
662
assert . strictEqual ( result , null ) ;
663
- assert . strictEqual (
664
- buildLogMessageFromArgs ( featureManagementLogger . log . lastCall . args ) ,
665
- 'PROJECT_CONFIG: Unable to cast value notadouble to type double, returning null.'
666
- ) ;
663
+
664
+ assert . deepEqual ( featureManagementLogger . error . lastCall . args , [ UNABLE_TO_CAST_VALUE , 'notadouble' , 'double' ] ) ;
667
665
} ) ;
668
666
} ) ;
669
667
} ) ;
0 commit comments