Skip to content

fix(ForcedDecision): remove config-ready check from forced-decision apis #288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion OptimizelySDK.Tests/DecisionServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ public void TestGetVariationForFeatureWhenTheUserIsNeitherBucketedIntoFeatureExp
OptimizelyUserContextMock.Setup(ouc => ouc.GetUserId()).Returns(UserProfileId);

var actualDecision = DecisionServiceMock.Object.GetVariationForFeature(featureFlag, OptimizelyUserContextMock.Object, ProjectConfig);
Assert.IsNull(actualDecision.ResultObject);
Assert.IsNull(actualDecision.ResultObject.Variation);

LoggerMock.Verify(l => l.Log(LogLevel.INFO, "The user \"userProfileId\" is not bucketed into a rollout for feature flag \"string_single_variable_feature\"."));
}
Expand Down
47 changes: 0 additions & 47 deletions OptimizelySDK.Tests/OptimizelyUserContextTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,21 +224,6 @@ public void TestGetForcedDecisionReturnsNullIfInvalidConfig()
Assert.IsNull(result);
}

[Test]
public void TestSetForcedDecisionReturnsFalseForNullConfig()
{
var optly = new Optimizely(new FallbackProjectConfigManager(null), logger: LoggerMock.Object);

var user = optly.CreateUserContext(UserID);

var context = new OptimizelyDecisionContext("flag", null);
var decision = new OptimizelyForcedDecision("variationKey");
var result = user.SetForcedDecision(context, decision);

Assert.IsFalse(result);
LoggerMock.Verify(log => log.Log(LogLevel.ERROR, "Optimizely SDK not configured properly yet."), Times.Once);
}

[Test]
public void TestGetForcedDecisionReturnsNullWithNullFlagKey()
{
Expand Down Expand Up @@ -341,22 +326,6 @@ public void TestRemoveForcedDecisionRemovesDecision()
Assert.AreEqual(null, result);
}

[Test]
public void TestRemoveForcedDecisionReturnsFalseForNullConfig()
{
var optly = new Optimizely(new FallbackProjectConfigManager(null));

var user = optly.CreateUserContext(UserID);

var context = new OptimizelyDecisionContext("flagKey", null);
var decision = new OptimizelyForcedDecision("variationKey");
var setResult = user.SetForcedDecision(context, decision);

var result = user.RemoveForcedDecision(context);

Assert.AreEqual(false, result);
}

[Test]
public void TestRemoveAllForcedDecisionsRemovesDecisions()
{
Expand Down Expand Up @@ -386,22 +355,6 @@ public void TestRemoveAllForcedDecisionsRemovesDecisions()
Assert.AreEqual(null, result3);
}

[Test]
public void TestRemoveAllForcedDecisionsReturnsFalseForNullConfig()
{
var optly = new Optimizely(new FallbackProjectConfigManager(null));

var user = optly.CreateUserContext(UserID);

var context = new OptimizelyDecisionContext("flagKey");
var decision = new OptimizelyForcedDecision("variation");
user.SetForcedDecision(context, decision);

var result = user.RemoveAllForcedDecisions();

Assert.AreEqual(false, result);
}

[Test]
public void DecideInvalidFlagKey()
{
Expand Down
24 changes: 0 additions & 24 deletions OptimizelySDK/OptimizelyUserContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,6 @@ public virtual void TrackEvent(string eventName,
/// <returns></returns>
public bool SetForcedDecision(OptimizelyDecisionContext context, OptimizelyForcedDecision decision)
{
if (!Optimizely.IsValid)
{
Logger.Log(LogLevel.ERROR, DecisionMessage.SDK_NOT_READY);
return false;
}

lock (mutex)
{
ForcedDecisionsStore[context] = decision;
Expand All @@ -253,12 +247,6 @@ public bool SetForcedDecision(OptimizelyDecisionContext context, OptimizelyForce
/// <returns>The variation key for a forced decision</returns>
public OptimizelyForcedDecision GetForcedDecision(OptimizelyDecisionContext context)
{
if (!Optimizely.IsValid)
{
Logger.Log(LogLevel.ERROR, DecisionMessage.SDK_NOT_READY);
return null;
}

if (context == null || context.FlagKey == null)
{
Logger.Log(LogLevel.WARN, "flagKey cannot be null");
Expand Down Expand Up @@ -291,12 +279,6 @@ public bool RemoveForcedDecision(OptimizelyDecisionContext context)
Logger.Log(LogLevel.WARN, "FlagKey cannot be null");
return false;
}

if (!Optimizely.IsValid)
{
Logger.Log(LogLevel.ERROR, DecisionMessage.SDK_NOT_READY);
return false;
}

lock (mutex)
{
Expand All @@ -310,12 +292,6 @@ public bool RemoveForcedDecision(OptimizelyDecisionContext context)
/// <returns>Whether the clear was successful.</returns>
public bool RemoveAllForcedDecisions()
{
if (!Optimizely.IsValid)
{
Logger.Log(LogLevel.ERROR, DecisionMessage.SDK_NOT_READY);
return false;
}

lock (mutex)
{
ForcedDecisionsStore.RemoveAll();
Expand Down