diff --git a/packages/optimizely-sdk/lib/core/audience_evaluator/index.tests.js b/packages/optimizely-sdk/lib/core/audience_evaluator/index.tests.js index 077ec8761..06b993ea5 100644 --- a/packages/optimizely-sdk/lib/core/audience_evaluator/index.tests.js +++ b/packages/optimizely-sdk/lib/core/audience_evaluator/index.tests.js @@ -16,11 +16,13 @@ import sinon from 'sinon'; import { assert } from 'chai'; import { getLogger } from '@optimizely/js-sdk-logging'; +import { sprintf } from '@optimizely/js-sdk-utils'; import { createAudienceEvaluator } from './index'; import * as conditionTreeEvaluator from '../condition_tree_evaluator'; import * as customAttributeConditionEvaluator from '../custom_attribute_condition_evaluator'; +var buildLogMessageFromArgs = args => sprintf(args[1], ...args.splice(2)); var mockLogger = getLogger(); var chromeUserAudience = { @@ -233,10 +235,10 @@ describe('lib/core/audience_evaluator', function() { assert.isFalse(result); assert.strictEqual(2, mockLogger.log.callCount); assert.strictEqual( - mockLogger.log.args[0][1], + buildLogMessageFromArgs(mockLogger.log.args[0]), 'AUDIENCE_EVALUATOR: Starting to evaluate audience "1" with conditions: ["and",{"name":"device_model","value":"iphone","type":"custom_attribute"}].' ); - assert.strictEqual(mockLogger.log.args[1][1], 'AUDIENCE_EVALUATOR: Audience "1" evaluated to UNKNOWN.'); + assert.strictEqual(buildLogMessageFromArgs(mockLogger.log.args[1]), 'AUDIENCE_EVALUATOR: Audience "1" evaluated to UNKNOWN.'); }); it('logs correctly when conditionTreeEvaluator.evaluate returns true', function() { @@ -255,10 +257,10 @@ describe('lib/core/audience_evaluator', function() { assert.isTrue(result); assert.strictEqual(2, mockLogger.log.callCount); assert.strictEqual( - mockLogger.log.args[0][1], + buildLogMessageFromArgs(mockLogger.log.args[0]), 'AUDIENCE_EVALUATOR: Starting to evaluate audience "1" with conditions: ["and",{"name":"device_model","value":"iphone","type":"custom_attribute"}].' ); - assert.strictEqual(mockLogger.log.args[1][1], 'AUDIENCE_EVALUATOR: Audience "1" evaluated to TRUE.'); + assert.strictEqual(buildLogMessageFromArgs(mockLogger.log.args[1]), 'AUDIENCE_EVALUATOR: Audience "1" evaluated to TRUE.'); }); it('logs correctly when conditionTreeEvaluator.evaluate returns false', function() { @@ -277,10 +279,10 @@ describe('lib/core/audience_evaluator', function() { assert.isFalse(result); assert.strictEqual(2, mockLogger.log.callCount); assert.strictEqual( - mockLogger.log.args[0][1], + buildLogMessageFromArgs(mockLogger.log.args[0]), 'AUDIENCE_EVALUATOR: Starting to evaluate audience "1" with conditions: ["and",{"name":"device_model","value":"iphone","type":"custom_attribute"}].' ); - assert.strictEqual(mockLogger.log.args[1][1], 'AUDIENCE_EVALUATOR: Audience "1" evaluated to FALSE.'); + assert.strictEqual(buildLogMessageFromArgs(mockLogger.log.args[1]), 'AUDIENCE_EVALUATOR: Audience "1" evaluated to FALSE.'); }); }); }); diff --git a/packages/optimizely-sdk/lib/core/audience_evaluator/index.ts b/packages/optimizely-sdk/lib/core/audience_evaluator/index.ts index 706677079..be6e8bfcd 100644 --- a/packages/optimizely-sdk/lib/core/audience_evaluator/index.ts +++ b/packages/optimizely-sdk/lib/core/audience_evaluator/index.ts @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { sprintf } from '@optimizely/js-sdk-utils'; import { getLogger } from '@optimizely/js-sdk-logging'; import fns from '../../utils/fns'; @@ -77,14 +76,14 @@ export class AudienceEvaluator { if (audience) { logger.log( LOG_LEVEL.DEBUG, - sprintf(LOG_MESSAGES.EVALUATING_AUDIENCE, MODULE_NAME, audienceId, JSON.stringify(audience.conditions)) + LOG_MESSAGES.EVALUATING_AUDIENCE, MODULE_NAME, audienceId, JSON.stringify(audience.conditions) ); const result = conditionTreeEvaluator.evaluate( audience.conditions as unknown[] , this.evaluateConditionWithUserAttributes.bind(this, userAttributes) ); const resultText = result === null ? 'UNKNOWN' : result.toString().toUpperCase(); - logger.log(LOG_LEVEL.DEBUG, sprintf(LOG_MESSAGES.AUDIENCE_EVALUATION_RESULT, MODULE_NAME, audienceId, resultText)); + logger.log(LOG_LEVEL.DEBUG, LOG_MESSAGES.AUDIENCE_EVALUATION_RESULT, MODULE_NAME, audienceId, resultText); return result; } return null; @@ -103,7 +102,7 @@ export class AudienceEvaluator { evaluateConditionWithUserAttributes(userAttributes: UserAttributes, condition: Condition): boolean | null { const evaluator = this.typeToEvaluatorMap[condition.type]; if (!evaluator) { - logger.log(LOG_LEVEL.WARNING, sprintf(LOG_MESSAGES.UNKNOWN_CONDITION_TYPE, MODULE_NAME, JSON.stringify(condition))); + logger.log(LOG_LEVEL.WARNING, LOG_MESSAGES.UNKNOWN_CONDITION_TYPE, MODULE_NAME, JSON.stringify(condition)); return null; } try { @@ -111,7 +110,7 @@ export class AudienceEvaluator { } catch (err) { logger.log( LOG_LEVEL.ERROR, - sprintf(ERROR_MESSAGES.CONDITION_EVALUATOR_ERROR, MODULE_NAME, condition.type, err.message) + ERROR_MESSAGES.CONDITION_EVALUATOR_ERROR, MODULE_NAME, condition.type, err.message ); } diff --git a/packages/optimizely-sdk/lib/core/bucketer/index.tests.js b/packages/optimizely-sdk/lib/core/bucketer/index.tests.js index 17a5ecc2d..62aa43a84 100644 --- a/packages/optimizely-sdk/lib/core/bucketer/index.tests.js +++ b/packages/optimizely-sdk/lib/core/bucketer/index.tests.js @@ -28,6 +28,7 @@ import { createLogger } from '../../plugins/logger'; import projectConfig from '../project_config'; import { getTestProjectConfig } from '../../tests/test_data'; +var buildLogMessageFromArgs = args => sprintf(args[1], ...args.splice(2)); var testData = getTestProjectConfig(); describe('lib/core/bucketer', function() { @@ -75,7 +76,7 @@ describe('lib/core/bucketer', function() { var decisionResponse = bucketer.bucket(bucketerParamsTest1); expect(decisionResponse.result).to.equal('111128'); - var bucketedUser_log1 = createdLogger.log.args[0][1]; + var bucketedUser_log1 = buildLogMessageFromArgs(createdLogger.log.args[0]); expect(bucketedUser_log1).to.equal( sprintf(LOG_MESSAGES.USER_ASSIGNED_TO_EXPERIMENT_BUCKET, 'BUCKETER', '50', 'ppid1') ); @@ -84,7 +85,7 @@ describe('lib/core/bucketer', function() { bucketerParamsTest2.userId = 'ppid2'; expect(bucketer.bucket(bucketerParamsTest2).result).to.equal(null); - var notBucketedUser_log1 = createdLogger.log.args[1][1]; + var notBucketedUser_log1 = buildLogMessageFromArgs(createdLogger.log.args[1]); expect(notBucketedUser_log1).to.equal( sprintf(LOG_MESSAGES.USER_ASSIGNED_TO_EXPERIMENT_BUCKET, 'BUCKETER', '50000', 'ppid2') @@ -137,12 +138,12 @@ describe('lib/core/bucketer', function() { sinon.assert.calledTwice(bucketerStub); sinon.assert.callCount(createdLogger.log, 3); - var log1 = createdLogger.log.args[0][1]; + var log1 = buildLogMessageFromArgs(createdLogger.log.args[0]); expect(log1).to.equal( sprintf(LOG_MESSAGES.USER_ASSIGNED_TO_EXPERIMENT_BUCKET, 'BUCKETER', '50', 'testUser') ); - var log2 = createdLogger.log.args[1][1]; + var log2 = buildLogMessageFromArgs(createdLogger.log.args[1]); expect(log2).to.equal( sprintf( LOG_MESSAGES.USER_BUCKETED_INTO_EXPERIMENT_IN_GROUP, @@ -153,7 +154,7 @@ describe('lib/core/bucketer', function() { ) ); - var log3 = createdLogger.log.args[2][1]; + var log3 = buildLogMessageFromArgs(createdLogger.log.args[2]); expect(log3).to.equal( sprintf(LOG_MESSAGES.USER_ASSIGNED_TO_EXPERIMENT_BUCKET, 'BUCKETER', '50', 'testUser') ); @@ -168,11 +169,11 @@ describe('lib/core/bucketer', function() { sinon.assert.calledOnce(bucketerStub); sinon.assert.calledTwice(createdLogger.log); - var log1 = createdLogger.log.args[0][1]; + var log1 = buildLogMessageFromArgs(createdLogger.log.args[0]); expect(log1).to.equal( sprintf(LOG_MESSAGES.USER_ASSIGNED_TO_EXPERIMENT_BUCKET, 'BUCKETER', '5000', 'testUser') ); - var log2 = createdLogger.log.args[1][1]; + var log2 = buildLogMessageFromArgs(createdLogger.log.args[1]); expect(log2).to.equal( sprintf( LOG_MESSAGES.USER_NOT_BUCKETED_INTO_EXPERIMENT_IN_GROUP, @@ -193,11 +194,11 @@ describe('lib/core/bucketer', function() { sinon.assert.calledOnce(bucketerStub); sinon.assert.calledTwice(createdLogger.log); - var log1 = createdLogger.log.args[0][1]; + var log1 = buildLogMessageFromArgs(createdLogger.log.args[0]); expect(log1).to.equal( sprintf(LOG_MESSAGES.USER_ASSIGNED_TO_EXPERIMENT_BUCKET, 'BUCKETER', '50000', 'testUser') ); - var log2 = createdLogger.log.args[1][1]; + var log2 = buildLogMessageFromArgs(createdLogger.log.args[1]); expect(log2).to.equal(sprintf(LOG_MESSAGES.USER_NOT_IN_ANY_EXPERIMENT, 'BUCKETER', 'testUser', '666')); }); @@ -210,11 +211,11 @@ describe('lib/core/bucketer', function() { sinon.assert.calledOnce(bucketerStub); sinon.assert.calledTwice(createdLogger.log); - var log1 = createdLogger.log.args[0][1]; + var log1 = buildLogMessageFromArgs(createdLogger.log.args[0]); expect(log1).to.equal( sprintf(LOG_MESSAGES.USER_ASSIGNED_TO_EXPERIMENT_BUCKET, 'BUCKETER', '9000', 'testUser') ); - var log2 = createdLogger.log.args[1][1]; + var log2 = buildLogMessageFromArgs(createdLogger.log.args[1]); expect(log2).to.equal(sprintf(LOG_MESSAGES.USER_NOT_IN_ANY_EXPERIMENT, 'BUCKETER', 'testUser', '666')); }); @@ -252,7 +253,7 @@ describe('lib/core/bucketer', function() { sinon.assert.calledOnce(bucketerStub); sinon.assert.calledOnce(createdLogger.log); - var log1 = createdLogger.log.args[0][1]; + var log1 = buildLogMessageFromArgs(createdLogger.log.args[0]); expect(log1).to.equal(sprintf(LOG_MESSAGES.USER_ASSIGNED_TO_EXPERIMENT_BUCKET, 'BUCKETER', '0', 'testUser')); }); diff --git a/packages/optimizely-sdk/lib/core/bucketer/index.ts b/packages/optimizely-sdk/lib/core/bucketer/index.ts index f4d3f5088..4b689df42 100644 --- a/packages/optimizely-sdk/lib/core/bucketer/index.ts +++ b/packages/optimizely-sdk/lib/core/bucketer/index.ts @@ -56,7 +56,7 @@ const RANDOM_POLICY = 'random'; * null if user is not bucketed into any experiment and the decide reasons. */ export const bucket = function(bucketerParams: BucketerParams): DecisionResponse { - const decideReasons: string[] = []; + const decideReasons: (string | number)[][] = []; // Check if user is in a random group; if so, check if user is bucketed into a specific experiment const experiment = bucketerParams.experimentIdMap[bucketerParams.experimentId]; const groupId = experiment['groupId']; @@ -75,14 +75,19 @@ export const bucket = function(bucketerParams: BucketerParams): DecisionResponse // Return if user is not bucketed into any experiment if (bucketedExperimentId === null) { - const notbucketedInAnyExperimentLogMessage = sprintf( + bucketerParams.logger.log( + LOG_LEVEL.INFO, LOG_MESSAGES.USER_NOT_IN_ANY_EXPERIMENT, MODULE_NAME, bucketerParams.userId, - groupId + groupId, ); - bucketerParams.logger.log(LOG_LEVEL.INFO, notbucketedInAnyExperimentLogMessage); - decideReasons.push(notbucketedInAnyExperimentLogMessage); + decideReasons.push([ + LOG_MESSAGES.USER_NOT_IN_ANY_EXPERIMENT, + MODULE_NAME, + bucketerParams.userId, + groupId, + ]); return { result: null, reasons: decideReasons, @@ -90,53 +95,69 @@ export const bucket = function(bucketerParams: BucketerParams): DecisionResponse } // Return if user is bucketed into a different experiment than the one specified - if (bucketedExperimentId !== bucketerParams.experimentId) { - const notBucketedIntoExperimentOfGroupLogMessage = sprintf( + if (bucketedExperimentId !== bucketerParams.experimentId) { + bucketerParams.logger.log( + LOG_LEVEL.INFO, LOG_MESSAGES.USER_NOT_BUCKETED_INTO_EXPERIMENT_IN_GROUP, MODULE_NAME, bucketerParams.userId, bucketerParams.experimentKey, - groupId + groupId, ); - bucketerParams.logger.log(LOG_LEVEL.INFO, notBucketedIntoExperimentOfGroupLogMessage); - decideReasons.push(notBucketedIntoExperimentOfGroupLogMessage); + decideReasons.push([ + LOG_MESSAGES.USER_NOT_BUCKETED_INTO_EXPERIMENT_IN_GROUP, + MODULE_NAME, + bucketerParams.userId, + bucketerParams.experimentKey, + groupId, + ]); return { result: null, reasons: decideReasons, }; } - // Continue bucketing if user is bucketed into specified experiment - const bucketedIntoExperimentOfGroupLogMessage = sprintf( + // Continue bucketing if user is bucketed into specified experiment + bucketerParams.logger.log( + LOG_LEVEL.INFO, LOG_MESSAGES.USER_BUCKETED_INTO_EXPERIMENT_IN_GROUP, MODULE_NAME, bucketerParams.userId, bucketerParams.experimentKey, - groupId + groupId, ); - bucketerParams.logger.log(LOG_LEVEL.INFO, bucketedIntoExperimentOfGroupLogMessage); - decideReasons.push(bucketedIntoExperimentOfGroupLogMessage); + decideReasons.push([ + LOG_MESSAGES.USER_BUCKETED_INTO_EXPERIMENT_IN_GROUP, + MODULE_NAME, + bucketerParams.userId, + bucketerParams.experimentKey, + groupId, + ]); } } - const bucketingId = sprintf('%s%s', bucketerParams.bucketingId, bucketerParams.experimentId); + const bucketingId = `${bucketerParams.bucketingId}${bucketerParams.experimentId}`; const bucketValue = _generateBucketValue(bucketingId); - - const bucketedUserLogMessage = sprintf( + + bucketerParams.logger.log( + LOG_LEVEL.DEBUG, LOG_MESSAGES.USER_ASSIGNED_TO_EXPERIMENT_BUCKET, MODULE_NAME, bucketValue, - bucketerParams.userId + bucketerParams.userId, ); - bucketerParams.logger.log(LOG_LEVEL.DEBUG, bucketedUserLogMessage); - decideReasons.push(bucketedUserLogMessage); + decideReasons.push([ + LOG_MESSAGES.USER_ASSIGNED_TO_EXPERIMENT_BUCKET, + MODULE_NAME, + bucketValue, + bucketerParams.userId, + ]); const entityId = _findBucket(bucketValue, bucketerParams.trafficAllocationConfig); if (entityId !== null) { if (!bucketerParams.variationIdMap[entityId]) { - if (entityId) { - const invalidVariationIdLogMessage = sprintf(LOG_MESSAGES.INVALID_VARIATION_ID, MODULE_NAME); - bucketerParams.logger.log(LOG_LEVEL.WARNING, invalidVariationIdLogMessage); - decideReasons.push(invalidVariationIdLogMessage); + if (entityId) { + bucketerParams.logger.log(LOG_LEVEL.WARNING, LOG_MESSAGES.INVALID_VARIATION_ID, MODULE_NAME); + decideReasons.push([LOG_MESSAGES.INVALID_VARIATION_ID, MODULE_NAME]); } return { result: null, @@ -165,11 +186,14 @@ export const bucketUserIntoExperiment = function( userId: string, logger: LogHandler ): string | null { - const bucketingKey = sprintf('%s%s', bucketingId, group.id); + const bucketingKey = `${bucketingId}${group.id}`; const bucketValue = _generateBucketValue(bucketingKey); logger.log( LOG_LEVEL.DEBUG, - sprintf(LOG_MESSAGES.USER_ASSIGNED_TO_EXPERIMENT_BUCKET, MODULE_NAME, bucketValue, userId) + LOG_MESSAGES.USER_ASSIGNED_TO_EXPERIMENT_BUCKET, + MODULE_NAME, + bucketValue, + userId, ); const trafficAllocationConfig = group.trafficAllocation; const bucketedExperimentId = _findBucket(bucketValue, trafficAllocationConfig); 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 8da6be441..28c874ae4 100644 --- a/packages/optimizely-sdk/lib/core/decision_service/index.tests.js +++ b/packages/optimizely-sdk/lib/core/decision_service/index.tests.js @@ -39,6 +39,7 @@ import { var testData = getTestProjectConfig(); var testDataWithFeatures = getTestProjectConfigWithFeatures(); +var buildLogMessageFromArgs = args => sprintf(args[1], ...args.splice(2)); describe('lib/core/decision_service', function() { describe('APIs', function() { @@ -85,11 +86,11 @@ describe('lib/core/decision_service', function() { sinon.assert.notCalled(bucketerStub); assert.strictEqual(2, mockLogger.log.callCount); assert.strictEqual( - mockLogger.log.args[0][1], + buildLogMessageFromArgs(mockLogger.log.args[0]), 'DECISION_SERVICE: User user2 is not in the forced variation map.' ); assert.strictEqual( - mockLogger.log.args[1][1], + buildLogMessageFromArgs(mockLogger.log.args[1]), 'DECISION_SERVICE: User user2 is forced in variation variationWithAudience.' ); }); @@ -101,19 +102,19 @@ describe('lib/core/decision_service', function() { ); assert.strictEqual(4, mockLogger.log.callCount); assert.strictEqual( - mockLogger.log.args[0][1], + buildLogMessageFromArgs(mockLogger.log.args[0]), 'DECISION_SERVICE: User user3 is not in the forced variation map.' ); assert.strictEqual( - mockLogger.log.args[1][1], + buildLogMessageFromArgs(mockLogger.log.args[1]), 'DECISION_SERVICE: Evaluating audiences for experiment "testExperimentWithAudiences": ["11154"].' ); assert.strictEqual( - mockLogger.log.args[2][1], + buildLogMessageFromArgs(mockLogger.log.args[2]), 'DECISION_SERVICE: Audiences for experiment testExperimentWithAudiences collectively evaluated to FALSE.' ); assert.strictEqual( - mockLogger.log.args[3][1], + buildLogMessageFromArgs(mockLogger.log.args[3]), 'DECISION_SERVICE: User user3 does not meet conditions to be in experiment testExperimentWithAudiences.' ); }); @@ -124,7 +125,7 @@ describe('lib/core/decision_service', function() { sinon.assert.notCalled(bucketerStub); assert.strictEqual(1, mockLogger.log.callCount); assert.strictEqual( - mockLogger.log.args[0][1], + buildLogMessageFromArgs(mockLogger.log.args[0]), 'DECISION_SERVICE: Experiment testExperimentNotRunning is not running.' ); }); @@ -204,11 +205,11 @@ describe('lib/core/decision_service', function() { sinon.assert.calledWith(userProfileLookupStub, 'decision_service_user'); sinon.assert.notCalled(bucketerStub); assert.strictEqual( - mockLogger.log.args[0][1], + buildLogMessageFromArgs(mockLogger.log.args[0]), 'DECISION_SERVICE: User decision_service_user is not in the forced variation map.' ); assert.strictEqual( - mockLogger.log.args[1][1], + buildLogMessageFromArgs(mockLogger.log.args[1]), 'DECISION_SERVICE: Returning previously activated variation "control" of experiment "testExperiment" for user "decision_service_user" from user profile.' ); }); @@ -279,11 +280,11 @@ describe('lib/core/decision_service', function() { sinon.assert.calledWith(userProfileLookupStub, 'decision_service_user'); sinon.assert.calledOnce(bucketerStub); assert.strictEqual( - mockLogger.log.args[0][1], + buildLogMessageFromArgs(mockLogger.log.args[0]), 'DECISION_SERVICE: User decision_service_user is not in the forced variation map.' ); assert.strictEqual( - mockLogger.log.args[1][1], + buildLogMessageFromArgs(mockLogger.log.args[1]), 'DECISION_SERVICE: User decision_service_user was previously bucketed into variation with ID not valid variation for experiment testExperiment, but no matching variation was found.' ); // make sure we save the decision @@ -321,11 +322,11 @@ describe('lib/core/decision_service', function() { }, }); assert.strictEqual( - mockLogger.log.args[0][1], + buildLogMessageFromArgs(mockLogger.log.args[0]), 'DECISION_SERVICE: User decision_service_user is not in the forced variation map.' ); assert.strictEqual( - mockLogger.log.args[4][1], + buildLogMessageFromArgs(mockLogger.log.args[4]), 'DECISION_SERVICE: Saved variation "control" of experiment "testExperiment" for user "decision_service_user".' ); }); @@ -342,11 +343,11 @@ 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( - mockLogger.log.args[0][1], + buildLogMessageFromArgs(mockLogger.log.args[0]), 'DECISION_SERVICE: User decision_service_user is not in the forced variation map.' ); assert.strictEqual( - mockLogger.log.args[1][1], + buildLogMessageFromArgs(mockLogger.log.args[1]), 'DECISION_SERVICE: Error while looking up user profile for user ID "decision_service_user": I am an error.' ); }); @@ -366,11 +367,11 @@ describe('lib/core/decision_service', function() { assert.strictEqual(5, mockLogger.log.callCount); assert.strictEqual( - mockLogger.log.args[0][1], + buildLogMessageFromArgs(mockLogger.log.args[0]), 'DECISION_SERVICE: User decision_service_user is not in the forced variation map.' ); assert.strictEqual( - mockLogger.log.args[4][1], + buildLogMessageFromArgs(mockLogger.log.args[4]), 'DECISION_SERVICE: Error while saving user profile for user ID "decision_service_user": I am an error.' ); @@ -413,11 +414,11 @@ describe('lib/core/decision_service', function() { sinon.assert.calledWith(userProfileLookupStub, 'decision_service_user'); sinon.assert.notCalled(bucketerStub); assert.strictEqual( - mockLogger.log.args[0][1], + buildLogMessageFromArgs(mockLogger.log.args[0]), 'DECISION_SERVICE: User decision_service_user is not in the forced variation map.' ); assert.strictEqual( - mockLogger.log.args[1][1], + buildLogMessageFromArgs(mockLogger.log.args[1]), 'DECISION_SERVICE: Returning previously activated variation "variation" of experiment "testExperiment" for user "decision_service_user" from user profile.' ); }); @@ -451,11 +452,11 @@ describe('lib/core/decision_service', function() { sinon.assert.calledWith(userProfileLookupStub, 'decision_service_user'); sinon.assert.notCalled(bucketerStub); assert.strictEqual( - mockLogger.log.args[0][1], + buildLogMessageFromArgs(mockLogger.log.args[0]), 'DECISION_SERVICE: User decision_service_user is not in the forced variation map.' ); assert.strictEqual( - mockLogger.log.args[1][1], + buildLogMessageFromArgs(mockLogger.log.args[1]), 'DECISION_SERVICE: Returning previously activated variation "control" of experiment "testExperiment" for user "decision_service_user" from user profile.' ); }); @@ -489,11 +490,11 @@ describe('lib/core/decision_service', function() { sinon.assert.calledWith(userProfileLookupStub, 'decision_service_user'); sinon.assert.notCalled(bucketerStub); assert.strictEqual( - mockLogger.log.args[0][1], + buildLogMessageFromArgs(mockLogger.log.args[0]), 'DECISION_SERVICE: User decision_service_user is not in the forced variation map.' ); assert.strictEqual( - mockLogger.log.args[1][1], + buildLogMessageFromArgs(mockLogger.log.args[1]), 'DECISION_SERVICE: Returning previously activated variation "variation" of experiment "testExperiment" for user "decision_service_user" from user profile.' ); }); @@ -518,11 +519,11 @@ describe('lib/core/decision_service', function() { sinon.assert.calledWith(userProfileLookupStub, 'decision_service_user'); sinon.assert.notCalled(bucketerStub); assert.strictEqual( - mockLogger.log.args[0][1], + buildLogMessageFromArgs(mockLogger.log.args[0]), 'DECISION_SERVICE: User decision_service_user is not in the forced variation map.' ); assert.strictEqual( - mockLogger.log.args[1][1], + buildLogMessageFromArgs(mockLogger.log.args[1]), 'DECISION_SERVICE: Returning previously activated variation "variation" of experiment "testExperiment" for user "decision_service_user" from user profile.' ); }); @@ -602,11 +603,11 @@ describe('lib/core/decision_service', function() { ); assert.strictEqual(2, mockLogger.log.callCount); assert.strictEqual( - mockLogger.log.args[0][1], + buildLogMessageFromArgs(mockLogger.log.args[0]), 'DECISION_SERVICE: Evaluating audiences for experiment "testExperimentWithAudiences": ["11154"].' ); assert.strictEqual( - mockLogger.log.args[1][1], + buildLogMessageFromArgs(mockLogger.log.args[1]), 'DECISION_SERVICE: Audiences for experiment testExperimentWithAudiences collectively evaluated to TRUE.' ); }); @@ -626,11 +627,11 @@ describe('lib/core/decision_service', function() { assert.strictEqual(2, mockLogger.log.callCount); assert.strictEqual( - mockLogger.log.args[0][1], + buildLogMessageFromArgs(mockLogger.log.args[0]), 'DECISION_SERVICE: Evaluating audiences for experiment "testExperiment": [].' ); assert.strictEqual( - mockLogger.log.args[1][1], + buildLogMessageFromArgs(mockLogger.log.args[1]), 'DECISION_SERVICE: Audiences for experiment testExperiment collectively evaluated to TRUE.' ); }); @@ -650,11 +651,11 @@ describe('lib/core/decision_service', function() { assert.strictEqual(2, mockLogger.log.callCount); assert.strictEqual( - mockLogger.log.args[0][1], + buildLogMessageFromArgs(mockLogger.log.args[0]), 'DECISION_SERVICE: Evaluating audiences for experiment "testExperimentWithAudiences": ["11154"].' ); assert.strictEqual( - mockLogger.log.args[1][1], + buildLogMessageFromArgs(mockLogger.log.args[1]), 'DECISION_SERVICE: Audiences for experiment testExperimentWithAudiences collectively evaluated to FALSE.' ); }); @@ -674,11 +675,11 @@ describe('lib/core/decision_service', function() { assert.strictEqual(2, mockLogger.log.callCount); assert.strictEqual( - mockLogger.log.args[0][1], + buildLogMessageFromArgs(mockLogger.log.args[0]), 'DECISION_SERVICE: Evaluating audiences for experiment "testExperimentWithAudiences": ["11154"].' ); assert.strictEqual( - mockLogger.log.args[1][1], + buildLogMessageFromArgs(mockLogger.log.args[1]), 'DECISION_SERVICE: Audiences for experiment testExperimentWithAudiences collectively evaluated to FALSE.' ); }); @@ -1122,7 +1123,7 @@ describe('lib/core/decision_service', function() { assert.strictEqual(userId, decisionService.getBucketingId(userId, userAttributesWithInvalidBucketingId)); assert.strictEqual(1, mockLogger.log.callCount); assert.strictEqual( - mockLogger.log.args[0][1], + buildLogMessageFromArgs(mockLogger.log.args[0]), 'DECISION_SERVICE: BucketingID attribute is not a string. Defaulted to userId' ); }); @@ -1130,7 +1131,7 @@ describe('lib/core/decision_service', function() { it('should return correct bucketingId when provided in attributes', function() { assert.strictEqual('123456789', decisionService.getBucketingId(userId, userAttributesWithBucketingId)); assert.strictEqual(1, mockLogger.log.callCount); - assert.strictEqual(mockLogger.log.args[0][1], 'DECISION_SERVICE: BucketingId is valid: "123456789"'); + assert.strictEqual(buildLogMessageFromArgs(mockLogger.log.args[0]), 'DECISION_SERVICE: BucketingId is valid: "123456789"'); }); }); @@ -1420,9 +1421,8 @@ describe('lib/core/decision_service', function() { decisionSource: DECISION_SOURCES.ROLLOUT, }; assert.deepEqual(decision, expectedDecision); - sinon.assert.calledWithExactly( - mockLogger.log, - LOG_LEVEL.DEBUG, + assert.strictEqual( + buildLogMessageFromArgs(mockLogger.log.lastCall.args), 'DECISION_SERVICE: User user1 is not in rollout of feature test_feature_for_experiment.' ); }); @@ -1505,9 +1505,8 @@ describe('lib/core/decision_service', function() { decisionSource: DECISION_SOURCES.ROLLOUT, }; assert.deepEqual(decision, expectedDecision); - sinon.assert.calledWithExactly( - mockLogger.log, - LOG_LEVEL.DEBUG, + assert.strictEqual( + buildLogMessageFromArgs(mockLogger.log.lastCall.args), 'DECISION_SERVICE: User user1 is not in rollout of feature feature_with_group.' ); }); @@ -1524,7 +1523,8 @@ describe('lib/core/decision_service', function() { sinon.assert.calledWithExactly( mockLogger.log, LOG_LEVEL.DEBUG, - 'DECISION_SERVICE: There is no rollout of feature feature_exp_no_traffic.' + '%s: There is no rollout of feature %s.', + 'DECISION_SERVICE', 'feature_exp_no_traffic' ); }); }); @@ -1651,17 +1651,21 @@ describe('lib/core/decision_service', function() { sinon.assert.calledWithExactly( mockLogger.log, LOG_LEVEL.DEBUG, - 'DECISION_SERVICE: User user1 meets conditions for targeting rule 1.' + '%s: User %s meets conditions for targeting rule %s.', + 'DECISION_SERVICE', 'user1', 1 ); sinon.assert.calledWithExactly( mockLogger.log, LOG_LEVEL.DEBUG, - 'DECISION_SERVICE: User user1 bucketed into targeting rule 1.' + '%s: User %s bucketed into targeting rule %s.', + 'DECISION_SERVICE', 'user1', 1 + ); sinon.assert.calledWithExactly( mockLogger.log, LOG_LEVEL.DEBUG, - 'DECISION_SERVICE: User user1 is in rollout of feature test_feature.' + '%s: User %s is in rollout of feature %s.', + 'DECISION_SERVICE', 'user1', 'test_feature' ); }); }); @@ -1779,17 +1783,20 @@ describe('lib/core/decision_service', function() { sinon.assert.calledWithExactly( mockLogger.log, LOG_LEVEL.DEBUG, - 'DECISION_SERVICE: User user1 does not meet conditions for targeting rule 1.' + '%s: User %s does not meet conditions for targeting rule %s.', + 'DECISION_SERVICE', 'user1', 1 ); sinon.assert.calledWithExactly( mockLogger.log, LOG_LEVEL.DEBUG, - 'DECISION_SERVICE: User user1 bucketed into everyone targeting rule.' + '%s: User %s bucketed into everyone targeting rule.', + 'DECISION_SERVICE', 'user1' ); sinon.assert.calledWithExactly( mockLogger.log, LOG_LEVEL.DEBUG, - 'DECISION_SERVICE: User user1 is in rollout of feature test_feature.' + '%s: User %s is in rollout of feature %s.', + 'DECISION_SERVICE', 'user1', 'test_feature' ); }); }); @@ -1814,12 +1821,14 @@ describe('lib/core/decision_service', function() { sinon.assert.calledWithExactly( mockLogger.log, LOG_LEVEL.DEBUG, - 'DECISION_SERVICE: User user1 does not meet conditions for targeting rule 1.' + '%s: User %s does not meet conditions for targeting rule %s.', + 'DECISION_SERVICE', 'user1', 1 ); sinon.assert.calledWithExactly( mockLogger.log, LOG_LEVEL.DEBUG, - 'DECISION_SERVICE: User user1 is not in rollout of feature test_feature.' + '%s: User %s is not in rollout of feature %s.', + 'DECISION_SERVICE', 'user1', 'test_feature' ); }); }); @@ -1948,17 +1957,20 @@ describe('lib/core/decision_service', function() { sinon.assert.calledWithExactly( mockLogger.log, LOG_LEVEL.DEBUG, - 'DECISION_SERVICE: User user1 meets conditions for targeting rule 1.' + '%s: User %s meets conditions for targeting rule %s.', + 'DECISION_SERVICE', 'user1', 1 ); sinon.assert.calledWithExactly( mockLogger.log, LOG_LEVEL.DEBUG, - 'DECISION_SERVICE User user1 not bucketed into targeting rule 1 due to traffic allocation. Trying everyone rule.' + '%s User %s not bucketed into targeting rule %s due to traffic allocation. Trying everyone rule.', + 'DECISION_SERVICE', 'user1', 1 ); sinon.assert.calledWithExactly( mockLogger.log, LOG_LEVEL.DEBUG, - 'DECISION_SERVICE: User user1 bucketed into everyone targeting rule.' + '%s: User %s bucketed into everyone targeting rule.', + 'DECISION_SERVICE', 'user1' ); }); }); @@ -2058,12 +2070,14 @@ describe('lib/core/decision_service', function() { sinon.assert.calledWithExactly( mockLogger.log, LOG_LEVEL.DEBUG, - 'DECISION_SERVICE: User user1 bucketed into everyone targeting rule.' + '%s: User %s bucketed into everyone targeting rule.', + 'DECISION_SERVICE', 'user1', ); sinon.assert.calledWithExactly( mockLogger.log, LOG_LEVEL.DEBUG, - 'DECISION_SERVICE: User user1 is in rollout of feature shared_feature.' + '%s: User %s is in rollout of feature %s.', + 'DECISION_SERVICE', 'user1', 'shared_feature' ); }); }); @@ -2085,12 +2099,14 @@ describe('lib/core/decision_service', function() { sinon.assert.calledWithExactly( mockLogger.log, LOG_LEVEL.DEBUG, - 'DECISION_SERVICE: Feature unused_flag is not attached to any experiments.' + '%s: Feature %s is not attached to any experiments.', + 'DECISION_SERVICE', 'unused_flag' ); sinon.assert.calledWithExactly( mockLogger.log, LOG_LEVEL.DEBUG, - 'DECISION_SERVICE: There is no rollout of feature unused_flag.' + '%s: There is no rollout of feature %s.', + 'DECISION_SERVICE', 'unused_flag' ); }); }); @@ -2120,7 +2136,7 @@ describe('lib/core/decision_service', function() { }; assert.deepEqual(decision, expectedDecision); assert.strictEqual( - mockLogger.log.args[3][1], + buildLogMessageFromArgs(mockLogger.log.args[3]), 'BUCKETER: Assigned bucket 2400 to user with bucketing ID user1.' ); sinon.assert.calledWithExactly( @@ -2146,7 +2162,7 @@ describe('lib/core/decision_service', function() { }; assert.deepEqual(decision, expectedDecision); assert.strictEqual( - mockLogger.log.args[3][1], + buildLogMessageFromArgs(mockLogger.log.args[3]), 'BUCKETER: Assigned bucket 4000 to user with bucketing ID user1.' ); sinon.assert.calledWithExactly( @@ -2172,7 +2188,7 @@ describe('lib/core/decision_service', function() { }; assert.deepEqual(decision, expectedDecision); assert.strictEqual( - mockLogger.log.args[3][1], + buildLogMessageFromArgs(mockLogger.log.args[3]), 'BUCKETER: Assigned bucket 6500 to user with bucketing ID user1.' ); sinon.assert.calledWithExactly( @@ -2216,7 +2232,7 @@ describe('lib/core/decision_service', function() { } assert.deepEqual(decision, expectedDecision); assert.strictEqual( - mockLogger.log.args[3][1], + buildLogMessageFromArgs(mockLogger.log.args[3]), 'BUCKETER: Assigned bucket 8000 to user with bucketing ID user1.' ); sinon.assert.calledWithExactly( @@ -2260,7 +2276,7 @@ describe('lib/core/decision_service', function() { } assert.deepEqual(decision, expectedDecision); assert.strictEqual( - mockLogger.log.args[18][1], + buildLogMessageFromArgs(mockLogger.log.args[18]), 'BUCKETER: Assigned bucket 2400 to user with bucketing ID user1.' ); sinon.assert.calledWithExactly( @@ -2296,7 +2312,7 @@ describe('lib/core/decision_service', function() { }; assert.deepEqual(decision, expectedDecision); assert.strictEqual( - mockLogger.log.args[3][1], + buildLogMessageFromArgs(mockLogger.log.args[3]), 'BUCKETER: Assigned bucket 2400 to user with bucketing ID user1.' ); sinon.assert.calledWithExactly( @@ -2323,7 +2339,7 @@ describe('lib/core/decision_service', function() { }; assert.deepEqual(decision, expectedDecision); assert.strictEqual( - mockLogger.log.args[3][1], + buildLogMessageFromArgs(mockLogger.log.args[3]), 'BUCKETER: Assigned bucket 4000 to user with bucketing ID user1.' ); sinon.assert.calledWithExactly( @@ -2350,7 +2366,7 @@ describe('lib/core/decision_service', function() { }; assert.deepEqual(decision, expectedDecision); assert.strictEqual( - mockLogger.log.args[3][1], + buildLogMessageFromArgs(mockLogger.log.args[3]), 'BUCKETER: Assigned bucket 6500 to user with bucketing ID user1.' ); sinon.assert.calledWithExactly( @@ -2394,7 +2410,7 @@ describe('lib/core/decision_service', function() { } assert.deepEqual(decision, expectedDecision); assert.strictEqual( - mockLogger.log.args[3][1], + buildLogMessageFromArgs(mockLogger.log.args[3]), 'BUCKETER: Assigned bucket 8000 to user with bucketing ID user1.' ); sinon.assert.calledWithExactly( @@ -2438,7 +2454,7 @@ describe('lib/core/decision_service', function() { } assert.deepEqual(decision, expectedDecision); assert.strictEqual( - mockLogger.log.args[18][1], + buildLogMessageFromArgs(mockLogger.log.args[18]), 'BUCKETER: Assigned bucket 4000 to user with bucketing ID user1.' ); sinon.assert.calledWithExactly( diff --git a/packages/optimizely-sdk/lib/core/decision_service/index.ts b/packages/optimizely-sdk/lib/core/decision_service/index.ts index df577c78a..75d08b7e6 100644 --- a/packages/optimizely-sdk/lib/core/decision_service/index.ts +++ b/packages/optimizely-sdk/lib/core/decision_service/index.ts @@ -113,12 +113,11 @@ export class DecisionService { ): DecisionResponse { // by default, the bucketing ID should be the user ID const bucketingId = this.getBucketingId(userId, attributes); - const decideReasons = []; + const decideReasons: (string | number)[][] = []; const experimentKey = experiment.key; if (!this.checkIfExperimentIsActive(configObj, experimentKey)) { - const experimentNotRunningLogMessage = sprintf(LOG_MESSAGES.EXPERIMENT_NOT_RUNNING, MODULE_NAME, experimentKey); - this.logger.log(LOG_LEVEL.INFO, experimentNotRunningLogMessage); - decideReasons.push(experimentNotRunningLogMessage); + this.logger.log(LOG_LEVEL.INFO, LOG_MESSAGES.EXPERIMENT_NOT_RUNNING, MODULE_NAME, experimentKey); + decideReasons.push([LOG_MESSAGES.EXPERIMENT_NOT_RUNNING, MODULE_NAME, experimentKey]); return { result: null, reasons: decideReasons, @@ -151,18 +150,21 @@ export class DecisionService { if (!shouldIgnoreUPS) { variation = this.getStoredVariation(configObj, experiment, userId, experimentBucketMap); if (variation) { - const returningStoredVariationMessage = sprintf( + this.logger.log( + LOG_LEVEL.INFO, LOG_MESSAGES.RETURNING_STORED_VARIATION, MODULE_NAME, variation.key, experimentKey, - userId - ); - this.logger.log( - LOG_LEVEL.INFO, - returningStoredVariationMessage + userId, ); - decideReasons.push(returningStoredVariationMessage); + decideReasons.push([ + LOG_MESSAGES.RETURNING_STORED_VARIATION, + MODULE_NAME, + variation.key, + experimentKey, + userId, + ]); return { result: variation.key, reasons: decideReasons, @@ -180,14 +182,19 @@ export class DecisionService { ); decideReasons.push(...decisionifUserIsInAudience.reasons); if (!decisionifUserIsInAudience.result) { - const userDoesNotMeetConditionsLogMessage = sprintf( + this.logger.log( + LOG_LEVEL.INFO, LOG_MESSAGES.USER_NOT_IN_EXPERIMENT, MODULE_NAME, userId, - experimentKey + experimentKey, ); - this.logger.log(LOG_LEVEL.INFO, userDoesNotMeetConditionsLogMessage); - decideReasons.push(userDoesNotMeetConditionsLogMessage); + decideReasons.push([ + LOG_MESSAGES.USER_NOT_IN_EXPERIMENT, + MODULE_NAME, + userId, + experimentKey, + ]); return { result: null, reasons: decideReasons, @@ -202,29 +209,40 @@ export class DecisionService { variation = configObj.variationIdMap[variationId]; } if (!variation) { - const userHasNoVariationLogMessage = sprintf( + this.logger.log( + LOG_LEVEL.DEBUG, LOG_MESSAGES.USER_HAS_NO_VARIATION, MODULE_NAME, userId, - experimentKey + experimentKey, ); - this.logger.log(LOG_LEVEL.DEBUG, userHasNoVariationLogMessage); - decideReasons.push(userHasNoVariationLogMessage); + decideReasons.push([ + LOG_MESSAGES.USER_HAS_NO_VARIATION, + MODULE_NAME, + userId, + experimentKey, + ]); return { result: null, reasons: decideReasons, }; } - const userInVariationLogMessage = sprintf( + this.logger.log( + LOG_LEVEL.INFO, LOG_MESSAGES.USER_HAS_VARIATION, MODULE_NAME, userId, variation.key, - experimentKey + experimentKey, ); - this.logger.log(LOG_LEVEL.INFO, userInVariationLogMessage); - decideReasons.push(userInVariationLogMessage); + decideReasons.push([ + LOG_MESSAGES.USER_HAS_VARIATION, + MODULE_NAME, + userId, + variation.key, + experimentKey, + ]); // persist bucketing if decide options do not include shouldIgnoreUPS if (!shouldIgnoreUPS) { this.saveUserProfile(experiment, variation, userId, experimentBucketMap); @@ -274,31 +292,41 @@ export class DecisionService { experiment: Experiment, userId: string ): DecisionResponse { - const decideReasons: string[] = []; + const decideReasons: (string | number)[][] = []; if (experiment.forcedVariations && experiment.forcedVariations.hasOwnProperty(userId)) { const forcedVariationKey = experiment.forcedVariations[userId]; if (experiment.variationKeyMap.hasOwnProperty(forcedVariationKey)) { - const forcedBucketingSucceededMessageLog = sprintf( + this.logger.log( + LOG_LEVEL.INFO, LOG_MESSAGES.USER_FORCED_IN_VARIATION, MODULE_NAME, userId, - forcedVariationKey + forcedVariationKey, ); - this.logger.log(LOG_LEVEL.INFO, forcedBucketingSucceededMessageLog); - decideReasons.push(forcedBucketingSucceededMessageLog); + decideReasons.push([ + LOG_MESSAGES.USER_FORCED_IN_VARIATION, + MODULE_NAME, + userId, + forcedVariationKey, + ]); return { result: experiment.variationKeyMap[forcedVariationKey], reasons: decideReasons, }; } else { - const forcedBucketingFailedMessageLog = sprintf( + this.logger.log( + LOG_LEVEL.ERROR, LOG_MESSAGES.FORCED_BUCKETING_FAILED, MODULE_NAME, forcedVariationKey, - userId + userId, ); - this.logger.log(LOG_LEVEL.ERROR, forcedBucketingFailedMessageLog); - decideReasons.push(forcedBucketingFailedMessageLog); + decideReasons.push([ + LOG_MESSAGES.FORCED_BUCKETING_FAILED, + MODULE_NAME, + forcedVariationKey, + userId, + ]); return { result: null, reasons: decideReasons, @@ -330,34 +358,40 @@ export class DecisionService { attributes?: UserAttributes, loggingKey?: string | number, ): DecisionResponse { - const decideReasons: string[] = []; + const decideReasons: (string | number)[][] = []; const experimentAudienceConditions = getExperimentAudienceConditions(configObj, experiment.id); const audiencesById = getAudiencesById(configObj); - const evaluatingAudiencesCombinedMessage = sprintf( + this.logger.log( + LOG_LEVEL.DEBUG, LOG_MESSAGES.EVALUATING_AUDIENCES_COMBINED, MODULE_NAME, evaluationAttribute, loggingKey || experiment.key, - JSON.stringify(experimentAudienceConditions) + JSON.stringify(experimentAudienceConditions), ); - this.logger.log( - LOG_LEVEL.DEBUG, - evaluatingAudiencesCombinedMessage - ); - decideReasons.push(evaluatingAudiencesCombinedMessage); - const result = this.audienceEvaluator.evaluate(experimentAudienceConditions, audiencesById, attributes); - const audienceEvaluationResultCombinedMessage = sprintf( - LOG_MESSAGES.AUDIENCE_EVALUATION_RESULT_COMBINED, + decideReasons.push([ + LOG_MESSAGES.EVALUATING_AUDIENCES_COMBINED, MODULE_NAME, evaluationAttribute, loggingKey || experiment.key, - result.toString().toUpperCase() - ); + JSON.stringify(experimentAudienceConditions), + ]); + const result = this.audienceEvaluator.evaluate(experimentAudienceConditions, audiencesById, attributes); this.logger.log( LOG_LEVEL.INFO, - audienceEvaluationResultCombinedMessage + LOG_MESSAGES.AUDIENCE_EVALUATION_RESULT_COMBINED, + MODULE_NAME, + evaluationAttribute, + loggingKey || experiment.key, + result.toString().toUpperCase(), ); - decideReasons.push(audienceEvaluationResultCombinedMessage); + decideReasons.push([ + LOG_MESSAGES.AUDIENCE_EVALUATION_RESULT_COMBINED, + MODULE_NAME, + evaluationAttribute, + loggingKey || experiment.key, + result.toString().toUpperCase(), + ]); return { result: result, @@ -414,13 +448,11 @@ export class DecisionService { return configObj.variationIdMap[decision.variation_id]; } else { this.logger.log( - LOG_LEVEL.INFO, - sprintf( - LOG_MESSAGES.SAVED_VARIATION_NOT_FOUND, - MODULE_NAME, userId, - variationId, - experiment.key - ) + LOG_LEVEL.INFO, + LOG_MESSAGES.SAVED_VARIATION_NOT_FOUND, + MODULE_NAME, userId, + variationId, + experiment.key, ); } } @@ -448,7 +480,10 @@ export class DecisionService { } catch (ex) { this.logger.log( LOG_LEVEL.ERROR, - sprintf(ERROR_MESSAGES.USER_PROFILE_LOOKUP_ERROR, MODULE_NAME, userId, ex.message) + ERROR_MESSAGES.USER_PROFILE_LOOKUP_ERROR, + MODULE_NAME, + userId, + ex.message, ); } @@ -484,10 +519,14 @@ export class DecisionService { this.logger.log( LOG_LEVEL.INFO, - sprintf(LOG_MESSAGES.SAVED_VARIATION, MODULE_NAME, variation.key, experiment.key, userId) + LOG_MESSAGES.SAVED_VARIATION, + MODULE_NAME, + variation.key, + experiment.key, + userId, ); } catch (ex) { - this.logger.log(LOG_LEVEL.ERROR, sprintf(ERROR_MESSAGES.USER_PROFILE_SAVE_ERROR, MODULE_NAME, userId, ex.message)); + this.logger.log(LOG_LEVEL.ERROR, ERROR_MESSAGES.USER_PROFILE_SAVE_ERROR, MODULE_NAME, userId, ex.message); } } @@ -515,7 +554,7 @@ export class DecisionService { options: { [key: string]: boolean } = {} ): DecisionResponse { - const decideReasons = []; + const decideReasons: (string | number)[][] = []; const decisionVariation = this.getVariationForFeatureExperiment(configObj, feature, userId, attributes, options); decideReasons.push(...decisionVariation.reasons); const experimentDecision = decisionVariation.result; @@ -531,18 +570,16 @@ export class DecisionService { decideReasons.push(...decisionRolloutVariation.reasons); const rolloutDecision = decisionRolloutVariation.result; if (rolloutDecision.variation) { - const userInRolloutMessage = sprintf(LOG_MESSAGES.USER_IN_ROLLOUT, MODULE_NAME, userId, feature.key); - this.logger.log(LOG_LEVEL.DEBUG, userInRolloutMessage); - decideReasons.push(userInRolloutMessage); + this.logger.log(LOG_LEVEL.DEBUG, LOG_MESSAGES.USER_IN_ROLLOUT, MODULE_NAME, userId, feature.key); + decideReasons.push([LOG_MESSAGES.USER_IN_ROLLOUT, MODULE_NAME, userId, feature.key]); return { result: rolloutDecision, reasons: decideReasons, }; } - - const userNotInRolloutMessage = sprintf(LOG_MESSAGES.USER_NOT_IN_ROLLOUT, MODULE_NAME, userId, feature.key); - this.logger.log(LOG_LEVEL.DEBUG, userNotInRolloutMessage); - decideReasons.push(userNotInRolloutMessage); + + this.logger.log(LOG_LEVEL.DEBUG, LOG_MESSAGES.USER_NOT_IN_ROLLOUT, MODULE_NAME, userId, feature.key); + decideReasons.push([LOG_MESSAGES.USER_NOT_IN_ROLLOUT, MODULE_NAME, userId, feature.key]); return { result: rolloutDecision, reasons: decideReasons, @@ -557,7 +594,7 @@ export class DecisionService { options: { [key: string]: boolean } = {} ): DecisionResponse { - const decideReasons = []; + const decideReasons: (string | number)[][] = []; let variationKey = null; let decisionVariation; let index; @@ -588,9 +625,8 @@ export class DecisionService { } } } else { - const featureHasNoExperimentsMessage = sprintf(LOG_MESSAGES.FEATURE_HAS_NO_EXPERIMENTS, MODULE_NAME, feature.key); - this.logger.log(LOG_LEVEL.DEBUG, featureHasNoExperimentsMessage); - decideReasons.push(featureHasNoExperimentsMessage); + this.logger.log(LOG_LEVEL.DEBUG, LOG_MESSAGES.FEATURE_HAS_NO_EXPERIMENTS, MODULE_NAME, feature.key); + decideReasons.push([LOG_MESSAGES.FEATURE_HAS_NO_EXPERIMENTS, MODULE_NAME, feature.key]); } variationForFeatureExperiment = { @@ -611,12 +647,11 @@ export class DecisionService { userId: string, attributes?: UserAttributes ): DecisionResponse { - const decideReasons = []; + const decideReasons: (string | number)[][] = []; let decisionObj: DecisionObj; if (!feature.rolloutId) { - const noRolloutExistsMessage = sprintf(LOG_MESSAGES.NO_ROLLOUT_EXISTS, MODULE_NAME, feature.key); - this.logger.log(LOG_LEVEL.DEBUG, noRolloutExistsMessage); - decideReasons.push(noRolloutExistsMessage); + this.logger.log(LOG_LEVEL.DEBUG, LOG_MESSAGES.NO_ROLLOUT_EXISTS, MODULE_NAME, feature.key); + decideReasons.push([LOG_MESSAGES.NO_ROLLOUT_EXISTS, MODULE_NAME, feature.key]); decisionObj = { experiment: null, variation: null, @@ -631,14 +666,14 @@ export class DecisionService { const rollout = configObj.rolloutIdMap[feature.rolloutId]; if (!rollout) { - const invalidRolloutIdMessage = sprintf( + this.logger.log( + LOG_LEVEL.ERROR, ERROR_MESSAGES.INVALID_ROLLOUT_ID, MODULE_NAME, feature.rolloutId, - feature.key + feature.key, ); - this.logger.log(LOG_LEVEL.ERROR, invalidRolloutIdMessage); - decideReasons.push(invalidRolloutIdMessage); + decideReasons.push([ERROR_MESSAGES.INVALID_ROLLOUT_ID, MODULE_NAME, feature.rolloutId, feature.key]); decisionObj = { experiment: null, variation: null, @@ -651,13 +686,13 @@ export class DecisionService { } if (rollout.experiments.length === 0) { - const rolloutHasNoExperimentsMessage = sprintf( + this.logger.log( + LOG_LEVEL.ERROR, LOG_MESSAGES.ROLLOUT_HAS_NO_EXPERIMENTS, MODULE_NAME, - feature.rolloutId + feature.rolloutId, ); - this.logger.log(LOG_LEVEL.ERROR, rolloutHasNoExperimentsMessage); - decideReasons.push(rolloutHasNoExperimentsMessage); + decideReasons.push([LOG_MESSAGES.ROLLOUT_HAS_NO_EXPERIMENTS, MODULE_NAME, feature.rolloutId]); decisionObj = { experiment: null, variation: null, @@ -693,31 +728,35 @@ export class DecisionService { ); decideReasons.push(...decisionifUserIsInAudience.reasons); if (!decisionifUserIsInAudience.result) { - const userDoesNotMeetConditionsForTargetingRuleMessage = sprintf( + this.logger.log( + LOG_LEVEL.DEBUG, LOG_MESSAGES.USER_DOESNT_MEET_CONDITIONS_FOR_TARGETING_RULE, MODULE_NAME, userId, - loggingKey + loggingKey, ); - this.logger.log( - LOG_LEVEL.DEBUG, - userDoesNotMeetConditionsForTargetingRuleMessage - ); - decideReasons.push(userDoesNotMeetConditionsForTargetingRuleMessage); + decideReasons.push([ + LOG_MESSAGES.USER_DOESNT_MEET_CONDITIONS_FOR_TARGETING_RULE, + MODULE_NAME, + userId, + loggingKey, + ]); continue; } - const userMeetsConditionsForTargetingRuleMessage = sprintf( + this.logger.log( + LOG_LEVEL.DEBUG, LOG_MESSAGES.USER_MEETS_CONDITIONS_FOR_TARGETING_RULE, MODULE_NAME, userId, - loggingKey + loggingKey, ); - this.logger.log( - LOG_LEVEL.DEBUG, - userMeetsConditionsForTargetingRuleMessage - ); - decideReasons.push(userMeetsConditionsForTargetingRuleMessage); + decideReasons.push([ + LOG_MESSAGES.USER_MEETS_CONDITIONS_FOR_TARGETING_RULE, + MODULE_NAME, + userId, + loggingKey, + ]); bucketerParams = this.buildBucketerParams(configObj, rolloutRule, bucketingId, userId); decisionVariation = bucket(bucketerParams); decideReasons.push(...decisionVariation.reasons); @@ -726,16 +765,17 @@ export class DecisionService { variation = configObj.variationIdMap[variationId]; } if (variation) { - const userBucketeredIntoTargetingRuleMessage = sprintf( - LOG_MESSAGES.USER_BUCKETED_INTO_TARGETING_RULE, - MODULE_NAME, userId, - loggingKey - ); this.logger.log( LOG_LEVEL.DEBUG, - userBucketeredIntoTargetingRuleMessage + LOG_MESSAGES.USER_BUCKETED_INTO_TARGETING_RULE, + MODULE_NAME, userId, + loggingKey, ); - decideReasons.push(userBucketeredIntoTargetingRuleMessage); + decideReasons.push([ + LOG_MESSAGES.USER_BUCKETED_INTO_TARGETING_RULE, + MODULE_NAME, userId, + loggingKey, + ]); decisionObj = { experiment: rolloutRule, variation: variation, @@ -746,16 +786,17 @@ export class DecisionService { reasons: decideReasons, }; } else { - const userNotBucketeredIntoTargetingRuleMessage = sprintf( - LOG_MESSAGES.USER_NOT_BUCKETED_INTO_TARGETING_RULE, - MODULE_NAME, userId, - loggingKey - ); this.logger.log( LOG_LEVEL.DEBUG, - userNotBucketeredIntoTargetingRuleMessage + LOG_MESSAGES.USER_NOT_BUCKETED_INTO_TARGETING_RULE, + MODULE_NAME, userId, + loggingKey, ); - decideReasons.push(userNotBucketeredIntoTargetingRuleMessage); + decideReasons.push([ + LOG_MESSAGES.USER_NOT_BUCKETED_INTO_TARGETING_RULE, + MODULE_NAME, userId, + loggingKey, + ]); break; } } @@ -770,16 +811,17 @@ export class DecisionService { ); decideReasons.push(...decisionifUserIsInEveryoneRule.reasons); if (decisionifUserIsInEveryoneRule.result) { - const userMeetsConditionsForEveryoneTargetingRuleMessage = sprintf( - LOG_MESSAGES.USER_MEETS_CONDITIONS_FOR_TARGETING_RULE, - MODULE_NAME, userId, - 'Everyone Else' - ); this.logger.log( LOG_LEVEL.DEBUG, - userMeetsConditionsForEveryoneTargetingRuleMessage + LOG_MESSAGES.USER_MEETS_CONDITIONS_FOR_TARGETING_RULE, + MODULE_NAME, userId, + 'Everyone Else', ); - decideReasons.push(userMeetsConditionsForEveryoneTargetingRuleMessage); + decideReasons.push([ + LOG_MESSAGES.USER_MEETS_CONDITIONS_FOR_TARGETING_RULE, + MODULE_NAME, userId, + 'Everyone Else', + ]); bucketerParams = this.buildBucketerParams(configObj, everyoneElseRule, bucketingId, userId); decisionVariation = bucket(bucketerParams); decideReasons.push(...decisionVariation.reasons); @@ -788,16 +830,17 @@ export class DecisionService { variation = configObj.variationIdMap[variationId]; } if (variation) { - const userBucketeredIntoEveryoneTargetingRuleMessage = sprintf( - LOG_MESSAGES.USER_BUCKETED_INTO_EVERYONE_TARGETING_RULE, - MODULE_NAME, - userId - ); this.logger.log( LOG_LEVEL.DEBUG, - userBucketeredIntoEveryoneTargetingRuleMessage + LOG_MESSAGES.USER_BUCKETED_INTO_EVERYONE_TARGETING_RULE, + MODULE_NAME, + userId, ); - decideReasons.push(userBucketeredIntoEveryoneTargetingRuleMessage); + decideReasons.push([ + LOG_MESSAGES.USER_BUCKETED_INTO_EVERYONE_TARGETING_RULE, + MODULE_NAME, + userId, + ]); decisionObj = { experiment: everyoneElseRule, variation: variation, @@ -808,16 +851,17 @@ export class DecisionService { reasons: decideReasons, }; } else { - const userNotBucketeredIntoEveryoneTargetingRuleMessage = sprintf( - LOG_MESSAGES.USER_NOT_BUCKETED_INTO_EVERYONE_TARGETING_RULE, - MODULE_NAME, - userId - ); this.logger.log( LOG_LEVEL.DEBUG, - userNotBucketeredIntoEveryoneTargetingRuleMessage + LOG_MESSAGES.USER_NOT_BUCKETED_INTO_EVERYONE_TARGETING_RULE, + MODULE_NAME, + userId, ); - decideReasons.push(userNotBucketeredIntoEveryoneTargetingRuleMessage); + decideReasons.push([ + LOG_MESSAGES.USER_NOT_BUCKETED_INTO_EVERYONE_TARGETING_RULE, + MODULE_NAME, + userId, + ]); } } @@ -849,9 +893,9 @@ export class DecisionService { ) { if (typeof attributes[CONTROL_ATTRIBUTES.BUCKETING_ID] === 'string') { bucketingId = attributes[CONTROL_ATTRIBUTES.BUCKETING_ID]; - this.logger.log(LOG_LEVEL.DEBUG, sprintf(LOG_MESSAGES.VALID_BUCKETING_ID, MODULE_NAME, bucketingId)); + this.logger.log(LOG_LEVEL.DEBUG, LOG_MESSAGES.VALID_BUCKETING_ID, MODULE_NAME, bucketingId); } else { - this.logger.log(LOG_LEVEL.WARNING, sprintf(LOG_MESSAGES.BUCKETING_ID_NOT_STRING, MODULE_NAME)); + this.logger.log(LOG_LEVEL.WARNING, LOG_MESSAGES.BUCKETING_ID_NOT_STRING, MODULE_NAME); } } @@ -874,7 +918,10 @@ export class DecisionService { delete this.forcedVariationMap[userId][experimentId]; this.logger.log( LOG_LEVEL.DEBUG, - sprintf(LOG_MESSAGES.VARIATION_REMOVED_FOR_USER, MODULE_NAME, experimentKey, userId) + LOG_MESSAGES.VARIATION_REMOVED_FOR_USER, + MODULE_NAME, + experimentKey, + userId, ); } else { throw new Error(sprintf(ERROR_MESSAGES.USER_NOT_IN_FORCED_VARIATION, MODULE_NAME, userId)); @@ -898,7 +945,11 @@ export class DecisionService { this.logger.log( LOG_LEVEL.DEBUG, - sprintf(LOG_MESSAGES.USER_MAPPED_TO_FORCED_VARIATION, MODULE_NAME, variationId, experimentId, userId) + LOG_MESSAGES.USER_MAPPED_TO_FORCED_VARIATION, + MODULE_NAME, + variationId, + experimentId, + userId, ); } @@ -915,15 +966,14 @@ export class DecisionService { experimentKey: string, userId: string ): DecisionResponse { - const decideReasons: string[] = []; + const decideReasons: (string | number)[][] = []; const experimentToVariationMap = this.forcedVariationMap[userId]; if (!experimentToVariationMap) { - this.logger.log(LOG_LEVEL.DEBUG, - sprintf( - LOG_MESSAGES.USER_HAS_NO_FORCED_VARIATION, - MODULE_NAME, - userId - ) + this.logger.log( + LOG_LEVEL.DEBUG, + LOG_MESSAGES.USER_HAS_NO_FORCED_VARIATION, + MODULE_NAME, + userId, ); return { @@ -939,13 +989,17 @@ export class DecisionService { experimentId = experiment['id']; } else { // catching improperly formatted experiments - const improperlyFormattedExperimentMessage = sprintf( + this.logger.log( + LOG_LEVEL.ERROR, ERROR_MESSAGES.IMPROPERLY_FORMATTED_EXPERIMENT, MODULE_NAME, - experimentKey + experimentKey, ); - this.logger.log(LOG_LEVEL.ERROR, improperlyFormattedExperimentMessage); - decideReasons.push(improperlyFormattedExperimentMessage); + decideReasons.push([ + ERROR_MESSAGES.IMPROPERLY_FORMATTED_EXPERIMENT, + MODULE_NAME, + experimentKey, + ]); return { result: null, @@ -967,12 +1021,10 @@ export class DecisionService { if (!variationId) { this.logger.log( LOG_LEVEL.DEBUG, - sprintf( - LOG_MESSAGES.USER_HAS_NO_FORCED_VARIATION_FOR_EXPERIMENT, - MODULE_NAME, - experimentKey, - userId - ) + LOG_MESSAGES.USER_HAS_NO_FORCED_VARIATION_FOR_EXPERIMENT, + MODULE_NAME, + experimentKey, + userId, ); return { result: null, @@ -982,24 +1034,28 @@ export class DecisionService { const variationKey = getVariationKeyFromId(configObj, variationId); if (variationKey) { - const userHasForcedVariationMessage = sprintf( + this.logger.log( + LOG_LEVEL.DEBUG, LOG_MESSAGES.USER_HAS_FORCED_VARIATION, MODULE_NAME, variationKey, experimentKey, - userId + userId, ); - this.logger.log(LOG_LEVEL.DEBUG, userHasForcedVariationMessage); - decideReasons.push(userHasForcedVariationMessage); + decideReasons.push([ + LOG_MESSAGES.USER_HAS_FORCED_VARIATION, + MODULE_NAME, + variationKey, + experimentKey, + userId, + ]); } else { this.logger.log( LOG_LEVEL.DEBUG, - sprintf( - LOG_MESSAGES.USER_HAS_NO_FORCED_VARIATION_FOR_EXPERIMENT, - MODULE_NAME, - experimentKey, - userId - ) + LOG_MESSAGES.USER_HAS_NO_FORCED_VARIATION_FOR_EXPERIMENT, + MODULE_NAME, + experimentKey, + userId, ); } @@ -1024,7 +1080,7 @@ export class DecisionService { variationKey: string | null ): boolean { if (variationKey != null && !stringValidator.validate(variationKey)) { - this.logger.log(LOG_LEVEL.ERROR, sprintf(ERROR_MESSAGES.INVALID_VARIATION_KEY, MODULE_NAME)); + this.logger.log(LOG_LEVEL.ERROR, ERROR_MESSAGES.INVALID_VARIATION_KEY, MODULE_NAME); return false; } @@ -1037,7 +1093,9 @@ export class DecisionService { // catching improperly formatted experiments this.logger.log( LOG_LEVEL.ERROR, - sprintf(ERROR_MESSAGES.IMPROPERLY_FORMATTED_EXPERIMENT, MODULE_NAME, experimentKey) + ERROR_MESSAGES.IMPROPERLY_FORMATTED_EXPERIMENT, + MODULE_NAME, + experimentKey, ); return false; } @@ -1062,7 +1120,10 @@ export class DecisionService { if (!variationId) { this.logger.log( LOG_LEVEL.ERROR, - sprintf(ERROR_MESSAGES.NO_VARIATION_FOR_EXPERIMENT_KEY, MODULE_NAME, variationKey, experimentKey) + ERROR_MESSAGES.NO_VARIATION_FOR_EXPERIMENT_KEY, + MODULE_NAME, + variationKey, + experimentKey, ); return false; } diff --git a/packages/optimizely-sdk/lib/core/notification_center/index.ts b/packages/optimizely-sdk/lib/core/notification_center/index.ts index f4831af06..c28504947 100644 --- a/packages/optimizely-sdk/lib/core/notification_center/index.ts +++ b/packages/optimizely-sdk/lib/core/notification_center/index.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { sprintf, objectValues } from '@optimizely/js-sdk-utils'; +import { objectValues } from '@optimizely/js-sdk-utils'; import { LogHandler, ErrorHandler } from '@optimizely/js-sdk-logging'; import { NOTIFICATION_TYPES as notificationTypesEnum } from '@optimizely/js-sdk-utils'; import { NotificationListener, ListenerPayload } from '../../shared_types'; @@ -216,7 +216,10 @@ export class NotificationCenter { } catch (ex) { this.logger.log( LOG_LEVEL.ERROR, - sprintf(LOG_MESSAGES.NOTIFICATION_LISTENER_EXCEPTION, MODULE_NAME, notificationType, ex.message) + LOG_MESSAGES.NOTIFICATION_LISTENER_EXCEPTION, + MODULE_NAME, + notificationType, + ex.message, ); } } diff --git a/packages/optimizely-sdk/lib/core/project_config/index.tests.js b/packages/optimizely-sdk/lib/core/project_config/index.tests.js index 06d0a71ba..6e846519c 100644 --- a/packages/optimizely-sdk/lib/core/project_config/index.tests.js +++ b/packages/optimizely-sdk/lib/core/project_config/index.tests.js @@ -30,6 +30,7 @@ import * as loggerPlugin from '../../plugins/logger'; import testDatafile from '../../tests/test_data'; import configValidator from '../../utils/config_validator'; +var buildLogMessageFromArgs = args => sprintf(args[1], ...args.splice(2)); var logger = getLogger(); describe('lib/core/project_config', function() { @@ -301,9 +302,8 @@ describe('lib/core/project_config', function() { it('should return null for invalid attribute key in getAttributeId', function() { assert.isNull(projectConfig.getAttributeId(configObj, 'invalidAttributeKey', createdLogger)); - sinon.assert.calledWithExactly( - createdLogger.log, - LOG_LEVEL.DEBUG, + assert.strictEqual( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'PROJECT_CONFIG: Unrecognized attribute invalidAttributeKey provided. Pruning before sending event to Optimizely.' ); }); @@ -315,9 +315,8 @@ describe('lib/core/project_config', function() { key: '$opt_some_reserved_attribute', }; assert.strictEqual(projectConfig.getAttributeId(configObj, '$opt_some_reserved_attribute', createdLogger), '42'); - sinon.assert.calledWithExactly( - createdLogger.log, - LOG_LEVEL.WARNING, + assert.strictEqual( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'Attribute $opt_some_reserved_attribute unexpectedly has reserved prefix $opt_; using attribute ID instead of reserved attribute name.' ); }); @@ -461,9 +460,8 @@ describe('lib/core/project_config', function() { var result = projectConfig.getVariableForFeature(configObj, featureKey, variableKey, featureManagementLogger); assert.strictEqual(result, null); sinon.assert.calledOnce(featureManagementLogger.log); - sinon.assert.calledWithExactly( - featureManagementLogger.log, - LOG_LEVEL.ERROR, + assert.strictEqual( + buildLogMessageFromArgs(featureManagementLogger.log.lastCall.args), 'PROJECT_CONFIG: Variable with key "notARealVariable____" associated with feature with key "test_feature_for_experiment" is not in datafile.' ); }); @@ -474,9 +472,8 @@ describe('lib/core/project_config', function() { var result = projectConfig.getVariableForFeature(configObj, featureKey, variableKey, featureManagementLogger); assert.strictEqual(result, null); sinon.assert.calledOnce(featureManagementLogger.log); - sinon.assert.calledWithExactly( - featureManagementLogger.log, - LOG_LEVEL.ERROR, + assert.strictEqual( + buildLogMessageFromArgs(featureManagementLogger.log.lastCall.args), 'PROJECT_CONFIG: Feature key notARealFeature_____ is not in datafile.' ); }); @@ -487,9 +484,8 @@ describe('lib/core/project_config', function() { var result = projectConfig.getVariableForFeature(configObj, featureKey, variableKey, featureManagementLogger); assert.strictEqual(result, null); sinon.assert.calledOnce(featureManagementLogger.log); - sinon.assert.calledWithExactly( - featureManagementLogger.log, - LOG_LEVEL.ERROR, + assert.strictEqual( + buildLogMessageFromArgs(featureManagementLogger.log.lastCall.args), 'PROJECT_CONFIG: Feature key notARealFeature_____ is not in datafile.' ); }); @@ -633,9 +629,8 @@ describe('lib/core/project_config', function() { featureManagementLogger ); assert.strictEqual(result, null); - sinon.assert.calledWithExactly( - featureManagementLogger.log, - LOG_LEVEL.ERROR, + assert.strictEqual( + buildLogMessageFromArgs(featureManagementLogger.log.lastCall.args), 'PROJECT_CONFIG: Unable to cast value notabool to type boolean, returning null.' ); }); @@ -647,9 +642,8 @@ describe('lib/core/project_config', function() { featureManagementLogger ); assert.strictEqual(result, null); - sinon.assert.calledWithExactly( - featureManagementLogger.log, - LOG_LEVEL.ERROR, + assert.strictEqual( + buildLogMessageFromArgs(featureManagementLogger.log.lastCall.args), 'PROJECT_CONFIG: Unable to cast value notanint to type integer, returning null.' ); }); @@ -661,9 +655,8 @@ describe('lib/core/project_config', function() { featureManagementLogger ); assert.strictEqual(result, null); - sinon.assert.calledWithExactly( - featureManagementLogger.log, - LOG_LEVEL.ERROR, + assert.strictEqual( + buildLogMessageFromArgs(featureManagementLogger.log.lastCall.args), 'PROJECT_CONFIG: Unable to cast value notadouble to type double, returning null.' ); }); diff --git a/packages/optimizely-sdk/lib/core/project_config/index.ts b/packages/optimizely-sdk/lib/core/project_config/index.ts index 99cb0e6d8..1a24266fd 100644 --- a/packages/optimizely-sdk/lib/core/project_config/index.ts +++ b/packages/optimizely-sdk/lib/core/project_config/index.ts @@ -271,11 +271,9 @@ export const getAttributeId = function( if (hasReservedPrefix) { logger.log( LOG_LEVEL.WARNING, - sprintf( - 'Attribute %s unexpectedly has reserved prefix %s; using attribute ID instead of reserved attribute name.', - attributeKey, - RESERVED_ATTRIBUTE_PREFIX - ) + 'Attribute %s unexpectedly has reserved prefix %s; using attribute ID instead of reserved attribute name.', + attributeKey, + RESERVED_ATTRIBUTE_PREFIX, ); } return attribute.id; @@ -283,7 +281,7 @@ export const getAttributeId = function( return attributeKey; } - logger.log(LOG_LEVEL.DEBUG, sprintf(ERROR_MESSAGES.UNRECOGNIZED_ATTRIBUTE, MODULE_NAME, attributeKey)); + logger.log(LOG_LEVEL.DEBUG, ERROR_MESSAGES.UNRECOGNIZED_ATTRIBUTE, MODULE_NAME, attributeKey); return null; }; @@ -466,7 +464,7 @@ export const getExperimentFromId = function( } } - logger.log(LOG_LEVEL.ERROR, sprintf(ERROR_MESSAGES.INVALID_EXPERIMENT_ID, MODULE_NAME, experimentId)); + logger.log(LOG_LEVEL.ERROR, ERROR_MESSAGES.INVALID_EXPERIMENT_ID, MODULE_NAME, experimentId); return null; }; @@ -491,7 +489,7 @@ export const getFeatureFromKey = function( } } - logger.log(LOG_LEVEL.ERROR, sprintf(ERROR_MESSAGES.FEATURE_NOT_IN_DATAFILE, MODULE_NAME, featureKey)); + logger.log(LOG_LEVEL.ERROR, ERROR_MESSAGES.FEATURE_NOT_IN_DATAFILE, MODULE_NAME, featureKey); return null; }; @@ -514,7 +512,7 @@ export const getVariableForFeature = function( ): FeatureVariable | null { const feature = projectConfig.featureKeyMap[featureKey]; if (!feature) { - logger.log(LOG_LEVEL.ERROR, sprintf(ERROR_MESSAGES.FEATURE_NOT_IN_DATAFILE, MODULE_NAME, featureKey)); + logger.log(LOG_LEVEL.ERROR, ERROR_MESSAGES.FEATURE_NOT_IN_DATAFILE, MODULE_NAME, featureKey); return null; } @@ -522,7 +520,10 @@ export const getVariableForFeature = function( if (!variable) { logger.log( LOG_LEVEL.ERROR, - sprintf(ERROR_MESSAGES.VARIABLE_KEY_NOT_IN_DATAFILE, MODULE_NAME, variableKey, featureKey) + ERROR_MESSAGES.VARIABLE_KEY_NOT_IN_DATAFILE, + MODULE_NAME, + variableKey, + featureKey, ); return null; } @@ -555,7 +556,9 @@ export const getVariableValueForVariation = function( if (!projectConfig.variationVariableUsageMap.hasOwnProperty(variation.id)) { logger.log( LOG_LEVEL.ERROR, - sprintf(ERROR_MESSAGES.VARIATION_ID_NOT_IN_DATAFILE_NO_EXPERIMENT, MODULE_NAME, variation.id) + ERROR_MESSAGES.VARIATION_ID_NOT_IN_DATAFILE_NO_EXPERIMENT, + MODULE_NAME, + variation.id, ); return null; } @@ -594,7 +597,10 @@ export const getTypeCastValue = function( if (variableValue !== 'true' && variableValue !== 'false') { logger.log( LOG_LEVEL.ERROR, - sprintf(ERROR_MESSAGES.UNABLE_TO_CAST_VALUE, MODULE_NAME, variableValue, variableType) + ERROR_MESSAGES.UNABLE_TO_CAST_VALUE, + MODULE_NAME, + variableValue, + variableType, ); castValue = null; } else { @@ -607,7 +613,10 @@ export const getTypeCastValue = function( if (isNaN(castValue)) { logger.log( LOG_LEVEL.ERROR, - sprintf(ERROR_MESSAGES.UNABLE_TO_CAST_VALUE, MODULE_NAME, variableValue, variableType) + ERROR_MESSAGES.UNABLE_TO_CAST_VALUE, + MODULE_NAME, + variableValue, + variableType, ); castValue = null; } @@ -618,7 +627,10 @@ export const getTypeCastValue = function( if (isNaN(castValue)) { logger.log( LOG_LEVEL.ERROR, - sprintf(ERROR_MESSAGES.UNABLE_TO_CAST_VALUE, MODULE_NAME, variableValue, variableType) + ERROR_MESSAGES.UNABLE_TO_CAST_VALUE, + MODULE_NAME, + variableValue, + variableType, ); castValue = null; } @@ -630,7 +642,10 @@ export const getTypeCastValue = function( } catch (e) { logger.log( LOG_LEVEL.ERROR, - sprintf(ERROR_MESSAGES.UNABLE_TO_CAST_VALUE, MODULE_NAME, variableValue, variableType) + ERROR_MESSAGES.UNABLE_TO_CAST_VALUE, + MODULE_NAME, + variableValue, + variableType, ); castValue = null; } @@ -715,12 +730,12 @@ export const tryCreatingProjectConfig = function( if (config.jsonSchemaValidator) { try { config.jsonSchemaValidator.validate(newDatafileObj); - config.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.VALID_DATAFILE, MODULE_NAME)); + config.logger.log(LOG_LEVEL.INFO, LOG_MESSAGES.VALID_DATAFILE, MODULE_NAME); } catch (error) { return { configObj: null, error }; } } else { - config.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.SKIPPING_JSON_VALIDATION, MODULE_NAME)); + config.logger.log(LOG_LEVEL.INFO, LOG_MESSAGES.SKIPPING_JSON_VALIDATION, MODULE_NAME); } const createProjectConfigArgs = [newDatafileObj]; diff --git a/packages/optimizely-sdk/lib/optimizely/index.tests.js b/packages/optimizely-sdk/lib/optimizely/index.tests.js index d364cca7c..ae6522f2a 100644 --- a/packages/optimizely-sdk/lib/optimizely/index.tests.js +++ b/packages/optimizely-sdk/lib/optimizely/index.tests.js @@ -48,6 +48,8 @@ var DECISION_MESSAGES = enums.DECISION_MESSAGES; var DECISION_NOTIFICATION_TYPES = enums.DECISION_NOTIFICATION_TYPES; var FEATURE_VARIABLE_TYPES = enums.FEATURE_VARIABLE_TYPES; +var buildLogMessageFromArgs = args => sprintf(args[1], ...args.splice(2)); + describe('lib/optimizely', function() { var ProjectConfigManagerStub; var globalStubErrorHandler; @@ -144,7 +146,7 @@ describe('lib/optimizely', function() { }); sinon.assert.called(createdLogger.log); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual(logMessage, sprintf(LOG_MESSAGES.INVALID_CLIENT_ENGINE, 'OPTIMIZELY', 'undefined')); }); @@ -161,7 +163,7 @@ describe('lib/optimizely', function() { }); sinon.assert.called(createdLogger.log); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual(logMessage, sprintf(LOG_MESSAGES.INVALID_DEFAULT_DECIDE_OPTIONS, 'OPTIMIZELY')); }); @@ -210,7 +212,7 @@ describe('lib/optimizely', function() { UNSTABLE_conditionEvaluators: undefined, }); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual(logMessage, 'OPTIMIZELY: Valid user profile service provided.'); }); @@ -235,7 +237,7 @@ describe('lib/optimizely', function() { UNSTABLE_conditionEvaluators: undefined, }); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual( logMessage, "USER_PROFILE_SERVICE_VALIDATOR: Provided user profile service instance is in an invalid format: Missing function 'lookup'." @@ -816,13 +818,13 @@ describe('lib/optimizely', function() { sinon.assert.calledWithExactly( createdLogger.log, LOG_LEVEL.DEBUG, - sprintf(LOG_MESSAGES.USER_HAS_NO_FORCED_VARIATION, 'DECISION_SERVICE', 'testUser') + LOG_MESSAGES.USER_HAS_NO_FORCED_VARIATION, 'DECISION_SERVICE', 'testUser' ); sinon.assert.calledWithExactly( createdLogger.log, LOG_LEVEL.INFO, - sprintf(LOG_MESSAGES.NOT_ACTIVATING_USER, 'OPTIMIZELY', 'testUser', 'testExperiment') + LOG_MESSAGES.NOT_ACTIVATING_USER, 'OPTIMIZELY', 'testUser', 'testExperiment' ); }); @@ -832,19 +834,19 @@ describe('lib/optimizely', function() { sinon.assert.calledWithExactly( createdLogger.log, LOG_LEVEL.DEBUG, - sprintf(LOG_MESSAGES.USER_HAS_NO_FORCED_VARIATION, 'DECISION_SERVICE', 'testUser') + LOG_MESSAGES.USER_HAS_NO_FORCED_VARIATION, 'DECISION_SERVICE', 'testUser' ); sinon.assert.calledWithExactly( createdLogger.log, LOG_LEVEL.INFO, - sprintf(LOG_MESSAGES.USER_NOT_IN_EXPERIMENT, 'DECISION_SERVICE', 'testUser', 'testExperimentWithAudiences') + LOG_MESSAGES.USER_NOT_IN_EXPERIMENT, 'DECISION_SERVICE', 'testUser', 'testExperimentWithAudiences' ); sinon.assert.calledWithExactly( createdLogger.log, LOG_LEVEL.INFO, - sprintf(LOG_MESSAGES.NOT_ACTIVATING_USER, 'OPTIMIZELY', 'testUser', 'testExperimentWithAudiences') + LOG_MESSAGES.NOT_ACTIVATING_USER, 'OPTIMIZELY', 'testUser', 'testExperimentWithAudiences' ); }); @@ -854,19 +856,19 @@ describe('lib/optimizely', function() { sinon.assert.calledWithExactly( createdLogger.log, LOG_LEVEL.DEBUG, - sprintf(LOG_MESSAGES.USER_HAS_NO_FORCED_VARIATION, 'DECISION_SERVICE', 'testUser') + LOG_MESSAGES.USER_HAS_NO_FORCED_VARIATION, 'DECISION_SERVICE', 'testUser' ); sinon.assert.calledWithExactly( createdLogger.log, LOG_LEVEL.INFO, - sprintf(LOG_MESSAGES.USER_NOT_IN_EXPERIMENT, 'DECISION_SERVICE', 'testUser', 'groupExperiment1') + LOG_MESSAGES.USER_NOT_IN_EXPERIMENT, 'DECISION_SERVICE', 'testUser', 'groupExperiment1' ); sinon.assert.calledWithExactly( createdLogger.log, LOG_LEVEL.INFO, - sprintf(LOG_MESSAGES.NOT_ACTIVATING_USER, 'OPTIMIZELY', 'testUser', 'groupExperiment1') + LOG_MESSAGES.NOT_ACTIVATING_USER, 'OPTIMIZELY', 'testUser', 'groupExperiment1' ); }); @@ -874,12 +876,12 @@ describe('lib/optimizely', function() { assert.isNull(optlyInstance.activate('testExperimentNotRunning', 'testUser')); sinon.assert.calledTwice(createdLogger.log); - var logMessage1 = createdLogger.log.args[0][1]; + var logMessage1 = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual( logMessage1, sprintf(LOG_MESSAGES.EXPERIMENT_NOT_RUNNING, 'DECISION_SERVICE', 'testExperimentNotRunning') ); - var logMessage2 = createdLogger.log.args[1][1]; + var logMessage2 = buildLogMessageFromArgs(createdLogger.log.args[1]); assert.strictEqual( logMessage2, sprintf(LOG_MESSAGES.NOT_ACTIVATING_USER, 'OPTIMIZELY', 'testUser', 'testExperimentNotRunning') @@ -897,9 +899,9 @@ describe('lib/optimizely', function() { sinon.assert.calledTwice(createdLogger.log); - var logMessage1 = createdLogger.log.args[0][1]; + var logMessage1 = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual(logMessage1, sprintf(ERROR_MESSAGES.INVALID_INPUT_FORMAT, 'OPTIMIZELY', 'user_id')); - var logMessage2 = createdLogger.log.args[1][1]; + var logMessage2 = buildLogMessageFromArgs(createdLogger.log.args[1]); assert.strictEqual( logMessage2, sprintf(LOG_MESSAGES.NOT_ACTIVATING_USER, 'OPTIMIZELY', 'null', 'testExperiment') @@ -912,12 +914,12 @@ describe('lib/optimizely', function() { sinon.assert.notCalled(eventDispatcher.dispatchEvent); sinon.assert.calledTwice(createdLogger.log); - var logMessage1 = createdLogger.log.args[0][1]; + var logMessage1 = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual( logMessage1, sprintf(ERROR_MESSAGES.INVALID_EXPERIMENT_KEY, 'OPTIMIZELY', 'invalidExperimentKey') ); - var logMessage2 = createdLogger.log.args[1][1]; + var logMessage2 = buildLogMessageFromArgs(createdLogger.log.args[1]); assert.strictEqual( logMessage2, sprintf(LOG_MESSAGES.NOT_ACTIVATING_USER, 'OPTIMIZELY', 'testUser', 'invalidExperimentKey') @@ -933,9 +935,9 @@ describe('lib/optimizely', function() { assert.strictEqual(errorMessage, sprintf(ERROR_MESSAGES.INVALID_ATTRIBUTES, 'ATTRIBUTES_VALIDATOR')); sinon.assert.calledTwice(createdLogger.log); - var logMessage1 = createdLogger.log.args[0][1]; + var logMessage1 = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual(logMessage1, sprintf(ERROR_MESSAGES.INVALID_ATTRIBUTES, 'ATTRIBUTES_VALIDATOR')); - var logMessage2 = createdLogger.log.args[1][1]; + var logMessage2 = buildLogMessageFromArgs(createdLogger.log.args[1]); assert.strictEqual( logMessage2, sprintf(LOG_MESSAGES.NOT_ACTIVATING_USER, 'OPTIMIZELY', 'testUser', 'testExperimentWithAudiences') @@ -983,12 +985,12 @@ describe('lib/optimizely', function() { sinon.assert.calledTwice(Optimizely.prototype.validateInputs); - var logMessage0 = createdLogger.log.args[0][1]; + var logMessage0 = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual( logMessage0, sprintf(LOG_MESSAGES.USER_HAS_NO_FORCED_VARIATION, 'DECISION_SERVICE', 'user1') ); - var logMessage1 = createdLogger.log.args[1][1]; + var logMessage1 = buildLogMessageFromArgs(createdLogger.log.args[1]); assert.strictEqual( logMessage1, sprintf(LOG_MESSAGES.USER_FORCED_IN_VARIATION, 'DECISION_SERVICE', 'user1', 'control') @@ -1050,7 +1052,7 @@ describe('lib/optimizely', function() { instance.activate('testExperiment', 'testUser'); sinon.assert.calledOnce(createdLogger.log); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual(logMessage, sprintf(LOG_MESSAGES.INVALID_OBJECT, 'OPTIMIZELY', 'activate')); sinon.assert.notCalled(eventDispatcher.dispatchEvent); @@ -1674,7 +1676,7 @@ describe('lib/optimizely', function() { assert.strictEqual(errorMessage, sprintf(ERROR_MESSAGES.INVALID_INPUT_FORMAT, 'OPTIMIZELY', 'user_id')); sinon.assert.calledOnce(createdLogger.log); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual(logMessage, sprintf(ERROR_MESSAGES.INVALID_INPUT_FORMAT, 'OPTIMIZELY', 'user_id')); }); @@ -1687,14 +1689,14 @@ describe('lib/optimizely', function() { sinon.assert.calledWithExactly( logCall1, LOG_LEVEL.WARNING, - sprintf(LOG_MESSAGES.EVENT_KEY_NOT_FOUND, 'OPTIMIZELY', 'invalidEventKey') + LOG_MESSAGES.EVENT_KEY_NOT_FOUND, 'OPTIMIZELY', 'invalidEventKey' ); var logCall2 = createdLogger.log.getCall(1); sinon.assert.calledWithExactly( logCall2, LOG_LEVEL.WARNING, - sprintf(LOG_MESSAGES.NOT_TRACKING_USER, 'OPTIMIZELY', 'testUser') + LOG_MESSAGES.NOT_TRACKING_USER, 'OPTIMIZELY', 'testUser' ); sinon.assert.notCalled(errorHandler.handleError); @@ -1710,7 +1712,7 @@ describe('lib/optimizely', function() { assert.strictEqual(errorMessage, sprintf(ERROR_MESSAGES.INVALID_ATTRIBUTES, 'ATTRIBUTES_VALIDATOR')); sinon.assert.calledOnce(createdLogger.log); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual(logMessage, sprintf(ERROR_MESSAGES.INVALID_ATTRIBUTES, 'ATTRIBUTES_VALIDATOR')); }); @@ -1754,7 +1756,7 @@ describe('lib/optimizely', function() { instance.track('testExperiment', 'testUser'); sinon.assert.calledOnce(createdLogger.log); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual(logMessage, sprintf(LOG_MESSAGES.INVALID_OBJECT, 'OPTIMIZELY', 'track')); sinon.assert.notCalled(eventDispatcher.dispatchEvent); @@ -1778,7 +1780,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWithExactly( createdLogger.log, LOG_LEVEL.DEBUG, - sprintf(LOG_MESSAGES.USER_HAS_NO_FORCED_VARIATION, 'DECISION_SERVICE', 'testUser') + LOG_MESSAGES.USER_HAS_NO_FORCED_VARIATION, 'DECISION_SERVICE', 'testUser' ); }); @@ -1811,19 +1813,19 @@ describe('lib/optimizely', function() { sinon.assert.calledWithExactly( createdLogger.log, LOG_LEVEL.DEBUG, - sprintf(LOG_MESSAGES.USER_HAS_NO_FORCED_VARIATION, 'DECISION_SERVICE', 'testUser') + LOG_MESSAGES.USER_HAS_NO_FORCED_VARIATION, 'DECISION_SERVICE', 'testUser' ); sinon.assert.calledWithExactly( createdLogger.log, LOG_LEVEL.INFO, - sprintf(LOG_MESSAGES.USER_NOT_IN_EXPERIMENT, 'DECISION_SERVICE', 'testUser', 'testExperimentWithAudiences') + LOG_MESSAGES.USER_NOT_IN_EXPERIMENT, 'DECISION_SERVICE', 'testUser', 'testExperimentWithAudiences' ); sinon.assert.calledWithExactly( createdLogger.log, LOG_LEVEL.INFO, - sprintf(LOG_MESSAGES.EXPERIMENT_NOT_RUNNING, 'DECISION_SERVICE', 'testExperimentNotRunning') + LOG_MESSAGES.EXPERIMENT_NOT_RUNNING, 'DECISION_SERVICE', 'testExperimentNotRunning' ); }); @@ -1837,7 +1839,7 @@ describe('lib/optimizely', function() { assert.strictEqual(errorMessage, sprintf(ERROR_MESSAGES.INVALID_INPUT_FORMAT, 'OPTIMIZELY', 'user_id')); sinon.assert.calledOnce(createdLogger.log); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual(logMessage, sprintf(ERROR_MESSAGES.INVALID_INPUT_FORMAT, 'OPTIMIZELY', 'user_id')); }); @@ -1846,7 +1848,7 @@ describe('lib/optimizely', function() { assert.isNull(getVariationWithError); sinon.assert.calledOnce(createdLogger.log); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual( logMessage, sprintf(ERROR_MESSAGES.INVALID_EXPERIMENT_KEY, 'OPTIMIZELY', 'invalidExperimentKey') @@ -1863,7 +1865,7 @@ describe('lib/optimizely', function() { assert.strictEqual(errorMessage, sprintf(ERROR_MESSAGES.INVALID_ATTRIBUTES, 'ATTRIBUTES_VALIDATOR')); sinon.assert.calledOnce(createdLogger.log); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual(logMessage, sprintf(ERROR_MESSAGES.INVALID_ATTRIBUTES, 'ATTRIBUTES_VALIDATOR')); }); @@ -1884,12 +1886,12 @@ describe('lib/optimizely', function() { sinon.assert.calledTwice(createdLogger.log); - var logMessage0 = createdLogger.log.args[0][1]; + var logMessage0 = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual( logMessage0, sprintf(LOG_MESSAGES.USER_HAS_NO_FORCED_VARIATION, 'DECISION_SERVICE', 'user1') ); - var logMessage = createdLogger.log.args[1][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[1]); assert.strictEqual( logMessage, sprintf(LOG_MESSAGES.USER_FORCED_IN_VARIATION, 'DECISION_SERVICE', 'user1', 'control') @@ -1912,7 +1914,7 @@ describe('lib/optimizely', function() { instance.getVariation('testExperiment', 'testUser'); sinon.assert.calledOnce(createdLogger.log); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual(logMessage, sprintf(LOG_MESSAGES.INVALID_OBJECT, 'OPTIMIZELY', 'getVariation')); sinon.assert.notCalled(eventDispatcher.dispatchEvent); @@ -1964,7 +1966,7 @@ describe('lib/optimizely', function() { var forcedVariation = optlyInstance.getForcedVariation('testExperiment', 'user1'); assert.strictEqual(forcedVariation, null); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual(logMessage, sprintf(LOG_MESSAGES.USER_HAS_NO_FORCED_VARIATION, 'DECISION_SERVICE', 'user1')); }); @@ -1972,7 +1974,7 @@ describe('lib/optimizely', function() { var forcedVariation = optlyInstance.getForcedVariation(null, 'user1'); assert.strictEqual(forcedVariation, null); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual(logMessage, sprintf(ERROR_MESSAGES.INVALID_INPUT_FORMAT, 'OPTIMIZELY', 'experiment_key')); }); @@ -1980,7 +1982,7 @@ describe('lib/optimizely', function() { var forcedVariation = optlyInstance.getForcedVariation(undefined, 'user1'); assert.strictEqual(forcedVariation, null); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual(logMessage, sprintf(ERROR_MESSAGES.INVALID_INPUT_FORMAT, 'OPTIMIZELY', 'experiment_key')); }); @@ -1988,7 +1990,7 @@ describe('lib/optimizely', function() { var forcedVariation = optlyInstance.getForcedVariation('testExperiment', null); assert.strictEqual(forcedVariation, null); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual(logMessage, sprintf(ERROR_MESSAGES.INVALID_INPUT_FORMAT, 'OPTIMIZELY', 'user_id')); }); @@ -1996,7 +1998,7 @@ describe('lib/optimizely', function() { var forcedVariation = optlyInstance.getForcedVariation('testExperiment', undefined); assert.strictEqual(forcedVariation, null); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual(logMessage, sprintf(ERROR_MESSAGES.INVALID_INPUT_FORMAT, 'OPTIMIZELY', 'user_id')); }); }); @@ -2006,7 +2008,7 @@ describe('lib/optimizely', function() { var didSetVariation = optlyInstance.setForcedVariation('testExperiment', 'user1', 'control'); assert.strictEqual(didSetVariation, true); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual( logMessage, sprintf(LOG_MESSAGES.USER_MAPPED_TO_FORCED_VARIATION, 'DECISION_SERVICE', 111128, 111127, 'user1') @@ -2042,9 +2044,9 @@ describe('lib/optimizely', function() { var forcedVariation2 = optlyInstance.getForcedVariation('testExperiment', 'user1'); assert.strictEqual(forcedVariation2, null); - var setVariationLogMessage = createdLogger.log.args[0][1]; - var variationIsMappedLogMessage = createdLogger.log.args[1][1]; - var variationMappingRemovedLogMessage = createdLogger.log.args[2][1]; + var setVariationLogMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); + var variationIsMappedLogMessage = buildLogMessageFromArgs(createdLogger.log.args[1]); + var variationMappingRemovedLogMessage = buildLogMessageFromArgs(createdLogger.log.args[2]); assert.strictEqual( setVariationLogMessage, @@ -2084,7 +2086,7 @@ describe('lib/optimizely', function() { ); assert.strictEqual(didSetVariation, false); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual( logMessage, sprintf( @@ -2100,7 +2102,7 @@ describe('lib/optimizely', function() { var didSetVariation = optlyInstance.setForcedVariation('definitely_not_valid_exp_key', 'user1', 'control'); assert.strictEqual(didSetVariation, false); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual( logMessage, sprintf(ERROR_MESSAGES.EXPERIMENT_KEY_NOT_IN_DATAFILE, 'PROJECT_CONFIG', 'definitely_not_valid_exp_key') @@ -2114,13 +2116,13 @@ describe('lib/optimizely', function() { var forcedVariation = optlyInstance.getForcedVariation('testExperimentLaunched', 'user1'); assert.strictEqual(forcedVariation, null); - var setVariationLogMessage = createdLogger.log.args[0][1]; + var setVariationLogMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual( setVariationLogMessage, sprintf(LOG_MESSAGES.USER_MAPPED_TO_FORCED_VARIATION, 'DECISION_SERVICE', 111128, 111127, 'user1') ); - var noVariationToGetLogMessage = createdLogger.log.args[1][1]; + var noVariationToGetLogMessage = buildLogMessageFromArgs(createdLogger.log.args[1]); assert.strictEqual( noVariationToGetLogMessage, sprintf( @@ -2136,7 +2138,7 @@ describe('lib/optimizely', function() { var didSetVariation = optlyInstance.setForcedVariation(null, 'user1', 'control'); assert.strictEqual(didSetVariation, false); - var setVariationLogMessage = createdLogger.log.args[0][1]; + var setVariationLogMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual( setVariationLogMessage, sprintf(ERROR_MESSAGES.INVALID_INPUT_FORMAT, 'OPTIMIZELY', 'experiment_key') @@ -2147,7 +2149,7 @@ describe('lib/optimizely', function() { var didSetVariation = optlyInstance.setForcedVariation(undefined, 'user1', 'control'); assert.strictEqual(didSetVariation, false); - var setVariationLogMessage = createdLogger.log.args[0][1]; + var setVariationLogMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual( setVariationLogMessage, sprintf(ERROR_MESSAGES.INVALID_INPUT_FORMAT, 'OPTIMIZELY', 'experiment_key') @@ -2158,7 +2160,7 @@ describe('lib/optimizely', function() { var didSetVariation = optlyInstance.setForcedVariation('', 'user1', 'control'); assert.strictEqual(didSetVariation, false); - var setVariationLogMessage = createdLogger.log.args[0][1]; + var setVariationLogMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual( setVariationLogMessage, sprintf(ERROR_MESSAGES.INVALID_INPUT_FORMAT, 'OPTIMIZELY', 'experiment_key') @@ -2169,7 +2171,7 @@ describe('lib/optimizely', function() { var didSetVariation = optlyInstance.setForcedVariation('testExperiment', null, 'control'); assert.strictEqual(didSetVariation, false); - var setVariationLogMessage = createdLogger.log.args[0][1]; + var setVariationLogMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual( setVariationLogMessage, sprintf(ERROR_MESSAGES.INVALID_INPUT_FORMAT, 'OPTIMIZELY', 'user_id') @@ -2180,7 +2182,7 @@ describe('lib/optimizely', function() { var didSetVariation = optlyInstance.setForcedVariation('testExperiment', undefined, 'control'); assert.strictEqual(didSetVariation, false); - var setVariationLogMessage = createdLogger.log.args[0][1]; + var setVariationLogMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual( setVariationLogMessage, sprintf(ERROR_MESSAGES.INVALID_INPUT_FORMAT, 'OPTIMIZELY', 'user_id') @@ -2196,7 +2198,7 @@ describe('lib/optimizely', function() { var didSetVariation = optlyInstance.setForcedVariation('testExperiment', 'user1', null); assert.strictEqual(didSetVariation, false); - var setVariationLogMessage = createdLogger.log.args[0][1]; + var setVariationLogMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual( setVariationLogMessage, sprintf(ERROR_MESSAGES.USER_NOT_IN_FORCED_VARIATION, 'DECISION_SERVICE', 'user1') @@ -2207,7 +2209,7 @@ describe('lib/optimizely', function() { var didSetVariation = optlyInstance.setForcedVariation('testExperiment', 'user1', undefined); assert.strictEqual(didSetVariation, false); - var setVariationLogMessage = createdLogger.log.args[0][1]; + var setVariationLogMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual( setVariationLogMessage, sprintf(ERROR_MESSAGES.USER_NOT_IN_FORCED_VARIATION, 'DECISION_SERVICE', 'user1') @@ -2225,13 +2227,13 @@ describe('lib/optimizely', function() { var variation = optlyInstance.getVariation('testExperimentNotRunning', 'user1', {}); assert.strictEqual(variation, null); - var logMessage0 = createdLogger.log.args[0][1]; + var logMessage0 = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual( logMessage0, sprintf(LOG_MESSAGES.USER_MAPPED_TO_FORCED_VARIATION, 'DECISION_SERVICE', 133338, 133337, 'user1') ); - var logMessage1 = createdLogger.log.args[1][1]; + var logMessage1 = buildLogMessageFromArgs(createdLogger.log.args[1]); assert.strictEqual( logMessage1, sprintf(LOG_MESSAGES.EXPERIMENT_NOT_RUNNING, 'DECISION_SERVICE', 'testExperimentNotRunning') @@ -2262,7 +2264,7 @@ describe('lib/optimizely', function() { assert.strictEqual(errorMessage, sprintf(ERROR_MESSAGES.INVALID_INPUT_FORMAT, 'OPTIMIZELY', 'user_id')); sinon.assert.calledThrice(createdLogger.log); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual(logMessage, sprintf(ERROR_MESSAGES.INVALID_INPUT_FORMAT, 'OPTIMIZELY', 'user_id')); }); @@ -2275,7 +2277,7 @@ describe('lib/optimizely', function() { assert.strictEqual(errorMessage, sprintf(ERROR_MESSAGES.INVALID_ATTRIBUTES, 'ATTRIBUTES_VALIDATOR')); sinon.assert.calledOnce(createdLogger.log); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual(logMessage, sprintf(ERROR_MESSAGES.INVALID_ATTRIBUTES, 'ATTRIBUTES_VALIDATOR')); }); }); @@ -3044,7 +3046,8 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Feature test_feature is not enabled for user user1.' + '%s: Feature %s is not enabled for user %s.', + 'OPTIMIZELY', 'test_feature', 'user1' ); var expectedArguments = { @@ -4579,7 +4582,7 @@ describe('lib/optimizely', function() { var errorMessage = errorHandler.handleError.lastCall.args[0].message; assert.strictEqual(errorMessage, sprintf(ERROR_MESSAGES.INVALID_INPUT_FORMAT, 'OPTIMIZELY', 'user_id')); sinon.assert.calledOnce(createdLogger.log); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual(logMessage, sprintf(ERROR_MESSAGES.INVALID_INPUT_FORMAT, 'OPTIMIZELY', 'user_id')); }); @@ -4589,7 +4592,7 @@ describe('lib/optimizely', function() { var errorMessage = errorHandler.handleError.lastCall.args[0].message; assert.strictEqual(errorMessage, sprintf(ERROR_MESSAGES.INVALID_ATTRIBUTES, 'ATTRIBUTES_VALIDATOR')); sinon.assert.calledOnce(createdLogger.log); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual(logMessage, sprintf(ERROR_MESSAGES.INVALID_ATTRIBUTES, 'ATTRIBUTES_VALIDATOR')); }); }); @@ -6238,9 +6241,8 @@ describe('lib/optimizely', function() { }); var result = optlyInstance.isFeatureEnabled('test_feature_for_experiment', 'user1'); assert.strictEqual(result, false); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Optimizely object is not valid. Failing isFeatureEnabled.' ); }); @@ -6338,10 +6340,9 @@ describe('lib/optimizely', function() { }; var callArgs = eventDispatcher.dispatchEvent.getCalls()[0].args; assert.deepEqual(callArgs[0], expectedImpressionEvent); - assert.isFunction(callArgs[1]); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.isFunction(callArgs[1]); + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Feature test_feature_for_experiment is enabled for user user1.' ); }); @@ -6619,9 +6620,8 @@ describe('lib/optimizely', function() { }); assert.strictEqual(result, true); sinon.assert.notCalled(eventDispatcher.dispatchEvent); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Feature test_feature is enabled for user user1.' ); }); @@ -6649,9 +6649,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, false); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Feature test_feature is not enabled for user user1.' ); }); @@ -6679,9 +6678,8 @@ describe('lib/optimizely', function() { var result = optlyInstance.isFeatureEnabled('test_feature', 'user1'); assert.strictEqual(result, false); sinon.assert.notCalled(eventDispatcher.dispatchEvent); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Feature test_feature is not enabled for user user1.' ); }); @@ -6693,9 +6691,8 @@ describe('lib/optimizely', function() { var result = optlyInstance.isFeatureEnabled('test_feature', 'user1'); assert.strictEqual(result, false); sinon.assert.notCalled(eventDispatcher.dispatchEvent); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Feature test_feature is not enabled for user user1.' ); }); @@ -6788,9 +6785,8 @@ describe('lib/optimizely', function() { }); var result = optlyInstance.getEnabledFeatures('user1', { test_attribute: 'test_value' }); assert.deepEqual(result, []); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Optimizely object is not valid. Failing getEnabledFeatures.' ); }); @@ -6959,9 +6955,8 @@ describe('lib/optimizely', function() { { test_attribute: 'test_value' } ); assert.strictEqual(result, true); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Got variable value "true" for variable "is_button_animated" of feature flag "test_feature_for_experiment"' ); }); @@ -6971,9 +6966,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 20.25); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Got variable value "20.25" for variable "button_width" of feature flag "test_feature_for_experiment"' ); }); @@ -6983,9 +6977,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 2); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Got variable value "2" for variable "num_buttons" of feature flag "test_feature_for_experiment"' ); }); @@ -6995,9 +6988,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 'Buy me NOW'); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Got variable value "Buy me NOW" for variable "button_txt" of feature flag "test_feature_for_experiment"' ); }); @@ -7010,9 +7002,8 @@ describe('lib/optimizely', function() { num_buttons: 1, text: 'first variation', }); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Got variable value "{ "num_buttons": 1, "text": "first variation"}" for variable "button_info" of feature flag "test_feature_for_experiment"' ); }); @@ -7025,9 +7016,8 @@ describe('lib/optimizely', function() { { test_attribute: 'test_value' } ); assert.strictEqual(result, true); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Got variable value "true" for variable "is_button_animated" of feature flag "test_feature_for_experiment"' ); }); @@ -7040,9 +7030,8 @@ describe('lib/optimizely', function() { { test_attribute: 'test_value' } ); assert.strictEqual(result, 20.25); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Got variable value "20.25" for variable "button_width" of feature flag "test_feature_for_experiment"' ); }); @@ -7055,9 +7044,8 @@ describe('lib/optimizely', function() { { test_attribute: 'test_value' } ); assert.strictEqual(result, 2); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Got variable value "2" for variable "num_buttons" of feature flag "test_feature_for_experiment"' ); }); @@ -7067,9 +7055,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 'Buy me NOW'); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Got variable value "Buy me NOW" for variable "button_txt" of feature flag "test_feature_for_experiment"' ); }); @@ -7082,9 +7069,8 @@ describe('lib/optimizely', function() { num_buttons: 1, text: 'first variation', }); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Got variable value "{ "num_buttons": 1, "text": "first variation"}" for variable "button_info" of feature flag "test_feature_for_experiment"' ); }); @@ -7106,27 +7092,47 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Got variable value "true" for variable "is_button_animated" of feature flag "test_feature_for_experiment"' + '%s: Got variable value "%s" for variable "%s" of feature flag "%s"', + 'OPTIMIZELY', + '2', + 'num_buttons', + 'test_feature_for_experiment', ); sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Got variable value "20.25" for variable "button_width" of feature flag "test_feature_for_experiment"' + '%s: Got variable value "%s" for variable "%s" of feature flag "%s"', + 'OPTIMIZELY', + 'true', + 'is_button_animated', + 'test_feature_for_experiment', ); sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Got variable value "2" for variable "num_buttons" of feature flag "test_feature_for_experiment"' + '%s: Got variable value "%s" for variable "%s" of feature flag "%s"', + 'OPTIMIZELY', + 'Buy me NOW', + 'button_txt', + 'test_feature_for_experiment' ); sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Got variable value "Buy me NOW" for variable "button_txt" of feature flag "test_feature_for_experiment"' + '%s: Got variable value "%s" for variable "%s" of feature flag "%s"', + 'OPTIMIZELY', + '20.25', + 'button_width', + 'test_feature_for_experiment' ); sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Got variable value "{ "num_buttons": 1, "text": "first variation"}" for variable "button_info" of feature flag "test_feature_for_experiment"' + '%s: Got variable value "%s" for variable "%s" of feature flag "%s"', + 'OPTIMIZELY', + '{ "num_buttons": 1, "text": "first variation"}', + 'button_info', + 'test_feature_for_experiment' ); }); @@ -7143,9 +7149,8 @@ describe('lib/optimizely', function() { { test_attribute: 'test_value' } ); assert.strictEqual(result, false); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Variable "is_button_animated" is not used in variation "variation". Returning default value.' ); }); @@ -7155,9 +7160,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 50.55); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Variable "button_width" is not used in variation "variation". Returning default value.' ); }); @@ -7167,9 +7171,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 10); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Variable "num_buttons" is not used in variation "variation". Returning default value.' ); }); @@ -7179,9 +7182,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 'Buy me'); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Variable "button_txt" is not used in variation "variation". Returning default value.' ); }); @@ -7194,9 +7196,8 @@ describe('lib/optimizely', function() { num_buttons: 0, text: 'default value', }); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Variable "button_info" is not used in variation "variation". Returning default value.' ); }); @@ -7209,9 +7210,8 @@ describe('lib/optimizely', function() { { test_attribute: 'test_value' } ); assert.strictEqual(result, false); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Variable "is_button_animated" is not used in variation "variation". Returning default value.' ); }); @@ -7224,9 +7224,8 @@ describe('lib/optimizely', function() { { test_attribute: 'test_value' } ); assert.strictEqual(result, 50.55); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Variable "button_width" is not used in variation "variation". Returning default value.' ); }); @@ -7239,9 +7238,8 @@ describe('lib/optimizely', function() { { test_attribute: 'test_value' } ); assert.strictEqual(result, 10); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Variable "num_buttons" is not used in variation "variation". Returning default value.' ); }); @@ -7254,9 +7252,8 @@ describe('lib/optimizely', function() { { test_attribute: 'test_value' } ); assert.strictEqual(result, 'Buy me'); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Variable "button_txt" is not used in variation "variation". Returning default value.' ); }); @@ -7272,9 +7269,8 @@ describe('lib/optimizely', function() { num_buttons: 0, text: "default value", }); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Variable "button_info" is not used in variation "variation". Returning default value.' ); }); @@ -7296,27 +7292,42 @@ describe('lib/optimizely', function() { sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Variable "is_button_animated" is not used in variation "variation". Returning default value.' + '%s: Variable "%s" is not used in variation "%s". Returning default value.', + 'OPTIMIZELY', + 'num_buttons', + 'variation' ); sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Variable "button_width" is not used in variation "variation". Returning default value.' + '%s: Variable "%s" is not used in variation "%s". Returning default value.', + 'OPTIMIZELY', + 'is_button_animated', + 'variation' ); sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Variable "num_buttons" is not used in variation "variation". Returning default value.' + '%s: Variable "%s" is not used in variation "%s". Returning default value.', + 'OPTIMIZELY', + 'button_txt', + 'variation' ); sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Variable "button_txt" is not used in variation "variation". Returning default value.' + '%s: Variable "%s" is not used in variation "%s". Returning default value.', + 'OPTIMIZELY', + 'button_width', + 'variation' ); sinon.assert.calledWith( createdLogger.log, LOG_LEVEL.INFO, - 'OPTIMIZELY: Variable "button_info" is not used in variation "variation". Returning default value.' + '%s: Variable "%s" is not used in variation "%s". Returning default value.', + 'OPTIMIZELY', + 'button_info', + 'variation' ); }); }); @@ -7349,9 +7360,8 @@ describe('lib/optimizely', function() { { test_attribute: 'test_value' } ); assert.strictEqual(result, false); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning the default variable value "false".' ); }); @@ -7361,9 +7371,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 50.55); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning the default variable value "50.55".' ); }); @@ -7373,9 +7382,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 10); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning the default variable value "10".' ); }); @@ -7385,9 +7393,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 'Buy me'); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning the default variable value "Buy me".' ); }); @@ -7400,9 +7407,8 @@ describe('lib/optimizely', function() { num_buttons: 0, text: "default value", }); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning the default variable value "{ "num_buttons": 0, "text": "default value"}".' ); }); @@ -7415,9 +7421,8 @@ describe('lib/optimizely', function() { { test_attribute: 'test_value' } ); assert.strictEqual(result, false); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning the default variable value "false".' ); }); @@ -7430,9 +7435,8 @@ describe('lib/optimizely', function() { { test_attribute: 'test_value' } ); assert.strictEqual(result, 50.55); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning the default variable value "50.55".' ); }); @@ -7445,9 +7449,8 @@ describe('lib/optimizely', function() { { test_attribute: 'test_value' } ); assert.strictEqual(result, 10); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning the default variable value "10".' ); }); @@ -7457,9 +7460,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 'Buy me'); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning the default variable value "Buy me".' ); }); @@ -7472,9 +7474,8 @@ describe('lib/optimizely', function() { num_buttons: 0, text: 'default value', }); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Feature "test_feature_for_experiment" is not enabled for user user1. Returning the default variable value "{ "num_buttons": 0, "text": "default value"}".' ); }); @@ -7493,31 +7494,48 @@ describe('lib/optimizely', function() { text: "default value", }, }); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, - '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 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 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 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 the default variable value "{ "num_buttons": 0, "text": "default value"}".' - ); + assert.deepEqual(createdLogger.log.args, [ + [ + LOG_LEVEL.INFO, + '%s: Feature "%s" is not enabled for user %s. Returning the default variable value "%s".', + 'OPTIMIZELY', + 'test_feature_for_experiment', + 'user1', + '10' + ], + [ + LOG_LEVEL.INFO, + '%s: Feature "%s" is not enabled for user %s. Returning the default variable value "%s".', + 'OPTIMIZELY', + 'test_feature_for_experiment', + 'user1', + 'false' + ], + [ + LOG_LEVEL.INFO, + '%s: Feature "%s" is not enabled for user %s. Returning the default variable value "%s".', + 'OPTIMIZELY', + 'test_feature_for_experiment', + 'user1', + 'Buy me' + ], + [ + LOG_LEVEL.INFO, + '%s: Feature "%s" is not enabled for user %s. Returning the default variable value "%s".', + 'OPTIMIZELY', + 'test_feature_for_experiment', + 'user1', + '50.55' + ], + [ + LOG_LEVEL.INFO, + '%s: Feature "%s" is not enabled for user %s. Returning the default variable value "%s".', + 'OPTIMIZELY', + 'test_feature_for_experiment', + 'user1', + '{ "num_buttons": 0, "text": "default value"}' + ] + ]); }); }); }); @@ -7547,9 +7565,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, true); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Got variable value "true" for variable "new_content" of feature flag "test_feature"' ); }); @@ -7559,9 +7576,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 4.99); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Got variable value "4.99" for variable "price" of feature flag "test_feature"' ); }); @@ -7571,9 +7587,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 395); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Got variable value "395" for variable "lasers" of feature flag "test_feature"' ); }); @@ -7583,9 +7598,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 'Hello audience'); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Got variable value "Hello audience" for variable "message" of feature flag "test_feature"' ); }); @@ -7598,9 +7612,8 @@ describe('lib/optimizely', function() { count: 2, message: 'Hello audience', }); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Got variable value "{ "count": 2, "message": "Hello audience" }" for variable "message_info" of feature flag "test_feature"' ); }); @@ -7610,9 +7623,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, true); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Got variable value "true" for variable "new_content" of feature flag "test_feature"' ); }); @@ -7622,9 +7634,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 4.99); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Got variable value "4.99" for variable "price" of feature flag "test_feature"' ); }); @@ -7634,9 +7645,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 395); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Got variable value "395" for variable "lasers" of feature flag "test_feature"' ); }); @@ -7646,9 +7656,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 'Hello audience'); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Got variable value "Hello audience" for variable "message" of feature flag "test_feature"' ); }); @@ -7661,9 +7670,8 @@ describe('lib/optimizely', function() { count: 2, message: 'Hello audience', }); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Got variable value "{ "count": 2, "message": "Hello audience" }" for variable "message_info" of feature flag "test_feature"' ); }); @@ -7682,31 +7690,51 @@ describe('lib/optimizely', function() { message: 'Hello audience', }, }); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, - 'OPTIMIZELY: Got variable value "true" for variable "new_content" of feature flag "test_feature"' - ); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, - 'OPTIMIZELY: Got variable value "4.99" for variable "price" of feature flag "test_feature"' - ); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, - 'OPTIMIZELY: Got variable value "395" for variable "lasers" of feature flag "test_feature"' - ); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, - 'OPTIMIZELY: Got variable value "Hello audience" for variable "message" of feature flag "test_feature"' - ); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, - 'OPTIMIZELY: Got variable value "{ "count": 2, "message": "Hello audience" }" for variable "message_info" of feature flag "test_feature"' - ); + assert.deepEqual( + createdLogger.log.args, + [ + [ + LOG_LEVEL.INFO, + '%s: Got variable value "%s" for variable "%s" of feature flag "%s"', + 'OPTIMIZELY', + 'true', + 'new_content', + 'test_feature' + ], + [ + LOG_LEVEL.INFO, + '%s: Got variable value "%s" for variable "%s" of feature flag "%s"', + 'OPTIMIZELY', + '395', + 'lasers', + 'test_feature' + ], + [ + LOG_LEVEL.INFO, + '%s: Got variable value "%s" for variable "%s" of feature flag "%s"', + 'OPTIMIZELY', + '4.99', + 'price', + 'test_feature' + ], + [ + LOG_LEVEL.INFO, + '%s: Got variable value "%s" for variable "%s" of feature flag "%s"', + 'OPTIMIZELY', + 'Hello audience', + 'message', + 'test_feature' + ], + [ + LOG_LEVEL.INFO, + '%s: Got variable value "%s" for variable "%s" of feature flag "%s"', + 'OPTIMIZELY', + '{ "count": 2, "message": "Hello audience" }', + 'message_info', + 'test_feature' + ] + ] + ) }); describe('when the variable is not used in the variation', function() { @@ -7719,9 +7747,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, false); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Variable "new_content" is not used in variation "594032". Returning default value.' ); }); @@ -7731,9 +7758,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 14.99); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Variable "price" is not used in variation "594032". Returning default value.' ); }); @@ -7743,9 +7769,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 400); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Variable "lasers" is not used in variation "594032". Returning default value.' ); }); @@ -7755,9 +7780,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 'Hello'); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Variable "message" is not used in variation "594032". Returning default value.' ); }); @@ -7770,9 +7794,8 @@ describe('lib/optimizely', function() { count: 1, message: 'Hello', }); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Variable "message_info" is not used in variation "594032". Returning default value.' ); }); @@ -7782,9 +7805,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, false); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Variable "new_content" is not used in variation "594032". Returning default value.' ); }); @@ -7794,9 +7816,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 14.99); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Variable "price" is not used in variation "594032". Returning default value.' ); }); @@ -7806,9 +7827,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 400); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Variable "lasers" is not used in variation "594032". Returning default value.' ); }); @@ -7818,9 +7838,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 'Hello'); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Variable "message" is not used in variation "594032". Returning default value.' ); }); @@ -7833,9 +7852,8 @@ describe('lib/optimizely', function() { count: 1, message: 'Hello' }); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Variable "message_info" is not used in variation "594032". Returning default value.' ); }); @@ -7854,31 +7872,47 @@ describe('lib/optimizely', function() { message: 'Hello', }, }); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, - 'OPTIMIZELY: Variable "new_content" is not used in variation "594032". Returning default value.' - ); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, - 'OPTIMIZELY: Variable "price" is not used in variation "594032". Returning default value.' - ); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, - 'OPTIMIZELY: Variable "lasers" is not used in variation "594032". Returning default value.' - ); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, - 'OPTIMIZELY: Variable "message" is not used in variation "594032". Returning default value.' - ); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, - 'OPTIMIZELY: Variable "message_info" is not used in variation "594032". Returning default value.' - ); + assert.deepEqual( + createdLogger.log.args, + [ + [ + LOG_LEVEL.INFO, + '%s: Variable "%s" is not used in variation "%s". Returning default value.', + 'OPTIMIZELY', + 'new_content', + '594032' + ], + [ + LOG_LEVEL.INFO, + '%s: Variable "%s" is not used in variation "%s". Returning default value.', + 'OPTIMIZELY', + 'lasers', + '594032' + ], + [ + LOG_LEVEL.INFO, + '%s: Variable "%s" is not used in variation "%s". Returning default value.', + 'OPTIMIZELY', + 'price', + '594032' + ], + [ + LOG_LEVEL.INFO, + '%s: Variable "%s" is not used in variation "%s". Returning default value.', + 'OPTIMIZELY', + 'message', + '594032' + ], + [ + LOG_LEVEL.INFO, + '%s: Variable "%s" is not used in variation "%s". Returning default value.', + 'OPTIMIZELY', + 'message_info', + '594032' + ] + ] + + ) }); }); }); @@ -7907,9 +7941,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, false); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning the default variable value "false".' ); }); @@ -7919,9 +7952,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 14.99); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning the default variable value "14.99".' ); }); @@ -7931,9 +7963,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 400); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning the default variable value "400".' ); }); @@ -7943,9 +7974,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 'Hello'); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning the default variable value "Hello".' ); }); @@ -7958,9 +7988,8 @@ describe('lib/optimizely', function() { count: 1, message: 'Hello' }); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning the default variable value "{ "count": 1, "message": "Hello" }".' ); }); @@ -7970,9 +7999,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, false); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning the default variable value "false".' ); }); @@ -7982,9 +8010,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 14.99); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning the default variable value "14.99".' ); }); @@ -7994,9 +8021,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 400); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning the default variable value "400".' ); }); @@ -8006,9 +8032,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 'Hello'); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning the default variable value "Hello".' ); }); @@ -8021,9 +8046,8 @@ describe('lib/optimizely', function() { count: 1, message: 'Hello' }); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Feature "test_feature" is not enabled for user user1. Returning the default variable value "{ "count": 1, "message": "Hello" }".' ); }); @@ -8042,31 +8066,51 @@ describe('lib/optimizely', function() { message: 'Hello', }, }); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, - '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 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 the default variable value "400".' - ); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, - '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 the default variable value "{ "count": 1, "message": "Hello" }".' - ); + assert.deepEqual( + createdLogger.log.args, + [ + [ + LOG_LEVEL.INFO, + '%s: Feature "%s" is not enabled for user %s. Returning the default variable value "%s".', + 'OPTIMIZELY', + 'test_feature', + 'user1', + 'false' + ], + [ + LOG_LEVEL.INFO, + '%s: Feature "%s" is not enabled for user %s. Returning the default variable value "%s".', + 'OPTIMIZELY', + 'test_feature', + 'user1', + '400' + ], + [ + LOG_LEVEL.INFO, + '%s: Feature "%s" is not enabled for user %s. Returning the default variable value "%s".', + 'OPTIMIZELY', + 'test_feature', + 'user1', + '14.99' + ], + [ + LOG_LEVEL.INFO, + '%s: Feature "%s" is not enabled for user %s. Returning the default variable value "%s".', + 'OPTIMIZELY', + 'test_feature', + 'user1', + 'Hello' + ], + [ + LOG_LEVEL.INFO, + '%s: Feature "%s" is not enabled for user %s. Returning the default variable value "%s".', + 'OPTIMIZELY', + 'test_feature', + 'user1', + '{ "count": 1, "message": "Hello" }' + ] + ] + ) }); }); }); @@ -8090,9 +8134,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, false); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: User "user1" is not in any variation or rollout rule. Returning default value for variable "is_button_animated" of feature flag "test_feature_for_experiment".' ); }); @@ -8102,9 +8145,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 50.55); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: User "user1" is not in any variation or rollout rule. Returning default value for variable "button_width" of feature flag "test_feature_for_experiment".' ); }); @@ -8114,9 +8156,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 10); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: User "user1" is not in any variation or rollout rule. Returning default value for variable "num_buttons" of feature flag "test_feature_for_experiment".' ); }); @@ -8126,9 +8167,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 'Buy me'); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: User "user1" is not in any variation or rollout rule. Returning default value for variable "button_txt" of feature flag "test_feature_for_experiment".' ); }); @@ -8141,9 +8181,8 @@ describe('lib/optimizely', function() { num_buttons: 0, text: 'default value', }); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: User "user1" is not in any variation or rollout rule. Returning default value for variable "button_info" of feature flag "test_feature_for_experiment".' ); }); @@ -8156,9 +8195,8 @@ describe('lib/optimizely', function() { { test_attribute: 'test_value' } ); assert.strictEqual(result, false); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: User "user1" is not in any variation or rollout rule. Returning default value for variable "is_button_animated" of feature flag "test_feature_for_experiment".' ); }); @@ -8168,9 +8206,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 50.55); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: User "user1" is not in any variation or rollout rule. Returning default value for variable "button_width" of feature flag "test_feature_for_experiment".' ); }); @@ -8180,9 +8217,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 10); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: User "user1" is not in any variation or rollout rule. Returning default value for variable "num_buttons" of feature flag "test_feature_for_experiment".' ); }); @@ -8192,9 +8228,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, 'Buy me'); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: User "user1" is not in any variation or rollout rule. Returning default value for variable "button_txt" of feature flag "test_feature_for_experiment".' ); }); @@ -8207,9 +8242,8 @@ describe('lib/optimizely', function() { num_buttons: 0, text: 'default value', }); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: User "user1" is not in any variation or rollout rule. Returning default value for variable "button_info" of feature flag "test_feature_for_experiment".' ); }); @@ -8228,30 +8262,50 @@ describe('lib/optimizely', function() { text: 'default value', }, }); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, - 'OPTIMIZELY: User "user1" is not in any variation or rollout rule. Returning default value for variable "is_button_animated" of feature flag "test_feature_for_experiment".' - ); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, - 'OPTIMIZELY: User "user1" is not in any variation or rollout rule. Returning default value for variable "button_width" of feature flag "test_feature_for_experiment".' - ); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, - 'OPTIMIZELY: User "user1" is not in any variation or rollout rule. Returning default value for variable "num_buttons" of feature flag "test_feature_for_experiment".' - ); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, - 'OPTIMIZELY: User "user1" is not in any variation or rollout rule. Returning default value for variable "button_txt" of feature flag "test_feature_for_experiment".' - ); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.INFO, - 'OPTIMIZELY: User "user1" is not in any variation or rollout rule. Returning default value for variable "button_info" of feature flag "test_feature_for_experiment".' + assert.deepEqual( + createdLogger.log.args, + [ + [ + LOG_LEVEL.INFO, + '%s: User "%s" is not in any variation or rollout rule. Returning default value for variable "%s" of feature flag "%s".', + 'OPTIMIZELY', + 'user1', + 'num_buttons', + 'test_feature_for_experiment' + ], + [ + LOG_LEVEL.INFO, + '%s: User "%s" is not in any variation or rollout rule. Returning default value for variable "%s" of feature flag "%s".', + 'OPTIMIZELY', + 'user1', + 'is_button_animated', + 'test_feature_for_experiment' + ], + [ + LOG_LEVEL.INFO, + '%s: User "%s" is not in any variation or rollout rule. Returning default value for variable "%s" of feature flag "%s".', + 'OPTIMIZELY', + 'user1', + 'button_txt', + 'test_feature_for_experiment' + ], + [ + LOG_LEVEL.INFO, + '%s: User "%s" is not in any variation or rollout rule. Returning default value for variable "%s" of feature flag "%s".', + 'OPTIMIZELY', + 'user1', + 'button_width', + 'test_feature_for_experiment' + ], + [ + LOG_LEVEL.INFO, + '%s: User "%s" is not in any variation or rollout rule. Returning default value for variable "%s" of feature flag "%s".', + 'OPTIMIZELY', + 'user1', + 'button_info', + 'test_feature_for_experiment' + ] + ] ); }); }); @@ -8261,9 +8315,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8273,9 +8326,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8283,9 +8335,8 @@ describe('lib/optimizely', function() { it('returns null from getFeatureVariable if user id is not provided when variable type is boolean', function() { var result = optlyInstance.getFeatureVariable('test_feature_for_experiment', 'is_button_animated'); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8295,9 +8346,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8307,9 +8357,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8317,9 +8366,8 @@ describe('lib/optimizely', function() { it('returns null from getFeatureVariable if user id is not provided when variable type is double', function() { var result = optlyInstance.getFeatureVariable('test_feature_for_experiment', 'button_width'); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8329,9 +8377,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8341,9 +8388,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8351,9 +8397,8 @@ describe('lib/optimizely', function() { it('returns null from getFeatureVariable if user id is not provided when variable type is integer', function() { var result = optlyInstance.getFeatureVariable('test_feature_for_experiment', 'num_buttons'); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8363,9 +8408,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8375,9 +8419,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8385,9 +8428,8 @@ describe('lib/optimizely', function() { it('returns null from getFeatureVariable if user id is not provided when variable type is string', function() { var result = optlyInstance.getFeatureVariable('test_feature_for_experiment', 'button_txt'); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8397,9 +8439,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8409,9 +8450,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8419,9 +8459,8 @@ describe('lib/optimizely', function() { it('returns null from getFeatureVariable if user id is not provided when variable type is json', function() { var result = optlyInstance.getFeatureVariable('test_feature_for_experiment', 'button_info'); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8429,9 +8468,8 @@ describe('lib/optimizely', function() { it('returns null from getFeatureVariableBoolean when called with a non-boolean variable', function() { var result = optlyInstance.getFeatureVariableBoolean('test_feature_for_experiment', 'button_width', 'user1'); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.WARNING, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Requested variable type "boolean", but variable is of type "double". Use correct API to retrieve value. Returning None.' ); }); @@ -8443,9 +8481,8 @@ describe('lib/optimizely', function() { 'user1' ); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.WARNING, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Requested variable type "double", but variable is of type "boolean". Use correct API to retrieve value. Returning None.' ); }); @@ -8453,9 +8490,8 @@ describe('lib/optimizely', function() { it('returns null from getFeatureVariableInteger when called with a non-integer variable', function() { var result = optlyInstance.getFeatureVariableInteger('test_feature_for_experiment', 'button_width', 'user1'); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.WARNING, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Requested variable type "integer", but variable is of type "double". Use correct API to retrieve value. Returning None.' ); }); @@ -8463,9 +8499,8 @@ describe('lib/optimizely', function() { it('returns null from getFeatureVariableString when called with a non-string variable', function() { var result = optlyInstance.getFeatureVariableString('test_feature_for_experiment', 'num_buttons', 'user1'); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.WARNING, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Requested variable type "string", but variable is of type "integer". Use correct API to retrieve value. Returning None.' ); }); @@ -8473,9 +8508,8 @@ describe('lib/optimizely', function() { it('returns null from getFeatureVariableJSON when called with a non-json variable', function() { var result = optlyInstance.getFeatureVariableJSON('test_feature_for_experiment', 'button_txt', 'user1'); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.WARNING, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Requested variable type "json", but variable is of type "string". Use correct API to retrieve value. Returning None.' ); }); @@ -8488,9 +8522,8 @@ describe('lib/optimizely', function() { { test_attribute: 'test_value' } ); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8503,9 +8536,8 @@ describe('lib/optimizely', function() { { test_attribute: 'test_value' } ); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8513,9 +8545,8 @@ describe('lib/optimizely', function() { it('returns null from getFeatureVariableBoolean if user id is not provided', function() { var result = optlyInstance.getFeatureVariableBoolean('test_feature_for_experiment', 'is_button_animated'); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8525,9 +8556,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8537,9 +8567,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8547,9 +8576,8 @@ describe('lib/optimizely', function() { it('returns null from getFeatureVariableDouble if user id is not provided', function() { var result = optlyInstance.getFeatureVariableDouble('test_feature_for_experiment', 'button_width'); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8559,9 +8587,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8571,9 +8598,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8581,9 +8607,8 @@ describe('lib/optimizely', function() { it('returns null from getFeatureVariableInteger if user id is not provided', function() { var result = optlyInstance.getFeatureVariableInteger('test_feature_for_experiment', 'num_buttons'); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8593,9 +8618,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8605,9 +8629,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8615,9 +8638,8 @@ describe('lib/optimizely', function() { it('returns null from getFeatureVariableString if user id is not provided', function() { var result = optlyInstance.getFeatureVariableString('test_feature_for_experiment', 'button_txt'); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8627,9 +8649,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8639,9 +8660,8 @@ describe('lib/optimizely', function() { test_attribute: 'test_value', }); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8649,9 +8669,8 @@ describe('lib/optimizely', function() { it('returns null from getFeatureVariableJSON if user id is not provided', function() { var result = optlyInstance.getFeatureVariableJSON('test_feature_for_experiment', 'button_info'); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'OPTIMIZELY: Provided user_id is in an invalid format.' ); }); @@ -8669,9 +8688,8 @@ describe('lib/optimizely', function() { 'user1' ); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'PROJECT_CONFIG: Unable to cast value falsezzz to type boolean, returning null.' ); }); @@ -8685,9 +8703,8 @@ describe('lib/optimizely', function() { it('should return null and log an error', function() { var result = optlyInstance.getFeatureVariableInteger('test_feature_for_experiment', 'num_buttons', 'user1'); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'PROJECT_CONFIG: Unable to cast value zzz123 to type integer, returning null.' ); }); @@ -8701,9 +8718,8 @@ describe('lib/optimizely', function() { it('should return null and log an error', function() { var result = optlyInstance.getFeatureVariableDouble('test_feature_for_experiment', 'button_width', 'user1'); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'PROJECT_CONFIG: Unable to cast value zzz44.55 to type double, returning null.' ); }); @@ -8717,9 +8733,8 @@ describe('lib/optimizely', function() { it('should return null and log an error', function() { var result = optlyInstance.getFeatureVariableJSON('test_feature_for_experiment', 'button_info', 'user1'); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'PROJECT_CONFIG: Unable to cast value zzz44.55 to type json, returning null.' ); }); @@ -8729,9 +8744,8 @@ describe('lib/optimizely', function() { it('returns null from getFeatureVariable if the argument feature key is invalid when variable type is boolean', function() { var result = optlyInstance.getFeatureVariable('thisIsNotAValidKey<><><>', 'is_button_animated', 'user1'); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'PROJECT_CONFIG: Feature key thisIsNotAValidKey<><><> is not in datafile.' ); }); @@ -8739,9 +8753,8 @@ describe('lib/optimizely', function() { it('returns null from getFeatureVariable if the argument feature key is invalid when variable type is double', function() { var result = optlyInstance.getFeatureVariable('thisIsNotAValidKey<><><>', 'button_width', 'user1'); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'PROJECT_CONFIG: Feature key thisIsNotAValidKey<><><> is not in datafile.' ); }); @@ -8749,9 +8762,8 @@ describe('lib/optimizely', function() { it('returns null from getFeatureVariable if the argument feature key is invalid when variable type is integer', function() { var result = optlyInstance.getFeatureVariable('thisIsNotAValidKey<><><>', 'num_buttons', 'user1'); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'PROJECT_CONFIG: Feature key thisIsNotAValidKey<><><> is not in datafile.' ); }); @@ -8759,9 +8771,8 @@ describe('lib/optimizely', function() { it('returns null from getFeatureVariable if the argument feature key is invalid when variable type is string', function() { var result = optlyInstance.getFeatureVariable('thisIsNotAValidKey<><><>', 'button_txt', 'user1'); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'PROJECT_CONFIG: Feature key thisIsNotAValidKey<><><> is not in datafile.' ); }); @@ -8769,9 +8780,8 @@ describe('lib/optimizely', function() { it('returns null from getFeatureVariable if the argument feature key is invalid when variable type is json', function() { var result = optlyInstance.getFeatureVariable('thisIsNotAValidKey<><><>', 'button_info', 'user1'); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'PROJECT_CONFIG: Feature key thisIsNotAValidKey<><><> is not in datafile.' ); }); @@ -8783,9 +8793,8 @@ describe('lib/optimizely', function() { 'user1' ); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'PROJECT_CONFIG: Variable with key "thisIsNotAVariableKey****" associated with feature with key "test_feature_for_experiment" is not in datafile.' ); }); @@ -8793,9 +8802,8 @@ describe('lib/optimizely', function() { it('returns null from getFeatureVariableBoolean if the argument feature key is invalid', function() { var result = optlyInstance.getFeatureVariableBoolean('thisIsNotAValidKey<><><>', 'is_button_animated', 'user1'); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'PROJECT_CONFIG: Feature key thisIsNotAValidKey<><><> is not in datafile.' ); }); @@ -8803,9 +8811,8 @@ describe('lib/optimizely', function() { it('returns null from getFeatureVariableDouble if the argument feature key is invalid', function() { var result = optlyInstance.getFeatureVariableDouble('thisIsNotAValidKey<><><>', 'button_width', 'user1'); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'PROJECT_CONFIG: Feature key thisIsNotAValidKey<><><> is not in datafile.' ); }); @@ -8813,9 +8820,8 @@ describe('lib/optimizely', function() { it('returns null from getFeatureVariableInteger if the argument feature key is invalid', function() { var result = optlyInstance.getFeatureVariableInteger('thisIsNotAValidKey<><><>', 'num_buttons', 'user1'); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'PROJECT_CONFIG: Feature key thisIsNotAValidKey<><><> is not in datafile.' ); }); @@ -8823,9 +8829,8 @@ describe('lib/optimizely', function() { it('returns null from getFeatureVariableString if the argument feature key is invalid', function() { var result = optlyInstance.getFeatureVariableString('thisIsNotAValidKey<><><>', 'button_txt', 'user1'); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'PROJECT_CONFIG: Feature key thisIsNotAValidKey<><><> is not in datafile.' ); }); @@ -8833,9 +8838,8 @@ describe('lib/optimizely', function() { it('returns null from getFeatureVariableJSON if the argument feature key is invalid', function() { var result = optlyInstance.getFeatureVariableJSON('thisIsNotAValidKey<><><>', 'button_info', 'user1'); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'PROJECT_CONFIG: Feature key thisIsNotAValidKey<><><> is not in datafile.' ); }); @@ -8847,9 +8851,8 @@ describe('lib/optimizely', function() { 'user1' ); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'PROJECT_CONFIG: Variable with key "thisIsNotAVariableKey****" associated with feature with key "test_feature_for_experiment" is not in datafile.' ); }); @@ -8861,9 +8864,8 @@ describe('lib/optimizely', function() { 'user1' ); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'PROJECT_CONFIG: Variable with key "thisIsNotAVariableKey****" associated with feature with key "test_feature_for_experiment" is not in datafile.' ); }); @@ -8875,9 +8877,8 @@ describe('lib/optimizely', function() { 'user1' ); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'PROJECT_CONFIG: Variable with key "thisIsNotAVariableKey****" associated with feature with key "test_feature_for_experiment" is not in datafile.' ); }); @@ -8889,9 +8890,8 @@ describe('lib/optimizely', function() { 'user1' ); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'PROJECT_CONFIG: Variable with key "thisIsNotAVariableKey****" associated with feature with key "test_feature_for_experiment" is not in datafile.' ); }); @@ -8903,9 +8903,8 @@ describe('lib/optimizely', function() { 'user1' ); assert.strictEqual(result, null); - sinon.assert.calledWith( - createdLogger.log, - LOG_LEVEL.ERROR, + assert.equal( + buildLogMessageFromArgs(createdLogger.log.lastCall.args), 'PROJECT_CONFIG: Variable with key "thisIsNotAVariableKey****" associated with feature with key "test_feature_for_experiment" is not in datafile.' ); }); @@ -8925,7 +8924,7 @@ describe('lib/optimizely', function() { instance.getFeatureVariable('test_feature_for_experiment', 'thisIsNotAVariableKey****', 'user1'); sinon.assert.calledOnce(createdLogger.log); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual(logMessage, sprintf(LOG_MESSAGES.INVALID_OBJECT, 'OPTIMIZELY', 'getFeatureVariable')); }); @@ -8944,7 +8943,7 @@ describe('lib/optimizely', function() { instance.getFeatureVariableBoolean('test_feature_for_experiment', 'thisIsNotAVariableKey****', 'user1'); sinon.assert.calledOnce(createdLogger.log); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual(logMessage, sprintf(LOG_MESSAGES.INVALID_OBJECT, 'OPTIMIZELY', 'getFeatureVariableBoolean')); }); @@ -8963,7 +8962,7 @@ describe('lib/optimizely', function() { instance.getFeatureVariableDouble('test_feature_for_experiment', 'thisIsNotAVariableKey****', 'user1'); sinon.assert.calledOnce(createdLogger.log); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual(logMessage, sprintf(LOG_MESSAGES.INVALID_OBJECT, 'OPTIMIZELY', 'getFeatureVariableDouble')); }); @@ -8982,7 +8981,7 @@ describe('lib/optimizely', function() { instance.getFeatureVariableInteger('test_feature_for_experiment', 'thisIsNotAVariableKey****', 'user1'); sinon.assert.calledOnce(createdLogger.log); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual(logMessage, sprintf(LOG_MESSAGES.INVALID_OBJECT, 'OPTIMIZELY', 'getFeatureVariableInteger')); }); @@ -9001,7 +9000,7 @@ describe('lib/optimizely', function() { instance.getFeatureVariableString('test_feature_for_experiment', 'thisIsNotAVariableKey****', 'user1'); sinon.assert.calledOnce(createdLogger.log); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual(logMessage, sprintf(LOG_MESSAGES.INVALID_OBJECT, 'OPTIMIZELY', 'getFeatureVariableString')); }); @@ -9020,7 +9019,7 @@ describe('lib/optimizely', function() { instance.getFeatureVariableJSON('test_feature_for_experiment', 'thisIsNotAVariableKey****', 'user1'); sinon.assert.calledOnce(createdLogger.log); - var logMessage = createdLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(createdLogger.log.args[0]); assert.strictEqual(logMessage, sprintf(LOG_MESSAGES.INVALID_OBJECT, 'OPTIMIZELY', 'getFeatureVariableJSON')); }); }); diff --git a/packages/optimizely-sdk/lib/optimizely/index.ts b/packages/optimizely-sdk/lib/optimizely/index.ts index fcea036fa..8374779ac 100644 --- a/packages/optimizely-sdk/lib/optimizely/index.ts +++ b/packages/optimizely-sdk/lib/optimizely/index.ts @@ -87,7 +87,9 @@ export default class Optimizely { if (enums.VALID_CLIENT_ENGINES.indexOf(clientEngine) === -1) { config.logger.log( LOG_LEVEL.INFO, - sprintf(LOG_MESSAGES.INVALID_CLIENT_ENGINE, MODULE_NAME, clientEngine) + LOG_MESSAGES.INVALID_CLIENT_ENGINE, + MODULE_NAME, + clientEngine, ); clientEngine = enums.NODE_CLIENT_ENGINE; } @@ -100,7 +102,7 @@ export default class Optimizely { let decideOptionsArray = config.defaultDecideOptions ?? []; if (!Array.isArray(decideOptionsArray)) { - this.logger.log(LOG_LEVEL.DEBUG, sprintf(LOG_MESSAGES.INVALID_DEFAULT_DECIDE_OPTIONS, MODULE_NAME)); + this.logger.log(LOG_LEVEL.DEBUG, LOG_MESSAGES.INVALID_DEFAULT_DECIDE_OPTIONS, MODULE_NAME); decideOptionsArray = []; } @@ -112,7 +114,9 @@ export default class Optimizely { } else { this.logger.log( LOG_LEVEL.WARNING, - sprintf(LOG_MESSAGES.UNRECOGNIZED_DECIDE_OPTION, MODULE_NAME, option) + LOG_MESSAGES.UNRECOGNIZED_DECIDE_OPTION, + MODULE_NAME, + option, ); } }); @@ -128,7 +132,10 @@ export default class Optimizely { (configObj: projectConfig.ProjectConfig) => { this.logger.log( LOG_LEVEL.INFO, - sprintf(LOG_MESSAGES.UPDATED_OPTIMIZELY_CONFIG, MODULE_NAME, configObj.revision, configObj.projectId) + LOG_MESSAGES.UPDATED_OPTIMIZELY_CONFIG, + MODULE_NAME, + configObj.revision, + configObj.projectId, ); this.notificationCenter.sendNotifications(NOTIFICATION_TYPES.OPTIMIZELY_CONFIG_UPDATE); } @@ -141,7 +148,7 @@ export default class Optimizely { try { if (userProfileServiceValidator.validate(config.userProfileService)) { userProfileService = config.userProfileService; - this.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.VALID_USER_PROFILE_SERVICE, MODULE_NAME)); + this.logger.log(LOG_LEVEL.INFO, LOG_MESSAGES.VALID_USER_PROFILE_SERVICE, MODULE_NAME); } } catch (ex) { this.logger.log(LOG_LEVEL.WARNING, ex.message); @@ -189,7 +196,7 @@ export default class Optimizely { activate(experimentKey: string, userId: string, attributes?: UserAttributes): string | null { try { if (!this.isValidInstance()) { - this.logger.log(LOG_LEVEL.ERROR, sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'activate')); + this.logger.log(LOG_LEVEL.ERROR, LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'activate'); return null; } @@ -210,12 +217,12 @@ export default class Optimizely { // If experiment is not set to 'Running' status, log accordingly and return variation key if (!projectConfig.isRunning(configObj, experimentKey)) { - const shouldNotDispatchActivateLogMessage = sprintf( + this.logger.log( + LOG_LEVEL.DEBUG, LOG_MESSAGES.SHOULD_NOT_DISPATCH_ACTIVATE, MODULE_NAME, - experimentKey + experimentKey, ); - this.logger.log(LOG_LEVEL.DEBUG, shouldNotDispatchActivateLogMessage); return variationKey; } @@ -237,13 +244,13 @@ export default class Optimizely { return variationKey; } catch (ex) { this.logger.log(LOG_LEVEL.ERROR, ex.message); - const failedActivationLogMessage = sprintf( + this.logger.log( + LOG_LEVEL.INFO, LOG_MESSAGES.NOT_ACTIVATING_USER, MODULE_NAME, userId, - experimentKey + experimentKey, ); - this.logger.log(LOG_LEVEL.INFO, failedActivationLogMessage); this.errorHandler.handleError(ex); return null; } @@ -362,7 +369,7 @@ export default class Optimizely { track(eventKey: string, userId: string, attributes?: UserAttributes, eventTags?: EventTags): void { try { if (!this.isValidInstance()) { - this.logger.log(LOG_LEVEL.ERROR, sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'track')); + this.logger.log(LOG_LEVEL.ERROR, LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'track'); return; } @@ -378,9 +385,11 @@ export default class Optimizely { if (!projectConfig.eventWithKeyExists(configObj, eventKey)) { this.logger.log( LOG_LEVEL.WARNING, - sprintf(enums.LOG_MESSAGES.EVENT_KEY_NOT_FOUND, MODULE_NAME, eventKey) + enums.LOG_MESSAGES.EVENT_KEY_NOT_FOUND, + MODULE_NAME, + eventKey, ); - this.logger.log(LOG_LEVEL.WARNING, sprintf(LOG_MESSAGES.NOT_TRACKING_USER, MODULE_NAME, userId)); + this.logger.log(LOG_LEVEL.WARNING, LOG_MESSAGES.NOT_TRACKING_USER, MODULE_NAME, userId); return; } @@ -395,15 +404,14 @@ export default class Optimizely { clientVersion: this.clientVersion, configObj: configObj, }); - this.logger.log(LOG_LEVEL.INFO, sprintf(enums.LOG_MESSAGES.TRACK_EVENT, MODULE_NAME, eventKey, userId)); + this.logger.log(LOG_LEVEL.INFO, enums.LOG_MESSAGES.TRACK_EVENT, MODULE_NAME, eventKey, userId); // TODO is it okay to not pass a projectConfig as second argument this.eventProcessor.process(conversionEvent); this.emitNotificationCenterTrack(eventKey, userId, attributes, eventTags); } catch (e) { this.logger.log(LOG_LEVEL.ERROR, e.message); - this.errorHandler.handleError(e); - const failedTrackLogMessage = sprintf(LOG_MESSAGES.NOT_TRACKING_USER, MODULE_NAME, userId); - this.logger.log(LOG_LEVEL.ERROR, failedTrackLogMessage); + this.errorHandler.handleError(e); + this.logger.log(LOG_LEVEL.ERROR, LOG_MESSAGES.NOT_TRACKING_USER, MODULE_NAME, userId); } } /** @@ -455,7 +463,7 @@ export default class Optimizely { getVariation(experimentKey: string, userId: string, attributes?: UserAttributes): string | null { try { if (!this.isValidInstance()) { - this.logger.log(LOG_LEVEL.ERROR, sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'getVariation')); + this.logger.log(LOG_LEVEL.ERROR, LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'getVariation'); return null; } @@ -473,7 +481,9 @@ export default class Optimizely { if (!experiment) { this.logger.log( LOG_LEVEL.DEBUG, - sprintf(ERROR_MESSAGES.INVALID_EXPERIMENT_KEY, MODULE_NAME, experimentKey) + ERROR_MESSAGES.INVALID_EXPERIMENT_KEY, + MODULE_NAME, + experimentKey, ); return null; } @@ -608,13 +618,13 @@ export default class Optimizely { * @return {null} */ private notActivatingExperiment(experimentKey: string, userId: string): null { - const failedActivationLogMessage = sprintf( + this.logger.log( + LOG_LEVEL.INFO, LOG_MESSAGES.NOT_ACTIVATING_USER, MODULE_NAME, userId, - experimentKey + experimentKey, ); - this.logger.log(LOG_LEVEL.INFO, failedActivationLogMessage); return null; } @@ -644,7 +654,9 @@ export default class Optimizely { if (!this.isValidInstance()) { this.logger.log( LOG_LEVEL.ERROR, - sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'isFeatureEnabled') + LOG_MESSAGES.INVALID_OBJECT, + MODULE_NAME, + 'isFeatureEnabled', ); return false; } @@ -694,12 +706,18 @@ export default class Optimizely { if (featureEnabled === true) { this.logger.log( LOG_LEVEL.INFO, - sprintf(LOG_MESSAGES.FEATURE_ENABLED_FOR_USER, MODULE_NAME, featureKey, userId) + LOG_MESSAGES.FEATURE_ENABLED_FOR_USER, + MODULE_NAME, + featureKey, + userId, ); } else { this.logger.log( LOG_LEVEL.INFO, - sprintf(LOG_MESSAGES.FEATURE_NOT_ENABLED_FOR_USER, MODULE_NAME, featureKey, userId) + LOG_MESSAGES.FEATURE_NOT_ENABLED_FOR_USER, + MODULE_NAME, + featureKey, + userId, ); featureEnabled = false; } @@ -739,7 +757,9 @@ export default class Optimizely { if (!this.isValidInstance()) { this.logger.log( LOG_LEVEL.ERROR, - sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'getEnabledFeatures') + LOG_MESSAGES.INVALID_OBJECT, + MODULE_NAME, + 'getEnabledFeatures', ); return enabledFeatures; } @@ -791,7 +811,7 @@ export default class Optimizely { ): unknown { try { if (!this.isValidInstance()) { - this.logger.log(LOG_LEVEL.ERROR, sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'getFeatureVariable')); + this.logger.log(LOG_LEVEL.ERROR, LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'getFeatureVariable'); return null; } return this.getFeatureVariableForType(featureKey, variableKey, null, userId, attributes); @@ -852,7 +872,10 @@ export default class Optimizely { if (variableType && variable.type !== variableType) { this.logger.log( LOG_LEVEL.WARNING, - sprintf(LOG_MESSAGES.VARIABLE_REQUESTED_WITH_WRONG_TYPE, MODULE_NAME, variableType, variable.type) + LOG_MESSAGES.VARIABLE_REQUESTED_WITH_WRONG_TYPE, + MODULE_NAME, + variableType, + variable.type, ); return null; } @@ -925,47 +948,39 @@ export default class Optimizely { variableValue = value; this.logger.log( LOG_LEVEL.INFO, - sprintf( - LOG_MESSAGES.USER_RECEIVED_VARIABLE_VALUE, - MODULE_NAME, - variableValue, - variable.key, - featureKey - ) + LOG_MESSAGES.USER_RECEIVED_VARIABLE_VALUE, + MODULE_NAME, + variableValue, + variable.key, + featureKey, ); } else { this.logger.log( LOG_LEVEL.INFO, - sprintf( - LOG_MESSAGES.FEATURE_NOT_ENABLED_RETURN_DEFAULT_VARIABLE_VALUE, - MODULE_NAME, - featureKey, - userId, - variableValue - ) + LOG_MESSAGES.FEATURE_NOT_ENABLED_RETURN_DEFAULT_VARIABLE_VALUE, + MODULE_NAME, + featureKey, + userId, + variableValue, ); } } else { this.logger.log( LOG_LEVEL.INFO, - sprintf( - LOG_MESSAGES.VARIABLE_NOT_USED_RETURN_DEFAULT_VARIABLE_VALUE, - MODULE_NAME, - variable.key, - variation.key - ) + LOG_MESSAGES.VARIABLE_NOT_USED_RETURN_DEFAULT_VARIABLE_VALUE, + MODULE_NAME, + variable.key, + variation.key, ); } } else { this.logger.log( LOG_LEVEL.INFO, - sprintf( - LOG_MESSAGES.USER_RECEIVED_DEFAULT_VARIABLE_VALUE, - MODULE_NAME, - userId, - variable.key, - featureKey - ) + LOG_MESSAGES.USER_RECEIVED_DEFAULT_VARIABLE_VALUE, + MODULE_NAME, + userId, + variable.key, + featureKey, ); } @@ -993,7 +1008,7 @@ export default class Optimizely { ): boolean | null { try { if (!this.isValidInstance()) { - this.logger.log(LOG_LEVEL.ERROR, sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'getFeatureVariableBoolean')); + this.logger.log(LOG_LEVEL.ERROR, LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'getFeatureVariableBoolean'); return null; } return this.getFeatureVariableForType(featureKey, variableKey, FEATURE_VARIABLE_TYPES.BOOLEAN, userId, attributes) as boolean | null; @@ -1026,7 +1041,7 @@ export default class Optimizely { ): number | null { try { if (!this.isValidInstance()) { - this.logger.log(LOG_LEVEL.ERROR, sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'getFeatureVariableDouble')); + this.logger.log(LOG_LEVEL.ERROR, LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'getFeatureVariableDouble'); return null; } return this.getFeatureVariableForType(featureKey, variableKey, FEATURE_VARIABLE_TYPES.DOUBLE, userId, attributes) as number | null; @@ -1059,7 +1074,7 @@ export default class Optimizely { ): number | null { try { if (!this.isValidInstance()) { - this.logger.log(LOG_LEVEL.ERROR, sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'getFeatureVariableInteger')); + this.logger.log(LOG_LEVEL.ERROR, LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'getFeatureVariableInteger'); return null; } return this.getFeatureVariableForType(featureKey, variableKey, FEATURE_VARIABLE_TYPES.INTEGER, userId, attributes) as number | null; @@ -1092,7 +1107,7 @@ export default class Optimizely { ): string | null { try { if (!this.isValidInstance()) { - this.logger.log(LOG_LEVEL.ERROR, sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'getFeatureVariableString')); + this.logger.log(LOG_LEVEL.ERROR, LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'getFeatureVariableString'); return null; } return this.getFeatureVariableForType(featureKey, variableKey, FEATURE_VARIABLE_TYPES.STRING, userId, attributes) as string | null; @@ -1125,7 +1140,7 @@ export default class Optimizely { ): unknown { try { if (!this.isValidInstance()) { - this.logger.log(LOG_LEVEL.ERROR, sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'getFeatureVariableJSON')); + this.logger.log(LOG_LEVEL.ERROR, LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'getFeatureVariableJSON'); return null; } return this.getFeatureVariableForType(featureKey, variableKey, FEATURE_VARIABLE_TYPES.JSON, userId, attributes); @@ -1153,7 +1168,7 @@ export default class Optimizely { ): { [variableKey: string]: unknown } | null { try { if (!this.isValidInstance()) { - this.logger.log(LOG_LEVEL.ERROR, sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'getAllFeatureVariables')); + this.logger.log(LOG_LEVEL.ERROR, LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'getAllFeatureVariables'); return null; } @@ -1442,18 +1457,16 @@ export default class Optimizely { options: OptimizelyDecideOption[] = [] ): OptimizelyDecision { const configObj = this.projectConfigManager.getConfig(); - const reasons: string[] = []; + const reasons: (string | number)[][] = []; if (!this.isValidInstance() || !configObj) { - reasons.push(DECISION_MESSAGES.SDK_NOT_READY); - this.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'decide')); - return newErrorDecision(key, user, reasons); + this.logger.log(LOG_LEVEL.INFO, LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'decide'); + return newErrorDecision(key, user, [DECISION_MESSAGES.SDK_NOT_READY]); } const feature = configObj.featureKeyMap[key]; if (!feature) { - reasons.push(sprintf(DECISION_MESSAGES.FLAG_KEY_INVALID, key)); - this.logger.log(LOG_LEVEL.ERROR, sprintf(ERROR_MESSAGES.FEATURE_NOT_IN_DATAFILE, MODULE_NAME, key)); - return newErrorDecision(key, user, reasons); + this.logger.log(LOG_LEVEL.ERROR, ERROR_MESSAGES.FEATURE_NOT_IN_DATAFILE, MODULE_NAME, key); + return newErrorDecision(key, user, [sprintf(DECISION_MESSAGES.FLAG_KEY_INVALID, key)]); } const userId = user.getUserId(); @@ -1475,12 +1488,18 @@ export default class Optimizely { if (flagEnabled === true) { this.logger.log( LOG_LEVEL.INFO, - sprintf(LOG_MESSAGES.FEATURE_ENABLED_FOR_USER, MODULE_NAME, key, userId) + LOG_MESSAGES.FEATURE_ENABLED_FOR_USER, + MODULE_NAME, + key, + userId, ); } else { this.logger.log( LOG_LEVEL.INFO, - sprintf(LOG_MESSAGES.FEATURE_NOT_ENABLED_FOR_USER, MODULE_NAME, key, userId) + LOG_MESSAGES.FEATURE_NOT_ENABLED_FOR_USER, + MODULE_NAME, + key, + userId, ); } @@ -1516,7 +1535,11 @@ export default class Optimizely { } const shouldIncludeReasons = allDecideOptions[OptimizelyDecideOption.INCLUDE_REASONS]; - const reportedReasons = shouldIncludeReasons ? reasons : []; + + let reportedReasons: string[] = []; + if (shouldIncludeReasons) { + reportedReasons = reasons.map((reason) => sprintf(reason[0] as string, ...reason.slice(1))); + } const featureInfo = { flagKey: key, @@ -1554,7 +1577,7 @@ export default class Optimizely { private getAllDecideOptions(options: OptimizelyDecideOption[]): { [key: string]: boolean } { const allDecideOptions = { ...this.defaultDecideOptions }; if (!Array.isArray(options)) { - this.logger.log(LOG_LEVEL.DEBUG, sprintf(LOG_MESSAGES.INVALID_DECIDE_OPTIONS, MODULE_NAME)); + this.logger.log(LOG_LEVEL.DEBUG, LOG_MESSAGES.INVALID_DECIDE_OPTIONS, MODULE_NAME); } else { options.forEach((option) => { // Filter out all provided decide options that are not in OptimizelyDecideOption[] @@ -1563,7 +1586,9 @@ export default class Optimizely { } else { this.logger.log( LOG_LEVEL.WARNING, - sprintf(LOG_MESSAGES.UNRECOGNIZED_DECIDE_OPTION, MODULE_NAME, option) + LOG_MESSAGES.UNRECOGNIZED_DECIDE_OPTION, + MODULE_NAME, + option, ); } }); @@ -1588,7 +1613,7 @@ export default class Optimizely { ): { [key: string]: OptimizelyDecision } { const decisionMap: { [key: string]: OptimizelyDecision } = {}; if (!this.isValidInstance()) { - this.logger.log(LOG_LEVEL.ERROR, sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'decideForKeys')); + this.logger.log(LOG_LEVEL.ERROR, LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'decideForKeys'); return decisionMap; } if (keys.length === 0) { @@ -1619,7 +1644,7 @@ export default class Optimizely { const configObj = this.projectConfigManager.getConfig(); const decisionMap: { [key: string]: OptimizelyDecision } = {}; if (!this.isValidInstance() || !configObj) { - this.logger.log(LOG_LEVEL.ERROR, sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'decideAll')); + this.logger.log(LOG_LEVEL.ERROR, LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'decideAll'); return decisionMap; } diff --git a/packages/optimizely-sdk/lib/shared_types.ts b/packages/optimizely-sdk/lib/shared_types.ts index 636e9fa7f..50a8a84c3 100644 --- a/packages/optimizely-sdk/lib/shared_types.ts +++ b/packages/optimizely-sdk/lib/shared_types.ts @@ -33,7 +33,7 @@ export interface BucketerParams { export interface DecisionResponse { readonly result: T; - readonly reasons: string[]; + readonly reasons: (string | number)[][]; } export type UserAttributes = { diff --git a/packages/optimizely-sdk/lib/utils/event_tag_utils/index.tests.js b/packages/optimizely-sdk/lib/utils/event_tag_utils/index.tests.js index 0dc9da982..3189fae51 100644 --- a/packages/optimizely-sdk/lib/utils/event_tag_utils/index.tests.js +++ b/packages/optimizely-sdk/lib/utils/event_tag_utils/index.tests.js @@ -15,9 +15,12 @@ */ import sinon from 'sinon'; import { assert } from 'chai'; +import { sprintf } from '@optimizely/js-sdk-utils'; import * as eventTagUtils from './'; +var buildLogMessageFromArgs = args => sprintf(args[1], ...args.splice(2)); + describe('lib/utils/event_tag_utils', function() { var mockLogger; beforeEach(function() { @@ -38,7 +41,7 @@ describe('lib/utils/event_tag_utils', function() { ); assert.strictEqual(parsedRevenueValue, 1337); - var logMessage = mockLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(mockLogger.log.args[0]); assert.strictEqual(logMessage, 'EVENT_TAG_UTILS: Parsed revenue value "1337" from event tags.'); // test out a float @@ -64,7 +67,7 @@ describe('lib/utils/event_tag_utils', function() { assert.strictEqual(parsedRevenueValue, null); - var logMessage = mockLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(mockLogger.log.args[0]); assert.strictEqual(logMessage, 'EVENT_TAG_UTILS: Failed to parse revenue value "invalid" from event tags.'); }); }); @@ -94,7 +97,7 @@ describe('lib/utils/event_tag_utils', function() { ); assert.strictEqual(parsedEventValue, 1337); - var logMessage = mockLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(mockLogger.log.args[0]); assert.strictEqual(logMessage, 'EVENT_TAG_UTILS: Parsed event value "1337" from event tags.'); // test out a float @@ -120,7 +123,7 @@ describe('lib/utils/event_tag_utils', function() { assert.strictEqual(parsedEventValue, null); - var logMessage = mockLogger.log.args[0][1]; + var logMessage = buildLogMessageFromArgs(mockLogger.log.args[0]); assert.strictEqual(logMessage, 'EVENT_TAG_UTILS: Failed to parse event value "invalid" from event tags.'); }); }); diff --git a/packages/optimizely-sdk/lib/utils/event_tag_utils/index.ts b/packages/optimizely-sdk/lib/utils/event_tag_utils/index.ts index 56e8528c8..86c37ad2a 100644 --- a/packages/optimizely-sdk/lib/utils/event_tag_utils/index.ts +++ b/packages/optimizely-sdk/lib/utils/event_tag_utils/index.ts @@ -13,8 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { sprintf } from '@optimizely/js-sdk-utils'; - import { EventTags } from '@optimizely/js-sdk-event-processor'; import { LoggerFacade } from '@optimizely/js-sdk-logging'; @@ -44,15 +42,15 @@ export function getRevenueValue(eventTags: EventTags, logger: LoggerFacade): num if (typeof rawValue === 'string') { parsedRevenueValue = parseInt(rawValue); if (isNaN(parsedRevenueValue)) { - logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.FAILED_TO_PARSE_REVENUE, MODULE_NAME, rawValue)); + logger.log(LOG_LEVEL.INFO, LOG_MESSAGES.FAILED_TO_PARSE_REVENUE, MODULE_NAME, rawValue); return null; } - logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.PARSED_REVENUE_VALUE, MODULE_NAME, parsedRevenueValue)); + logger.log(LOG_LEVEL.INFO, LOG_MESSAGES.PARSED_REVENUE_VALUE, MODULE_NAME, parsedRevenueValue); return parsedRevenueValue; } if (typeof rawValue === 'number') { parsedRevenueValue = rawValue; - logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.PARSED_REVENUE_VALUE, MODULE_NAME, parsedRevenueValue)); + logger.log(LOG_LEVEL.INFO, LOG_MESSAGES.PARSED_REVENUE_VALUE, MODULE_NAME, parsedRevenueValue); return parsedRevenueValue; } return null; @@ -73,15 +71,15 @@ export function getEventValue(eventTags: EventTags, logger: LoggerFacade): numbe if (typeof rawValue === 'string') { parsedEventValue = parseFloat(rawValue); if (isNaN(parsedEventValue)) { - logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.FAILED_TO_PARSE_VALUE, MODULE_NAME, rawValue)); + logger.log(LOG_LEVEL.INFO, LOG_MESSAGES.FAILED_TO_PARSE_VALUE, MODULE_NAME, rawValue); return null; } - logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.PARSED_NUMERIC_VALUE, MODULE_NAME, parsedEventValue)); + logger.log(LOG_LEVEL.INFO, LOG_MESSAGES.PARSED_NUMERIC_VALUE, MODULE_NAME, parsedEventValue); return parsedEventValue; } if (typeof rawValue === 'number') { parsedEventValue = rawValue; - logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.PARSED_NUMERIC_VALUE, MODULE_NAME, parsedEventValue)); + logger.log(LOG_LEVEL.INFO, LOG_MESSAGES.PARSED_NUMERIC_VALUE, MODULE_NAME, parsedEventValue); return parsedEventValue; } return null; diff --git a/packages/optimizely-sdk/package-lock.json b/packages/optimizely-sdk/package-lock.json index 585e0fbaa..e9f55bb7c 100644 --- a/packages/optimizely-sdk/package-lock.json +++ b/packages/optimizely-sdk/package-lock.json @@ -310,40 +310,30 @@ "dev": true }, "@optimizely/js-sdk-datafile-manager": { - "version": "0.8.1", - "resolved": "https://registry.npmjs.org/@optimizely/js-sdk-datafile-manager/-/js-sdk-datafile-manager-0.8.1.tgz", - "integrity": "sha512-zMfyXQUqJlPoFGTNvreGSneGRnr5hn4jp03ofipIpA/RONNsf7DEi/H/uC4pAZxlYm1r5eHZRwKU6gwZTB31LQ==", + "version": "0.9.1", + "resolved": "https://registry.npmjs.org/@optimizely/js-sdk-datafile-manager/-/js-sdk-datafile-manager-0.9.1.tgz", + "integrity": "sha512-AaAu1zPtPY3/qsVp5UwGS77aB8gxyQ1GxvzzOlN/40Y5MbBN8ul2HnUVwl9ZfUlPVunBhe1cw5o1H5/T0IrZYA==", "requires": { - "@optimizely/js-sdk-logging": "^0.1.0", + "@optimizely/js-sdk-logging": "^0.3.1", "@optimizely/js-sdk-utils": "^0.4.0", "decompress-response": "^4.2.1" } }, "@optimizely/js-sdk-event-processor": { - "version": "0.8.2", - "resolved": "https://registry.npmjs.org/@optimizely/js-sdk-event-processor/-/js-sdk-event-processor-0.8.2.tgz", - "integrity": "sha512-5sVcQFqgKF0R+vJbBXy6ykKTlEfll0Ti0xGeKU3TLILRNvPDxTpVAlyrLfBC/yfF/hopjRPusGp3z9lZnVej0w==", + "version": "0.9.1", + "resolved": "https://registry.npmjs.org/@optimizely/js-sdk-event-processor/-/js-sdk-event-processor-0.9.1.tgz", + "integrity": "sha512-ytFualsBRu8H2e66MEsjXHhr1ab4QviH88QeP8Vba3zLeD1UTghGFQZ6lTe2fOTskEaoRrhlv9q+O5C6PYkhuA==", "requires": { - "@optimizely/js-sdk-logging": "^0.1.0", + "@optimizely/js-sdk-logging": "^0.3.1", "@optimizely/js-sdk-utils": "^0.4.0" } }, "@optimizely/js-sdk-logging": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/@optimizely/js-sdk-logging/-/js-sdk-logging-0.1.0.tgz", - "integrity": "sha512-Bs2zHvsdNIk2QSg05P6mKIlROHoBIRNStbrVwlePm603CucojKRPlFJG4rt7sFZQOo8xS8I7z1BmE4QI3/ZE9A==", + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/@optimizely/js-sdk-logging/-/js-sdk-logging-0.3.1.tgz", + "integrity": "sha512-K71Jf283FP0E4oXehcXTTM3gvgHZHr7FUrIsw//0mdJlotHJT4Nss4hE0CWPbBxO7LJAtwNnO+VIA/YOcO4vHg==", "requires": { - "@optimizely/js-sdk-utils": "^0.1.0" - }, - "dependencies": { - "@optimizely/js-sdk-utils": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/@optimizely/js-sdk-utils/-/js-sdk-utils-0.1.0.tgz", - "integrity": "sha512-p7499GgVaX94YmkrwOiEtLgxgjXTPbUQsvETaAil5J7zg1TOA4Wl8ClalLSvCh+AKWkxGdkL4/uM/zfbxPSNNw==", - "requires": { - "uuid": "^3.3.2" - } - } + "@optimizely/js-sdk-utils": "^0.4.0" } }, "@optimizely/js-sdk-utils": { diff --git a/packages/optimizely-sdk/package.json b/packages/optimizely-sdk/package.json index 90edbd7eb..24b82ce00 100644 --- a/packages/optimizely-sdk/package.json +++ b/packages/optimizely-sdk/package.json @@ -41,9 +41,9 @@ }, "homepage": "https://github.com/optimizely/javascript-sdk/tree/master/packages/optimizely-sdk", "dependencies": { - "@optimizely/js-sdk-datafile-manager": "^0.8.1", - "@optimizely/js-sdk-event-processor": "^0.8.2", - "@optimizely/js-sdk-logging": "^0.1.0", + "@optimizely/js-sdk-datafile-manager": "^0.9.1", + "@optimizely/js-sdk-event-processor": "^0.9.1", + "@optimizely/js-sdk-logging": "^0.3.1", "@optimizely/js-sdk-utils": "^0.4.0", "json-schema": "^0.2.3", "murmurhash": "0.0.2"