Skip to content

Commit

Permalink
fix: crash when user attribute is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoweii committed Jun 26, 2024
1 parent 45a4ad4 commit 9b6d945
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ class ClickstreamEvent: AnalyticsPropertiesModel {
if !items.isEmpty {
event["items"] = items
}
event["user"] = userAttributes
if !userAttributes.isEmpty {
event["user"] = userAttributes
}
event["attributes"] = getAttributeObject(from: attributes)
return event
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/ClickstreamTests/Clickstream/EventRecorderTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class EventRecorderTest: XCTestCase {
XCTAssertNotNil(event["app_version"])
XCTAssertNotNil(event["app_package_name"])
XCTAssertNotNil(event["app_title"])
XCTAssertNotNil(event["user"])
XCTAssertNil(event["user"])
XCTAssertNotNil(event["attributes"])
XCTAssertNil(event["noneExistAttribute"])
}
Expand Down
1 change: 1 addition & 0 deletions Tests/ClickstreamTests/IntegrationTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ class IntegrationTest: XCTestCase {
XCTAssertEqual((user["score"] as! JsonObject)["value"] as! Double, 85.2)
XCTAssertEqual((user["_user_name"] as! JsonObject)["value"] as! String, "carl")
XCTAssertNotNil(user[Event.ReservedAttribute.USER_FIRST_TOUCH_TIMESTAMP])
XCTAssertNotNil((user[Event.ReservedAttribute.USER_FIRST_TOUCH_TIMESTAMP] as! JsonObject)["value"])
}

func testProfileSetTimestamp() throws {
Expand Down

0 comments on commit 9b6d945

Please sign in to comment.