Skip to content

Commit

Permalink
test: corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
mikechu-optimizely committed Oct 18, 2024
1 parent 9c6e9bb commit 49f9584
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 36 deletions.
10 changes: 5 additions & 5 deletions OptimizelySDK.Tests/DecisionServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ public void TestGetVariationForFeatureExperimentGivenNonMutexGroupAndUserNotBuck

DecisionServiceMock.
Setup(ds => ds.GetVariation(multiVariateExp, OptimizelyUserContextMock.Object,
ProjectConfig, null)).
ProjectConfig, It.IsAny<OptimizelyDecideOption[]>(), It.IsAny<bool>())).
Returns<Variation>(null);
var featureFlag = ProjectConfig.GetFeatureFlagFromKey("multi_variate_feature");

Expand Down Expand Up @@ -736,7 +736,7 @@ public void TestGetVariationForFeatureExperimentGivenNonMutexGroupAndUserIsBucke
DecisionServiceMock.Setup(ds => ds.GetVariation(
ProjectConfig.GetExperimentFromKey("test_experiment_multivariate"),
OptimizelyUserContextMock.Object, ProjectConfig,
It.IsAny<OptimizelyDecideOption[]>())).
It.IsAny<OptimizelyDecideOption[]>(), It.IsAny<bool>())).
Returns(variation);

var featureFlag = ProjectConfig.GetFeatureFlagFromKey("multi_variate_feature");
Expand Down Expand Up @@ -771,7 +771,7 @@ public void TestGetVariationForFeatureExperimentGivenMutexGroupAndUserIsBucketed
DecisionServiceMock.
Setup(ds =>
ds.GetVariation(ProjectConfig.GetExperimentFromKey("group_experiment_1"),
OptimizelyUserContextMock.Object, ProjectConfig)).
OptimizelyUserContextMock.Object, ProjectConfig, It.IsAny<OptimizelyDecideOption[]>(), It.IsAny<bool>())).
Returns(variation);

var featureFlag = ProjectConfig.GetFeatureFlagFromKey("boolean_feature");
Expand All @@ -795,7 +795,7 @@ public void TestGetVariationForFeatureExperimentGivenMutexGroupAndUserNotBuckete
DecisionServiceMock.
Setup(ds => ds.GetVariation(It.IsAny<Experiment>(),
It.IsAny<OptimizelyUserContext>(), ProjectConfig,
It.IsAny<OptimizelyDecideOption[]>())).
It.IsAny<OptimizelyDecideOption[]>(), It.IsAny<bool>())).
Returns(Result<Variation>.NullResult(null));

var featureFlag = ProjectConfig.GetFeatureFlagFromKey("boolean_feature");
Expand Down Expand Up @@ -1311,7 +1311,7 @@ public void TestGetVariationForFeatureWhenTheUserIsBuckedtedInBothExperimentAndR

DecisionServiceMock.Setup(ds => ds.GetVariation(experiment,
OptimizelyUserContextMock.Object, ProjectConfig,
It.IsAny<OptimizelyDecideOption[]>())).
It.IsAny<OptimizelyDecideOption[]>(), It.IsAny<bool>())).
Returns(variation);
var actualDecision = DecisionServiceMock.Object.GetVariationForFeatureExperiment(
featureFlag, OptimizelyUserContextMock.Object, userAttributes, ProjectConfig,
Expand Down
65 changes: 38 additions & 27 deletions OptimizelySDK.Tests/OptimizelyTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2023, Optimizely
* Copyright 2017-2024, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -3395,8 +3395,9 @@ public void TestActivateListener(UserAttributes userAttributes)
mockUserContext.Setup(ouc => ouc.GetUserId()).Returns(TestUserId);

DecisionServiceMock.Setup(ds => ds.GetVariation(experiment,
It.IsAny<OptimizelyUserContext>(), It.IsAny<ProjectConfig>()))
.Returns(variation);
It.IsAny<OptimizelyUserContext>(), It.IsAny<ProjectConfig>(),
It.IsAny<OptimizelyDecideOption[]>(), It.IsAny<bool>())).
Returns(variation);
DecisionServiceMock.Setup(ds => ds.GetVariationForFeature(featureFlag,
It.IsAny<OptimizelyUserContext>(), It.IsAny<ProjectConfig>()))
.Returns(decision);
Expand Down Expand Up @@ -3509,9 +3510,10 @@ public void TestTrackListener(UserAttributes userAttributes, EventTags eventTags
ErrorHandlerMock.Object, LoggerMock.Object);
mockUserContext.Setup(ouc => ouc.GetUserId()).Returns(TestUserId);

