Skip to content

Commit bb12bac

Browse files
ericfichteleric-fichtel-adobeXDex
authored
TNT-45759 params with dots do not work (#35)
* 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]>
1 parent 31bd25a commit bb12bac

File tree

5 files changed

+202
-7
lines changed

5 files changed

+202
-7
lines changed

Source/Adobe.Target.Client/OnDevice/Collator/CustomParamsCollator.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,42 @@ public Dictionary<string, object> CollateParams(TargetDeliveryRequest deliveryRe
3232
result.Add(param.Key + LowerCasePostfix, param.Value?.ToLowerInvariant());
3333
}
3434

35+
return this.CreateNestedParametersFromDots(result);
36+
}
37+
38+
private Dictionary<string, object> CreateNestedParametersFromDots(Dictionary<string, object> custom)
39+
{
40+
var result = new Dictionary<string, object>();
41+
foreach (KeyValuePair<string, object> entry in custom)
42+
{
43+
if (entry.Key.Contains(".")
44+
&& !entry.Key.Contains("..")
45+
&& entry.Key[0] != '.'
46+
&& entry.Key[entry.Key.Length - 1] != '.')
47+
{
48+
this.AddNestedKeyToParameters(result, entry.Key, entry.Value);
49+
}
50+
51+
result.Add(entry.Key, entry.Value);
52+
}
53+
3554
return result;
3655
}
56+
57+
private void AddNestedKeyToParameters(Dictionary<string, object> custom, string key, object value)
58+
{
59+
string[] keys = key.Split('.');
60+
for (int i = 0; i < keys.Length - 1; i++)
61+
{
62+
if (!custom.ContainsKey(keys[i]))
63+
{
64+
custom.Add(keys[i], new Dictionary<string, object>());
65+
}
66+
67+
custom = (Dictionary<string, object>)custom[keys[i]];
68+
}
69+
70+
custom.Add(keys[keys.Length - 1], value);
71+
}
3772
}
3873
}

Tests/Adobe.Target.Client.Test/Artifacts/TEST_ARTIFACT_PARAMS.json

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"targetAdminActivityUrls": [
3-
"https://experience.adobe.com/#/@targettesting/target/activities/activitydetails/A-B/_unit-test_mbox-params"
3+
"https://experience.adobe.com/#/@targettesting/target/activities/activitydetails/A-B/_unit-test_mbox-params",
4+
"https://experience.adobe.com/#/@targettesting/target/activities/activitydetails/A-B/_unit-test_mbox-params-dots"
45
],
56
"version": "1.0.0",
67
"meta": { "clientCode": "targettesting", "environment": "production" },
@@ -130,6 +131,63 @@
130131
],
131132
"metrics": []
132133
}
134+
},
135+
{
136+
"ruleKey": "147386",
137+
"activityId": 147386,
138+
"meta": {
139+
"activity.id": 147386,
140+
"activity.name": "[unit-test] mbox-params-dots",
141+
"activity.type": "ab",
142+
"experience.id": 0,
143+
"experience.name": "Experience A",
144+
"location.name": "mbox-params",
145+
"location.type": "mbox",
146+
"location.id": 0,
147+
"audience.ids": [2059251],
148+
"offer.id": 320012,
149+
"offer.name": "Offer3",
150+
"option.id": 2,
151+
"option.name": "Offer2"
152+
},
153+
"condition": {
154+
"and": [
155+
{
156+
"and": [
157+
{ "<=": [0, { "var": "allocation" }] },
158+
{ ">=": [100, { "var": "allocation" }] }
159+
]
160+
},
161+
{
162+
"and": [
163+
{
164+
"==": [
165+
"racket",
166+
{ "var": "mbox.first.programming.language_lc" }
167+
]
168+
},
169+
{ "==": ["red", { "var": "mbox.favorite.color_lc" }] },
170+
{
171+
"==": [
172+
"the big lebowski",
173+
{ "var": "mbox.favorite.movie_lc" }
174+
]
175+
}
176+
]
177+
}
178+
]
179+
},
180+
"consequence": {
181+
"name": "mbox-params",
182+
"options": [
183+
{
184+
"type": "json",
185+
"eventToken": "WCoBzcT7Wkah1KKwsBiOkWqipfsIHvVzTQxHolz2IpSCnQ9Y9OaLL2gsdrWQTvE54PwSz67rmXWmSnkXpSSS2Q==",
186+
"content": { "foo": "bar", "fizz": "buzz", "experience": "C" }
187+
}
188+
],
189+
"metrics": []
190+
}
133191
}
134192
]
135193
},

