Skip to content
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

feat(ForcedDecisions): add forced-decisions APIs to OptimizelyUserContext #285

Merged
merged 132 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
e9f3ad3
Updated with new asserts. Created function to make map.
MiracleManS Sep 24, 2021
482628c
Updated assertions, changed a few tests
dustin-sier Sep 24, 2021
97acb39
updated decision service tests to be easier to discover issues.
dustin-sier Sep 24, 2021
c097e89
Test update
dustin-sier Sep 26, 2021
d23fcd0
Updated Usercontext tests
dustin-sier Oct 5, 2021
3abb3e5
Corrected a few missing tests/functionality
dustin-sier Oct 5, 2021
dd50814
Added more functionality
dustin-sier Oct 5, 2021
973f24d
Added remove all tests
dustin-sier Oct 5, 2021
4747186
space removed
dustin-sier Oct 5, 2021
3b3070c
cleaned up test/fixed test
dustin-sier Oct 8, 2021
68d918e
Added additional assertions to help with config test
dustin-sier Oct 8, 2021
30a808b
Fixed error
dustin-sier Oct 8, 2021
14a7288
Additional asserts
dustin-sier Oct 8, 2021
8c289b6
finished optimizely config assertions
dustin-sier Oct 8, 2021
6917f4d
Updating decision service
dustin-sier Oct 8, 2021
9723d7a
changed tests to use user context correctly
dustin-sier Oct 8, 2021
86a099b
spacing issues
dustin-sier Oct 8, 2021
d5583d7
Additional changes to try and have a working ctor
dustin-sier Oct 8, 2021
b7b8fb7
Fixes for test issues
dustin-sier Oct 11, 2021
a46516e
Updated comments and removed unused function
dustin-sier Oct 11, 2021
b62c547
Renamed arguments
dustin-sier Oct 13, 2021
7df6dd0
Additional updates
dustin-sier Oct 13, 2021
d1e8e68
Removed unnecessary config info
dustin-sier Oct 14, 2021
965c6bf
removed commented out code
dustin-sier Oct 15, 2021
63e86b7
added new lines to end of file
dustin-sier Oct 15, 2021
44229f0
updates from feedback
dustin-sier Oct 17, 2021
99c1769
Updates for tests, still failing/WIP
dustin-sier Oct 17, 2021
77626e0
Updated test for new way of handling flagmap
dustin-sier Oct 17, 2021
5287e54
Added null check and added test, removed unnecessary check for null i…
dustin-sier Oct 18, 2021
147773e
Updated comments
dustin-sier Oct 18, 2021
d418ea2
Changed to warn, since its not technically an error
dustin-sier Oct 18, 2021
13ca784
Refactored to be clearer where the issues can crop up
dustin-sier Oct 18, 2021
aefdf34
Another null check.
dustin-sier Oct 18, 2021
58d40bf
Added tests for unused publics
dustin-sier Oct 18, 2021
484dc21
Updated optimizely to correctly use the right object
dustin-sier Oct 18, 2021
7d420c4
Added copyright
dustin-sier Oct 18, 2021
e89f4a0
Updated tests, removed unnecessary call
dustin-sier Oct 19, 2021
ac5fd97
removed redundant calls
dustin-sier Oct 21, 2021
7570f48
const update
dustin-sier Oct 21, 2021
a01050b
Changed to IsValid for areas that make sense.
dustin-sier Oct 21, 2021
9efc42a
More IsValid changes
dustin-sier Oct 21, 2021
9da8ee5
Unintended up date.
dustin-sier Oct 21, 2021
4783824
Additional changes for str.format
dustin-sier Oct 21, 2021
8fa3198
Removed second collection for no rule key
dustin-sier Oct 21, 2021
5eb9922
WIP replacement for having two collections
dustin-sier Oct 21, 2021
0381512
Removed redundant assignment
dustin-sier Oct 21, 2021
874157e
Updated with single collection
dustin-sier Oct 21, 2021
f3ec5fb
Prepend with Test to new test method names
dustin-sier Oct 22, 2021
a139aa9
Added documentation
dustin-sier Oct 22, 2021
ba19e30
added lock to set/get
dustin-sier Oct 25, 2021
9e4409d
added to copy
dustin-sier Oct 25, 2021
044ad4a
rename failure
dustin-sier Oct 25, 2021
a073b79
update to pass unit tests correctly
dustin-sier Oct 25, 2021
a401aa9
updated tests
dustin-sier Oct 25, 2021
1106c44
refactored a bit to start
dustin-sier Oct 27, 2021
692ee26
added copyright language
dustin-sier Oct 27, 2021
cbbe452
changed error messages to be consistent
dustin-sier Nov 2, 2021
19eb3da
Updated additional project files
dustin-sier Nov 2, 2021
e72faee
Added checks for GetDecisionKey in tests
dustin-sier Nov 3, 2021
97b52a9
Added test for additional logging info
dustin-sier Nov 3, 2021
7b76612
Added additional config check
dustin-sier Nov 3, 2021
5288bb1
Removed unnecessary code
dustin-sier Nov 3, 2021
4323773
Fix for null experiment in decide all
dustin-sier Nov 3, 2021
86f8ea5
fix rule key being non-null
dustin-sier Nov 3, 2021
8240f6e
Corrected copying hte files instead of referencing them in the proj.
dustin-sier Nov 3, 2021
82a8d93
A few changes to help with deciding
dustin-sier Nov 4, 2021
87a1fc3
Corrected incorrect nulls
dustin-sier Nov 4, 2021
af39695
another update. Missed variation vs flag
dustin-sier Nov 4, 2021
2500dd7
additional fsc things
dustin-sier Nov 4, 2021
8b32b39
Added additional property
dustinsier Nov 4, 2021
b209680
Removed file
dustinsier Nov 4, 2021
758f5d0
Fixed project issues
dustinsier Nov 4, 2021
01a90ca
Updated to account for correct null rulekey
dustinsier Nov 4, 2021
7ea219e
Update for handling null rule key correctly
dustinsier Nov 4, 2021
9e17cd8
Updated message
dustinsier Nov 4, 2021
03002e2
Updated message again
dustinsier Nov 4, 2021
f4e348b
Fixed not checking for _just_ null on flagkey because empty is fine.
dustin-sier Nov 5, 2021
a061f72
fixed refactor after changes to forced decision
dustin-sier Nov 5, 2021
4427c9f
fixed unit tests
dustin-sier Nov 5, 2021
0838c14
merge
dustin-sier Nov 5, 2021
6793b0b
additonal cleanup after refactor
dustin-sier Nov 5, 2021
0211a2d
Updates to try and clean this up to handle nulls correctly across the…
dustin-sier Nov 5, 2021
5ff593e
Removed unnecessary tests
dustin-sier Nov 5, 2021
8ef2a93
Removed redundant test
dustin-sier Nov 5, 2021
85ca51d
Changed to return nullresult iinstead of null, like other places
dustin-sier Nov 5, 2021
5edcc18
updated test
dustin-sier Nov 5, 2021
a18f774
removed unneded list
dustin-sier Nov 5, 2021
c9db119
check for null on eventbuilder
dustin-sier Nov 5, 2021
c9acbdb
Removed unnecessary piece of test
dustin-sier Nov 8, 2021
964bba5
Added assertion to help with local FSC testing. Fixed logic in decisi…
dustin-sier Nov 8, 2021
d78a22b
Fixed content of message
dustin-sier Nov 8, 2021
3bd0991
Removed conditional toReport
dustin-sier Nov 8, 2021
b685bbd
removed local fsc test help
dustin-sier Nov 8, 2021
87fe232
Added reasons being returned
dustin-sier Nov 8, 2021
059fafd
Added a "true" for now
dustin-sier Nov 8, 2021
80abfa3
Added period to match string
dustin-sier Nov 8, 2021
9c87d71
cleaned up decision key
dustin-sier Nov 8, 2021
f0f8ee8
Updated message and tests for forced decision via experiment
dustin-sier Nov 8, 2021
9afc59a
Fixed key comparison test
dustin-sier Nov 8, 2021
e4c190c
Added missing chunk from decision service
dustin-sier Nov 10, 2021
07b69f2
decision service cleanup and tests
dustin-sier Nov 10, 2021
9e427fa
cleanup
dustin-sier Nov 10, 2021
1a3aab3
Added fixed of forced decisions
mnoman09 Nov 12, 2021
3bd0bb0
fixed decision service
mnoman09 Nov 12, 2021
ba225f9
test fixed
mnoman09 Nov 12, 2021
6f563bb
Fixed Group experiments were not added in experiment id list
mnoman09 Nov 16, 2021
c7312ec
updated git ignore, included additiona assertions
dustin-sier Nov 19, 2021
0db66fd
rename variationKey to include _
dustin-sier Nov 19, 2021
8bce727
Removed partial that...shouldn't have been in there
dustin-sier Nov 19, 2021
69a2f51
removed unnecessary usings
dustin-sier Nov 19, 2021
10eaf22
Renamed file
dustin-sier Nov 23, 2021
f608a70
changed to string.empty
dustin-sier Nov 23, 2021
d5c621b
Update to remove null error
dustin-sier Nov 29, 2021
5511a91
change to just experiement?.layerid
dustin-sier Nov 29, 2021
375d748
changed to experiment?.id
dustin-sier Nov 29, 2021
5be1a05
additional change
dustin-sier Nov 29, 2021
48b15ef
rename
dustin-sier Nov 29, 2021
4bca717
changedto string.empty
dustin-sier Nov 29, 2021
0b669eb
Updated to handle null
dustin-sier Nov 29, 2021
6478ed6
copyright fix
dustin-sier Nov 29, 2021
d359a0f
Refact: Refactored Forced decision (#287)
mnoman09 Dec 2, 2021
cdf53de
fix(ForcedDecision): remove config-ready check from forced-decision a…
mnoman09 Dec 3, 2021
b6170cd
some issues fixed.
msohailhussain Dec 5, 2021
0d46ef7
Fixed null experiment check
mnoman09 Dec 6, 2021
de95a2c
Null exception fixed
mnoman09 Dec 6, 2021
0063e26
Cleanup from pr comments
dustin-sier Dec 7, 2021
2fc7a47
merge
dustin-sier Dec 7, 2021
85b00ff
added reason
dustin-sier Dec 7, 2021
0dccc30
added elvis operator
dustin-sier Dec 7, 2021
a829f60
cleaned up ternary
dustin-sier Dec 7, 2021
e43898f
fixed eventValue typo
mnoman09 Dec 7, 2021
0ac3dbe
trying to force a build
dustin-sier Dec 7, 2021
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
603 changes: 603 additions & 0 deletions OptimizelySDK.Tests/Assertions.cs

Large diffs are not rendered by default.

158 changes: 103 additions & 55 deletions OptimizelySDK.Tests/DecisionServiceTest.cs

Large diffs are not rendered by default.

184 changes: 165 additions & 19 deletions OptimizelySDK.Tests/OptimizelyConfigTests/OptimizelyConfigTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright 2020-2021, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,23 +14,22 @@
* limitations under the License.
*/

using System;
using Moq;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
using OptimizelySDK.Config;
using OptimizelySDK.Entity;
using OptimizelySDK.Logger;
using OptimizelySDK.OptlyConfig;
using System.Collections.Generic;
using System.Threading;
using OptimizelySDK.Tests.UtilsTests;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;

namespace OptimizelySDK.Tests.OptimizelyConfigTests
{
[TestFixture]
public class OptimizelyConfigTest
{

private Mock<ILogger> LoggerMock;

[SetUp]
Expand All @@ -42,7 +41,7 @@ public void Setup()

#region Test OptimizelyConfigService

static Type[] ParameterTypes = {
private static Type[] ParameterTypes = {
typeof(ProjectConfig),
};

Expand Down Expand Up @@ -76,10 +75,9 @@ public void TestGetOptimizelyConfigServiceSerializedAudiences()
new List<object>() { "not", new JArray() { "and", "3468206642", "3988293898" } },
new List<object>() { },
new List<object>() { "or", "3468206642", "999999999" },

};

var expectedAudienceOutputs = new List<string>
var expectedAudienceOutputs = new List<string>
{
"\"exactString\" OR \"substringString\"",
"\"exactString\" OR \"substringString\" OR \"exactNumber\"",
Expand Down Expand Up @@ -147,7 +145,6 @@ public void TestGetOptimizelyConfigWithDuplicateExperimentKeys()
var experimentMapFlag2 = optimizelyConfig.FeaturesMap["flag2"].ExperimentsMap; // 9300000007573
Assert.AreEqual(experimentMapFlag1["targeted_delivery"].Id, "9300000007569");
Assert.AreEqual(experimentMapFlag2["targeted_delivery"].Id, "9300000007573");

}

[Test]
Expand All @@ -158,7 +155,7 @@ public void TestGetOptimizelyConfigWithDuplicateRuleKeys()
var optimizelyConfig = optimizelyConfigService.GetOptimizelyConfig();
Assert.AreEqual(optimizelyConfig.ExperimentsMap.Count, 0);

var rolloutFlag1 = optimizelyConfig.FeaturesMap["flag_1"].DeliveryRules[0]; // 9300000004977,
var rolloutFlag1 = optimizelyConfig.FeaturesMap["flag_1"].DeliveryRules[0]; // 9300000004977,
var rolloutFlag2 = optimizelyConfig.FeaturesMap["flag_2"].DeliveryRules[0]; // 9300000004979
var rolloutFlag3 = optimizelyConfig.FeaturesMap["flag_3"].DeliveryRules[0]; // 9300000004981
Assert.AreEqual(rolloutFlag1.Id, "9300000004977");
Expand All @@ -167,7 +164,6 @@ public void TestGetOptimizelyConfigWithDuplicateRuleKeys()
Assert.AreEqual(rolloutFlag2.Key, "targeted_delivery");
Assert.AreEqual(rolloutFlag3.Id, "9300000004981");
Assert.AreEqual(rolloutFlag3.Key, "targeted_delivery");

}

[Test]
Expand All @@ -185,6 +181,156 @@ public void TestGetOptimizelyConfigSDKAndEnvironmentKeyDefault()
public void TestGetOptimizelyConfigService()
{
var datafileProjectConfig = DatafileProjectConfig.Create(TestData.TypedAudienceDatafile, new NoOpLogger(), new ErrorHandler.NoOpErrorHandler());
var expectedflagVariations = new Dictionary<string, List<Variation>> {
{
"feat_no_vars",
new List<Variation> {
new Variation
{
FeatureEnabled = true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can consider to remove this from OptimizelyConfig.

FeatureVariableUsageInstances = new List<FeatureVariableUsage>(),
Key = "11557362669",
Id = "11557362669",
VariableIdToVariableUsageInstanceMap = new Dictionary<string, FeatureVariableUsage>()
},
new Variation
{
FeatureEnabled = false,
FeatureVariableUsageInstances = new List<FeatureVariableUsage>(),
Key = "11475708558",
Id = "11475708558",
VariableIdToVariableUsageInstanceMap = new Dictionary<string, FeatureVariableUsage>()
},
new Variation
{
FeatureEnabled = true,
FeatureVariableUsageInstances = new List<FeatureVariableUsage>(),
Key = "11557362670",
Id = "11557362670",
VariableIdToVariableUsageInstanceMap = new Dictionary<string, FeatureVariableUsage>()
},
new Variation
{
FeatureEnabled = false,
FeatureVariableUsageInstances = new List<FeatureVariableUsage>(),
Key = "11475708559",
Id = "11475708559",
VariableIdToVariableUsageInstanceMap = new Dictionary<string, FeatureVariableUsage>()
}
}
},
{
"feat_with_var",
new List<Variation> {
new Variation
{
FeatureEnabled = true,
FeatureVariableUsageInstances = new List<FeatureVariableUsage>(),
Key = "11557362669",
Id = "11557362669",
VariableIdToVariableUsageInstanceMap = new Dictionary<string, FeatureVariableUsage>()
},
new Variation
{
FeatureEnabled = false,
FeatureVariableUsageInstances = new List<FeatureVariableUsage>(),
Key = "11475708558",
Id = "11475708558",
VariableIdToVariableUsageInstanceMap = new Dictionary<string, FeatureVariableUsage>()
},
new Variation
{
FeatureEnabled = true,
FeatureVariableUsageInstances = new List<FeatureVariableUsage>(),
Key = "11557362670",
Id = "11557362670",
VariableIdToVariableUsageInstanceMap = new Dictionary<string, FeatureVariableUsage>()
},
new Variation
{
FeatureEnabled = false,
FeatureVariableUsageInstances = new List<FeatureVariableUsage>(),
Key = "11475708559",
Id = "11475708559",
VariableIdToVariableUsageInstanceMap = new Dictionary<string, FeatureVariableUsage>()
}
}
},
{
"feat2",
new List<Variation> {
new Variation
{
FeatureEnabled = true,
FeatureVariableUsageInstances = new List<FeatureVariableUsage>(),
Key = "11557362669",
Id = "11557362669",
VariableIdToVariableUsageInstanceMap = new Dictionary<string, FeatureVariableUsage>()
},
new Variation
{
FeatureEnabled = false,
FeatureVariableUsageInstances = new List<FeatureVariableUsage>(),
Key = "11475708558",
Id = "11475708558",
VariableIdToVariableUsageInstanceMap = new Dictionary<string, FeatureVariableUsage>()
},
new Variation
{
FeatureEnabled = true,
FeatureVariableUsageInstances = new List<FeatureVariableUsage>(),
Key = "11557362670",
Id = "11557362670",
VariableIdToVariableUsageInstanceMap = new Dictionary<string, FeatureVariableUsage>()
},
new Variation
{
FeatureEnabled = false,
FeatureVariableUsageInstances = new List<FeatureVariableUsage>(),
Key = "11475708559",
Id = "11475708559",
VariableIdToVariableUsageInstanceMap = new Dictionary<string, FeatureVariableUsage>()
}
}
},
{
"feat2_with_var",
new List<Variation> {
new Variation
{
FeatureEnabled = true,
FeatureVariableUsageInstances = new List<FeatureVariableUsage>(),
Key = "11557362669",
Id = "11557362669",
VariableIdToVariableUsageInstanceMap = new Dictionary<string, FeatureVariableUsage>()
},
new Variation
{
FeatureEnabled = false,
FeatureVariableUsageInstances = new List<FeatureVariableUsage>(),
Key = "11475708558",
Id = "11475708558",
VariableIdToVariableUsageInstanceMap = new Dictionary<string, FeatureVariableUsage>()
},
new Variation
{
FeatureEnabled = true,
FeatureVariableUsageInstances = new List<FeatureVariableUsage>(),
Key = "11557362670",
Id = "11557362670",
VariableIdToVariableUsageInstanceMap = new Dictionary<string, FeatureVariableUsage>()
},
new Variation
{
FeatureEnabled = false,
FeatureVariableUsageInstances = new List<FeatureVariableUsage>(),
Key = "11475708559",
Id = "11475708559",
VariableIdToVariableUsageInstanceMap = new Dictionary<string, FeatureVariableUsage>()
}
}
}
};
IDictionary<string, OptimizelyExperiment> experimentsMap = new Dictionary<string, OptimizelyExperiment>
{
{
Expand Down Expand Up @@ -275,7 +421,6 @@ public void TestGetOptimizelyConfigService()
}
};


var featuresMap = new Dictionary<string, OptimizelyFeature>
{
{
Expand Down Expand Up @@ -542,7 +687,7 @@ public void TestGetOptimizelyConfigService()
new OptimizelyAudience("3988293898", "substringString", "[\"and\",[\"or\",[\"or\",{\"name\":\"house\",\"type\":\"custom_attribute\",\"match\":\"substring\",\"value\":\"Slytherin\"}]]]"),
},
events: new OptimizelyEvent[]
{
{
new OptimizelyEvent()
{
Id = "594089", Key = "item_bought", ExperimentIds = new string[] { "11564051718", "1323241597" }
Expand All @@ -555,12 +700,13 @@ public void TestGetOptimizelyConfigService()
experimentsMap: experimentsMap,
featuresMap: featuresMap,
datafile: TestData.TypedAudienceDatafile);
Assert.IsTrue(TestData.CompareObjects(optimizelyConfig, expectedOptimizelyConfig));

Assertions.AreEqual(expectedOptimizelyConfig, optimizelyConfig);
}

#endregion
#endregion Test OptimizelyConfigService

#region OptimizelyConfig entity tests
#region OptimizelyConfig entity tests

[Test]
public void TestOptimizelyConfigEntity()
Expand Down Expand Up @@ -640,6 +786,6 @@ public void TestOptimizelyVariableEntity()
Assert.AreEqual(expectedOptlyVariable.Value, "2");
}

#endregion
#endregion OptimizelyConfig entity tests
}
}
}
5 changes: 2 additions & 3 deletions OptimizelySDK.Tests/OptimizelySDK.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<Reference Include="System.Net.Http.WebRequest" />
</ItemGroup>
<ItemGroup>
<Compile Include="Assertions.cs" />
<Compile Include="AudienceConditionsTests\ConditionEvaluationTest.cs" />
<Compile Include="AudienceConditionsTests\ConditionsTest.cs" />
<Compile Include="ConfigTest\HttpProjectConfigManagerTest.cs" />
Expand Down Expand Up @@ -143,9 +144,7 @@
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Folder Include="Utils\" />
</ItemGroup>
<ItemGroup />
dustin-sier marked this conversation as resolved.
Show resolved Hide resolved
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
Loading