@@ -47,9 +47,18 @@ import {
47
47
USER_DOESNT_MEET_CONDITIONS_FOR_TARGETING_RULE ,
48
48
USER_NOT_IN_EXPERIMENT ,
49
49
EXPERIMENT_NOT_RUNNING ,
50
- RETURNING_STORED_VARIATION
50
+ RETURNING_STORED_VARIATION ,
51
+ FEATURE_HAS_NO_EXPERIMENTS ,
52
+ NO_ROLLOUT_EXISTS ,
53
+ USER_BUCKETED_INTO_TARGETING_RULE ,
54
+ USER_IN_ROLLOUT ,
55
+ USER_MEETS_CONDITIONS_FOR_TARGETING_RULE ,
56
+ USER_NOT_BUCKETED_INTO_TARGETING_RULE ,
57
+ USER_NOT_IN_ROLLOUT ,
58
+ VALID_BUCKETING_ID
51
59
} from '../../log_messages' ;
52
60
import { mock } from 'node:test' ;
61
+ import { BUCKETING_ID_NOT_STRING } from '../../error_messages' ;
53
62
54
63
var testData = getTestProjectConfig ( ) ;
55
64
var testDataWithFeatures = getTestProjectConfigWithFeatures ( ) ;
@@ -1209,15 +1218,22 @@ describe('lib/core/decision_service', function() {
1209
1218
} ;
1210
1219
1211
1220
beforeEach ( function ( ) {
1212
- sinon . stub ( mockLogger , 'log' ) ;
1221
+ sinon . stub ( mockLogger , 'debug' ) ;
1222
+ sinon . stub ( mockLogger , 'info' ) ;
1223
+ sinon . stub ( mockLogger , 'warn' ) ;
1224
+ sinon . stub ( mockLogger , 'error' ) ;
1225
+
1213
1226
configObj = projectConfig . createProjectConfig ( cloneDeep ( testData ) ) ;
1214
1227
decisionService = createDecisionService ( {
1215
1228
logger : mockLogger ,
1216
1229
} ) ;
1217
1230
} ) ;
1218
1231
1219
1232
afterEach ( function ( ) {
1220
- mockLogger . log . restore ( ) ;
1233
+ mockLogger . debug . restore ( ) ;
1234
+ mockLogger . info . restore ( ) ;
1235
+ mockLogger . warn . restore ( ) ;
1236
+ mockLogger . error . restore ( ) ;
1221
1237
} ) ;
1222
1238
1223
1239
it ( 'should return userId if bucketingId is not defined in user attributes' , function ( ) {
@@ -1227,17 +1243,13 @@ describe('lib/core/decision_service', function() {
1227
1243
1228
1244
it ( 'should log warning in case of invalid bucketingId' , function ( ) {
1229
1245
assert . strictEqual ( userId , decisionService . getBucketingId ( userId , userAttributesWithInvalidBucketingId ) ) ;
1230
- assert . strictEqual ( 1 , mockLogger . log . callCount ) ;
1231
- assert . strictEqual (
1232
- buildLogMessageFromArgs ( mockLogger . log . args [ 0 ] ) ,
1233
- 'DECISION_SERVICE: BucketingID attribute is not a string. Defaulted to userId'
1234
- ) ;
1246
+ assert . deepEqual ( mockLogger . warn . args [ 0 ] , [ BUCKETING_ID_NOT_STRING ] ) ;
1235
1247
} ) ;
1236
1248
1237
1249
it ( 'should return correct bucketingId when provided in attributes' , function ( ) {
1238
1250
assert . strictEqual ( '123456789' , decisionService . getBucketingId ( userId , userAttributesWithBucketingId ) ) ;
1239
- assert . strictEqual ( 1 , mockLogger . log . callCount ) ;
1240
- assert . strictEqual ( buildLogMessageFromArgs ( mockLogger . log . args [ 0 ] ) , 'DECISION_SERVICE: BucketingId is valid: " 123456789"' ) ;
1251
+ assert . strictEqual ( 1 , mockLogger . debug . callCount ) ;
1252
+ assert . deepEqual ( mockLogger . debug . args [ 0 ] , [ VALID_BUCKETING_ID , ' 123456789' ] ) ;
1241
1253
} ) ;
1242
1254
} ) ;
1243
1255
@@ -1538,10 +1550,8 @@ describe('lib/core/decision_service', function() {
1538
1550
decisionSource : DECISION_SOURCES . ROLLOUT ,
1539
1551
} ;
1540
1552
assert . deepEqual ( decision , expectedDecision ) ;
1541
- assert . strictEqual (
1542
- buildLogMessageFromArgs ( mockLogger . log . lastCall . args ) ,
1543
- 'DECISION_SERVICE: User user1 is not in rollout of feature test_feature_for_experiment.'
1544
- ) ;
1553
+
1554
+ assert . deepEqual ( mockLogger . debug . lastCall . args , [ USER_NOT_IN_ROLLOUT , 'user1' , 'test_feature_for_experiment' ] ) ;
1545
1555
} ) ;
1546
1556
} ) ;
1547
1557
} ) ;
@@ -1634,10 +1644,8 @@ describe('lib/core/decision_service', function() {
1634
1644
decisionSource : DECISION_SOURCES . ROLLOUT ,
1635
1645
} ;
1636
1646
assert . deepEqual ( decision , expectedDecision ) ;
1637
- assert . strictEqual (
1638
- buildLogMessageFromArgs ( mockLogger . log . lastCall . args ) ,
1639
- 'DECISION_SERVICE: User user1 is not in rollout of feature feature_with_group.'
1640
- ) ;
1647
+
1648
+ assert . deepEqual ( mockLogger . debug . lastCall . args , [ USER_NOT_IN_ROLLOUT , 'user1' , 'feature_with_group' ] ) ;
1641
1649
} ) ;
1642
1650
1643
1651
it ( 'returns null decision for group experiment not referenced by the feature' , function ( ) {
@@ -1650,10 +1658,9 @@ describe('lib/core/decision_service', function() {
1650
1658
} ;
1651
1659
assert . deepEqual ( decision , expectedDecision ) ;
1652
1660
sinon . assert . calledWithExactly (
1653
- mockLogger . log ,
1654
- LOG_LEVEL . DEBUG ,
1655
- '%s: There is no rollout of feature %s.' ,
1656
- 'DECISION_SERVICE' , 'feature_exp_no_traffic'
1661
+ mockLogger . debug ,
1662
+ NO_ROLLOUT_EXISTS ,
1663
+ 'feature_exp_no_traffic'
1657
1664
) ;
1658
1665
} ) ;
1659
1666
} ) ;
@@ -1784,23 +1791,20 @@ describe('lib/core/decision_service', function() {
1784
1791
} ;
1785
1792
assert . deepEqual ( decision , expectedDecision ) ;
1786
1793
sinon . assert . calledWithExactly (
1787
- mockLogger . log ,
1788
- LOG_LEVEL . DEBUG ,
1789
- '%s: User %s meets conditions for targeting rule %s.' ,
1790
- 'DECISION_SERVICE' , 'user1' , 1
1794
+ mockLogger . debug ,
1795
+ USER_MEETS_CONDITIONS_FOR_TARGETING_RULE ,
1796
+ 'user1' , 1
1791
1797
) ;
1792
1798
sinon . assert . calledWithExactly (
1793
- mockLogger . log ,
1794
- LOG_LEVEL . DEBUG ,
1795
- '%s: User %s bucketed into targeting rule %s.' ,
1796
- 'DECISION_SERVICE' , 'user1' , 1
1799
+ mockLogger . debug ,
1800
+ USER_BUCKETED_INTO_TARGETING_RULE ,
1801
+ 'user1' , 1
1797
1802
1798
1803
) ;
1799
1804
sinon . assert . calledWithExactly (
1800
- mockLogger . log ,
1801
- LOG_LEVEL . DEBUG ,
1802
- '%s: User %s is in rollout of feature %s.' ,
1803
- 'DECISION_SERVICE' , 'user1' , 'test_feature'
1805
+ mockLogger . debug ,
1806
+ USER_IN_ROLLOUT ,
1807
+ 'user1' , 'test_feature'
1804
1808
) ;
1805
1809
} ) ;
1806
1810
} ) ;
@@ -1922,22 +1926,19 @@ describe('lib/core/decision_service', function() {
1922
1926
} ;
1923
1927
assert . deepEqual ( decision , expectedDecision ) ;
1924
1928
sinon . assert . calledWithExactly (
1925
- mockLogger . log ,
1926
- LOG_LEVEL . DEBUG ,
1927
- '%s: User %s does not meet conditions for targeting rule %s.' ,
1928
- 'DECISION_SERVICE' , 'user1' , 1
1929
+ mockLogger . debug ,
1930
+ USER_DOESNT_MEET_CONDITIONS_FOR_TARGETING_RULE ,
1931
+ 'user1' , 1
1929
1932
) ;
1930
1933
sinon . assert . calledWithExactly (
1931
- mockLogger . log ,
1932
- LOG_LEVEL . DEBUG ,
1933
- '%s: User %s bucketed into targeting rule %s.' ,
1934
- 'DECISION_SERVICE' , 'user1' , 'Everyone Else'
1934
+ mockLogger . debug ,
1935
+ USER_BUCKETED_INTO_TARGETING_RULE ,
1936
+ 'user1' , 'Everyone Else'
1935
1937
) ;
1936
1938
sinon . assert . calledWithExactly (
1937
- mockLogger . log ,
1938
- LOG_LEVEL . DEBUG ,
1939
- '%s: User %s is in rollout of feature %s.' ,
1940
- 'DECISION_SERVICE' , 'user1' , 'test_feature'
1939
+ mockLogger . debug ,
1940
+ USER_IN_ROLLOUT ,
1941
+ 'user1' , 'test_feature'
1941
1942
) ;
1942
1943
} ) ;
1943
1944
} ) ;
@@ -1965,16 +1966,14 @@ describe('lib/core/decision_service', function() {
1965
1966
} ;
1966
1967
assert . deepEqual ( decision , expectedDecision ) ;
1967
1968
sinon . assert . calledWithExactly (
1968
- mockLogger . log ,
1969
- LOG_LEVEL . DEBUG ,
1970
- '%s: User %s does not meet conditions for targeting rule %s.' ,
1971
- 'DECISION_SERVICE' , 'user1' , 1
1969
+ mockLogger . debug ,
1970
+ USER_DOESNT_MEET_CONDITIONS_FOR_TARGETING_RULE ,
1971
+ 'user1' , 1
1972
1972
) ;
1973
1973
sinon . assert . calledWithExactly (
1974
- mockLogger . log ,
1975
- LOG_LEVEL . DEBUG ,
1976
- '%s: User %s is not in rollout of feature %s.' ,
1977
- 'DECISION_SERVICE' , 'user1' , 'test_feature'
1974
+ mockLogger . debug ,
1975
+ USER_NOT_IN_ROLLOUT ,
1976
+ 'user1' , 'test_feature'
1978
1977
) ;
1979
1978
} ) ;
1980
1979
} ) ;
@@ -2107,22 +2106,19 @@ describe('lib/core/decision_service', function() {
2107
2106
} ;
2108
2107
assert . deepEqual ( decision , expectedDecision ) ;
2109
2108
sinon . assert . calledWithExactly (
2110
- mockLogger . log ,
2111
- LOG_LEVEL . DEBUG ,
2112
- '%s: User %s meets conditions for targeting rule %s.' ,
2113
- 'DECISION_SERVICE' , 'user1' , 1
2109
+ mockLogger . debug ,
2110
+ USER_MEETS_CONDITIONS_FOR_TARGETING_RULE ,
2111
+ 'user1' , 1
2114
2112
) ;
2115
2113
sinon . assert . calledWithExactly (
2116
- mockLogger . log ,
2117
- LOG_LEVEL . DEBUG ,
2118
- '%s User %s not bucketed into targeting rule %s due to traffic allocation. Trying everyone rule.' ,
2119
- 'DECISION_SERVICE' , 'user1' , 1
2114
+ mockLogger . debug ,
2115
+ USER_NOT_BUCKETED_INTO_TARGETING_RULE ,
2116
+ 'user1' , 1
2120
2117
) ;
2121
2118
sinon . assert . calledWithExactly (
2122
- mockLogger . log ,
2123
- LOG_LEVEL . DEBUG ,
2124
- '%s: User %s bucketed into targeting rule %s.' ,
2125
- 'DECISION_SERVICE' , 'user1' , 'Everyone Else'
2119
+ mockLogger . debug ,
2120
+ USER_BUCKETED_INTO_TARGETING_RULE ,
2121
+ 'user1' , 'Everyone Else'
2126
2122
) ;
2127
2123
} ) ;
2128
2124
} ) ;
@@ -2226,16 +2222,14 @@ describe('lib/core/decision_service', function() {
2226
2222
} ;
2227
2223
assert . deepEqual ( decision , expectedDecision ) ;
2228
2224
sinon . assert . calledWithExactly (
2229
- mockLogger . log ,
2230
- LOG_LEVEL . DEBUG ,
2231
- '%s: User %s bucketed into targeting rule %s.' ,
2232
- 'DECISION_SERVICE' , 'user1' , 'Everyone Else'
2225
+ mockLogger . debug ,
2226
+ USER_BUCKETED_INTO_TARGETING_RULE ,
2227
+ 'user1' , 'Everyone Else'
2233
2228
) ;
2234
2229
sinon . assert . calledWithExactly (
2235
- mockLogger . log ,
2236
- LOG_LEVEL . DEBUG ,
2237
- '%s: User %s is in rollout of feature %s.' ,
2238
- 'DECISION_SERVICE' , 'user1' , 'shared_feature'
2230
+ mockLogger . debug ,
2231
+ USER_IN_ROLLOUT ,
2232
+ 'user1' , 'shared_feature'
2239
2233
) ;
2240
2234
} ) ;
2241
2235
} ) ;
@@ -2260,16 +2254,14 @@ describe('lib/core/decision_service', function() {
2260
2254
} ;
2261
2255
assert . deepEqual ( decision , expectedDecision ) ;
2262
2256
sinon . assert . calledWithExactly (
2263
- mockLogger . log ,
2264
- LOG_LEVEL . DEBUG ,
2265
- '%s: Feature %s is not attached to any experiments.' ,
2266
- 'DECISION_SERVICE' , 'unused_flag'
2257
+ mockLogger . debug ,
2258
+ FEATURE_HAS_NO_EXPERIMENTS ,
2259
+ 'unused_flag'
2267
2260
) ;
2268
2261
sinon . assert . calledWithExactly (
2269
- mockLogger . log ,
2270
- LOG_LEVEL . DEBUG ,
2271
- '%s: There is no rollout of feature %s.' ,
2272
- 'DECISION_SERVICE' , 'unused_flag'
2262
+ mockLogger . debug ,
2263
+ NO_ROLLOUT_EXISTS ,
2264
+ 'unused_flag'
2273
2265
) ;
2274
2266
} ) ;
2275
2267
} ) ;
0 commit comments