Tests/Adobe.Target.Client.Test/Models/TEST_SUITE_PARAMS.json

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,17 @@
1717
},
1818
"context": {
1919
"channel": "web",
20+
"mobilePlatform": null,
21+
"application": null,
22+
"screen": null,
23+
"window": null,
24+
"browser": null,
2025
"address": {
21-
"url": "http://local-target-test:8080/home?fabulous=true#sosumi"
26+
"url": "http://local-target-test:8080/home?fabulous=true#sosumi",
27+
"referringUrl": null
2228
},
29+
"geo": null,
30+
"timeOffsetInMinutes": null,
2331
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:73.0) Gecko/20100101 Firefox/73.0",
2432
"beacon": false
2533
},
@@ -69,9 +77,17 @@
6977
},
7078
"context": {
7179
"channel": "web",
80+
"mobilePlatform": null,
81+
"application": null,
82+
"screen": null,
83+
"window": null,
84+
"browser": null,
7285
"address": {
73-
"url": "http://local-target-test:8080/home?fabulous=true#sosumi"
86+
"url": "http://local-target-test:8080/home?fabulous=true#sosumi",
87+
"referringUrl": null
7488
},
89+
"geo": null,
90+
"timeOffsetInMinutes": null,
7591
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:73.0) Gecko/20100101 Firefox/73.0",
7692
"beacon": false
7793
},
@@ -99,6 +115,68 @@
99115
]
100116
}
101117
}
118+
},
119+
"mbox_params_with_dots": {
120+
"description": "supports matching params with dot notation",
121+
"input": {
122+
"request": {
123+
"id": {
124+
"tntId": "338e3c1e51f7416a8e1ccba4f81acea0.28_0",
125+
"marketingCloudVisitorId": "07327024324407615852294135870030620007"
126+
},
127+
"context": {
128+
"channel": "web",
129+
"mobilePlatform": null,
130+
"application": null,
131+
"screen": null,
132+
"window": null,
133+
"browser": null,
134+
"address": {
135+
"url": "http://local-target-test:8080/home?fabulous=true#sosumi",
136+
"referringUrl": null
137+
},
138+
"geo": null,
139+
"timeOffsetInMinutes": null,
140+
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:73.0) Gecko/20100101 Firefox/73.0",
141+
"beacon": false
142+
},
143+
"prefetch": {
144+
"mboxes": [
145+
{
146+
"name": "mbox-params",
147+
"parameters": {
148+
"first.programming.language": "racket",
149+
"favorite.color": "red",
150+
"favorite.movie": "the big lebowski"
151+
},
152+
"index": 1
153+
}
154+
]
155+
}
156+
},
157+
"sessionId": "dummy_session"
158+
},
159+
"output": {
160+
"prefetch": {
161+
"mboxes": [
162+
{
163+
"index": 1,
164+
"name": "mbox-params",
165+
"options": [
166+
{
167+
"type": "json",
168+
"content": {
169+
"foo": "bar",
170+
"fizz": "buzz",
171+
"experience": "C"
172+
},
173+
"eventToken": "WCoBzcT7Wkah1KKwsBiOkWqipfsIHvVzTQxHolz2IpSCnQ9Y9OaLL2gsdrWQTvE54PwSz67rmXWmSnkXpSSS2Q=="
174+
}
175+
]
176+
}
177+
]
178+
}
179+
}
102180
}
103181
}
104182
}

Tests/Adobe.Target.Client.Test/ParamsCollatorsShould.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace Adobe.Target.Client.Test
1717
using Moq;
1818
using OnDevice.Collator;
1919
using Client.Util;
20+
using Newtonsoft.Json;
2021
using Xunit;
2122

2223
[Collection("Datetime-mocked Collection")]
@@ -95,14 +96,37 @@ public void CollateParams_ReturnGeoParams()
9596
[Fact]
9697
public void CollateParams_ReturnCustomParams()
9798
{
98-
var paramDict = new Dictionary<string, string> {{"Param1", "Value1"}, {"Param2", "Value2"}};
99+
var paramDict = new Dictionary<string, string>
100+
{
101+
{"foo", "bar"},
102+
{"BAZ", "BUZ"},
103+
{"dot.notation", "isConfusing"},
104+
{"first.second.third", "value"},
105+
{"first.second.wonky", "DONKEY"},
106+
{"this..should..be", "ignored"},
107+
{".something", "aaa"},
108+
{"=cranky .chicken.", "bbb"}
109+
};
99110
var details = new RequestDetails(parameters: paramDict);
100111
var result = new CustomParamsCollator().CollateParams(requestDetails: details);
101112

102-
Assert.Equal("Value1", result["Param1"]);
103-
Assert.Equal("Value2", result["Param2"]);
113+
var dot = (Dictionary<String, Object>) result["dot"];
114+
Assert.Equal("isConfusing", dot["notation"]);
115+
Assert.Equal("isconfusing", dot["notation_lc"]);
116+
117+
var first = (Dictionary<String, Object>) result["first"];
118+
var second = (Dictionary<String, Object>) first["second"];
119+
120+
Assert.Equal("value", second["third"]);
121+
Assert.Equal("value", second["third_lc"]);
122+
Assert.Equal("DONKEY", second["wonky"]);
123+
Assert.Equal("donkey", second["wonky_lc"]);
124+
125+
Assert.Equal("aaa", result[".something"]);
126+
Assert.Equal("bbb", result["=cranky .chicken."]);
104127
}
105128

129+
106130
[Fact]
107131
public void CollateParams_ReturnTimeParams()
108132
{

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
33
"rollForward": "latestMajor",
4-
"version": "5.0.100"
4+
"version": "5.0.202"
55
}
66
}

0 commit comments

Comments
 (0)