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: Datafile parsing + audience evaluation for ODP integration #305

Merged
merged 45 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
3d20b51
Updated user context
mikechu-optimizely Jul 15, 2022
0b4d1b9
Added ref to SDK from DemoApp so solution builds.
mikechu-optimizely Jul 15, 2022
7542ca6
Merge branch 'master' into mike/datafile-parsing-audience-evaluation
mikechu-optimizely Jul 18, 2022
b80966d
(Datafile)ProjectConfig & Integration added
mikechu-optimizely Jul 18, 2022
bac1f1d
Update Condition interface & implementing classes
mikechu-optimizely Jul 19, 2022
b8022ae
Add copyright notice
mikechu-optimizely Jul 19, 2022
15f5b63
Add AttributeType
mikechu-optimizely Jul 19, 2022
7915232
Implement changes from DoesUserMeetAudienceConditions
mikechu-optimizely Jul 19, 2022
af97fcc
Correct accessibility & missing interface item
mikechu-optimizely Jul 19, 2022
cdc6c29
Bring AttributeType into BaseCondition
mikechu-optimizely Jul 20, 2022
4c415b3
Add missing reference
mikechu-optimizely Jul 20, 2022
5cd1eeb
Fix parsing
mikechu-optimizely Jul 20, 2022
d998b57
Add test for Integration parsing
mikechu-optimizely Jul 20, 2022
7fedccb
Move reference to Integration
mikechu-optimizely Jul 20, 2022
a9295d2
Correction to NetStandard 2.0 project reference
mikechu-optimizely Jul 20, 2022
dd62705
Add empty Integration test
mikechu-optimizely Jul 20, 2022
5420bf6
Test for empty integration and non "odp" integration
mikechu-optimizely Jul 20, 2022
e29a61a
Fix missed Copyright update
mikechu-optimizely Jul 20, 2022
ecbd7ec
Fix copyright notice
mikechu-optimizely Jul 21, 2022
4d5bba9
Merge branch 'master' into mike/datafile-parsing-audience-evaluation
mikechu-optimizely Jul 25, 2022
c0bcf38
Add additional line to eof
mikechu-optimizely Jul 25, 2022
a7e0b19
Refactor `user` to `context` for OptimizelyUserContext param
mikechu-optimizely Jul 25, 2022
67d28cf
Refactor: use static array of valid types
mikechu-optimizely Jul 25, 2022
2cf6fb4
Oops use `userContext` instead of `context`
mikechu-optimizely Jul 25, 2022
3957c22
Merge branch 'master' into mike/datafile-parsing-audience-evaluation
mikechu-optimizely Jul 25, 2022
2d033eb
Update OptimizelySDK/AudienceConditions/ICondition.cs
mikechu-optimizely Jul 27, 2022
3ab49f8
Update OptimizelySDK/AudienceConditions/EmptyCondition.cs
mikechu-optimizely Jul 27, 2022
ee72d48
Support Copy() including QualifiedSegments
mikechu-optimizely Jul 27, 2022
d91c00b
Move datafile Integration tests
mikechu-optimizely Jul 27, 2022
fa56206
Merge branch 'master' into mike/datafile-parsing-audience-evaluation
mikechu-optimizely Jul 27, 2022
aeff581
Integration ToString made generic + tests
mikechu-optimizely Aug 1, 2022
f08359e
Minor refactor and doc to userconext
mikechu-optimizely Aug 1, 2022
92f38f8
Lock UserContext before determining IsQualifiedFor
mikechu-optimizely Aug 1, 2022
845cc30
Separate integration test datafile content
mikechu-optimizely Aug 1, 2022
3aa98ba
Add good integration config but also has other key-values
mikechu-optimizely Aug 1, 2022
006e63a
Add copyright and EOL
mikechu-optimizely Aug 1, 2022
514e5d5
Correction to Qualified Segments check + Add tests
mikechu-optimizely Aug 1, 2022
18b8085
Update OptimizelySDK/OptimizelyUserContext.cs
mikechu-optimizely Aug 2, 2022
b96a009
Update OptimizelySDK.Tests/ProjectConfigTest.cs
mikechu-optimizely Aug 2, 2022
9ec3300
Add thread-safe getter+setter; fix formatting
mikechu-optimizely Aug 2, 2022
a8581a7
Use third party dimension in qualified segments test
mikechu-optimizely Aug 2, 2022
2e97a8e
Fixing Mike's sloppiness
mikechu-optimizely Aug 2, 2022
3336c0c
Correct parameter order
mikechu-optimizely Aug 2, 2022
847ba3e
Rename tests
mikechu-optimizely Aug 2, 2022
e094199
Maintain previous constructor signature
mikechu-optimizely Aug 2, 2022
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
6 changes: 6 additions & 0 deletions OptimizelySDK.DemoApp/OptimizelySDK.DemoApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@
<ItemGroup>
<Content Include="packages.config" />
</ItemGroup>
<ItemGroup>
mikechu-optimizely marked this conversation as resolved.
Show resolved Hide resolved
<ProjectReference Include="..\OptimizelySDK\OptimizelySDK.csproj">
<Project>{4dde7faa-110d-441c-ab3b-3f31b593e8bf}</Project>
<Name>OptimizelySDK</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
Expand Down
3 changes: 3 additions & 0 deletions OptimizelySDK.Net35/OptimizelySDK.Net35.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@
<Compile Include="..\OptimizelySDK\Config\DatafileProjectConfig.cs">
<Link>Config\DatafileProjectConfig</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Entity\Integration.cs">
<Link>Entity\Integration</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Config\ProjectConfigManager.cs">
<Link>Config\ProjectConfigManager</Link>
</Compile>
Expand Down
3 changes: 3 additions & 0 deletions OptimizelySDK.Net40/OptimizelySDK.Net40.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@
<Compile Include="..\OptimizelySDK\Config\DatafileProjectConfig.cs">
<Link>Config\DatafileProjectConfig</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Entity\Integration.cs">
mikechu-optimizely marked this conversation as resolved.
Show resolved Hide resolved
<Link>Entity\Integration</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Config\ProjectConfigManager.cs">
<Link>Config\ProjectConfigManager</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<Compile Include="..\OptimizelySDK\Bucketing\UserProfileUtil.cs" />
<Compile Include="..\OptimizelySDK\ProjectConfig.cs" />
<Compile Include="..\OptimizelySDK\Config\DatafileProjectConfig.cs" />
<Compile Include="..\OptimizelySDK\Entity\Integration.cs" />
<Compile Include="..\OptimizelySDK\Config\ProjectConfigManager.cs" />
<Compile Include="..\OptimizelySDK\Config\PollingProjectConfigManager.cs" />
<Compile Include="..\OptimizelySDK\Config\HttpProjectConfigManager.cs" />
Expand Down Expand Up @@ -159,5 +160,4 @@
<PackageReference Include="NJsonSchema" Version="8.33.6323.36213" />
<PackageReference Include="murmurhash-signed" Version="1.0.2" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
<Compile Include="..\OptimizelySDK\Entity\Group.cs">
<Link>Entity\Group.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Entity\Integration.cs">
<Link>Entity\Integration.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Entity\IdKeyEntity.cs">
<Link>Entity\IdKeyEntity.cs</Link>
</Compile>
Expand Down
368 changes: 216 additions & 152 deletions OptimizelySDK.Tests/AudienceConditionsTests/ConditionEvaluationTest.cs

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions OptimizelySDK.Tests/AudienceConditionsTests/ConditionsTest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2019, Optimizely
* Copyright 2019-2022, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -41,11 +41,11 @@ public class ConditionsTest
public void Initialize()
{
TrueConditionMock = new Mock<ICondition>();
TrueConditionMock.Setup(condition => condition.Evaluate(It.IsAny<ProjectConfig>(), It.IsAny<UserAttributes>(), It.IsAny<ILogger>())).Returns(true);
TrueConditionMock.Setup(condition => condition.Evaluate(It.IsAny<ProjectConfig>(), It.IsAny<OptimizelyUserContext>(), It.IsAny<ILogger>())).Returns(true);
FalseConditionMock = new Mock<ICondition>();
FalseConditionMock.Setup(condition => condition.Evaluate(It.IsAny<ProjectConfig>(), It.IsAny<UserAttributes>(), It.IsAny<ILogger>())).Returns(false);
FalseConditionMock.Setup(condition => condition.Evaluate(It.IsAny<ProjectConfig>(), It.IsAny<OptimizelyUserContext>(), It.IsAny<ILogger>())).Returns(false);
NullConditionMock = new Mock<ICondition>();
NullConditionMock.Setup(condition => condition.Evaluate(It.IsAny<ProjectConfig>(), It.IsAny<UserAttributes>(), It.IsAny<ILogger>())).Returns((bool?)null);
NullConditionMock.Setup(condition => condition.Evaluate(It.IsAny<ProjectConfig>(), It.IsAny<OptimizelyUserContext>(), It.IsAny<ILogger>())).Returns((bool?)null);

TrueCondition = TrueConditionMock.Object;
FalseCondition = FalseConditionMock.Object;
Expand Down Expand Up @@ -76,7 +76,7 @@ public void TestAndEvaluatorReturnsFalseWhenAnyOperandEvaluatesToFalse()
Assert.That(andCondition.Evaluate(null, null, Logger), Is.False);

// Should not be called due to short circuiting.
TrueConditionMock.Verify(condition => condition.Evaluate(It.IsAny<ProjectConfig>(), It.IsAny<UserAttributes>(), Logger), Times.Never);
TrueConditionMock.Verify(condition => condition.Evaluate(It.IsAny<ProjectConfig>(), It.IsAny<OptimizelyUserContext>(), Logger), Times.Never);
}

