Skip to content

Commit 61c4d89

Browse files
fix: correct event tag mapping key in setConfiguration for urbanairship-19 and urbanairship-20
The event tags block in setConfiguration: guarded on kMPUAEventTagKey ("eventUserTags") but read from kMPUAEventAttributeTagKey ("eventAttributeUserTags"), causing eventTagsMapping to always be populated with attribute tag data instead of event tag data. Fixed in both urbanairship-19 and urbanairship-20. Added tests to confirm each mapping is populated from its correct configuration key. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d3f20d1 commit 61c4d89

File tree

4 files changed

+86
-2
lines changed

4 files changed

+86
-2
lines changed

Kits/urbanairship/urbanairship-19/Sources/mParticle-UrbanAirship/MPKitUrbanAirship.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ - (void)setConfiguration:(NSDictionary *)configuration {
215215
NSData *tagMappingData;
216216

217217
if (configuration && configuration[kMPUAEventTagKey] != [NSNull null]) {
218-
tagMappingStr = [configuration[kMPUAEventAttributeTagKey] stringByRemovingPercentEncoding];
218+
tagMappingStr = [configuration[kMPUAEventTagKey] stringByRemovingPercentEncoding];
219219
tagMappingData = [tagMappingStr dataUsingEncoding:NSUTF8StringEncoding];
220220
}
221221

Kits/urbanairship/urbanairship-19/Tests/mParticle-UrbanAirshipTests/MPKitUrbanAirshipTests.swift

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,46 @@ final class MPKitUrbanAirshipTests: XCTestCase {
1010

1111
XCTAssertEqual(actualKitCode, expectedKitCode, "Kit code should be 25")
1212
}
13+
14+
func testEventTagsMappingUsesCorrectKey() {
15+
let kit = MPKitUrbanAirship()
16+
kit.setConfiguration(makeConfiguration(
17+
eventTagsMapType: "EventClass.Id",
18+
eventAttributeTagsMapType: "EventAttributeClass.Id"
19+
))
20+
21+
let mappings = kit.value(forKey: "eventTagsMapping") as? [NSObject]
22+
let firstMapType = mappings?.first?.value(forKey: "mapType") as? String
23+
24+
XCTAssertEqual(firstMapType, "EventClass.Id",
25+
"eventTagsMapping should be populated from eventUserTags, not eventAttributeUserTags")
26+
}
27+
28+
func testEventAttributeTagsMappingUsesCorrectKey() {
29+
let kit = MPKitUrbanAirship()
30+
kit.setConfiguration(makeConfiguration(
31+
eventTagsMapType: "EventClass.Id",
32+
eventAttributeTagsMapType: "EventAttributeClass.Id"
33+
))
34+
35+
let mappings = kit.value(forKey: "eventAttributeTagsMapping") as? [NSObject]
36+
let firstMapType = mappings?.first?.value(forKey: "mapType") as? String
37+
38+
XCTAssertEqual(firstMapType, "EventAttributeClass.Id",
39+
"eventAttributeTagsMapping should be populated from eventAttributeUserTags")
40+
}
41+
42+
private func makeConfiguration(eventTagsMapType: String, eventAttributeTagsMapType: String) -> [String: String] {
43+
[
44+
"appKey": "test-app-key",
45+
"appSecret": "test-app-secret",
46+
"eventUserTags": percentEncodedTagJSON(mapType: eventTagsMapType),
47+
"eventAttributeUserTags": percentEncodedTagJSON(mapType: eventAttributeTagsMapType)
48+
]
49+
}
50+
51+
private func percentEncodedTagJSON(mapType: String) -> String {
52+
let json = "[{\"maptype\":\"\(mapType)\",\"value\":\"test-tag\",\"map\":\"abc123\"}]"
53+
return json.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? json
54+
}
1355
}

Kits/urbanairship/urbanairship-20/Sources/mParticle-UrbanAirship/MPKitUrbanAirship.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ - (void)setConfiguration:(NSDictionary *)configuration {
215215
NSData *tagMappingData;
216216

217217
if (configuration && configuration[kMPUAEventTagKey] != [NSNull null]) {
218-
tagMappingStr = [configuration[kMPUAEventAttributeTagKey] stringByRemovingPercentEncoding];
218+
tagMappingStr = [configuration[kMPUAEventTagKey] stringByRemovingPercentEncoding];
219219
tagMappingData = [tagMappingStr dataUsingEncoding:NSUTF8StringEncoding];
220220
}
221221

Kits/urbanairship/urbanairship-20/Tests/mParticle-UrbanAirshipTests/MPKitUrbanAirshipTests.swift

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,46 @@ final class MPKitUrbanAirshipTests: XCTestCase {
1010

1111
XCTAssertEqual(actualKitCode, expectedKitCode, "Kit code should be 25")
1212
}
13+
14+
func testEventTagsMappingUsesCorrectKey() {
15+
let kit = MPKitUrbanAirship()
16+
kit.setConfiguration(makeConfiguration(
17+
eventTagsMapType: "EventClass.Id",
18+
eventAttributeTagsMapType: "EventAttributeClass.Id"
19+
))
20+
21+
let mappings = kit.value(forKey: "eventTagsMapping") as? [NSObject]
22+
let firstMapType = mappings?.first?.value(forKey: "mapType") as? String
23+
24+
XCTAssertEqual(firstMapType, "EventClass.Id",
25+
"eventTagsMapping should be populated from eventUserTags, not eventAttributeUserTags")
26+
}
27+
28+
func testEventAttributeTagsMappingUsesCorrectKey() {
29+
let kit = MPKitUrbanAirship()
30+
kit.setConfiguration(makeConfiguration(
31+
eventTagsMapType: "EventClass.Id",
32+
eventAttributeTagsMapType: "EventAttributeClass.Id"
33+
))
34+
35+
let mappings = kit.value(forKey: "eventAttributeTagsMapping") as? [NSObject]
36+
let firstMapType = mappings?.first?.value(forKey: "mapType") as? String
37+
38+
XCTAssertEqual(firstMapType, "EventAttributeClass.Id",
39+
"eventAttributeTagsMapping should be populated from eventAttributeUserTags")
40+
}
41+
42+
private func makeConfiguration(eventTagsMapType: String, eventAttributeTagsMapType: String) -> [String: String] {
43+
[
44+
"appKey": "test-app-key",
45+
"appSecret": "test-app-secret",
46+
"eventUserTags": percentEncodedTagJSON(mapType: eventTagsMapType),
47+
"eventAttributeUserTags": percentEncodedTagJSON(mapType: eventAttributeTagsMapType)
48+
]
49+
}
50+
51+
private func percentEncodedTagJSON(mapType: String) -> String {
52+
let json = "[{\"maptype\":\"\(mapType)\",\"value\":\"test-tag\",\"map\":\"abc123\"}]"
53+
return json.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? json
54+
}
1355
}

0 commit comments

Comments
 (0)