Skip to content

Feat: Adds Decide All, DecideForKeys and track event #251

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 53 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
01bad8f
Added OptimizelyUserContext and basic functionalities
mnoman09 Nov 5, 2020
35c5e76
Added DecisionTests
mnoman09 Nov 6, 2020
f79974c
Added classes of optimizelyDecision in net35 file
mnoman09 Nov 6, 2020
7531f3c
Updated decisionmessage class and added decisionMessage test
mnoman09 Nov 6, 2020
f006b08
Added OptimizelyDecisionTest
mnoman09 Nov 9, 2020
ac0c6a5
Added CreateUserContext in Optimizely
mnoman09 Nov 9, 2020
6c9ac4d
Added UserContext add reason logs
mnoman09 Nov 11, 2020
9e36946
Revert "Added UserContext add reason logs"
mnoman09 Nov 11, 2020
8c78330
Added UserContext add reason logs
mnoman09 Nov 11, 2020
ee465c3
Added TrackEvent, DecideForKeys and DecideAllFunction
mnoman09 Nov 12, 2020
591c770
Replaced list of reasons to array.
mnoman09 Nov 13, 2020
f644b24
Merge branch 'mnoman/user-context' into mnoman/decideapi
mnoman09 Nov 13, 2020
ad77477
Merge remote-tracking branch 'origin/master' into mnoman/user-context
mnoman09 Nov 13, 2020
bab871e
Merge branch 'mnoman/user-context' into mnoman/decideapi
mnoman09 Nov 13, 2020
2c0c3ec
Merge branch 'mnoman/decideapi' into mnoman/decideAllApi
mnoman09 Nov 13, 2020
c3db077
Bug fix
mnoman09 Nov 13, 2020
055bb93
Resolved comments of adding null check before reasons
mnoman09 Nov 13, 2020
5ce1419
removed underscores
mnoman09 Nov 13, 2020
1e388b7
Merge branch 'mnoman/user-context' into mnoman/decideapi
mnoman09 Nov 13, 2020
a7e684b
Merge branch 'mnoman/decideapi' into mnoman/decideAllApi
mnoman09 Nov 13, 2020
a424fef
Added Decide Options unit tests
mnoman09 Nov 16, 2020
7eeb588
Added track event tests and fixes defaultDecideOptions
mnoman09 Nov 16, 2020
8e1750e
Changed UserAttribute to Attributes
mnoman09 Nov 17, 2020
1163cde
Merge branch 'master' into mnoman/user-context
mnoman09 Nov 18, 2020
6330750
Merge branch 'mnoman/user-context' into mnoman/decideapi
mnoman09 Nov 18, 2020
9ec58d3
Merge branch 'mnoman/decideapi' into mnoman/decideAllApi
mnoman09 Nov 18, 2020
980abd0
Added DecisionNotificationType flag
mnoman09 Nov 18, 2020
14769f8
Added check of Key != null in decide
mnoman09 Nov 20, 2020
fafb14c
Added Additional unit tests of optimizelyUserContext
mnoman09 Nov 24, 2020
f9d3939
Merge branch 'mnoman/user-context' into mnoman/decideapi
mnoman09 Nov 24, 2020
671aa29
added notification type flag
mnoman09 Nov 24, 2020
108cc06
Merge branch 'mnoman/decideapi' into mnoman/decideAllApi
mnoman09 Nov 24, 2020
0628e68
Added additional test cases
mnoman09 Nov 25, 2020
a0753a6
Added mutex lock in setting attributes value
mnoman09 Nov 25, 2020
0e9faa1
replaced list from array of decideOptions
mnoman09 Nov 26, 2020
4bd0b3e
Merge branch 'mnoman/user-context' into mnoman/decideapi
mnoman09 Nov 26, 2020
9455e92
Merge branch 'mnoman/decideapi' into mnoman/decideAllApi
mnoman09 Nov 26, 2020
5d0028f
changed decide decideall and decide for keys from public to internal
mnoman09 Nov 26, 2020
320ddc4
Resolved failing scenario
mnoman09 Nov 27, 2020
451e001
Added unit test that byUPS will not call save in userprofile even once
mnoman09 Nov 30, 2020
54e9e74
Removed unnecessary methods from errorDecisionsReasons
mnoman09 Dec 2, 2020
6934f30
Merge branch 'mnoman/user-context' into mnoman/decideapi
mnoman09 Dec 2, 2020
b824b99
Added ignoreUps check first in decision service
mnoman09 Dec 2, 2020
cac22e4
Merge branch 'mnoman/decideapi' into mnoman/decideAllApi
mnoman09 Dec 2, 2020
7eb41c7
Converted a loop to lambda
mnoman09 Dec 2, 2020
eda2743
Nit Fix
mnoman09 Dec 7, 2020
74bd4a5
Merge branch 'mnoman/decideapi' into mnoman/decideAllApi
mnoman09 Dec 7, 2020
f97e302
Changed decide keys to array
mnoman09 Dec 7, 2020
869b655
Added additional test with count of Notfication
mnoman09 Dec 7, 2020
73cd357
Merge branch 'master' into mnoman/decideapi
mnoman09 Dec 8, 2020
fb2ebe4
Merge branch 'mnoman/decideapi' into mnoman/decideAllApi
mnoman09 Dec 8, 2020
fa90e13
replaced copiedOptions = copiedOptions.Concat(options).Concat(Default…
mnoman09 Dec 9, 2020
0f25fb2
Merge remote-tracking branch 'origin/master' into mnoman/decideAllApi
mnoman09 Dec 9, 2020
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
39 changes: 23 additions & 16 deletions OptimizelySDK.Tests/BucketerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using OptimizelySDK.Config;
using OptimizelySDK.Entity;
using OptimizelySDK.Logger;
using OptimizelySDK.OptimizelyDecisions;

namespace OptimizelySDK.Tests
{
Expand All @@ -27,6 +28,7 @@ public class BucketerTest
{
private Mock<ILogger> LoggerMock;
private ProjectConfig Config;
private IDecisionReasons DecisionReasons;
private const string TestUserId = "testUserId";
public string TestBucketingIdControl { get; } = "testBucketingIdControl!"; // generates bucketing number 3741
public string TestBucketingIdVariation { get; } = "123456789'"; // generates bucketing number 4567
Expand Down Expand Up @@ -59,6 +61,7 @@ public override string ToString()
public void Initialize()
{
LoggerMock = new Mock<ILogger>();
DecisionReasons = DefaultDecisionReasons.NewInstance();
Config = DatafileProjectConfig.Create(TestData.Datafile, LoggerMock.Object, new ErrorHandler.NoOpErrorHandler());
}

Expand Down Expand Up @@ -95,42 +98,41 @@ public void TestBucketValidExperimentNotInGroup()
{
TestBucketer bucketer = new TestBucketer(LoggerMock.Object);
bucketer.SetBucketValues(new[] { 3000, 7000, 9000 });

// control
Assert.AreEqual(new Variation { Id = "7722370027", Key = "control" },
bucketer.Bucket(Config, Config.GetExperimentFromKey("test_experiment"), TestBucketingIdControl, TestUserId));
bucketer.Bucket(Config, Config.GetExperimentFromKey("test_experiment"), TestBucketingIdControl, TestUserId, DecisionReasons));

LoggerMock.Verify(l => l.Log(It.IsAny<LogLevel>(), It.IsAny<string>()), Times.Exactly(2));
LoggerMock.Verify(l => l.Log(LogLevel.DEBUG, "Assigned bucket [3000] to user [testUserId] with bucketing ID [testBucketingIdControl!]."));
LoggerMock.Verify(l => l.Log(LogLevel.INFO, "User [testUserId] is in variation [control] of experiment [test_experiment]."));

// variation
Assert.AreEqual(new Variation { Id = "7721010009", Key = "variation" },
bucketer.Bucket(Config, Config.GetExperimentFromKey("test_experiment"), TestBucketingIdControl, TestUserId));
bucketer.Bucket(Config, Config.GetExperimentFromKey("test_experiment"), TestBucketingIdControl, TestUserId, DecisionReasons));

LoggerMock.Verify(l => l.Log(It.IsAny<LogLevel>(), It.IsAny<string>()), Times.Exactly(4));
LoggerMock.Verify(l => l.Log(LogLevel.DEBUG, "Assigned bucket [7000] to user [testUserId] with bucketing ID [testBucketingIdControl!]."));
LoggerMock.Verify(l => l.Log(LogLevel.INFO, "User [testUserId] is in variation [variation] of experiment [test_experiment]."));

// no variation
Assert.AreEqual(new Variation { },
bucketer.Bucket(Config, Config.GetExperimentFromKey("test_experiment"), TestBucketingIdControl, TestUserId));
bucketer.Bucket(Config, Config.GetExperimentFromKey("test_experiment"), TestBucketingIdControl, TestUserId, DecisionReasons));

LoggerMock.Verify(l => l.Log(It.IsAny<LogLevel>(), It.IsAny<string>()), Times.Exactly(6));
LoggerMock.Verify(l => l.Log(LogLevel.DEBUG, "Assigned bucket [9000] to user [testUserId] with bucketing ID [testBucketingIdControl!]."));
LoggerMock.Verify(l => l.Log(LogLevel.INFO, "User [testUserId] is in no variation."));
Assert.AreEqual(DecisionReasons.ToReport().Count, 0);
}

