Skip to content

Commit

Permalink
TNT-45759 params with dots do not work (#35)
Browse files Browse the repository at this point in the history
* initial dot params fix using local Adobe.Target.Client package

* bumping sdk version

* removing unnecessary cast and changing helper method visibility

* Update Source/Adobe.Target.Client/Adobe.Target.Client.csproj

Co-authored-by: Andrei Anischevici <[email protected]>

Co-authored-by: Eric Fichtel <[email protected]>
Co-authored-by: Andrei Anischevici <[email protected]>
  • Loading branch information
3 people authored Nov 11, 2022
1 parent 31bd25a commit bb12bac
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,42 @@ public Dictionary<string, object> CollateParams(TargetDeliveryRequest deliveryRe
result.Add(param.Key + LowerCasePostfix, param.Value?.ToLowerInvariant());
}

return this.CreateNestedParametersFromDots(result);
}

private Dictionary<string, object> CreateNestedParametersFromDots(Dictionary<string, object> custom)
{
var result = new Dictionary<string, object>();
foreach (KeyValuePair<string, object> entry in custom)
{
if (entry.Key.Contains(".")
&& !entry.Key.Contains("..")
&& entry.Key[0] != '.'
&& entry.Key[entry.Key.Length - 1] != '.')
{
this.AddNestedKeyToParameters(result, entry.Key, entry.Value);
}

result.Add(entry.Key, entry.Value);
}

return result;
}

private void AddNestedKeyToParameters(Dictionary<string, object> custom, string key, object value)
{
string[] keys = key.Split('.');
for (int i = 0; i < keys.Length - 1; i++)
{
if (!custom.ContainsKey(keys[i]))
{
custom.Add(keys[i], new Dictionary<string, object>());
}

custom = (Dictionary<string, object>)custom[keys[i]];
}

custom.Add(keys[keys.Length - 1], value);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"targetAdminActivityUrls": [
"https://experience.adobe.com/#/@targettesting/target/activities/activitydetails/A-B/_unit-test_mbox-params"
"https://experience.adobe.com/#/@targettesting/target/activities/activitydetails/A-B/_unit-test_mbox-params",
"https://experience.adobe.com/#/@targettesting/target/activities/activitydetails/A-B/_unit-test_mbox-params-dots"
],
"version": "1.0.0",
"meta": { "clientCode": "targettesting", "environment": "production" },
Expand Down Expand Up @@ -130,6 +131,63 @@
],
"metrics": []
}
},
{
"ruleKey": "147386",
"activityId": 147386,
"meta": {
"activity.id": 147386,
"activity.name": "[unit-test] mbox-params-dots",
"activity.type": "ab",
"experience.id": 0,
"experience.name": "Experience A",
"location.name": "mbox-params",
"location.type": "mbox",
"location.id": 0,
"audience.ids": [2059251],
"offer.id": 320012,
"offer.name": "Offer3",
"option.id": 2,
"option.name": "Offer2"
},
"condition": {
"and": [
{
"and": [
{ "<=": [0, { "var": "allocation" }] },
{ ">=": [100, { "var": "allocation" }] }
]
},
{
"and": [
{
"==": [
"racket",
{ "var": "mbox.first.programming.language_lc" }
]
},
{ "==": ["red", { "var": "mbox.favorite.color_lc" }] },
{
"==": [
"the big lebowski",
{ "var": "mbox.favorite.movie_lc" }
]
}
]
}
]
},
"consequence": {
"name": "mbox-params",
"options": [
{
"type": "json",
"eventToken": "WCoBzcT7Wkah1KKwsBiOkWqipfsIHvVzTQxHolz2IpSCnQ9Y9OaLL2gsdrWQTvE54PwSz67rmXWmSnkXpSSS2Q==",
"content": { "foo": "bar", "fizz": "buzz", "experience": "C" }
}
],
"metrics": []
}
}
]
},
Expand Down
82 changes: 80 additions & 2 deletions Tests/Adobe.Target.Client.Test/Models/TEST_SUITE_PARAMS.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,17 @@
},
"context": {
"channel": "web",
"mobilePlatform": null,
"application": null,
"screen": null,
"window": null,
"browser": null,
"address": {
"url": "http://local-target-test:8080/home?fabulous=true#sosumi"
"url": "http://local-target-test:8080/home?fabulous=true#sosumi",
"referringUrl": null
},
"geo": null,
"timeOffsetInMinutes": null,
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:73.0) Gecko/20100101 Firefox/73.0",
"beacon": false
},
Expand Down Expand Up @@ -69,9 +77,17 @@
},
"context": {
"channel": "web",
"mobilePlatform": null,
"application": null,
"screen": null,
"window": null,
"browser": null,
"address": {
"url": "http://local-target-test:8080/home?fabulous=true#sosumi"
"url": "http://local-target-test:8080/home?fabulous=true#sosumi",
"referringUrl": null
},
"geo": null,
"timeOffsetInMinutes": null,
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:73.0) Gecko/20100101 Firefox/73.0",
"beacon": false
},
Expand Down Expand Up @@ -99,6 +115,68 @@
]
}
}
},
"mbox_params_with_dots": {
"description": "supports matching params with dot notation",
"input": {
"request": {
"id": {
"tntId": "338e3c1e51f7416a8e1ccba4f81acea0.28_0",
"marketingCloudVisitorId": "07327024324407615852294135870030620007"
},
"context": {
"channel": "web",
"mobilePlatform": null,
"application": null,
"screen": null,
"window": null,
"browser": null,
"address": {
"url": "http://local-target-test:8080/home?fabulous=true#sosumi",
"referringUrl": null
},
"geo": null,
"timeOffsetInMinutes": null,
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:73.0) Gecko/20100101 Firefox/73.0",
"beacon": false
},
"prefetch": {
"mboxes": [
{
"name": "mbox-params",
"parameters": {
"first.programming.language": "racket",
"favorite.color": "red",
"favorite.movie": "the big lebowski"
},
"index": 1
}
]
}
},
"sessionId": "dummy_session"
},
"output": {
"prefetch": {
"mboxes": [
{
"index": 1,
"name": "mbox-params",
"options": [
{
"type": "json",
"content": {
"foo": "bar",
"fizz": "buzz",
"experience": "C"
},
"eventToken": "WCoBzcT7Wkah1KKwsBiOkWqipfsIHvVzTQxHolz2IpSCnQ9Y9OaLL2gsdrWQTvE54PwSz67rmXWmSnkXpSSS2Q=="
}
]
}
]
}
}
}
}
}
30 changes: 27 additions & 3 deletions Tests/Adobe.Target.Client.Test/ParamsCollatorsShould.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace Adobe.Target.Client.Test
using Moq;
using OnDevice.Collator;
using Client.Util;
using Newtonsoft.Json;
using Xunit;

