From 92a902c3973528fde6e4442d5a78dbe325e6d25b Mon Sep 17 00:00:00 2001 From: Ali Baker Date: Tue, 14 Jan 2020 16:47:53 -0800 Subject: [PATCH 1/4] refactor(project_config): remove 'Launched' status check from isActive and change associated tests --- packages/optimizely-sdk/lib/core/project_config/index.js | 6 ++---- .../optimizely-sdk/lib/core/project_config/index.tests.js | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/optimizely-sdk/lib/core/project_config/index.js b/packages/optimizely-sdk/lib/core/project_config/index.js index a14d85238..0fc47dce5 100644 --- a/packages/optimizely-sdk/lib/core/project_config/index.js +++ b/packages/optimizely-sdk/lib/core/project_config/index.js @@ -19,7 +19,6 @@ var sprintf = require('@optimizely/js-sdk-utils').sprintf; var configValidator = require('../../utils/config_validator'); var projectConfigSchema = require('./project_config_schema'); -var EXPERIMENT_LAUNCHED_STATUS = 'Launched'; var EXPERIMENT_RUNNING_STATUS = 'Running'; var RESERVED_ATTRIBUTE_PREFIX = '$opt_'; var MODULE_NAME = 'PROJECT_CONFIG'; @@ -198,14 +197,13 @@ module.exports = { }, /** - * Returns whether experiment has a status of 'Running' or 'Launched' + * Returns whether experiment has a status of 'Running' * @param {Object} projectConfig Object representing project configuration * @param {string} experimentKey Experiment key for which status is to be compared with 'Running' * @return {Boolean} true if experiment status is set to 'Running', false otherwise */ isActive: function(projectConfig, experimentKey) { - return module.exports.getExperimentStatus(projectConfig, experimentKey) === EXPERIMENT_RUNNING_STATUS || - module.exports.getExperimentStatus(projectConfig, experimentKey) === EXPERIMENT_LAUNCHED_STATUS; + return module.exports.getExperimentStatus(projectConfig, experimentKey) === EXPERIMENT_RUNNING_STATUS }, /** 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 b30980225..9a9276639 100644 --- a/packages/optimizely-sdk/lib/core/project_config/index.tests.js +++ b/packages/optimizely-sdk/lib/core/project_config/index.tests.js @@ -305,13 +305,11 @@ describe('lib/core/project_config', function() { }, sprintf(ERROR_MESSAGES.INVALID_EXPERIMENT_KEY, 'PROJECT_CONFIG', 'invalidExperimentKey')); }); - it('should return true if experiment status is set to Running or Launch in isActive', function() { + it('should return true if experiment status is set to Running in isActive', function() { assert.isTrue(projectConfig.isActive(configObj, 'testExperiment')); - - assert.isTrue(projectConfig.isActive(configObj, 'testExperimentLaunched')); }); - it('should return true if experiment status is set to Running or Launch in isActive', function() { + it('should return false if experiment status is not set to Running in isActive', function() { assert.isFalse(projectConfig.isActive(configObj, 'testExperimentNotRunning')); }); From 8accb78a5f8d00d5f9a404981270d19d1412290f Mon Sep 17 00:00:00 2001 From: Ali Baker Date: Tue, 14 Jan 2020 17:08:23 -0800 Subject: [PATCH 2/4] refactor(optimizely): remove test that specifically depends on Launched status --- packages/optimizely-sdk/lib/optimizely/index.tests.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/packages/optimizely-sdk/lib/optimizely/index.tests.js b/packages/optimizely-sdk/lib/optimizely/index.tests.js index dd671d291..1f3a5406e 100644 --- a/packages/optimizely-sdk/lib/optimizely/index.tests.js +++ b/packages/optimizely-sdk/lib/optimizely/index.tests.js @@ -786,15 +786,6 @@ describe('lib/optimizely', function() { }); }); - it('returns the variation key but does not dispatch the event if user is in experiment and experiment is set to Launched', function() { - bucketStub.returns('144448'); - - var bucketedVariation = optlyInstance.activate('testExperimentLaunched', 'testUser'); - assert.strictEqual(bucketedVariation, 'controlLaunched'); - - sinon.assert.notCalled(eventDispatcher.dispatchEvent); - }); - it('should not activate when optimizely object is not a valid instance', function() { var instance = new Optimizely({ datafile: {}, From 401e2e9075e97f65ba8ffa9e1e825d95625a1836 Mon Sep 17 00:00:00 2001 From: Ali Baker Date: Tue, 14 Jan 2020 17:14:46 -0800 Subject: [PATCH 3/4] refactor(utils): change log message to more accurately reflect its usage as a not 'Running' check and remove reference to 'Launched' status --- packages/optimizely-sdk/lib/utils/enums/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/optimizely-sdk/lib/utils/enums/index.js b/packages/optimizely-sdk/lib/utils/enums/index.js index 28e9a7962..ddd025d89 100644 --- a/packages/optimizely-sdk/lib/utils/enums/index.js +++ b/packages/optimizely-sdk/lib/utils/enums/index.js @@ -92,7 +92,7 @@ exports.LOG_MESSAGES = { ROLLOUT_HAS_NO_EXPERIMENTS: '%s: Rollout of feature %s has no experiments', SAVED_VARIATION: '%s: Saved variation "%s" of experiment "%s" for user "%s".', SAVED_VARIATION_NOT_FOUND: '%s: User %s was previously bucketed into variation with ID %s for experiment %s, but no matching variation was found.', - SHOULD_NOT_DISPATCH_ACTIVATE: '%s: Experiment %s is in "Launched" state. Not activating user.', + SHOULD_NOT_DISPATCH_ACTIVATE: '%s: Experiment %s is not in "Running" state. Not activating user.', SKIPPING_JSON_VALIDATION: '%s: Skipping JSON schema validation.', TRACK_EVENT: '%s: Tracking event %s for user %s.', USER_ASSIGNED_TO_VARIATION_BUCKET: '%s: Assigned variation bucket %s to user %s.', From 296f644ff374568ed60b952b8fc8e1a36ee3ae8d Mon Sep 17 00:00:00 2001 From: Ali Baker Date: Tue, 14 Jan 2020 17:30:09 -0800 Subject: [PATCH 4/4] refactor(decision_service): remove reference to launched status in comments --- packages/optimizely-sdk/lib/core/decision_service/index.js | 2 +- packages/optimizely-sdk/lib/core/project_config/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/optimizely-sdk/lib/core/decision_service/index.js b/packages/optimizely-sdk/lib/core/decision_service/index.js index 3f5c7028f..321da3844 100644 --- a/packages/optimizely-sdk/lib/core/decision_service/index.js +++ b/packages/optimizely-sdk/lib/core/decision_service/index.js @@ -121,7 +121,7 @@ DecisionService.prototype.__resolveExperimentBucketMap = function(userId, attrib /** - * Checks whether the experiment is running or launched + * Checks whether the experiment is running * @param {Object} configObj The parsed project configuration object * @param {string} experimentKey Key of experiment being validated * @param {string} userId ID of user diff --git a/packages/optimizely-sdk/lib/core/project_config/index.js b/packages/optimizely-sdk/lib/core/project_config/index.js index 0fc47dce5..eeda8f1f9 100644 --- a/packages/optimizely-sdk/lib/core/project_config/index.js +++ b/packages/optimizely-sdk/lib/core/project_config/index.js @@ -203,7 +203,7 @@ module.exports = { * @return {Boolean} true if experiment status is set to 'Running', false otherwise */ isActive: function(projectConfig, experimentKey) { - return module.exports.getExperimentStatus(projectConfig, experimentKey) === EXPERIMENT_RUNNING_STATUS + return module.exports.getExperimentStatus(projectConfig, experimentKey) === EXPERIMENT_RUNNING_STATUS; }, /**