[Test]
public void TestBucketValidExperimentInGroup()
{
TestBucketer bucketer = new TestBucketer(LoggerMock.Object);

// group_experiment_1 (20% experiment)
// variation 1
bucketer.SetBucketValues(new[] { 1000, 4000 });
Assert.AreEqual(new Variation { Id = "7722260071", Key = "group_exp_1_var_1" },
bucketer.Bucket(Config, Config.GetExperimentFromKey("group_experiment_1"), TestBucketingIdControl, TestUserId));
bucketer.Bucket(Config, Config.GetExperimentFromKey("group_experiment_1"), TestBucketingIdControl, TestUserId, DecisionReasons));
LoggerMock.Verify(l => l.Log(LogLevel.DEBUG, "Assigned bucket [1000] to user [testUserId] with bucketing ID [testBucketingIdControl!]."));
LoggerMock.Verify(l => l.Log(LogLevel.INFO, "User [testUserId] is in experiment [group_experiment_1] of group [7722400015]."));
LoggerMock.Verify(l => l.Log(LogLevel.DEBUG, "Assigned bucket [4000] to user [testUserId] with bucketing ID [testBucketingIdControl!]."));
Expand All @@ -139,7 +141,7 @@ public void TestBucketValidExperimentInGroup()
// variation 2
bucketer.SetBucketValues(new[] { 1500, 7000 });
Assert.AreEqual(new Variation { Id = "7722360022", Key = "group_exp_1_var_2" },
bucketer.Bucket(Config, Config.GetExperimentFromKey("group_experiment_1"), TestBucketingIdControl, TestUserId));
bucketer.Bucket(Config, Config.GetExperimentFromKey("group_experiment_1"), TestBucketingIdControl, TestUserId, DecisionReasons));
LoggerMock.Verify(l => l.Log(LogLevel.DEBUG, "Assigned bucket [1500] to user [testUserId] with bucketing ID [testBucketingIdControl!]."));
LoggerMock.Verify(l => l.Log(LogLevel.INFO, "User [testUserId] is in experiment [group_experiment_1] of group [7722400015]."));
LoggerMock.Verify(l => l.Log(LogLevel.DEBUG, "Assigned bucket [7000] to user [testUserId] with bucketing ID [testBucketingIdControl!]."));
Expand All @@ -148,20 +150,21 @@ public void TestBucketValidExperimentInGroup()
// User not in experiment
bucketer.SetBucketValues(new[] { 5000, 7000 });
Assert.AreEqual(new Variation { },
bucketer.Bucket(Config, Config.GetExperimentFromKey("group_experiment_1"), TestBucketingIdControl, TestUserId));
bucketer.Bucket(Config, Config.GetExperimentFromKey("group_experiment_1"), TestBucketingIdControl, TestUserId, DecisionReasons));
LoggerMock.Verify(l => l.Log(LogLevel.DEBUG, "Assigned bucket [5000] to user [testUserId] with bucketing ID [testBucketingIdControl!]."));
LoggerMock.Verify(l => l.Log(LogLevel.INFO, "User [testUserId] is not in experiment [group_experiment_1] of group [7722400015]."));