[Collection("Datetime-mocked Collection")]
Expand Down Expand Up @@ -95,14 +96,37 @@ public void CollateParams_ReturnGeoParams()
[Fact]
public void CollateParams_ReturnCustomParams()
{
var paramDict = new Dictionary<string, string> {{"Param1", "Value1"}, {"Param2", "Value2"}};
var paramDict = new Dictionary<string, string>
{
{"foo", "bar"},
{"BAZ", "BUZ"},
{"dot.notation", "isConfusing"},
{"first.second.third", "value"},
{"first.second.wonky", "DONKEY"},
{"this..should..be", "ignored"},
{".something", "aaa"},
{"=cranky .chicken.", "bbb"}
};
var details = new RequestDetails(parameters: paramDict);
var result = new CustomParamsCollator().CollateParams(requestDetails: details);

Assert.Equal("Value1", result["Param1"]);
Assert.Equal("Value2", result["Param2"]);
var dot = (Dictionary<String, Object>) result["dot"];
Assert.Equal("isConfusing", dot["notation"]);
Assert.Equal("isconfusing", dot["notation_lc"]);

var first = (Dictionary<String, Object>) result["first"];
var second = (Dictionary<String, Object>) first["second"];

Assert.Equal("value", second["third"]);
Assert.Equal("value", second["third_lc"]);
Assert.Equal("DONKEY", second["wonky"]);
Assert.Equal("donkey", second["wonky_lc"]);

Assert.Equal("aaa", result[".something"]);
Assert.Equal("bbb", result["=cranky .chicken."]);
}


[Fact]
public void CollateParams_ReturnTimeParams()
{
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"rollForward": "latestMajor",
"version": "5.0.100"
"version": "5.0.202"
}
}

0 comments on commit bb12bac

Please sign in to comment.