Skip to content

Commit

Permalink
fix: crash when user attribute is empty (#71)
Browse files Browse the repository at this point in the history
Co-authored-by: xiaoweii <[email protected]>
  • Loading branch information
zhu-xiaowei and xiaoweii authored Jun 27, 2024
1 parent 45a4ad4 commit 6e7a814
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions IntegrationTest/devicefarm/logcat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def test_app_end(self, path):
def get_submitted_events(path):
submitted_events = []
with open(path, 'r') as file:
pattern = re.compile(r' Send (\d+) events')
pattern = re.compile(r'^Send (\d+) events')
for line in file:
match = pattern.search(line)
if match:
Expand All @@ -209,7 +209,7 @@ def get_recorded_events(path):
log_lines = file.readlines()
events = []
first_event_pattern = re.compile(r'app_event_log:Saved event (\w+):(.*)$')
event_pattern = re.compile(r' Saved event (\w+):(.*)$')
event_pattern = re.compile(r'^Saved event (\w+):(.*)$')

current_event_name = ''

Expand Down
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 6e7a814

Please sign in to comment.