LoggerMock.Verify(l => l.Log(It.IsAny<LogLevel>(), It.IsAny<string>()), Times.Exactly(10));
Assert.AreEqual(DecisionReasons.ToReport().Count, 0);
}

[Test]
public void TestBucketInvalidExperiment()
{
var bucketer = new Bucketer(LoggerMock.Object);

Assert.AreEqual(new Variation { },
bucketer.Bucket(Config, new Experiment(), TestBucketingIdControl, TestUserId));
bucketer.Bucket(Config, new Experiment(), TestBucketingIdControl, TestUserId, DecisionReasons));

LoggerMock.Verify(l => l.Log(It.IsAny<LogLevel>(), It.IsAny<string>()), Times.Never);
}
Expand All @@ -176,7 +179,8 @@ public void TestBucketWithBucketingId()

// make sure that the bucketing ID is used for the variation bucketing and not the user ID
Assert.AreEqual(expectedVariation,
bucketer.Bucket(Config, experiment, TestBucketingIdControl, TestUserIdBucketsToVariation));
bucketer.Bucket(Config, experiment, TestBucketingIdControl, TestUserIdBucketsToVariation, DecisionReasons));
Assert.AreEqual(DecisionReasons.ToReport().Count, 0);
}

// Test for invalid experiment keys, null variation should be returned
Expand All @@ -187,7 +191,8 @@ public void TestBucketVariationInvalidExperimentsWithBucketingId()
var expectedVariation = new Variation();

