8000 remove config-ready check from forced-decision apis (#727) · shaharyar123/javascript-sdk@a64f808 · GitHub
[go: up one dir, main page]

Skip to content

Commit a64f808

Browse files
authored
remove config-ready check from forced-decision apis (optimizely#727)
1 parent 9e5e51c commit a64f808

File tree

2 files changed

+15
-38
lines changed

2 files changed

+15
-38
lines changed

packages/optimizely-sdk/lib/optimizely_user_context/index.tests.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************
2-
* Copyright 2020, Optimizely, Inc. and contributors *
2+
* Copyright 2020-2021, Optimizely, Inc. and contributors *
33
* *
44
* Licensed under the Apache License, Version 2.0 (the "License"); *
55
* you may not use this file except in compliance with the License. *
@@ -26,7 +26,7 @@ import { createNotificationCenter } from '../core/notification_center';
2626
import Optimizely from '../optimizely';
2727
import errorHandler from '../plugins/error_handler';
2828
import eventDispatcher from '../plugins/event_dispatcher/index.node';
29-
import { CONTROL_ATTRIBUTES, DECISION_MESSAGES, LOG_LEVEL, LOG_MESSAGES } from '../utils/enums';
29+
import { CONTROL_ATTRIBUTES, LOG_LEVEL, LOG_MESSAGES } from '../utils/enums';
3030
import testData from '../tests/test_data';
3131
import { OptimizelyDecideOption } from '../shared_types';
3232

@@ -314,7 +314,7 @@ describe('lib/optimizely_user_context', function() {
314314
afterEach(function() {
315315
logging.resetLogger();
316316
});
317-
it('should return false when client is not ready', function() {
317+
it('should return true when client is not ready', function() {
318318
fakeOptimizely = {
319319
isValidInstance: sinon.stub().returns(false)
320320
};
@@ -323,9 +323,8 @@ describe('lib/optimizely_user_context', function() {
323323
userId,
324324
});
325325
var result = user.setForcedDecision({ flagKey: 'feature_1' }, '3324490562');
326-
assert.strictEqual(result, false);
327-
sinon.assert.calledOnce(stubLogHandler.log);
328-
assert.strictEqual(stubLogHandler.log.args[0][1], DECISION_MESSAGES.SDK_NOT_READY);
326+
assert.strictEqual(result, true);
327+
sinon.assert.notCalled(stubLogHandler.log);
329328
});
330329

331330
it('should return true when provided empty string flagKey', function() {
@@ -848,18 +847,17 @@ describe('lib/optimizely_user_context', function() {
848847
logging.resetLogger();
849848
});
850849

851-
it('should return false when client is not ready', function() {
850+
it('should return true when client is not ready and the forced decision has been removed successfully', function() {
852851
fakeOptimizely = {
853852
isValidInstance: sinon.stub().returns(false)
854853
};
855854
var user = new OptimizelyUserContext({
856855
optimizely: fakeOptimizely,
857-
userId,
856+
userId: 'user123',
858857
});
859-
var result = user.removeForcedDecision('feature_1');
860-
assert.strictEqual(result, false);
861-
sinon.assert.calledOnce(stubLogHandler.log);
862-
assert.strictEqual(stubLogHandler.log.args[0][1], DECISION_MESSAGES.SDK_NOT_READY);
858+
user.setForcedDecision({ flagKey: 'feature_1' }, '3324490562');
859+
var result = user.removeForcedDecision({ flagKey: 'feature_1' });
860+
assert.strictEqual(result, true);
863861
});
864862

865863
it('should return true when the forced decision has been removed successfully and false otherwise', function() {
@@ -923,7 +921,7 @@ describe('lib/optimizely_user_context', function() {
923921
logging.resetLogger();
924922
});
925923

926-
it('should return false when client is not ready', function() {
924+
it('should return true when client is not ready', function() {
927925
fakeOptimizely = {
928926
isValidInstance: sinon.stub().returns(false)
929927
};
@@ -932,9 +930,8 @@ describe('lib/optimizely_user_context', function() {
932930
userId,
933931
});
934932
var result = user.removeAllForcedDecisions();
935-
assert.strictEqual(result, false);
936-
sinon.assert.calledOnce(stubLogHandler.log);
937-
assert.strictEqual(stubLogHandler.log.args[0][1], DECISION_MESSAGES.SDK_NOT_READY);
933+
assert.strictEqual(result, true);
934+
sinon.assert.notCalled(stubLogHandler.log);
938935
});
939936

940937
it('should return true when all forced decisions have been removed successfully', function() {

packages/optimizely-sdk/lib/optimizely_user_context/index.ts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************
2-
* Copyright 2020, Optimizely, Inc. and contributors *
2+
* Copyright 2020-2021, Optimizely, Inc. and contributors *
33
* *
44
* Licensed under the Apache License, Version 2.0 (the "License"); *
55
* you may not use this file except in compliance with the License. *
@@ -26,7 +26,7 @@ import {
2626
UserAttributes,
2727
Variation
2828
} from '../../lib/shared_types';
29-
import { DECISION_MESSAGES, LOG_MESSAGES, CONTROL_ATTRIBUTES } from '../utils/enums';
29+
import { LOG_MESSAGES, CONTROL_ATTRIBUTES } from '../utils/enums';
3030

3131
const logger = getLogger();
3232

@@ -131,11 +131,6 @@ export default class OptimizelyUserContext {
131131
* @return {boolean} true if the forced decision has been set successfully.
132132
*/
133133
setForcedDecision(context: OptimizelyDecisionContext, decision: OptimizelyForcedDecision): boolean {
134-
if (!this.optimizely.isValidInstance()) {
135-
logger.error(DECISION_MESSAGES.SDK_NOT_READY);
136-
return false;
137-
}
138-
139134
const flagKey = context.flagKey;
140135

141136
const ruleKey = context.ruleKey ?? CONTROL_ATTRIBUTES.FORCED_DECISION_NULL_RULE_KEY;
@@ -156,11 +151,6 @@ export default class OptimizelyUserContext {
156151
* @return {OptimizelyForcedDecision|null} OptimizelyForcedDecision for specified context if exists or null.
157152
*/
158153
getForcedDecision(context: OptimizelyDecisionContext): OptimizelyForcedDecision | null {
159-
if (!this.optimizely.isValidInstance()) {
160-
logger.error(DECISION_MESSAGES.SDK_NOT_READY);
161-
return null;
162-
}
163-
164154
return this.findForcedDecision(context);
165155
}
166156

@@ -170,11 +160,6 @@ export default class OptimizelyUserContext {
170160
* @return {boolean} true if the forced decision has been removed successfully
171161
*/
172162
removeForcedDecision(context: OptimizelyDecisionContext): boolean {
173-
if (!this.optimizely.isValidInstance()) {
174-
logger.error(DECISION_MESSAGES.SDK_NOT_READY);
175-
return false;
176-
}
177-
178163
const ruleKey = context.ruleKey ?? CONTROL_ATTRIBUTES.FORCED_DECISION_NULL_RULE_KEY;
179164
const flagKey = context.flagKey;
180165

@@ -199,11 +184,6 @@ export default class OptimizelyUserContext {
199184
* @return {boolean} true if the forced decision has been removed successfully
200185
*/
201186
removeAllForcedDecisions(): boolean {
202-
if (!this.optimizely.isValidInstance()) {
203-
logger.error(DECISION_MESSAGES.SDK_NOT_READY);
204-
return false;
205-
206-
}
207187
this.forcedDecisionsMap = {};
208188
return true;
209189
}

0 commit comments

Comments
 (0)
0