@@ -1762,31 +1762,31 @@ describe('lib/optimizely', function() {
1762
1762
assert . strictEqual ( forcedVariation , null ) ;
1763
1763
1764
1764
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 ' ) ) ;
1766
1766
} ) ;
1767
1767
1768
1768
it ( 'should return null with an undefined experimentKey' , function ( ) {
1769
1769
var forcedVariation = optlyInstance . getForcedVariation ( undefined , 'user1' ) ;
1770
1770
assert . strictEqual ( forcedVariation , null ) ;
1771
1771
1772
1772
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 ' ) ) ;
1774
1774
} ) ;
1775
1775
1776
1776
it ( 'should return null with a null userId' , function ( ) {
1777
1777
var forcedVariation = optlyInstance . getForcedVariation ( 'testExperiment' , null ) ;
1778
1778
assert . strictEqual ( forcedVariation , null ) ;
1779
1779
1780
1780
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' ) ) ;
1782
1782
} ) ;
1783
1783
1784
1784
it ( 'should return null with an undefined userId' , function ( ) {
1785
1785
var forcedVariation = optlyInstance . getForcedVariation ( 'testExperiment' , undefined ) ;
1786
1786
assert . strictEqual ( forcedVariation , null ) ;
1787
1787
1788
1788
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' ) ) ;
1790
1790
} ) ;
1791
1791
} ) ;
1792
1792
@@ -1888,31 +1888,44 @@ describe('lib/optimizely', function() {
1888
1888
assert . strictEqual ( didSetVariation , false ) ;
1889
1889
1890
1890
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' ) ) ;
1892
1892
} ) ;
1893
1893
1894
1894
it ( 'should return false for an undefined experimentKey' , function ( ) {
1895
1895
var didSetVariation = optlyInstance . setForcedVariation ( undefined , 'user1' , 'control' ) ;
1896
1896
assert . strictEqual ( didSetVariation , false ) ;
1897
1897
1898
1898
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' ) ) ;
1900
1908
} ) ;
1901
1909
1902
1910
it ( 'should return false for a null userId' , function ( ) {
1903
1911
var didSetVariation = optlyInstance . setForcedVariation ( 'testExperiment' , null , 'control' ) ;
1904
1912
assert . strictEqual ( didSetVariation , false ) ;
1905
1913
1906
1914
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' ) ) ;
1908
1916
} ) ;
1909
1917
1910
1918
it ( 'should return false for an undefined userId' , function ( ) {
1911
1919
var didSetVariation = optlyInstance . setForcedVariation ( 'testExperiment' , undefined , 'control' ) ;
1912
1920
assert . strictEqual ( didSetVariation , false ) ;
1913
1921
1914
1922
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 ) ;
1916
1929
} ) ;
1917
1930
1918
1931
it ( 'should return false for a null variationKey' , function ( ) {
@@ -1949,6 +1962,7 @@ describe('lib/optimizely', function() {
1949
1962
describe ( '__validateInputs' , function ( ) {
1950
1963
it ( 'should return true if user ID and attributes are valid' , function ( ) {
1951
1964
assert . isTrue ( optlyInstance . __validateInputs ( { user_id : 'testUser' } ) ) ;
1965
+ assert . isTrue ( optlyInstance . __validateInputs ( { user_id : '' } ) ) ;
1952
1966
assert . isTrue ( optlyInstance . __validateInputs ( { user_id : 'testUser' } , { browser_type : 'firefox' } ) ) ;
1953
1967
sinon . assert . notCalled ( createdLogger . log ) ;
1954
1968
} ) ;
@@ -1957,11 +1971,17 @@ describe('lib/optimizely', function() {
1957
1971
var falseUserIdInput = optlyInstance . __validateInputs ( { user_id : [ ] } ) ;
1958
1972
assert . isFalse ( falseUserIdInput ) ;
1959
1973
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 ) ;
1961
1981
var errorMessage = errorHandler . handleError . lastCall . args [ 0 ] . message ;
1962
1982
assert . strictEqual ( errorMessage , sprintf ( ERROR_MESSAGES . INVALID_INPUT_FORMAT , 'OPTIMIZELY' , 'user_id' ) ) ;
1963
1983
1964
- sinon . assert . calledOnce ( createdLogger . log ) ;
1984
+ sinon . assert . calledThrice ( createdLogger . log ) ;
1965
1985
var logMessage = createdLogger . log . args [ 0 ] [ 1 ] ;
1966
1986
assert . strictEqual ( logMessage , sprintf ( ERROR_MESSAGES . INVALID_INPUT_FORMAT , 'OPTIMIZELY' , 'user_id' ) ) ;
1967
1987
} ) ;
@@ -2698,7 +2718,7 @@ describe('lib/optimizely', function() {
2698
2718
var result = optlyInstance . isFeatureEnabled ( null , null , attributes ) ;
2699
2719
assert . strictEqual ( result , false ) ;
2700
2720
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.' ) ;
2702
2722
} ) ;
2703
2723
2704
2724
it ( 'returns false when feature key is undefined' , function ( ) {
@@ -2725,7 +2745,7 @@ describe('lib/optimizely', function() {
2725
2745
var result = optlyInstance . isFeatureEnabled ( ) ;
2726
2746
assert . strictEqual ( result , false ) ;
2727
2747
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.' ) ;
2729
2749
} ) ;
2730
2750
2731
2751
it ( 'returns false when user id is an object' , function ( ) {
@@ -2749,10 +2769,10 @@ describe('lib/optimizely', function() {
2749
2769
sinon . assert . calledWithExactly ( createdLogger . log , LOG_LEVEL . ERROR , 'OPTIMIZELY: Provided feature_key is in an invalid format.' ) ;
2750
2770
} ) ;
2751
2771
2752
- it ( 'returns false when user id is an empty string' , function ( ) {
2772
+ it ( 'returns true when user id is an empty string' , function ( ) {
2753
2773
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 ) ;
2756
2776
} ) ;
2757
2777
2758
2778
it ( 'returns false when feature key is an empty string' , function ( ) {
0 commit comments