DecisionServiceMock
.Setup(ds => ds.GetVariation(experiment, It.IsAny<OptimizelyUserContext>(), Config))
.Returns(variation);
DecisionServiceMock.Setup(ds => ds.GetVariation(experiment,
It.IsAny<OptimizelyUserContext>(), Config, It.IsAny<OptimizelyDecideOption[]>(),
It.IsAny<bool>())).
Returns(variation);

// Adding notification listeners.
var notificationType = NotificationCenter.NotificationType.Track;
Expand Down Expand Up @@ -3565,9 +3567,10 @@ public void TestActivateSendsDecisionNotificationWithActualVariationKey()
It.IsAny<string>(),
It.IsAny<UserAttributes>(), It.IsAny<Dictionary<string, object>>()));

DecisionServiceMock
.Setup(ds => ds.GetVariation(experiment, It.IsAny<OptimizelyUserContext>(), Config))
.Returns(variation);
DecisionServiceMock.Setup(ds => ds.GetVariation(experiment,
It.IsAny<OptimizelyUserContext>(), Config, It.IsAny<OptimizelyDecideOption[]>(),
It.IsAny<bool>())).
Returns(variation);

var optly = Helper.CreatePrivateOptimizely();
optly.SetFieldOrProperty("ProjectConfigManager", ConfigManager);
Expand Down Expand Up @@ -3622,9 +3625,10 @@ public void
It.IsAny<string>(),
It.IsAny<UserAttributes>(), It.IsAny<Dictionary<string, object>>()));

DecisionServiceMock
.Setup(ds => ds.GetVariation(experiment, It.IsAny<OptimizelyUserContext>(), Config))
.Returns(variation);
DecisionServiceMock.Setup(ds => ds.GetVariation(experiment,
It.IsAny<OptimizelyUserContext>(), Config, It.IsAny<OptimizelyDecideOption[]>(),
It.IsAny<bool>())).
Returns(variation);

var optly = Helper.CreatePrivateOptimizely();
optly.SetFieldOrProperty("ProjectConfigManager", ConfigManager);
Expand Down Expand Up @@ -3666,8 +3670,9 @@ public void TestActivateSendsDecisionNotificationWithNullVariationKey()

DecisionServiceMock.Setup(ds => ds.GetVariation(experiment,
It.IsAny<OptimizelyUserContext>(),
It.IsAny<ProjectConfig>(), null))
.Returns(Result<Variation>.NullResult(null));
It.IsAny<ProjectConfig>(), It.IsAny<OptimizelyDecideOption[]>(),
It.IsAny<bool>())).
Returns(Result<Variation>.NullResult(null));

optStronglyTyped.NotificationCenter.AddNotification(
NotificationCenter.NotificationType.Decision,
Expand Down Expand Up @@ -3727,9 +3732,10 @@ public void TestGetVariationSendsDecisionNotificationWithActualVariationKey()
ErrorHandlerMock.Object, LoggerMock.Object);
mockUserContext.Setup(ouc => ouc.GetUserId()).Returns(TestUserId);

DecisionServiceMock
.Setup(ds => ds.GetVariation(experiment, It.IsAny<OptimizelyUserContext>(), Config))
.Returns(variation);
DecisionServiceMock.Setup(ds => ds.GetVariation(experiment,
It.IsAny<OptimizelyUserContext>(), Config, It.IsAny<OptimizelyDecideOption[]>(),
It.IsAny<bool>())).
Returns(variation);

optStronglyTyped.NotificationCenter.AddNotification(
NotificationCenter.NotificationType.Decision,
Expand Down Expand Up @@ -3788,9 +3794,10 @@ public void
ErrorHandlerMock.Object, LoggerMock.Object);
mockUserContext.Setup(ouc => ouc.GetUserId()).Returns(TestUserId);

