diff --git a/packages/optimizely-sdk/lib/core/bucketer/index.js b/packages/optimizely-sdk/lib/core/bucketer/index.js index 0b458ca15..c6beae0d0 100644 --- a/packages/optimizely-sdk/lib/core/bucketer/index.js +++ b/packages/optimizely-sdk/lib/core/bucketer/index.js @@ -104,7 +104,7 @@ export var bucket = function(bucketerParams) { var bucketValue = this._generateBucketValue(bucketingId); var bucketedUserLogMessage = sprintf( - LOG_MESSAGES.USER_ASSIGNED_TO_VARIATION_BUCKET, + LOG_MESSAGES.USER_ASSIGNED_TO_EXPERIMENT_BUCKET, MODULE_NAME, bucketValue, bucketerParams.userId @@ -112,28 +112,11 @@ export var bucket = function(bucketerParams) { bucketerParams.logger.log(LOG_LEVEL.DEBUG, bucketedUserLogMessage); var entityId = this._findBucket(bucketValue, bucketerParams.trafficAllocationConfig); - if (!entityId) { - var userHasNoVariationLogMessage = sprintf( - LOG_MESSAGES.USER_HAS_NO_VARIATION, - MODULE_NAME, - bucketerParams.userId, - bucketerParams.experimentKey - ); - bucketerParams.logger.log(LOG_LEVEL.DEBUG, userHasNoVariationLogMessage); - } else if (!bucketerParams.variationIdMap.hasOwnProperty(entityId)) { + + if (!bucketerParams.variationIdMap.hasOwnProperty(entityId)) { var invalidVariationIdLogMessage = sprintf(LOG_MESSAGES.INVALID_VARIATION_ID, MODULE_NAME); bucketerParams.logger.log(LOG_LEVEL.WARNING, invalidVariationIdLogMessage); return null; - } else { - var variationKey = bucketerParams.variationIdMap[entityId].key; - var userInVariationLogMessage = sprintf( - LOG_MESSAGES.USER_HAS_VARIATION, - MODULE_NAME, - bucketerParams.userId, - variationKey, - bucketerParams.experimentKey - ); - bucketerParams.logger.log(LOG_LEVEL.INFO, userInVariationLogMessage); } return entityId; diff --git a/packages/optimizely-sdk/lib/core/bucketer/index.tests.js b/packages/optimizely-sdk/lib/core/bucketer/index.tests.js index b2c45784f..8308301ab 100644 --- a/packages/optimizely-sdk/lib/core/bucketer/index.tests.js +++ b/packages/optimizely-sdk/lib/core/bucketer/index.tests.js @@ -75,27 +75,18 @@ describe('lib/core/bucketer', function() { expect(bucketer.bucket(bucketerParamsTest1)).to.equal('111128'); var bucketedUser_log1 = createdLogger.log.args[0][1]; - var bucketedUser_log2 = createdLogger.log.args[1][1]; - expect(bucketedUser_log1).to.equal( - sprintf(LOG_MESSAGES.USER_ASSIGNED_TO_VARIATION_BUCKET, 'BUCKETER', '50', 'ppid1') - ); - expect(bucketedUser_log2).to.equal( - sprintf(LOG_MESSAGES.USER_HAS_VARIATION, 'BUCKETER', 'ppid1', 'control', 'testExperiment') + sprintf(LOG_MESSAGES.USER_ASSIGNED_TO_EXPERIMENT_BUCKET, 'BUCKETER', '50', 'ppid1') ); var bucketerParamsTest2 = cloneDeep(bucketerParams); bucketerParamsTest2.userId = 'ppid2'; expect(bucketer.bucket(bucketerParamsTest2)).to.equal(null); - var notBucketedUser_log1 = createdLogger.log.args[2][1]; - var notBucketedUser_log2 = createdLogger.log.args[3][1]; + var notBucketedUser_log1 = createdLogger.log.args[1][1]; expect(notBucketedUser_log1).to.equal( - sprintf(LOG_MESSAGES.USER_ASSIGNED_TO_VARIATION_BUCKET, 'BUCKETER', '50000', 'ppid2') - ); - expect(notBucketedUser_log2).to.equal( - sprintf(LOG_MESSAGES.USER_HAS_NO_VARIATION, 'BUCKETER', 'ppid2', 'testExperiment') + sprintf(LOG_MESSAGES.USER_ASSIGNED_TO_EXPERIMENT_BUCKET, 'BUCKETER', '50000', 'ppid2') ); }); }); @@ -142,7 +133,7 @@ describe('lib/core/bucketer', function() { expect(bucketer.bucket(bucketerParams)).to.equal('551'); sinon.assert.calledTwice(bucketerStub); - sinon.assert.callCount(createdLogger.log, 4); + sinon.assert.callCount(createdLogger.log, 3); var log1 = createdLogger.log.args[0][1]; expect(log1).to.equal( @@ -162,12 +153,7 @@ describe('lib/core/bucketer', function() { var log3 = createdLogger.log.args[2][1]; expect(log3).to.equal( - sprintf(LOG_MESSAGES.USER_ASSIGNED_TO_VARIATION_BUCKET, 'BUCKETER', '50', 'testUser') - ); - - var log4 = createdLogger.log.args[3][1]; - expect(log4).to.equal( - sprintf(LOG_MESSAGES.USER_HAS_VARIATION, 'BUCKETER', 'testUser', 'var1exp1', 'groupExperiment1') + sprintf(LOG_MESSAGES.USER_ASSIGNED_TO_EXPERIMENT_BUCKET, 'BUCKETER', '50', 'testUser') ); }); @@ -258,20 +244,10 @@ describe('lib/core/bucketer', function() { expect(bucketer.bucket(bucketerParams)).to.equal('553'); sinon.assert.calledOnce(bucketerStub); - sinon.assert.calledTwice(createdLogger.log); + sinon.assert.calledOnce(createdLogger.log); var log1 = createdLogger.log.args[0][1]; - expect(log1).to.equal(sprintf(LOG_MESSAGES.USER_ASSIGNED_TO_VARIATION_BUCKET, 'BUCKETER', '0', 'testUser')); - var log2 = createdLogger.log.args[1][1]; - expect(log2).to.equal( - sprintf( - LOG_MESSAGES.USER_HAS_VARIATION, - 'BUCKETER', - 'testUser', - 'overlappingvar1', - 'overlappingGroupExperiment1' - ) - ); + expect(log1).to.equal(sprintf(LOG_MESSAGES.USER_ASSIGNED_TO_EXPERIMENT_BUCKET, 'BUCKETER', '0', 'testUser')); }); it('should return null when a user does not fall into an experiment within an overlapping group', function() { @@ -308,7 +284,7 @@ describe('lib/core/bucketer', function() { it('should return null', function() { var bucketerParamsTest1 = cloneDeep(bucketerParams); bucketerParamsTest1.userId = 'ppid1'; - expect(bucketer.bucket(bucketerParamsTest1)).to.equal(''); + expect(bucketer.bucket(bucketerParamsTest1)).to.equal(null); }); }); diff --git a/packages/optimizely-sdk/lib/core/decision_service/index.js b/packages/optimizely-sdk/lib/core/decision_service/index.js index 6c4ab46e6..6f5686fb1 100644 --- a/packages/optimizely-sdk/lib/core/decision_service/index.js +++ b/packages/optimizely-sdk/lib/core/decision_service/index.js @@ -27,6 +27,7 @@ var ERROR_MESSAGES = enums.ERROR_MESSAGES; var LOG_LEVEL = enums.LOG_LEVEL; var LOG_MESSAGES = enums.LOG_MESSAGES; var DECISION_SOURCES = enums.DECISION_SOURCES; +var AUDIENCE_EVALUATION_TYPES = enums.AUDIENCE_EVALUATION_TYPES; /** * Optimizely's decision service that determines which variation of an experiment the user will be allocated to. @@ -90,7 +91,14 @@ DecisionService.prototype.getVariation = function(configObj, experimentKey, user } // Perform regular targeting and bucketing - if (!this.__checkIfUserIsInAudience(configObj, experimentKey, userId, attributes)) { + if (!this.__checkIfUserIsInAudience(configObj, experimentKey, AUDIENCE_EVALUATION_TYPES.EXPERIMENT, userId, attributes, '')) { + var userDoesNotMeetConditionsLogMessage = sprintf( + LOG_MESSAGES.USER_NOT_IN_EXPERIMENT, + MODULE_NAME, + userId, + experimentKey + ); + this.logger.log(LOG_LEVEL.INFO, userDoesNotMeetConditionsLogMessage); return null; } @@ -98,9 +106,24 @@ DecisionService.prototype.getVariation = function(configObj, experimentKey, user var variationId = bucketer.bucket(bucketerParams); variation = configObj.variationIdMap[variationId]; if (!variation) { + var userHasNoVariationLogMessage = sprintf( + LOG_MESSAGES.USER_HAS_NO_VARIATION, + MODULE_NAME, + userId, + experimentKey + ); + this.logger.log(LOG_LEVEL.DEBUG, userHasNoVariationLogMessage); return null; } + var userInVariationLogMessage = sprintf( + LOG_MESSAGES.USER_HAS_VARIATION, + MODULE_NAME, + userId, + variation.key, + experimentKey + ); + this.logger.log(LOG_LEVEL.INFO, userInVariationLogMessage); // persist bucketing this.__saveUserProfile(experiment, variation, userId, experimentBucketMap); @@ -171,13 +194,15 @@ DecisionService.prototype.__getWhitelistedVariation = function(experiment, userI /** * Checks whether the user is included in experiment audience - * @param {Object} configObj The parsed project configuration object - * @param {string} experimentKey Key of experiment being validated - * @param {string} userId ID of user - * @param {Object} attributes Optional parameter for user's attributes + * @param {Object} configObj The parsed project configuration object + * @param {string} experimentKey Key of experiment being validated + * @param {string} evaluationAttribute String representing experiment key or rule + * @param {string} userId ID of user + * @param {Object} attributes Optional parameter for user's attributes + * @param {string} loggingKey String representing experiment key or rollout rule. To be used in log messages only. * @return {boolean} True if user meets audience conditions */ -DecisionService.prototype.__checkIfUserIsInAudience = function(configObj, experimentKey, userId, attributes) { +DecisionService.prototype.__checkIfUserIsInAudience = function(configObj, experimentKey, evaluationAttribute, userId, attributes, loggingKey) { var experimentAudienceConditions = projectConfig.getExperimentAudienceConditions(configObj, experimentKey); var audiencesById = projectConfig.getAudiencesById(configObj); this.logger.log( @@ -185,7 +210,8 @@ DecisionService.prototype.__checkIfUserIsInAudience = function(configObj, experi sprintf( LOG_MESSAGES.EVALUATING_AUDIENCES_COMBINED, MODULE_NAME, - experimentKey, + evaluationAttribute, + loggingKey || experimentKey, JSON.stringify(experimentAudienceConditions) ) ); @@ -195,23 +221,13 @@ DecisionService.prototype.__checkIfUserIsInAudience = function(configObj, experi sprintf( LOG_MESSAGES.AUDIENCE_EVALUATION_RESULT_COMBINED, MODULE_NAME, - experimentKey, + evaluationAttribute, + loggingKey || experimentKey, result.toString().toUpperCase() ) ); - if (!result) { - var userDoesNotMeetConditionsLogMessage = sprintf( - LOG_MESSAGES.USER_NOT_IN_EXPERIMENT, - MODULE_NAME, - userId, - experimentKey - ); - this.logger.log(LOG_LEVEL.INFO, userDoesNotMeetConditionsLogMessage); - return false; - } - - return true; + return result; }; /** @@ -335,25 +351,9 @@ DecisionService.prototype.__saveUserProfile = function(experiment, variation, us DecisionService.prototype.getVariationForFeature = function(configObj, feature, userId, attributes) { var experimentDecision = this._getVariationForFeatureExperiment(configObj, feature, userId, attributes); if (experimentDecision.variation !== null) { - this.logger.log( - LOG_LEVEL.DEBUG, - sprintf( - LOG_MESSAGES.USER_IN_FEATURE_EXPERIMENT, - MODULE_NAME, - userId, - experimentDecision.variation.key, - experimentDecision.experiment.key, - feature.key - ) - ); return experimentDecision; } - this.logger.log( - LOG_LEVEL.DEBUG, - sprintf(LOG_MESSAGES.USER_NOT_IN_FEATURE_EXPERIMENT, MODULE_NAME, userId, feature.key) - ); - var rolloutDecision = this._getVariationForRollout(configObj, feature, userId, attributes); if (rolloutDecision.variation !== null) { this.logger.log(LOG_LEVEL.DEBUG, sprintf(LOG_MESSAGES.USER_IN_ROLLOUT, MODULE_NAME, userId, feature.key)); @@ -456,50 +456,56 @@ DecisionService.prototype._getVariationForRollout = function(configObj, feature, // "everyone else", which will be evaluated separately outside this loop var endIndex = rollout.experiments.length - 1; var index; - var experiment; + var rolloutRule; var bucketerParams; var variationId; var variation; + var loggingKey; for (index = 0; index < endIndex; index++) { - experiment = configObj.experimentKeyMap[rollout.experiments[index].key]; + rolloutRule = configObj.experimentKeyMap[rollout.experiments[index].key]; + loggingKey = index + 1; - if (!this.__checkIfUserIsInAudience(configObj, experiment.key, userId, attributes)) { + if (!this.__checkIfUserIsInAudience(configObj, rolloutRule.key, AUDIENCE_EVALUATION_TYPES.RULE, userId, attributes, loggingKey)) { this.logger.log( LOG_LEVEL.DEBUG, - sprintf(LOG_MESSAGES.USER_DOESNT_MEET_CONDITIONS_FOR_TARGETING_RULE, MODULE_NAME, userId, index + 1) + sprintf(LOG_MESSAGES.USER_DOESNT_MEET_CONDITIONS_FOR_TARGETING_RULE, MODULE_NAME, userId, loggingKey) ); continue; } this.logger.log( LOG_LEVEL.DEBUG, - sprintf(LOG_MESSAGES.USER_MEETS_CONDITIONS_FOR_TARGETING_RULE, MODULE_NAME, userId, index + 1) + sprintf(LOG_MESSAGES.USER_MEETS_CONDITIONS_FOR_TARGETING_RULE, MODULE_NAME, userId, loggingKey) ); - bucketerParams = this.__buildBucketerParams(configObj, experiment.key, bucketingId, userId); + bucketerParams = this.__buildBucketerParams(configObj, rolloutRule.key, bucketingId, userId); variationId = bucketer.bucket(bucketerParams); variation = configObj.variationIdMap[variationId]; if (variation) { this.logger.log( LOG_LEVEL.DEBUG, - sprintf(LOG_MESSAGES.USER_BUCKETED_INTO_TARGETING_RULE, MODULE_NAME, userId, index + 1) + sprintf(LOG_MESSAGES.USER_BUCKETED_INTO_TARGETING_RULE, MODULE_NAME, userId, loggingKey) ); return { - experiment: experiment, + experiment: rolloutRule, variation: variation, decisionSource: DECISION_SOURCES.ROLLOUT, }; } else { this.logger.log( LOG_LEVEL.DEBUG, - sprintf(LOG_MESSAGES.USER_NOT_BUCKETED_INTO_TARGETING_RULE, MODULE_NAME, userId, index + 1) + sprintf(LOG_MESSAGES.USER_NOT_BUCKETED_INTO_TARGETING_RULE, MODULE_NAME, userId, loggingKey) ); break; } } - var everyoneElseExperiment = configObj.experimentKeyMap[rollout.experiments[endIndex].key]; - if (this.__checkIfUserIsInAudience(configObj, everyoneElseExperiment.key, userId, attributes)) { - bucketerParams = this.__buildBucketerParams(configObj, everyoneElseExperiment.key, bucketingId, userId); + var everyoneElseRule = configObj.experimentKeyMap[rollout.experiments[endIndex].key]; + if (this.__checkIfUserIsInAudience(configObj, everyoneElseRule.key, AUDIENCE_EVALUATION_TYPES.RULE, userId, attributes, 'Everyone Else')) { + this.logger.log( + LOG_LEVEL.DEBUG, + sprintf(LOG_MESSAGES.USER_MEETS_CONDITIONS_FOR_TARGETING_RULE, MODULE_NAME, userId, 'Everyone Else') + ); + bucketerParams = this.__buildBucketerParams(configObj, everyoneElseRule.key, bucketingId, userId); variationId = bucketer.bucket(bucketerParams); variation = configObj.variationIdMap[variationId]; if (variation) { @@ -508,7 +514,7 @@ DecisionService.prototype._getVariationForRollout = function(configObj, feature, sprintf(LOG_MESSAGES.USER_BUCKETED_INTO_EVERYONE_TARGETING_RULE, MODULE_NAME, userId) ); return { - experiment: everyoneElseExperiment, + experiment: everyoneElseRule, variation: variation, decisionSource: DECISION_SOURCES.ROLLOUT, }; diff --git a/packages/optimizely-sdk/lib/core/decision_service/index.tests.js b/packages/optimizely-sdk/lib/core/decision_service/index.tests.js index 6571364d1..7d51fec26 100644 --- a/packages/optimizely-sdk/lib/core/decision_service/index.tests.js +++ b/packages/optimizely-sdk/lib/core/decision_service/index.tests.js @@ -39,7 +39,7 @@ import { } from '../../tests/test_data'; var testData = getTestProjectConfig(); -var testDataWithFeatures = getTestProjectConfigWithFeatures(); +var testDataWithFeatures = getTestProjectConfigWithFeatures(); describe('lib/core/decision_service', function() { describe('APIs', function() { @@ -285,7 +285,7 @@ describe('lib/core/decision_service', function() { ); sinon.assert.calledWith(userProfileLookupStub, 'decision_service_user'); sinon.assert.calledOnce(bucketerStub); - assert.strictEqual(4, mockLogger.log.callCount); + assert.strictEqual(5, mockLogger.log.callCount); sinon.assert.calledWith(userProfileServiceInstance.save, { user_id: 'decision_service_user', experiment_bucket_map: { @@ -299,7 +299,7 @@ describe('lib/core/decision_service', function() { 'DECISION_SERVICE: User decision_service_user is not in the forced variation map.' ); assert.strictEqual( - mockLogger.log.args[3][1], + mockLogger.log.args[4][1], 'DECISION_SERVICE: Saved variation "control" of experiment "testExperiment" for user "decision_service_user".' ); }); @@ -336,13 +336,13 @@ describe('lib/core/decision_service', function() { sinon.assert.calledWith(userProfileLookupStub, 'decision_service_user'); sinon.assert.calledOnce(bucketerStub); // should still go through with bucketing - assert.strictEqual(4, mockLogger.log.callCount); + assert.strictEqual(5, mockLogger.log.callCount); assert.strictEqual( mockLogger.log.args[0][1], 'DECISION_SERVICE: User decision_service_user is not in the forced variation map.' ); assert.strictEqual( - mockLogger.log.args[3][1], + mockLogger.log.args[4][1], 'DECISION_SERVICE: Error while saving user profile for user ID "decision_service_user": I am an error.' ); @@ -560,9 +560,14 @@ describe('lib/core/decision_service', function() { it('should return true when audience conditions are met', function() { assert.isTrue( - decisionServiceInstance.__checkIfUserIsInAudience(configObj, 'testExperimentWithAudiences', 'testUser', { - browser_type: 'firefox', - }) + decisionServiceInstance.__checkIfUserIsInAudience( + configObj, + 'testExperimentWithAudiences', + "experiment", + 'testUser', + { browser_type: 'firefox' }, + '' + ) ); assert.strictEqual(2, mockLogger.log.callCount); assert.strictEqual( @@ -576,7 +581,16 @@ describe('lib/core/decision_service', function() { }); it('should return true when experiment has no audience', function() { - assert.isTrue(decisionServiceInstance.__checkIfUserIsInAudience(configObj, 'testExperiment', 'testUser')); + assert.isTrue( + decisionServiceInstance.__checkIfUserIsInAudience( + configObj, + 'testExperiment', + "experiment", + 'testUser', + {}, + '' + ) + ); assert.isTrue(__audienceEvaluateSpy.alwaysReturned(true)); assert.strictEqual(2, mockLogger.log.callCount); @@ -592,11 +606,18 @@ describe('lib/core/decision_service', function() { it('should return false when audience conditions can not be evaluated', function() { assert.isFalse( - decisionServiceInstance.__checkIfUserIsInAudience(configObj, 'testExperimentWithAudiences', 'testUser') + decisionServiceInstance.__checkIfUserIsInAudience( + configObj, + 'testExperimentWithAudiences', + "experiment", + 'testUser', + {}, + '' + ) ); assert.isTrue(__audienceEvaluateSpy.alwaysReturned(false)); - assert.strictEqual(3, mockLogger.log.callCount); + assert.strictEqual(2, mockLogger.log.callCount); assert.strictEqual( mockLogger.log.args[0][1], 'DECISION_SERVICE: Evaluating audiences for experiment "testExperimentWithAudiences": ["11154"].' @@ -605,21 +626,22 @@ describe('lib/core/decision_service', function() { mockLogger.log.args[1][1], 'DECISION_SERVICE: Audiences for experiment testExperimentWithAudiences collectively evaluated to FALSE.' ); - assert.strictEqual( - mockLogger.log.args[2][1], - 'DECISION_SERVICE: User testUser does not meet conditions to be in experiment testExperimentWithAudiences.' - ); }); it('should return false when audience conditions are not met', function() { assert.isFalse( - decisionServiceInstance.__checkIfUserIsInAudience(configObj, 'testExperimentWithAudiences', 'testUser', { - browser_type: 'chrome', - }) + decisionServiceInstance.__checkIfUserIsInAudience( + configObj, + 'testExperimentWithAudiences', + "experiment", + 'testUser', + { browser_type: 'chrome' }, + '' + ) ); assert.isTrue(__audienceEvaluateSpy.alwaysReturned(false)); - assert.strictEqual(3, mockLogger.log.callCount); + assert.strictEqual(2, mockLogger.log.callCount); assert.strictEqual( mockLogger.log.args[0][1], 'DECISION_SERVICE: Evaluating audiences for experiment "testExperimentWithAudiences": ["11154"].' @@ -628,10 +650,6 @@ describe('lib/core/decision_service', function() { mockLogger.log.args[1][1], 'DECISION_SERVICE: Audiences for experiment testExperimentWithAudiences collectively evaluated to FALSE.' ); - assert.strictEqual( - mockLogger.log.args[2][1], - 'DECISION_SERVICE: User testUser does not meet conditions to be in experiment testExperimentWithAudiences.' - ); }); }); @@ -1239,7 +1257,7 @@ describe('lib/core/decision_service', function() { { id: '1547854156498475', value: '{ "num_buttons": 2, "text": "second variation"}', - }, + }, ], featureEnabled: true, key: 'control', @@ -1330,11 +1348,6 @@ describe('lib/core/decision_service', function() { decisionSource: DECISION_SOURCES.FEATURE_TEST, }; assert.deepEqual(decision, expectedDecision); - sinon.assert.calledWithExactly( - mockLogger.log, - LOG_LEVEL.DEBUG, - 'DECISION_SERVICE: User user1 is in variation variation of experiment testing_my_feature on the feature test_feature_for_experiment.' - ); sinon.assert.calledWithExactly(getVariationStub, configObj, 'testing_my_feature', 'user1', { test_attribute: 'test_value', }); @@ -1359,7 +1372,7 @@ describe('lib/core/decision_service', function() { sinon.assert.calledWithExactly( mockLogger.log, LOG_LEVEL.DEBUG, - 'DECISION_SERVICE: User user1 is not in any experiment on the feature test_feature_for_experiment.' + 'DECISION_SERVICE: User user1 is not in rollout of feature test_feature_for_experiment.' ); }); }); @@ -1422,7 +1435,7 @@ describe('lib/core/decision_service', function() { sinon.assert.calledWithExactly( mockLogger.log, LOG_LEVEL.DEBUG, - 'DECISION_SERVICE: User user1 is in variation var of experiment exp_with_group on the feature feature_with_group.' + 'BUCKETER: Assigned bucket 593 to user with bucketing ID user1.' ); }); }); @@ -1445,7 +1458,7 @@ describe('lib/core/decision_service', function() { sinon.assert.calledWithExactly( mockLogger.log, LOG_LEVEL.DEBUG, - 'DECISION_SERVICE: User user1 is not in any experiment on the feature feature_with_group.' + 'DECISION_SERVICE: User user1 is not in rollout of feature feature_with_group.' ); }); @@ -1461,7 +1474,7 @@ describe('lib/core/decision_service', function() { sinon.assert.calledWithExactly( mockLogger.log, LOG_LEVEL.DEBUG, - 'DECISION_SERVICE: User user1 is not in any experiment on the feature feature_exp_no_traffic.' + 'DECISION_SERVICE: There is no rollout of feature feature_exp_no_traffic.' ); }); }); @@ -1484,7 +1497,7 @@ describe('lib/core/decision_service', function() { sinon.assert.calledWithExactly( mockLogger.log, LOG_LEVEL.DEBUG, - 'DECISION_SERVICE: User user1 is not in any experiment on the feature feature_with_group.' + 'DECISION_SERVICE: There is no rollout of feature feature_with_group.' ); }); }); @@ -1987,11 +2000,6 @@ describe('lib/core/decision_service', function() { decisionSource: DECISION_SOURCES.ROLLOUT, }; assert.deepEqual(decision, expectedDecision); - sinon.assert.calledWithExactly( - mockLogger.log, - LOG_LEVEL.DEBUG, - 'DECISION_SERVICE: User user1 is not in any experiment on the feature shared_feature.' - ); sinon.assert.calledWithExactly( mockLogger.log, LOG_LEVEL.DEBUG, @@ -2024,11 +2032,6 @@ describe('lib/core/decision_service', function() { LOG_LEVEL.DEBUG, 'DECISION_SERVICE: Feature unused_flag is not attached to any experiments.' ); - sinon.assert.calledWithExactly( - mockLogger.log, - LOG_LEVEL.DEBUG, - 'DECISION_SERVICE: User user1 is not in any experiment on the feature unused_flag.' - ); sinon.assert.calledWithExactly( mockLogger.log, LOG_LEVEL.DEBUG, diff --git a/packages/optimizely-sdk/lib/optimizely/index.js b/packages/optimizely-sdk/lib/optimizely/index.js index 52056568e..51a59be98 100644 --- a/packages/optimizely-sdk/lib/optimizely/index.js +++ b/packages/optimizely-sdk/lib/optimizely/index.js @@ -747,8 +747,8 @@ Optimizely.prototype._getFeatureVariableForType = function(featureKey, variableK ); return null; } - - var decision = this.decisionService.getVariationForFeature(configObj, featureFlag, userId, attributes); + + var decision = this.decisionService.getVariationForFeature(configObj, featureFlag, userId, attributes); var featureEnabled = decision.variation !== null ? decision.variation.featureEnabled : false; var variableValue = this._getFeatureVariableValueFromVariation(featureKey, featureEnabled, decision.variation, variable, userId); @@ -759,7 +759,7 @@ Optimizely.prototype._getFeatureVariableForType = function(featureKey, variableK variationKey: decision.variation.key, }; } - + this.notificationCenter.sendNotifications(NOTIFICATION_TYPES.DECISION, { type: DECISION_NOTIFICATION_TYPES.FEATURE_VARIABLE, userId: userId, @@ -778,10 +778,10 @@ Optimizely.prototype._getFeatureVariableForType = function(featureKey, variableK }; /** - * Helper method to get the non type-casted value for a variable attached to a - * feature flag. Returns appropriate variable value depending on whether there - * was a matching variation, feature was enabled or not or varible was part of the - * available variation or not. Also logs the appropriate message explaining how it + * Helper method to get the non type-casted value for a variable attached to a + * feature flag. Returns appropriate variable value depending on whether there + * was a matching variation, feature was enabled or not or varible was part of the + * available variation or not. Also logs the appropriate message explaining how it * evaluated the value of the variable. * * @param {string} featureKey Key of the feature whose variable's value is @@ -810,10 +810,9 @@ Optimizely.prototype._getFeatureVariableValueFromVariation = function(featureKey sprintf( LOG_MESSAGES.USER_RECEIVED_VARIABLE_VALUE, MODULE_NAME, - variable.key, - featureKey, variableValue, - userId + variable.key, + featureKey ) ); } else { @@ -824,7 +823,7 @@ Optimizely.prototype._getFeatureVariableValueFromVariation = function(featureKey MODULE_NAME, featureKey, userId, - variable.key + variableValue ) ); } @@ -851,7 +850,7 @@ Optimizely.prototype._getFeatureVariableValueFromVariation = function(featureKey ) ); } - + return projectConfig.getTypeCastValue(variableValue, variable.type, this.logger); } @@ -1015,21 +1014,21 @@ Optimizely.prototype.getAllFeatureVariables = function(featureKey, userId, attri if (!this.__validateInputs({ feature_key: featureKey, user_id: userId }, attributes)) { return null; } - + var configObj = this.projectConfigManager.getConfig(); if (!configObj) { return null; } - + var featureFlag = projectConfig.getFeatureFromKey(configObj, featureKey, this.logger); if (!featureFlag) { return null; } - - var decision = this.decisionService.getVariationForFeature(configObj, featureFlag, userId, attributes); - var featureEnabled = decision.variation !== null ? decision.variation.featureEnabled : false; + + var decision = this.decisionService.getVariationForFeature(configObj, featureFlag, userId, attributes); + var featureEnabled = decision.variation !== null ? decision.variation.featureEnabled : false; var allVariables = {}; - + featureFlag.variables.forEach(function (variable) { allVariables[variable.key] = this._getFeatureVariableValueFromVariation(featureKey, featureEnabled, decision.variation, variable, userId); }.bind(this)); @@ -1048,8 +1047,8 @@ Optimizely.prototype.getAllFeatureVariables = function(featureKey, userId, attri decisionInfo: { featureKey: featureKey, featureEnabled: featureEnabled, - source: decision.decisionSource, - variableValues: allVariables, + source: decision.decisionSource, + variableValues: allVariables, sourceInfo: sourceInfo, }, }); diff --git a/packages/optimizely-sdk/lib/optimizely/index.tests.js b/packages/optimizely-sdk/lib/optimizely/index.tests.js index 777d4c505..a492f6900 100644 --- a/packages/optimizely-sdk/lib/optimizely/index.tests.js +++ b/packages/optimizely-sdk/lib/optimizely/index.tests.js @@ -4953,7 +4953,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "is_button_animated" of feature flag "test_feature_for_experiment" is true for user "user1"' + 'OPTIMIZELY: Got variable value "true" for variable "is_button_animated" of feature flag "test_feature_for_experiment"' ); }); @@ -4965,7 +4965,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "button_width" of feature flag "test_feature_for_experiment" is 20.25 for user "user1"' + 'OPTIMIZELY: Got variable value "20.25" for variable "button_width" of feature flag "test_feature_for_experiment"' ); }); @@ -4977,7 +4977,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "num_buttons" of feature flag "test_feature_for_experiment" is 2 for user "user1"' + 'OPTIMIZELY: Got variable value "2" for variable "num_buttons" of feature flag "test_feature_for_experiment"' ); }); @@ -4989,7 +4989,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "button_txt" of feature flag "test_feature_for_experiment" is Buy me NOW for user "user1"' + 'OPTIMIZELY: Got variable value "Buy me NOW" for variable "button_txt" of feature flag "test_feature_for_experiment"' ); }); @@ -5004,7 +5004,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "button_info" of feature flag "test_feature_for_experiment" is { "num_buttons": 1, "text": "first variation"} for user "user1"' + 'OPTIMIZELY: Got variable value "{ "num_buttons": 1, "text": "first variation"}" for variable "button_info" of feature flag "test_feature_for_experiment"' ); }); @@ -5019,7 +5019,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "is_button_animated" of feature flag "test_feature_for_experiment" is true for user "user1"' + 'OPTIMIZELY: Got variable value "true" for variable "is_button_animated" of feature flag "test_feature_for_experiment"' ); }); @@ -5034,7 +5034,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "button_width" of feature flag "test_feature_for_experiment" is 20.25 for user "user1"' + 'OPTIMIZELY: Got variable value "20.25" for variable "button_width" of feature flag "test_feature_for_experiment"' ); }); @@ -5049,7 +5049,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "num_buttons" of feature flag "test_feature_for_experiment" is 2 for user "user1"' + 'OPTIMIZELY: Got variable value "2" for variable "num_buttons" of feature flag "test_feature_for_experiment"' ); }); @@ -5061,7 +5061,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "button_txt" of feature flag "test_feature_for_experiment" is Buy me NOW for user "user1"' + 'OPTIMIZELY: Got variable value "Buy me NOW" for variable "button_txt" of feature flag "test_feature_for_experiment"' ); }); @@ -5076,7 +5076,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "button_info" of feature flag "test_feature_for_experiment" is { "num_buttons": 1, "text": "first variation"} for user "user1"' + 'OPTIMIZELY: Got variable value "{ "num_buttons": 1, "text": "first variation"}" for variable "button_info" of feature flag "test_feature_for_experiment"' ); }); @@ -5097,27 +5097,27 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "is_button_animated" of feature flag "test_feature_for_experiment" is true for user "user1"' + 'OPTIMIZELY: Got variable value "true" for variable "is_button_animated" of feature flag "test_feature_for_experiment"' ); sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "button_width" of feature flag "test_feature_for_experiment" is 20.25 for user "user1"' + 'OPTIMIZELY: Got variable value "20.25" for variable "button_width" of feature flag "test_feature_for_experiment"' ); sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "num_buttons" of feature flag "test_feature_for_experiment" is 2 for user "user1"' + 'OPTIMIZELY: Got variable value "2" for variable "num_buttons" of feature flag "test_feature_for_experiment"' ); sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "button_txt" of feature flag "test_feature_for_experiment" is Buy me NOW for user "user1"' + 'OPTIMIZELY: Got variable value "Buy me NOW" for variable "button_txt" of feature flag "test_feature_for_experiment"' ); sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "button_info" of feature flag "test_feature_for_experiment" is { "num_buttons": 1, "text": "first variation"} for user "user1"' + 'OPTIMIZELY: Got variable value "{ "num_buttons": 1, "text": "first variation"}" for variable "button_info" of feature flag "test_feature_for_experiment"' ); }); @@ -5338,7 +5338,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning default value for variable "is_button_animated".' + 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning the default variable value "false".' ); }); @@ -5350,7 +5350,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning default value for variable "button_width".' + 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning the default variable value "50.55".' ); }); @@ -5362,7 +5362,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning default value for variable "num_buttons".' + 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning the default variable value "10".' ); }); @@ -5374,7 +5374,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning default value for variable "button_txt".' + 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning the default variable value "Buy me".' ); }); @@ -5389,7 +5389,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning default value for variable "button_info".' + 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning the default variable value "{ "num_buttons": 0, "text": "default value"}".' ); }); @@ -5404,7 +5404,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning default value for variable "is_button_animated".' + 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning the default variable value "false".' ); }); @@ -5419,7 +5419,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning default value for variable "button_width".' + 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning the default variable value "50.55".' ); }); @@ -5434,7 +5434,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning default value for variable "num_buttons".' + 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning the default variable value "10".' ); }); @@ -5446,7 +5446,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning default value for variable "button_txt".' + 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning the default variable value "Buy me".' ); }); @@ -5461,7 +5461,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning default value for variable "button_info".' + 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning the default variable value "{ "num_buttons": 0, "text": "default value"}".' ); }); @@ -5482,27 +5482,27 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning default value for variable "is_button_animated".' + 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning the default variable value "false".' ); sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning default value for variable "button_width".' + 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning the default variable value "50.55".' ); sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning default value for variable "num_buttons".' + 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning the default variable value "10".' ); sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning default value for variable "button_txt".' + 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning the default variable value "Buy me".' ); sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning default value for variable "button_info".' + 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning the default variable value "{ "num_buttons": 0, "text": "default value"}".' ); }); }); @@ -5531,7 +5531,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "new_content" of feature flag "test_feature" is true for user "user1"' + 'OPTIMIZELY: Got variable value "true" for variable "new_content" of feature flag "test_feature"' ); }); @@ -5543,7 +5543,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "price" of feature flag "test_feature" is 4.99 for user "user1"' + 'OPTIMIZELY: Got variable value "4.99" for variable "price" of feature flag "test_feature"' ); }); @@ -5555,7 +5555,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "lasers" of feature flag "test_feature" is 395 for user "user1"' + 'OPTIMIZELY: Got variable value "395" for variable "lasers" of feature flag "test_feature"' ); }); @@ -5567,7 +5567,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "message" of feature flag "test_feature" is Hello audience for user "user1"' + 'OPTIMIZELY: Got variable value "Hello audience" for variable "message" of feature flag "test_feature"' ); }); @@ -5582,7 +5582,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "message_info" of feature flag "test_feature" is { "count": 2, "message": "Hello audience" } for user "user1"' + 'OPTIMIZELY: Got variable value "{ "count": 2, "message": "Hello audience" }" for variable "message_info" of feature flag "test_feature"' ); }); @@ -5594,7 +5594,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "new_content" of feature flag "test_feature" is true for user "user1"' + 'OPTIMIZELY: Got variable value "true" for variable "new_content" of feature flag "test_feature"' ); }); @@ -5606,7 +5606,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "price" of feature flag "test_feature" is 4.99 for user "user1"' + 'OPTIMIZELY: Got variable value "4.99" for variable "price" of feature flag "test_feature"' ); }); @@ -5618,7 +5618,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "lasers" of feature flag "test_feature" is 395 for user "user1"' + 'OPTIMIZELY: Got variable value "395" for variable "lasers" of feature flag "test_feature"' ); }); @@ -5630,7 +5630,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "message" of feature flag "test_feature" is Hello audience for user "user1"' + 'OPTIMIZELY: Got variable value "Hello audience" for variable "message" of feature flag "test_feature"' ); }); @@ -5645,7 +5645,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "message_info" of feature flag "test_feature" is { "count": 2, "message": "Hello audience" } for user "user1"' + 'OPTIMIZELY: Got variable value "{ "count": 2, "message": "Hello audience" }" for variable "message_info" of feature flag "test_feature"' ); }); @@ -5666,27 +5666,27 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "new_content" of feature flag "test_feature" is true for user "user1"' + 'OPTIMIZELY: Got variable value "true" for variable "new_content" of feature flag "test_feature"' ); sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "price" of feature flag "test_feature" is 4.99 for user "user1"' + 'OPTIMIZELY: Got variable value "4.99" for variable "price" of feature flag "test_feature"' ); sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "lasers" of feature flag "test_feature" is 395 for user "user1"' + 'OPTIMIZELY: Got variable value "395" for variable "lasers" of feature flag "test_feature"' ); sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "message" of feature flag "test_feature" is Hello audience for user "user1"' + 'OPTIMIZELY: Got variable value "Hello audience" for variable "message" of feature flag "test_feature"' ); sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Value for variable "message_info" of feature flag "test_feature" is { "count": 2, "message": "Hello audience" } for user "user1"' + 'OPTIMIZELY: Got variable value "{ "count": 2, "message": "Hello audience" }" for variable "message_info" of feature flag "test_feature"' ); }); @@ -5886,7 +5886,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning default value for variable "new_content".' + 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning the default variable value "false".' ); }); @@ -5898,7 +5898,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning default value for variable "price".' + 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning the default variable value "14.99".' ); }); @@ -5910,7 +5910,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning default value for variable "lasers".' + 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning the default variable value "400".' ); }); @@ -5922,7 +5922,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning default value for variable "message".' + 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning the default variable value "Hello".' ); }); @@ -5937,7 +5937,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning default value for variable "message_info".' + 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning the default variable value "{ "count": 1, "message": "Hello" }".' ); }); @@ -5949,7 +5949,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning default value for variable "new_content".' + 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning the default variable value "false".' ); }); @@ -5961,7 +5961,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning default value for variable "price".' + 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning the default variable value "14.99".' ); }); @@ -5973,7 +5973,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning default value for variable "lasers".' + 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning the default variable value "400".' ); }); @@ -5985,7 +5985,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning default value for variable "message".' + 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning the default variable value "Hello".' ); }); @@ -6000,7 +6000,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning default value for variable "message_info".' + 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning the default variable value "{ "count": 1, "message": "Hello" }".' ); }); @@ -6021,27 +6021,27 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning default value for variable "new_content".' + 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning the default variable value "false".' ); sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning default value for variable "price".' + 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning the default variable value "14.99".' ); sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning default value for variable "lasers".' + 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning the default variable value "400".' ); sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning default value for variable "message".' + 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning the default variable value "Hello".' ); sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning default value for variable "message_info".' + 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning the default variable value "{ "count": 1, "message": "Hello" }".' ); }); }); diff --git a/packages/optimizely-sdk/lib/utils/enums/index.js b/packages/optimizely-sdk/lib/utils/enums/index.js index db6d52029..3cfc2ea0d 100644 --- a/packages/optimizely-sdk/lib/utils/enums/index.js +++ b/packages/optimizely-sdk/lib/utils/enums/index.js @@ -96,8 +96,7 @@ export var LOG_MESSAGES = { SHOULD_NOT_DISPATCH_ACTIVATE: '%s: Experiment %s is not in "Running" state. Not activating user.', SKIPPING_JSON_VALIDATION: '%s: Skipping JSON schema validation.', TRACK_EVENT: '%s: Tracking event %s for user %s.', - USER_ASSIGNED_TO_VARIATION_BUCKET: '%s: Assigned variation bucket %s to user %s.', - USER_ASSIGNED_TO_EXPERIMENT_BUCKET: '%s: Assigned experiment bucket %s to user %s.', + USER_ASSIGNED_TO_EXPERIMENT_BUCKET: '%s: Assigned bucket %s to user with bucketing ID %s.', USER_BUCKETED_INTO_EXPERIMENT_IN_GROUP: '%s: User %s is in experiment %s of group %s.', USER_BUCKETED_INTO_TARGETING_RULE: '%s: User %s bucketed into targeting rule %s.', USER_IN_FEATURE_EXPERIMENT: '%s: User %s is in variation %s of experiment %s on the feature %s.', @@ -125,10 +124,10 @@ export var LOG_MESSAGES = { USER_RECEIVED_DEFAULT_VARIABLE_VALUE: '%s: User "%s" is not in any variation or rollout rule. Returning default value for variable "%s" of feature flag "%s".', FEATURE_NOT_ENABLED_RETURN_DEFAULT_VARIABLE_VALUE: - '%s: Feature "%s" is not enabled for user %s. Returning default value for variable "%s".', + '%s: Feature "%s" is not enabled for user %s. Returning the default variable value "%s".', VARIABLE_NOT_USED_RETURN_DEFAULT_VARIABLE_VALUE: '%s: Variable "%s" is not used in variation "%s". Returning default value.', - USER_RECEIVED_VARIABLE_VALUE: '%s: Value for variable "%s" of feature flag "%s" is %s for user "%s"', + USER_RECEIVED_VARIABLE_VALUE: '%s: Got variable value "%s" for variable "%s" of feature flag "%s"', VALID_DATAFILE: '%s: Datafile is valid.', VALID_USER_PROFILE_SERVICE: '%s: Valid user profile service provided.', VARIATION_REMOVED_FOR_USER: '%s: Variation mapped to experiment %s has been removed for user %s.', @@ -137,9 +136,9 @@ export var LOG_MESSAGES = { VALID_BUCKETING_ID: '%s: BucketingId is valid: "%s"', BUCKETING_ID_NOT_STRING: '%s: BucketingID attribute is not a string. Defaulted to userId', EVALUATING_AUDIENCE: '%s: Starting to evaluate audience "%s" with conditions: %s.', - EVALUATING_AUDIENCES_COMBINED: '%s: Evaluating audiences for experiment "%s": %s.', + EVALUATING_AUDIENCES_COMBINED: '%s: Evaluating audiences for %s "%s": %s.', AUDIENCE_EVALUATION_RESULT: '%s: Audience "%s" evaluated to %s.', - AUDIENCE_EVALUATION_RESULT_COMBINED: '%s: Audiences for experiment %s collectively evaluated to %s.', + AUDIENCE_EVALUATION_RESULT_COMBINED: '%s: Audiences for %s %s collectively evaluated to %s.', MISSING_ATTRIBUTE_VALUE: '%s: Audience condition %s evaluated to UNKNOWN because no value was passed for user attribute "%s".', UNEXPECTED_CONDITION_VALUE: @@ -202,6 +201,11 @@ export var DECISION_SOURCES = { ROLLOUT: 'rollout', }; +export var AUDIENCE_EVALUATION_TYPES = { + RULE: 'rule', + EXPERIMENT: 'experiment', +} + /* * Possible types of variables attached to features */ @@ -238,4 +242,5 @@ export default { DECISION_SOURCES: DECISION_SOURCES, FEATURE_VARIABLE_TYPES: FEATURE_VARIABLE_TYPES, DATAFILE_VERSIONS: DATAFILE_VERSIONS, + AUDIENCE_EVALUATION_TYPES: AUDIENCE_EVALUATION_TYPES }