Skip to content

Commit

Permalink
fix: item attribute number limit issue
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoweii committed Dec 15, 2023
1 parent 4bb1f7b commit 788418b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ class EventChecker {
static func checkItem(currentNumber: Int, item: ClickstreamAttribute) ->
(eventError: EventError, resultItem: ClickstreamAttribute)
{
if itemKeySet.isEmpty {
initItemKeySet()
}
var resultItem: ClickstreamAttribute = [:]
if currentNumber >= Event.Limit.MAX_NUM_OF_ITEMS {
let itemJsonString = (item as JsonObject).toJsonString()
Expand Down
16 changes: 16 additions & 0 deletions Tests/ClickstreamTests/Clickstream/ClickstreamEventTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,22 @@ class ClickstreamEventTest: XCTestCase {
XCTAssertEqual(0, clickstreamEvent.items.count)
}

func testAddItemPrestAndCustomAttributeNotExceedTheLimit() {
var item: ClickstreamAttribute = [
ClickstreamAnalytics.Item.ITEM_ID: 123,
ClickstreamAnalytics.Item.ITEM_NAME: "testName1",
ClickstreamAnalytics.Item.ITEM_BRAND: "Google",
ClickstreamAnalytics.Item.CURRENCY: "CNY",
ClickstreamAnalytics.Item.LOCATION_ID: "1"
]
for i in 0 ..< 10 {
item["custom_attr_\(i)"] = "value_\(i)"
}
clickstreamEvent.addItem(item)
XCTAssertTrue(clickstreamEvent.attribute(forKey: Event.ReservedAttribute.ERROR_CODE) == nil)
XCTAssertEqual(1, clickstreamEvent.items.count)
}

func testAddItemErrorForExceedMaxLengthOfAttributeName() {
let longAttributeKey = String(repeating: "a", count: 51)
let item: ClickstreamAttribute = [
Expand Down

0 comments on commit 788418b

Please sign in to comment.