@@ -1762,31 +1762,31 @@ describe('lib/optimizely', function() {
17621762 assert . strictEqual ( forcedVariation , null ) ;
17631763
17641764 var logMessage = createdLogger . log . args [ 0 ] [ 1 ] ;
1765- assert . strictEqual ( logMessage , sprintf ( LOG_MESSAGES . USER_HAS_NO_FORCED_VARIATION , 'PROJECT_CONFIG ' , 'user1 ' ) ) ;
1765+ assert . strictEqual ( logMessage , sprintf ( ERROR_MESSAGES . INVALID_INPUT_FORMAT , 'OPTIMIZELY ' , 'experiment_key ' ) ) ;
17661766 } ) ;
17671767
17681768 it ( 'should return null with an undefined experimentKey' , function ( ) {
17691769 var forcedVariation = optlyInstance . getForcedVariation ( undefined , 'user1' ) ;
17701770 assert . strictEqual ( forcedVariation , null ) ;
17711771
17721772 var logMessage = createdLogger . log . args [ 0 ] [ 1 ] ;
1773- assert . strictEqual ( logMessage , sprintf ( LOG_MESSAGES . USER_HAS_NO_FORCED_VARIATION , 'PROJECT_CONFIG ' , 'user1 ' ) ) ;
1773+ assert . strictEqual ( logMessage , sprintf ( ERROR_MESSAGES . INVALID_INPUT_FORMAT , 'OPTIMIZELY ' , 'experiment_key ' ) ) ;
17741774 } ) ;
17751775
17761776 it ( 'should return null with a null userId' , function ( ) {
17771777 var forcedVariation = optlyInstance . getForcedVariation ( 'testExperiment' , null ) ;
17781778 assert . strictEqual ( forcedVariation , null ) ;
17791779
17801780 var logMessage = createdLogger . log . args [ 0 ] [ 1 ] ;
1781- assert . strictEqual ( logMessage , sprintf ( LOG_MESSAGES . USER_HAS_NO_FORCED_VARIATION , 'PROJECT_CONFIG ' , null ) ) ;
1781+ assert . strictEqual ( logMessage , sprintf ( ERROR_MESSAGES . INVALID_INPUT_FORMAT , 'OPTIMIZELY ' , 'user_id' ) ) ;
17821782 } ) ;
17831783
17841784 it ( 'should return null with an undefined userId' , function ( ) {
17851785 var forcedVariation = optlyInstance . getForcedVariation ( 'testExperiment' , undefined ) ;
17861786 assert . strictEqual ( forcedVariation , null ) ;
17871787
17881788 var logMessage = createdLogger . log . args [ 0 ] [ 1 ] ;
1789- assert . strictEqual ( logMessage , sprintf ( LOG_MESSAGES . USER_HAS_NO_FORCED_VARIATION , 'PROJECT_CONFIG ' , undefined ) ) ;
1789+ assert . strictEqual ( logMessage , sprintf ( ERROR_MESSAGES . INVALID_INPUT_FORMAT , 'OPTIMIZELY ' , 'user_id' ) ) ;
17901790 } ) ;
17911791 } ) ;
17921792
@@ -1888,31 +1888,44 @@ describe('lib/optimizely', function() {
18881888 assert . strictEqual ( didSetVariation , false ) ;
18891889
18901890 var setVariationLogMessage = createdLogger . log . args [ 0 ] [ 1 ] ;
1891- assert . strictEqual ( setVariationLogMessage , 'PROJECT_CONFIG: Experiment key null is not in datafile.' ) ;
1891+ assert . strictEqual ( setVariationLogMessage , sprintf ( ERROR_MESSAGES . INVALID_INPUT_FORMAT , 'OPTIMIZELY' , 'experiment_key' ) ) ;
18921892 } ) ;
18931893
18941894 it ( 'should return false for an undefined experimentKey' , function ( ) {
18951895 var didSetVariation = optlyInstance . setForcedVariation ( undefined , 'user1' , 'control' ) ;
18961896 assert . strictEqual ( didSetVariation , false ) ;
18971897
18981898 var setVariationLogMessage = createdLogger . log . args [ 0 ] [ 1 ] ;
1899- assert . strictEqual ( setVariationLogMessage , 'PROJECT_CONFIG: Experiment key undefined is not in datafile.' ) ;
1899+ assert . strictEqual ( setVariationLogMessage , sprintf ( ERROR_MESSAGES . INVALID_INPUT_FORMAT , 'OPTIMIZELY' , 'experiment_key' ) ) ;
1900+ } ) ;
1901+
1902+ it ( 'should return false for an empty experimentKey' , function ( ) {
1903+ var didSetVariation = optlyInstance . setForcedVariation ( '' , 'user1' , 'control' ) ;
1904+ assert . strictEqual ( didSetVariation , false ) ;
1905+
1906+ var setVariationLogMessage = createdLogger . log . args [ 0 ] [ 1 ] ;
1907+ assert . strictEqual ( setVariationLogMessage , sprintf ( ERROR_MESSAGES . INVALID_INPUT_FORMAT , 'OPTIMIZELY' , 'experiment_key' ) ) ;
19001908 } ) ;
19011909
19021910 it ( 'should return false for a null userId' , function ( ) {
19031911 var didSetVariation = optlyInstance . setForcedVariation ( 'testExperiment' , null , 'control' ) ;
19041912 assert . strictEqual ( didSetVariation , false ) ;
19051913
19061914 var setVariationLogMessage = createdLogger . log . args [ 0 ] [ 1 ] ;
1907- assert . strictEqual ( setVariationLogMessage , 'PROJECT_CONFIG: Provided user ID is in an invalid format.' ) ;
1915+ assert . strictEqual ( setVariationLogMessage , sprintf ( ERROR_MESSAGES . INVALID_INPUT_FORMAT , 'OPTIMIZELY' , 'user_id' ) ) ;
19081916 } ) ;
19091917
19101918 it ( 'should return false for an undefined userId' , function ( ) {
19111919 var didSetVariation = optlyInstance . setForcedVariation ( 'testExperiment' , undefined , 'control' ) ;
19121920 assert . strictEqual ( didSetVariation , false ) ;
19131921
19141922 var setVariationLogMessage = createdLogger . log . args [ 0 ] [ 1 ] ;
1915- assert . strictEqual ( setVariationLogMessage , 'PROJECT_CONFIG: Provided user ID is in an invalid format.' ) ;
1923+ assert . strictEqual ( setVariationLogMessage , sprintf ( ERROR_MESSAGES . INVALID_INPUT_FORMAT , 'OPTIMIZELY' , 'user_id' ) ) ;
1924+ } ) ;
1925+
1926+ it ( 'should return true for an empty userId' , function ( ) {
1927+ var didSetVariation = optlyInstance . setForcedVariation ( 'testExperiment' , '' , 'control' ) ;
1928+ assert . strictEqual ( didSetVariation , true ) ;
19161929 } ) ;
19171930
19181931 it ( 'should return false for a null variationKey' , function ( ) {
@@ -1949,6 +1962,7 @@ describe('lib/optimizely', function() {
19491962 describe ( '__validateInputs' , function ( ) {
19501963 it ( 'should return true if user ID and attributes are valid' , function ( ) {
19511964 assert . isTrue ( optlyInstance . __validateInputs ( { user_id : 'testUser' } ) ) ;
1965+ assert . isTrue ( optlyInstance . __validateInputs ( { user_id : '' } ) ) ;
19521966 assert . isTrue ( optlyInstance . __validateInputs ( { user_id : 'testUser' } , { browser_type : 'firefox' } ) ) ;
19531967 sinon . assert . notCalled ( createdLogger . log ) ;
19541968 } ) ;
@@ -1957,11 +1971,17 @@ describe('lib/optimizely', function() {
19571971 var falseUserIdInput = optlyInstance . __validateInputs ( { user_id : [ ] } ) ;
19581972 assert . isFalse ( falseUserIdInput ) ;
19591973
1960- sinon . assert . calledOnce ( errorHandler . handleError ) ;
1974+ falseUserIdInput = optlyInstance . __validateInputs ( { user_id : null } ) ;
1975+ assert . isFalse ( falseUserIdInput ) ;
1976+
1977+ falseUserIdInput = optlyInstance . __validateInputs ( { user_id : 3.14 } ) ;
1978+ assert . isFalse ( falseUserIdInput ) ;
1979+
1980+ sinon . assert . calledThrice ( errorHandler . handleError ) ;
19611981 var errorMessage = errorHandler . handleError . lastCall . args [ 0 ] . message ;
19621982 assert . strictEqual ( errorMessage , sprintf ( ERROR_MESSAGES . INVALID_INPUT_FORMAT , 'OPTIMIZELY' , 'user_id' ) ) ;
19631983
1964- sinon . assert . calledOnce ( createdLogger . log ) ;
1984+ sinon . assert . calledThrice ( createdLogger . log ) ;
19651985 var logMessage = createdLogger . log . args [ 0 ] [ 1 ] ;
19661986 assert . strictEqual ( logMessage , sprintf ( ERROR_MESSAGES . INVALID_INPUT_FORMAT , 'OPTIMIZELY' , 'user_id' ) ) ;
19671987 } ) ;
@@ -2698,7 +2718,7 @@ describe('lib/optimizely', function() {
26982718 var result = optlyInstance . isFeatureEnabled ( null , null , attributes ) ;
26992719 assert . strictEqual ( result , false ) ;
27002720 sinon . assert . notCalled ( eventDispatcher . dispatchEvent ) ;
2701- sinon . assert . calledWithExactly ( createdLogger . log , LOG_LEVEL . ERROR , 'OPTIMIZELY: Provided feature_key is in an invalid format.' ) ;
2721+ sinon . assert . calledWithExactly ( createdLogger . log , LOG_LEVEL . ERROR , 'OPTIMIZELY: Provided user_id is in an invalid format.' ) ;
27022722 } ) ;
27032723
27042724 it ( 'returns false when feature key is undefined' , function ( ) {
@@ -2725,7 +2745,7 @@ describe('lib/optimizely', function() {
27252745 var result = optlyInstance . isFeatureEnabled ( ) ;
27262746 assert . strictEqual ( result , false ) ;
27272747 sinon . assert . notCalled ( eventDispatcher . dispatchEvent ) ;
2728- sinon . assert . calledWithExactly ( createdLogger . log , LOG_LEVEL . ERROR , 'OPTIMIZELY: Provided feature_key is in an invalid format.' ) ;
2748+ sinon . assert . calledWithExactly ( createdLogger . log , LOG_LEVEL . ERROR , 'OPTIMIZELY: Provided user_id is in an invalid format.' ) ;
27292749 } ) ;
27302750
27312751 it ( 'returns false when user id is an object' , function ( ) {
@@ -2749,10 +2769,10 @@ describe('lib/optimizely', function() {
27492769 sinon . assert . calledWithExactly ( createdLogger . log , LOG_LEVEL . ERROR , 'OPTIMIZELY: Provided feature_key is in an invalid format.' ) ;
27502770 } ) ;
27512771
2752- it ( 'returns false when user id is an empty string' , function ( ) {
2772+ it ( 'returns true when user id is an empty string' , function ( ) {
27532773 var result = optlyInstance . isFeatureEnabled ( 'test_feature_for_experiment' , '' , attributes ) ;
2754- assert . strictEqual ( result , false ) ;
2755- sinon . assert . notCalled ( eventDispatcher . dispatchEvent ) ;
2774+ assert . strictEqual ( result , true ) ;
2775+ sinon . assert . calledOnce ( eventDispatcher . dispatchEvent ) ;
27562776 } ) ;
27572777
27582778 it ( 'returns false when feature key is an empty string' , function ( ) {
0 commit comments