Skip to content

Commit cdf53de

Browse files
authored
fix(ForcedDecision): remove config-ready check from forced-decision apis (#288)
1 parent d359a0f commit cdf53de

File tree

3 files changed

+1
-72
lines changed

3 files changed

+1
-72
lines changed

OptimizelySDK.Tests/DecisionServiceTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ public void TestGetVariationForFeatureWhenTheUserIsNeitherBucketedIntoFeatureExp
951951
OptimizelyUserContextMock.Setup(ouc => ouc.GetUserId()).Returns(UserProfileId);
952952

953953
var actualDecision = DecisionServiceMock.Object.GetVariationForFeature(featureFlag, OptimizelyUserContextMock.Object, ProjectConfig);
954-
Assert.IsNull(actualDecision.ResultObject);
954+
Assert.IsNull(actualDecision.ResultObject.Variation);
955955

956956
LoggerMock.Verify(l => l.Log(LogLevel.INFO, "The user \"userProfileId\" is not bucketed into a rollout for feature flag \"string_single_variable_feature\"."));
957957
}

OptimizelySDK.Tests/OptimizelyUserContextTest.cs

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -224,21 +224,6 @@ public void TestGetForcedDecisionReturnsNullIfInvalidConfig()
224224
Assert.IsNull(result);
225225
}
226226

227-
[Test]
228-
public void TestSetForcedDecisionReturnsFalseForNullConfig()
229-
{
230-
var optly = new Optimizely(new FallbackProjectConfigManager(null), logger: LoggerMock.Object);
231-
232-
var user = optly.CreateUserContext(UserID);
233-
234-
var context = new OptimizelyDecisionContext("flag", null);
235-
var decision = new OptimizelyForcedDecision("variationKey");
236-
var result = user.SetForcedDecision(context, decision);
237-
238-
Assert.IsFalse(result);
239-
LoggerMock.Verify(log => log.Log(LogLevel.ERROR, "Optimizely SDK not configured properly yet."), Times.Once);
240-
}
241-
242227
[Test]
243228
public void TestGetForcedDecisionReturnsNullWithNullFlagKey()
244229
{
@@ -341,22 +326,6 @@ public void TestRemoveForcedDecisionRemovesDecision()
341326
Assert.AreEqual(null, result);
342327
}
343328

344-
[Test]
345-
public void TestRemoveForcedDecisionReturnsFalseForNullConfig()
346-
{
347-
var optly = new Optimizely(new FallbackProjectConfigManager(null));
348-
349-
var user = optly.CreateUserContext(UserID);
350-
351-
var context = new OptimizelyDecisionContext("flagKey", null);
352-
var decision = new OptimizelyForcedDecision("variationKey");
353-
var setResult = user.SetForcedDecision(context, decision);
354-
355-
var result = user.RemoveForcedDecision(context);
356-
357-
Assert.AreEqual(false, result);
358-
}
359-
360329
[Test]
361330
public void TestRemoveAllForcedDecisionsRemovesDecisions()
362331
{
@@ -386,22 +355,6 @@ public void TestRemoveAllForcedDecisionsRemovesDecisions()
386355
Assert.AreEqual(null, result3);
387356
}
388357

389-
[Test]
390-
public void TestRemoveAllForcedDecisionsReturnsFalseForNullConfig()
391-
{
392-
var optly = new Optimizely(new FallbackProjectConfigManager(null));
393-
394-
var user = optly.CreateUserContext(UserID);
395-
396-
var context = new OptimizelyDecisionContext("flagKey");
397-
var decision = new OptimizelyForcedDecision("variation");
398-
user.SetForcedDecision(context, decision);
399-
400-
var result = user.RemoveAllForcedDecisions();
401-
402-
Assert.AreEqual(false, result);
403-
}
404-
405358
[Test]
406359
public void DecideInvalidFlagKey()
407360
{

OptimizelySDK/OptimizelyUserContext.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,6 @@ public virtual void TrackEvent(string eventName,
232232
/// <returns></returns>
233233
public bool SetForcedDecision(OptimizelyDecisionContext context, OptimizelyForcedDecision decision)
234234
{
235-
if (!Optimizely.IsValid)
236-
{
237-
Logger.Log(LogLevel.ERROR, DecisionMessage.SDK_NOT_READY);
238-
return false;
239-
}
240-
241235
lock (mutex)
242236
{
243237
ForcedDecisionsStore[context] = decision;
@@ -253,12 +247,6 @@ public bool SetForcedDecision(OptimizelyDecisionContext context, OptimizelyForce
253247
/// <returns>The variation key for a forced decision</returns>
254248
public OptimizelyForcedDecision GetForcedDecision(OptimizelyDecisionContext context)
255249
{
256-
if (!Optimizely.IsValid)
257-
{
258-
Logger.Log(LogLevel.ERROR, DecisionMessage.SDK_NOT_READY);
259-
return null;
260-
}
261-
262250
if (context == null || context.FlagKey == null)
263251
{
264252
Logger.Log(LogLevel.WARN, "flagKey cannot be null");
@@ -291,12 +279,6 @@ public bool RemoveForcedDecision(OptimizelyDecisionContext context)
291279
Logger.Log(LogLevel.WARN, "FlagKey cannot be null");
292280
return false;
293281
}
294-
295-
if (!Optimizely.IsValid)
296-
{
297-
Logger.Log(LogLevel.ERROR, DecisionMessage.SDK_NOT_READY);
298-
return false;
299-
}
300282

301283
lock (mutex)
302284
{
@@ -310,12 +292,6 @@ public bool RemoveForcedDecision(OptimizelyDecisionContext context)
310292
/// <returns>Whether the clear was successful.</returns>
311293
public bool RemoveAllForcedDecisions()
312294
{
313-
if (!Optimizely.IsValid)
314-
{
315-
Logger.Log(LogLevel.ERROR, DecisionMessage.SDK_NOT_READY);
316-
return false;
317-
}
318-
319295
lock (mutex)
320296
{
321297
ForcedDecisionsStore.RemoveAll();

0 commit comments

Comments
 (0)