Assert.AreEqual(expectedVariation,
bucketer.Bucket(Config, Config.GetExperimentFromKey("invalid_experiment"), TestBucketingIdVariation, TestUserId));
bucketer.Bucket(Config, Config.GetExperimentFromKey("invalid_experiment"), TestBucketingIdVariation, TestUserId, DecisionReasons));
Assert.AreEqual(DecisionReasons.ToReport().Count, 0);
}

// Make sure that the bucketing ID is used to bucket the user into a group and not the user ID
Expand All @@ -200,7 +205,8 @@ public void TestBucketVariationGroupedExperimentsWithBucketingId()

Assert.AreEqual(expectedGroupVariation,
bucketer.Bucket(Config, Config.GetExperimentFromKey("group_experiment_2"),
TestBucketingIdGroupExp2Var2, TestUserIdBucketsToNoGroup));
TestBucketingIdGroupExp2Var2, TestUserIdBucketsToNoGroup, DecisionReasons));
Assert.AreEqual(DecisionReasons.ToReport().Count, 0);
}

// Make sure that user gets bucketed into the rollout rule.
Expand All @@ -213,7 +219,8 @@ public void TestBucketRolloutRule()
var expectedVariation = Config.GetVariationFromId(rolloutRule.Key, "177773");

Assert.True(TestData.CompareObjects(expectedVariation,
bucketer.Bucket(Config, rolloutRule, "testBucketingId", TestUserId)));
bucketer.Bucket(Config, rolloutRule, "testBucketingId", TestUserId, DecisionReasons)));
Assert.AreEqual(DecisionReasons.ToReport().Count, 0);
}
}
}
}
Loading