DecisionServiceMock
.Setup(ds => ds.GetVariation(experiment, It.IsAny<OptimizelyUserContext>(), Config))
.Returns(variation);
DecisionServiceMock.
Setup(ds => ds.GetVariation(experiment, It.IsAny<OptimizelyUserContext>(), Config
, It.IsAny<OptimizelyDecideOption[]>(), It.IsAny<bool>())).
Returns(variation);

optStronglyTyped.NotificationCenter.AddNotification(
NotificationCenter.NotificationType.Decision,
Expand Down Expand Up @@ -3828,8 +3835,9 @@ public void TestGetVariationSendsDecisionNotificationWithNullVariationKey()
It.IsAny<UserAttributes>(), It.IsAny<Dictionary<string, object>>()));

DecisionServiceMock.Setup(ds => ds.GetVariation(It.IsAny<Experiment>(),
It.IsAny<OptimizelyUserContext>(), It.IsAny<ProjectConfig>()))
.Returns(Result<Variation>.NullResult(null));
It.IsAny<OptimizelyUserContext>(), It.IsAny<ProjectConfig>()
, It.IsAny<OptimizelyDecideOption[]>(), It.IsAny<bool>())).
Returns(Result<Variation>.NullResult(null));
//DecisionServiceMock.Setup(ds => ds.GetVariation(experiment, TestUserId, Config, null)).Returns(Result<Variation>.NullResult(null));

optStronglyTyped.NotificationCenter.AddNotification(
Expand Down Expand Up @@ -3875,8 +3883,9 @@ public void
It.IsAny<UserAttributes>(), It.IsAny<Dictionary<string, object>>()));

DecisionServiceMock.Setup(ds => ds.GetVariation(experiment,
It.IsAny<OptimizelyUserContext>(), ConfigManager.GetConfig(), null))
.Returns(variation);
It.IsAny<OptimizelyUserContext>(), ConfigManager.GetConfig()
, It.IsAny<OptimizelyDecideOption[]>(), It.IsAny<bool>())).
Returns(variation);

var optly = Helper.CreatePrivateOptimizely();
var optStronglyTyped = optly.GetObject() as Optimizely;
Expand Down Expand Up @@ -3936,8 +3945,9 @@ public void
It.IsAny<UserAttributes>(), It.IsAny<Dictionary<string, object>>()));

DecisionServiceMock.Setup(ds =>
ds.GetVariation(experiment, It.IsAny<OptimizelyUserContext>(), Config, null))
.Returns(variation);
ds.GetVariation(experiment, It.IsAny<OptimizelyUserContext>(), Config
, It.IsAny<OptimizelyDecideOption[]>(), It.IsAny<bool>())).
Returns(variation);

var optly = Helper.CreatePrivateOptimizely();
var optStronglyTyped = optly.GetObject() as Optimizely;
Expand Down Expand Up @@ -5322,7 +5332,8 @@ public void TestGetAllFeatureVariablesReturnsNullScenarios()

LoggerMock.Verify(
log => log.Log(LogLevel.ERROR,
"Optimizely instance is not valid, failing getAllFeatureVariableValues call. type"),
"Optimizely instance is not valid, failing getAllFeatureVariableValues call. type")
,
Times.Once);
}

Expand Down
11 changes: 7 additions & 4 deletions OptimizelySDK/Optimizely.cs
Original file line number Diff line number Diff line change
Expand Up @@ -931,10 +931,13 @@ internal OptimizelyDecision Decide(OptimizelyUserContext user,
decisionReasons += flagDecisionResult.DecisionReasons;
decision = flagDecisionResult.ResultObject;
}

DecisionService.AddDecisionToUnitOfWork(userId, decision.Experiment?.Id,
new Decision(decision.Variation?.Id));


if (!options.Contains(OptimizelyDecideOption.IGNORE_USER_PROFILE_SERVICE))
{
DecisionService.AddDecisionToUnitOfWork(userId, decision.Experiment?.Id,
new Decision(decision.Variation?.Id));
}

var featureEnabled = false;

if (decision?.Variation != null)
Expand Down

0 comments on commit 49f9584

Please sign in to comment.