Skip to content

Commit

Permalink
fix: WIP tests & code under tests
Browse files Browse the repository at this point in the history
mikechu-optimizely committed Oct 17, 2024
1 parent 236728b commit d6258f1
Showing 3 changed files with 16 additions and 4 deletions.
10 changes: 9 additions & 1 deletion OptimizelySDK/Bucketing/DecisionService.cs
Original file line number Diff line number Diff line change
@@ -463,7 +463,15 @@ UserProfile userProfile

public void AddDecisionToUnitOfWork(string userId, string experimentId, Decision decision)
{
_decisionUnitOfWork.AddDecision(userId, experimentId, decision);
if (UserProfileService == null)
{
return;
}

if (!string.IsNullOrEmpty(experimentId))
{
_decisionUnitOfWork.AddDecision(userId, experimentId, decision);
}
}

/// <summary>
5 changes: 5 additions & 0 deletions OptimizelySDK/Bucketing/DecisionUnitOfWork.cs
Original file line number Diff line number Diff line change
@@ -25,6 +25,11 @@ public class DecisionUnitOfWork

public void AddDecision(string userId, string experimentId, Decision decision)
{
if (string.IsNullOrEmpty(userId) || string.IsNullOrEmpty(experimentId))
{
return;
}

if (!_decisions.ContainsKey(userId))
{
_decisions[userId] = new Dictionary<string, Decision>();
5 changes: 2 additions & 3 deletions OptimizelySDK/Optimizely.cs
Original file line number Diff line number Diff line change
@@ -926,10 +926,9 @@ internal OptimizelyDecision Decide(OptimizelyUserContext user,
decisionReasons += flagDecisionResult.DecisionReasons;
decision = flagDecisionResult.ResultObject;
}

// TODO: Fix when the flag is a rollout instead of an experiment

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

var featureEnabled = false;

0 comments on commit d6258f1

Please sign in to comment.