From 394b9eca2ddf190c1b32e584717e44f519611876 Mon Sep 17 00:00:00 2001 From: fayyazarshad Date: Wed, 8 Apr 2020 19:25:30 +0500 Subject: [PATCH 1/4] update test data --- packages/optimizely-sdk/lib/tests/test_data.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/optimizely-sdk/lib/tests/test_data.js b/packages/optimizely-sdk/lib/tests/test_data.js index 31c9097b7..4d5d4ce66 100644 --- a/packages/optimizely-sdk/lib/tests/test_data.js +++ b/packages/optimizely-sdk/lib/tests/test_data.js @@ -2328,7 +2328,6 @@ var typedAudiencesConfig = { { id: '3988293898', name: '$$dummySubstringString', - conditions: '["and", ["or"]]', conditions: '{ "type": "custom_attribute", "name": "$opt_dummy_attribute", "value": "impossible_value" }', }, { From d4dbbe215bf3de81fbf1c4304094d7f92b51fef4 Mon Sep 17 00:00:00 2001 From: fayyazarshad Date: Thu, 9 Apr 2020 13:55:18 +0500 Subject: [PATCH 2/4] updated as per entry points --- .../lib/core/decision_service/index.tests.js | 2 +- .../optimizely-sdk/lib/optimizely/index.js | 34 ++++++------- .../lib/optimizely/index.tests.js | 48 +++++++++---------- .../optimizely-sdk/lib/tests/test_data.js | 40 ++++++++-------- packages/optimizely-sdk/rollup.config.js | 1 + 5 files changed, 62 insertions(+), 63 deletions(-) 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 4f5c01675..2936ca514 100644 --- a/packages/optimizely-sdk/lib/core/decision_service/index.tests.js +++ b/packages/optimizely-sdk/lib/core/decision_service/index.tests.js @@ -14,7 +14,7 @@ * limitations under the License. * ***************************************************************************/ -var Optimizely = require('../../optimizely'); +var Optimizely = require('../../optimizely').default; var eventBuilder = require('../../core/event_builder/index.js'); var eventDispatcher = require('../../plugins/event_dispatcher/index.node'); var errorHandler = require('../../plugins/error_handler'); diff --git a/packages/optimizely-sdk/lib/optimizely/index.js b/packages/optimizely-sdk/lib/optimizely/index.js index 706c6df69..23984b2f2 100644 --- a/packages/optimizely-sdk/lib/optimizely/index.js +++ b/packages/optimizely-sdk/lib/optimizely/index.js @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2016-2019, Optimizely, Inc. and contributors * + * Copyright 2016-2020 Optimizely, Inc. and contributors * * * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * @@ -13,21 +13,21 @@ * See the License for the specific language governing permissions and * * limitations under the License. * ***************************************************************************/ - -var fns = require('../utils/fns'); -var attributesValidator = require('../utils/attributes_validator'); -var decisionService = require('../core/decision_service'); -var enums = require('../utils/enums'); -var eventBuilder = require('../core/event_builder/index.js'); -var eventHelpers = require('../core/event_builder/event_helpers'); -var eventProcessor = require('@optimizely/js-sdk-event-processor'); -var eventTagsValidator = require('../utils/event_tags_validator'); -var notificationCenter = require('../core/notification_center'); -var projectConfig = require('../core/project_config'); -var jsSdkUtils = require('@optimizely/js-sdk-utils'); -var userProfileServiceValidator = require('../utils/user_profile_service_validator'); -var stringValidator = require('../utils/string_value_validator'); -var projectConfigManager = require('../core/project_config/project_config_manager'); +import * as jsSdkUtils from '@optimizely/js-sdk-utils'; +import * as eventProcessor from '@optimizely/js-sdk-event-processor'; + +import fns from '../utils/fns' +import attributesValidator from '../utils/attributes_validator'; +import decisionService from '../core/decision_service'; +import enums from '../utils/enums'; +import eventBuilder from '../core/event_builder/index.js'; +import eventHelpers from '../core/event_builder/event_helpers'; +import eventTagsValidator from '../utils/event_tags_validator'; +import notificationCenter from '../core/notification_center'; +import projectConfig from '../core/project_config'; +import userProfileServiceValidator from '../utils/user_profile_service_validator'; +import stringValidator from '../utils/string_value_validator'; +import projectConfigManager from '../core/project_config/project_config_manager'; var ERROR_MESSAGES = enums.ERROR_MESSAGES; var LOG_LEVEL = enums.LOG_LEVEL; @@ -1132,4 +1132,4 @@ Optimizely.prototype.onReady = function(options) { return Promise.race([this.__readyPromise, timeoutPromise]); }; -module.exports = Optimizely; +export default Optimizely; diff --git a/packages/optimizely-sdk/lib/optimizely/index.tests.js b/packages/optimizely-sdk/lib/optimizely/index.tests.js index 3fa217fbe..64e9caab0 100644 --- a/packages/optimizely-sdk/lib/optimizely/index.tests.js +++ b/packages/optimizely-sdk/lib/optimizely/index.tests.js @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2016-2019, Optimizely, Inc. and contributors * + * Copyright 2016-2020 Optimizely, Inc. and contributors * * * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * @@ -13,31 +13,29 @@ * See the License for the specific language governing permissions and * * limitations under the License. * ***************************************************************************/ +import * as eventProcessor from '@optimizely/js-sdk-event-processor'; +import * as testData from '../tests/test_data'; +import * as logging from '@optimizely/js-sdk-logging'; +import Optimizely from './'; +import AudienceEvaluator from '../core/audience_evaluator'; +import bluebird from 'bluebird'; +import bucketer from '../core/bucketer'; +import projectConfigManager from '../core/project_config/project_config_manager'; +import enums from '../utils/enums'; +import eventBuilder from '../core/event_builder/index.js'; +import eventDispatcher from '../plugins/event_dispatcher/index.node'; +import errorHandler from '../plugins/error_handler'; +import fns from '../utils/fns'; +import logger from '../plugins/logger'; +import decisionService from '../core/decision_service'; +import jsonSchemaValidator from '../utils/json_schema_validator'; +import projectConfig from '../core/project_config'; +import chai from 'chai'; +import sinon from 'sinon'; +import { sprintf } from '@optimizely/js-sdk-utils'; +import uuid from 'uuid'; -var Optimizely = require('./'); -var AudienceEvaluator = require('../core/audience_evaluator'); -var bluebird = require('bluebird'); -var bucketer = require('../core/bucketer'); -var projectConfigManager = require('../core/project_config/project_config_manager'); -var enums = require('../utils/enums'); -var eventBuilder = require('../core/event_builder/index.js'); -var eventDispatcher = require('../plugins/event_dispatcher/index.node'); -var eventProcessor = require('@optimizely/js-sdk-event-processor'); -var errorHandler = require('../plugins/error_handler'); -var fns = require('../utils/fns'); -var jsonSchemaValidator = require('../utils/json_schema_validator'); -var logger = require('../plugins/logger'); -var decisionService = require('../core/decision_service'); -var testData = require('../tests/test_data'); -var jsonSchemaValidator = require('../utils/json_schema_validator'); -var projectConfig = require('../core/project_config'); -var logging = require('@optimizely/js-sdk-logging'); - -var chai = require('chai'); var assert = chai.assert; -var sinon = require('sinon'); -var sprintf = require('@optimizely/js-sdk-utils').sprintf; -var uuid = require('uuid'); var ERROR_MESSAGES = enums.ERROR_MESSAGES; var LOG_LEVEL = enums.LOG_LEVEL; @@ -6650,7 +6648,7 @@ describe('lib/optimizely', function() { }); it('should instantiate the eventProcessor with the provided event flush interval and event batch size', function() { - optlyInstance = new Optimizely({ + var optlyInstance = new Optimizely({ clientEngine: 'node-sdk', errorHandler: errorHandler, eventDispatcher: eventDispatcher, diff --git a/packages/optimizely-sdk/lib/tests/test_data.js b/packages/optimizely-sdk/lib/tests/test_data.js index 4d5d4ce66..06d5c6f01 100644 --- a/packages/optimizely-sdk/lib/tests/test_data.js +++ b/packages/optimizely-sdk/lib/tests/test_data.js @@ -1,5 +1,5 @@ /** - * Copyright 2016-2019, Optimizely + * Copyright 2016-2020 Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -var cloneDeep = require('lodash/cloneDeep'); +import cloneDeep from 'lodash/cloneDeep'; var config = { revision: '42', @@ -336,7 +336,7 @@ var config = { projectId: '111001', }; -var getParsedAudiences = [ +export var getParsedAudiences = [ { name: 'Firefox users', conditions: ['and', ['or', ['or', { name: 'browser_type', type: 'custom_attribute', value: 'firefox' }]]], @@ -344,7 +344,7 @@ var getParsedAudiences = [ }, ]; -var getTestProjectConfig = function() { +export var getTestProjectConfig = function() { return cloneDeep(config); }; @@ -1009,11 +1009,11 @@ var configWithFeatures = { variables: [], }; -var getTestProjectConfigWithFeatures = function() { +export var getTestProjectConfigWithFeatures = function() { return cloneDeep(configWithFeatures); }; -var datafileWithFeaturesExpectedData = { +export var datafileWithFeaturesExpectedData = { rolloutIdMap: { 599055: { id: '599055', @@ -2035,7 +2035,7 @@ var unsupportedVersionConfig = { projectId: '111001', }; -var getUnsupportedVersionConfig = function() { +export var getUnsupportedVersionConfig = function() { return cloneDeep(unsupportedVersionConfig); }; @@ -2435,11 +2435,11 @@ var typedAudiencesConfig = { revision: '3', }; -var getTypedAudiencesConfig = function() { +export var getTypedAudiencesConfig = function() { return cloneDeep(typedAudiencesConfig); }; -var typedAudiencesById = { +export var typedAudiencesById = { 3468206642: { id: '3468206642', name: 'exactString', @@ -2573,17 +2573,17 @@ var mutexFeatureTestsConfig = { revision: '12', }; -var getMutexFeatureTestsConfig = function() { +export var getMutexFeatureTestsConfig = function() { return cloneDeep(mutexFeatureTestsConfig); }; -module.exports = { - getTestProjectConfig: getTestProjectConfig, - getParsedAudiences: getParsedAudiences, - getTestProjectConfigWithFeatures: getTestProjectConfigWithFeatures, - datafileWithFeaturesExpectedData: datafileWithFeaturesExpectedData, - getUnsupportedVersionConfig: getUnsupportedVersionConfig, - getTypedAudiencesConfig: getTypedAudiencesConfig, - typedAudiencesById: typedAudiencesById, - getMutexFeatureTestsConfig: getMutexFeatureTestsConfig, -}; +export default { + getParsedAudiences, + getTestProjectConfig, + getTestProjectConfigWithFeatures, + datafileWithFeaturesExpectedData, + getUnsupportedVersionConfig, + getTypedAudiencesConfig, + typedAudiencesById, + getMutexFeatureTestsConfig, +} diff --git a/packages/optimizely-sdk/rollup.config.js b/packages/optimizely-sdk/rollup.config.js index 9508b4530..1d241bc79 100644 --- a/packages/optimizely-sdk/rollup.config.js +++ b/packages/optimizely-sdk/rollup.config.js @@ -62,6 +62,7 @@ const umdconfig = { 'getErrorHandler' ], '@optimizely/js-sdk-event-processor': [ + 'LogTierV1EventProcessor', 'LocalStoragePendingEventsDispatcher' ] } From 2a6d490160c2ad50a2e14e02a3379e97b70a1f20 Mon Sep 17 00:00:00 2001 From: Zeeshan Ashraf Date: Thu, 9 Apr 2020 13:02:22 -0700 Subject: [PATCH 3/4] some minor cleanup --- .../optimizely-sdk/lib/optimizely/index.js | 58 +++++++++---------- .../lib/optimizely/index.tests.js | 13 ++--- .../optimizely-sdk/lib/tests/test_data.js | 2 +- 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/packages/optimizely-sdk/lib/optimizely/index.js b/packages/optimizely-sdk/lib/optimizely/index.js index 23984b2f2..c33661424 100644 --- a/packages/optimizely-sdk/lib/optimizely/index.js +++ b/packages/optimizely-sdk/lib/optimizely/index.js @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * * limitations under the License. * ***************************************************************************/ -import * as jsSdkUtils from '@optimizely/js-sdk-utils'; +import { sprintf, objectValues } from '@optimizely/js-sdk-utils'; import * as eventProcessor from '@optimizely/js-sdk-event-processor'; import fns from '../utils/fns' @@ -58,7 +58,7 @@ function Optimizely(config) { if (enums.VALID_CLIENT_ENGINES.indexOf(clientEngine) === -1) { config.logger.log( LOG_LEVEL.INFO, - jsSdkUtils.sprintf(LOG_MESSAGES.INVALID_CLIENT_ENGINE, MODULE_NAME, clientEngine) + sprintf(LOG_MESSAGES.INVALID_CLIENT_ENGINE, MODULE_NAME, clientEngine) ); clientEngine = enums.NODE_CLIENT_ENGINE; } @@ -81,7 +81,7 @@ function Optimizely(config) { function(configObj) { this.logger.log( LOG_LEVEL.INFO, - jsSdkUtils.sprintf(LOG_MESSAGES.UPDATED_OPTIMIZELY_CONFIG, MODULE_NAME, configObj.revision, configObj.projectId) + sprintf(LOG_MESSAGES.UPDATED_OPTIMIZELY_CONFIG, MODULE_NAME, configObj.revision, configObj.projectId) ); this.notificationCenter.sendNotifications(NOTIFICATION_TYPES.OPTIMIZELY_CONFIG_UPDATE); }.bind(this) @@ -94,7 +94,7 @@ function Optimizely(config) { try { if (userProfileServiceValidator.validate(config.userProfileService)) { userProfileService = config.userProfileService; - this.logger.log(LOG_LEVEL.INFO, jsSdkUtils.sprintf(LOG_MESSAGES.VALID_USER_PROFILE_SERVICE, MODULE_NAME)); + this.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.VALID_USER_PROFILE_SERVICE, MODULE_NAME)); } } catch (ex) { this.logger.log(LOG_LEVEL.WARNING, ex.message); @@ -144,7 +144,7 @@ Optimizely.prototype.__isValidInstance = function() { Optimizely.prototype.activate = function(experimentKey, userId, attributes) { try { if (!this.__isValidInstance()) { - this.logger.log(LOG_LEVEL.ERROR, jsSdkUtils.sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'activate')); + this.logger.log(LOG_LEVEL.ERROR, sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'activate')); return null; } @@ -165,7 +165,7 @@ Optimizely.prototype.activate = function(experimentKey, userId, attributes) { // If experiment is not set to 'Running' status, log accordingly and return variation key if (!projectConfig.isRunning(configObj, experimentKey)) { - var shouldNotDispatchActivateLogMessage = jsSdkUtils.sprintf( + var shouldNotDispatchActivateLogMessage = sprintf( LOG_MESSAGES.SHOULD_NOT_DISPATCH_ACTIVATE, MODULE_NAME, experimentKey @@ -179,7 +179,7 @@ Optimizely.prototype.activate = function(experimentKey, userId, attributes) { return variationKey; } catch (ex) { this.logger.log(LOG_LEVEL.ERROR, ex.message); - var failedActivationLogMessage = jsSdkUtils.sprintf( + var failedActivationLogMessage = sprintf( LOG_MESSAGES.NOT_ACTIVATING_USER, MODULE_NAME, userId, @@ -275,7 +275,7 @@ Optimizely.prototype.__emitNotificationCenterActivate = function(experimentKey, Optimizely.prototype.track = function(eventKey, userId, attributes, eventTags) { try { if (!this.__isValidInstance()) { - this.logger.log(LOG_LEVEL.ERROR, jsSdkUtils.sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'track')); + this.logger.log(LOG_LEVEL.ERROR, sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'track')); return; } @@ -291,9 +291,9 @@ Optimizely.prototype.track = function(eventKey, userId, attributes, eventTags) { if (!projectConfig.eventWithKeyExists(configObj, eventKey)) { this.logger.log( LOG_LEVEL.WARNING, - jsSdkUtils.sprintf(enums.LOG_MESSAGES.EVENT_KEY_NOT_FOUND, MODULE_NAME, eventKey) + sprintf(enums.LOG_MESSAGES.EVENT_KEY_NOT_FOUND, MODULE_NAME, eventKey) ); - this.logger.log(LOG_LEVEL.WARNING, jsSdkUtils.sprintf(LOG_MESSAGES.NOT_TRACKING_USER, MODULE_NAME, userId)); + this.logger.log(LOG_LEVEL.WARNING, sprintf(LOG_MESSAGES.NOT_TRACKING_USER, MODULE_NAME, userId)); return; } @@ -308,14 +308,14 @@ Optimizely.prototype.track = function(eventKey, userId, attributes, eventTags) { clientVersion: this.clientVersion, configObj: configObj, }); - this.logger.log(LOG_LEVEL.INFO, jsSdkUtils.sprintf(enums.LOG_MESSAGES.TRACK_EVENT, MODULE_NAME, eventKey, userId)); + this.logger.log(LOG_LEVEL.INFO, sprintf(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); - var failedTrackLogMessage = jsSdkUtils.sprintf(LOG_MESSAGES.NOT_TRACKING_USER, MODULE_NAME, userId); + var failedTrackLogMessage = sprintf(LOG_MESSAGES.NOT_TRACKING_USER, MODULE_NAME, userId); this.logger.log(LOG_LEVEL.ERROR, failedTrackLogMessage); } }; @@ -369,7 +369,7 @@ Optimizely.prototype.__emitNotificationCenterTrack = function(eventKey, userId, Optimizely.prototype.getVariation = function(experimentKey, userId, attributes) { try { if (!this.__isValidInstance()) { - this.logger.log(LOG_LEVEL.ERROR, jsSdkUtils.sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'getVariation')); + this.logger.log(LOG_LEVEL.ERROR, sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'getVariation')); return null; } @@ -387,7 +387,7 @@ Optimizely.prototype.getVariation = function(experimentKey, userId, attributes) if (!experiment) { this.logger.log( LOG_LEVEL.DEBUG, - jsSdkUtils.sprintf(ERROR_MESSAGES.INVALID_EXPERIMENT_KEY, MODULE_NAME, experimentKey) + sprintf(ERROR_MESSAGES.INVALID_EXPERIMENT_KEY, MODULE_NAME, experimentKey) ); return null; } @@ -485,7 +485,7 @@ Optimizely.prototype.__validateInputs = function(stringInputs, userAttributes, e if (stringInputs.hasOwnProperty('user_id')) { var userId = stringInputs.user_id; if (typeof userId !== 'string' || userId === null || userId === 'undefined') { - throw new Error(jsSdkUtils.sprintf(ERROR_MESSAGES.INVALID_INPUT_FORMAT, MODULE_NAME, 'user_id')); + throw new Error(sprintf(ERROR_MESSAGES.INVALID_INPUT_FORMAT, MODULE_NAME, 'user_id')); } delete stringInputs.user_id; @@ -495,7 +495,7 @@ Optimizely.prototype.__validateInputs = function(stringInputs, userAttributes, e for (var index = 0; index < inputKeys.length; index++) { var key = inputKeys[index]; if (!stringValidator.validate(stringInputs[key])) { - throw new Error(jsSdkUtils.sprintf(ERROR_MESSAGES.INVALID_INPUT_FORMAT, MODULE_NAME, key)); + throw new Error(sprintf(ERROR_MESSAGES.INVALID_INPUT_FORMAT, MODULE_NAME, key)); } } if (userAttributes) { @@ -519,7 +519,7 @@ Optimizely.prototype.__validateInputs = function(stringInputs, userAttributes, e * @return {null} */ Optimizely.prototype.__notActivatingExperiment = function(experimentKey, userId) { - var failedActivationLogMessage = jsSdkUtils.sprintf( + var failedActivationLogMessage = sprintf( LOG_MESSAGES.NOT_ACTIVATING_USER, MODULE_NAME, userId, @@ -555,7 +555,7 @@ Optimizely.prototype.isFeatureEnabled = function(featureKey, userId, attributes) if (!this.__isValidInstance()) { this.logger.log( LOG_LEVEL.ERROR, - jsSdkUtils.sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'isFeatureEnabled') + sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'isFeatureEnabled') ); return false; } @@ -594,12 +594,12 @@ Optimizely.prototype.isFeatureEnabled = function(featureKey, userId, attributes) if (featureEnabled === true) { this.logger.log( LOG_LEVEL.INFO, - jsSdkUtils.sprintf(LOG_MESSAGES.FEATURE_ENABLED_FOR_USER, MODULE_NAME, featureKey, userId) + sprintf(LOG_MESSAGES.FEATURE_ENABLED_FOR_USER, MODULE_NAME, featureKey, userId) ); } else { this.logger.log( LOG_LEVEL.INFO, - jsSdkUtils.sprintf(LOG_MESSAGES.FEATURE_NOT_ENABLED_FOR_USER, MODULE_NAME, featureKey, userId) + sprintf(LOG_MESSAGES.FEATURE_NOT_ENABLED_FOR_USER, MODULE_NAME, featureKey, userId) ); featureEnabled = false; } @@ -639,7 +639,7 @@ Optimizely.prototype.getEnabledFeatures = function(userId, attributes) { if (!this.__isValidInstance()) { this.logger.log( LOG_LEVEL.ERROR, - jsSdkUtils.sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'getEnabledFeatures') + sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'getEnabledFeatures') ); return enabledFeatures; } @@ -653,7 +653,7 @@ Optimizely.prototype.getEnabledFeatures = function(userId, attributes) { return enabledFeatures; } - jsSdkUtils.objectValues(configObj.featureKeyMap).forEach( + objectValues(configObj.featureKeyMap).forEach( function(feature) { if (this.isFeatureEnabled(feature.key, userId, attributes)) { enabledFeatures.push(feature.key); @@ -721,7 +721,7 @@ Optimizely.prototype._getFeatureVariableForType = function(featureKey, variableK var apiName = variableType ? 'getFeatureVariable' + variableType.charAt(0).toUpperCase() + variableType.slice(1) : 'getFeatureVariable'; - this.logger.log(LOG_LEVEL.ERROR, jsSdkUtils.sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, apiName)); + this.logger.log(LOG_LEVEL.ERROR, sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, apiName)); return null; } @@ -749,7 +749,7 @@ Optimizely.prototype._getFeatureVariableForType = function(featureKey, variableK } else if (variable.type !== variableType) { this.logger.log( LOG_LEVEL.WARNING, - jsSdkUtils.sprintf(LOG_MESSAGES.VARIABLE_REQUESTED_WITH_WRONG_TYPE, MODULE_NAME, variableType, variable.type) + sprintf(LOG_MESSAGES.VARIABLE_REQUESTED_WITH_WRONG_TYPE, MODULE_NAME, variableType, variable.type) ); return null; } @@ -766,7 +766,7 @@ Optimizely.prototype._getFeatureVariableForType = function(featureKey, variableK variableValue = value; this.logger.log( LOG_LEVEL.INFO, - jsSdkUtils.sprintf( + sprintf( LOG_MESSAGES.USER_RECEIVED_VARIABLE_VALUE, MODULE_NAME, variableKey, @@ -778,7 +778,7 @@ Optimizely.prototype._getFeatureVariableForType = function(featureKey, variableK } else { this.logger.log( LOG_LEVEL.INFO, - jsSdkUtils.sprintf( + sprintf( LOG_MESSAGES.FEATURE_NOT_ENABLED_RETURN_DEFAULT_VARIABLE_VALUE, MODULE_NAME, featureFlag.key, @@ -790,7 +790,7 @@ Optimizely.prototype._getFeatureVariableForType = function(featureKey, variableK } else { this.logger.log( LOG_LEVEL.INFO, - jsSdkUtils.sprintf( + sprintf( LOG_MESSAGES.VARIABLE_NOT_USED_RETURN_DEFAULT_VARIABLE_VALUE, MODULE_NAME, variableKey, @@ -801,7 +801,7 @@ Optimizely.prototype._getFeatureVariableForType = function(featureKey, variableK } else { this.logger.log( LOG_LEVEL.INFO, - jsSdkUtils.sprintf( + sprintf( LOG_MESSAGES.USER_RECEIVED_DEFAULT_VARIABLE_VALUE, MODULE_NAME, userId, @@ -1103,7 +1103,7 @@ Optimizely.prototype.onReady = function(options) { delete this.__readyTimeouts[timeoutId]; resolveTimeoutPromise({ success: false, - reason: jsSdkUtils.sprintf('onReady timeout expired after %s ms', timeout), + reason: sprintf('onReady timeout expired after %s ms', timeout), }); }.bind(this); var readyTimeout = setTimeout(onReadyTimeout, timeout); diff --git a/packages/optimizely-sdk/lib/optimizely/index.tests.js b/packages/optimizely-sdk/lib/optimizely/index.tests.js index 64e9caab0..15dc19335 100644 --- a/packages/optimizely-sdk/lib/optimizely/index.tests.js +++ b/packages/optimizely-sdk/lib/optimizely/index.tests.js @@ -13,9 +13,13 @@ * See the License for the specific language governing permissions and * * limitations under the License. * ***************************************************************************/ +import { assert } from 'chai'; +import sinon from 'sinon'; +import uuid from 'uuid'; +import { sprintf } from '@optimizely/js-sdk-utils'; import * as eventProcessor from '@optimizely/js-sdk-event-processor'; -import * as testData from '../tests/test_data'; import * as logging from '@optimizely/js-sdk-logging'; + import Optimizely from './'; import AudienceEvaluator from '../core/audience_evaluator'; import bluebird from 'bluebird'; @@ -30,12 +34,7 @@ import logger from '../plugins/logger'; import decisionService from '../core/decision_service'; import jsonSchemaValidator from '../utils/json_schema_validator'; import projectConfig from '../core/project_config'; -import chai from 'chai'; -import sinon from 'sinon'; -import { sprintf } from '@optimizely/js-sdk-utils'; -import uuid from 'uuid'; - -var assert = chai.assert; +import testData from '../tests/test_data'; var ERROR_MESSAGES = enums.ERROR_MESSAGES; var LOG_LEVEL = enums.LOG_LEVEL; diff --git a/packages/optimizely-sdk/lib/tests/test_data.js b/packages/optimizely-sdk/lib/tests/test_data.js index 06d5c6f01..8264436f8 100644 --- a/packages/optimizely-sdk/lib/tests/test_data.js +++ b/packages/optimizely-sdk/lib/tests/test_data.js @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import cloneDeep from 'lodash/cloneDeep'; +import { cloneDeep } from 'lodash'; var config = { revision: '42', From f2dbd046d67c1af97029da03c4d5acdef4db7a3f Mon Sep 17 00:00:00 2001 From: Zeeshan Ashraf Date: Thu, 9 Apr 2020 13:21:43 -0700 Subject: [PATCH 4/4] some more minor cleanup --- .../lib/core/decision_service/index.tests.js | 2 +- .../optimizely-sdk/lib/optimizely/index.js | 2 +- .../lib/optimizely/index.tests.js | 2 +- .../optimizely-sdk/lib/tests/test_data.js | 22 +++++++++---------- 4 files changed, 14 insertions(+), 14 deletions(-) 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 2936ca514..72813fe13 100644 --- a/packages/optimizely-sdk/lib/core/decision_service/index.tests.js +++ b/packages/optimizely-sdk/lib/core/decision_service/index.tests.js @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2017-2019, Optimizely, Inc. and contributors * + * Copyright 2017-2020, Optimizely, Inc. and contributors * * * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * diff --git a/packages/optimizely-sdk/lib/optimizely/index.js b/packages/optimizely-sdk/lib/optimizely/index.js index c33661424..9b2d1e5e4 100644 --- a/packages/optimizely-sdk/lib/optimizely/index.js +++ b/packages/optimizely-sdk/lib/optimizely/index.js @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2016-2020 Optimizely, Inc. and contributors * + * Copyright 2016-2020, Optimizely, Inc. and contributors * * * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * diff --git a/packages/optimizely-sdk/lib/optimizely/index.tests.js b/packages/optimizely-sdk/lib/optimizely/index.tests.js index 15dc19335..917820493 100644 --- a/packages/optimizely-sdk/lib/optimizely/index.tests.js +++ b/packages/optimizely-sdk/lib/optimizely/index.tests.js @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2016-2020 Optimizely, Inc. and contributors * + * Copyright 2016-2020, Optimizely, Inc. and contributors * * * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * diff --git a/packages/optimizely-sdk/lib/tests/test_data.js b/packages/optimizely-sdk/lib/tests/test_data.js index 8264436f8..d0592c359 100644 --- a/packages/optimizely-sdk/lib/tests/test_data.js +++ b/packages/optimizely-sdk/lib/tests/test_data.js @@ -1,5 +1,5 @@ /** - * Copyright 2016-2020 Optimizely + * Copyright 2016-2020, Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { cloneDeep } from 'lodash'; +import cloneDeep from 'lodash/cloneDeep'; var config = { revision: '42', @@ -2578,12 +2578,12 @@ export var getMutexFeatureTestsConfig = function() { }; export default { - getParsedAudiences, - getTestProjectConfig, - getTestProjectConfigWithFeatures, - datafileWithFeaturesExpectedData, - getUnsupportedVersionConfig, - getTypedAudiencesConfig, - typedAudiencesById, - getMutexFeatureTestsConfig, -} + getTestProjectConfig: getTestProjectConfig, + getParsedAudiences: getParsedAudiences, + getTestProjectConfigWithFeatures: getTestProjectConfigWithFeatures, + datafileWithFeaturesExpectedData: datafileWithFeaturesExpectedData, + getUnsupportedVersionConfig: getUnsupportedVersionConfig, + getTypedAudiencesConfig: getTypedAudiencesConfig, + typedAudiencesById: typedAudiencesById, + getMutexFeatureTestsConfig: getMutexFeatureTestsConfig, +};