[Test]
Expand Down
97 changes: 97 additions & 0 deletions OptimizelySDK.Tests/EntityTests/IntegrationTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright 2022, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using NUnit.Framework;
using OptimizelySDK.Entity;

namespace OptimizelySDK.Tests.EntityTests
{
[TestFixture]
public class IntegrationTest
{
private const string KEY = "test-key";

private const string HOST = "api.example.com";
private const string PUBLIC_KEY = "FAk3-pUblic-K3y";

[Test]
public void ToStringWithNoHostShouldSucceed()
{
var integration = new Integration()
{
Key = KEY,
PublicKey = PUBLIC_KEY,
};

var stringValue = integration.ToString();

Assert.True(stringValue.Contains($@"key='{KEY}'"));
Assert.True(stringValue.Contains($@"publicKey='{PUBLIC_KEY}'"));
Assert.False(stringValue.Contains("host"));
Assert.False(stringValue.Contains(HOST));
}

[Test]
public void ToStringWithNoPublicKeyShouldSucceed()
{
var integration = new Integration()
{
Key = KEY,
Host = HOST,
};

var stringValue = integration.ToString();

Assert.True(stringValue.Contains($@"key='{KEY}'"));
Assert.True(stringValue.Contains($@"host='{HOST}'"));
Assert.False(stringValue.Contains("publicKey"));
Assert.False(stringValue.Contains(PUBLIC_KEY));
}

[Test]
public void ToStringWithAllPropertiesShouldSucceed()
{
var integration = new Integration()
{
Key = KEY,
Host = HOST,
PublicKey = PUBLIC_KEY,
};

var stringValue = integration.ToString();

Assert.True(
stringValue.Contains($@"key='{KEY}', host='{HOST}', publicKey='{PUBLIC_KEY}'"));
}

[Test]
public void ToStringWithOnlyKeyShouldSucceed()
{
var integration = new Integration()
{
Key = KEY,
};

var stringValue = integration.ToString();

Assert.True(stringValue.Contains($@"key='{KEY}'"));
Assert.False(stringValue.Contains("host"));
Assert.False(stringValue.Contains(HOST));
Assert.False(stringValue.Contains("publicKey"));
Assert.False(stringValue.Contains(PUBLIC_KEY));
}
}
}
18 changes: 18 additions & 0 deletions OptimizelySDK.Tests/IntegrationEmptyDatafile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": "4",
"rollouts": [],
"anonymizeIP": true,
"projectId": "20441150641",
"variables": [],
"featureFlags": [],
"experiments": [],
"audiences": [],
"groups": [],
"integrations": [],
"attributes": [],
"accountId": "11467598500",
"events": [],
"revision": "241",
"sdkKey": "EmptyIntegrationDatafile",
"environmentKey": "Production"
}
65 changes: 65 additions & 0 deletions OptimizelySDK.Tests/IntegrationNonOdpDatafile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"version": "4",
"rollouts": [
{
"experiments": [
],
"id": "18309384009"
}
],
"typedAudiences": [],
"anonymizeIP": true,
"projectId": "18326250003",
"variables": [],
"featureFlags": [
{
"experimentIds": [],
"rolloutId": "18309384009",
"variables": [
{
"defaultValue": "",
"type": "string",
"id": "18323951833",
"key": "var_1"
}
],
"id": "18244658520",
"key": "empty_rollout"
},
{
"experimentIds": [],
"rolloutId": "",
"variables": [
{
"defaultValue": "",
"type": "string",
"id": "2832355113",
"key": "var_2"
}
],
"id": "24246538512",
"key": "empty_rollout_id"
}
],
"experiments": [],
"audiences": [
{
"conditions": "[\"or\", {\"match\": \"exact\", \"name\": \"$opt_dummy_attribute\", \"type\": \"custom_attribute\", \"value\": \"$opt_dummy_value\"}]",
"id": "$opt_dummy_audience",
"name": "Optimizely-Generated Audience for Backwards Compatibility"
}
],
"groups": [],
"integrations": [
{
"key": "not-odp",
"host": "https://example.com",
"publicKey": "CleAr1y-!a-R3a7-pUbl1c-k3y"
}
],
"attributes": [],
"botFiltering": false,
"accountId": "8272261422",
"events": [],
"revision": "2"
}
Loading