From bb12bac9df68f89339dde74ded1d7aa9fc267f86 Mon Sep 17 00:00:00 2001 From: ericfichtel <33603621+ericfichtel@users.noreply.github.com> Date: Fri, 11 Nov 2022 13:26:49 -0800 Subject: [PATCH] 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 Co-authored-by: Eric Fichtel Co-authored-by: Andrei Anischevici --- .../OnDevice/Collator/CustomParamsCollator.cs | 35 ++++++++ .../Artifacts/TEST_ARTIFACT_PARAMS.json | 60 +++++++++++++- .../Models/TEST_SUITE_PARAMS.json | 82 ++++++++++++++++++- .../ParamsCollatorsShould.cs | 30 ++++++- global.json | 2 +- 5 files changed, 202 insertions(+), 7 deletions(-) diff --git a/Source/Adobe.Target.Client/OnDevice/Collator/CustomParamsCollator.cs b/Source/Adobe.Target.Client/OnDevice/Collator/CustomParamsCollator.cs index 357a6db..27049dd 100644 --- a/Source/Adobe.Target.Client/OnDevice/Collator/CustomParamsCollator.cs +++ b/Source/Adobe.Target.Client/OnDevice/Collator/CustomParamsCollator.cs @@ -32,7 +32,42 @@ public Dictionary CollateParams(TargetDeliveryRequest deliveryRe result.Add(param.Key + LowerCasePostfix, param.Value?.ToLowerInvariant()); } + return this.CreateNestedParametersFromDots(result); + } + + private Dictionary CreateNestedParametersFromDots(Dictionary custom) + { + var result = new Dictionary(); + foreach (KeyValuePair 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 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()); + } + + custom = (Dictionary)custom[keys[i]]; + } + + custom.Add(keys[keys.Length - 1], value); + } } } diff --git a/Tests/Adobe.Target.Client.Test/Artifacts/TEST_ARTIFACT_PARAMS.json b/Tests/Adobe.Target.Client.Test/Artifacts/TEST_ARTIFACT_PARAMS.json index 1ed518f..92c54d5 100644 --- a/Tests/Adobe.Target.Client.Test/Artifacts/TEST_ARTIFACT_PARAMS.json +++ b/Tests/Adobe.Target.Client.Test/Artifacts/TEST_ARTIFACT_PARAMS.json @@ -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" }, @@ -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": [] + } } ] }, diff --git a/Tests/Adobe.Target.Client.Test/Models/TEST_SUITE_PARAMS.json b/Tests/Adobe.Target.Client.Test/Models/TEST_SUITE_PARAMS.json index 886a151..25ba78a 100644 --- a/Tests/Adobe.Target.Client.Test/Models/TEST_SUITE_PARAMS.json +++ b/Tests/Adobe.Target.Client.Test/Models/TEST_SUITE_PARAMS.json @@ -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 }, @@ -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 }, @@ -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==" + } + ] + } + ] + } + } } } } diff --git a/Tests/Adobe.Target.Client.Test/ParamsCollatorsShould.cs b/Tests/Adobe.Target.Client.Test/ParamsCollatorsShould.cs index e4b5ed2..897f23a 100644 --- a/Tests/Adobe.Target.Client.Test/ParamsCollatorsShould.cs +++ b/Tests/Adobe.Target.Client.Test/ParamsCollatorsShould.cs @@ -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")] @@ -95,14 +96,37 @@ public void CollateParams_ReturnGeoParams() [Fact] public void CollateParams_ReturnCustomParams() { - var paramDict = new Dictionary {{"Param1", "Value1"}, {"Param2", "Value2"}}; + var paramDict = new Dictionary + { + {"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) result["dot"]; + Assert.Equal("isConfusing", dot["notation"]); + Assert.Equal("isconfusing", dot["notation_lc"]); + + var first = (Dictionary) result["first"]; + var second = (Dictionary) 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() { diff --git a/global.json b/global.json index ec868cb..5fefc00 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { "rollForward": "latestMajor", - "version": "5.0.100" + "version": "5.0.202" } }