Skip to content

Commit

Permalink
fix: experiment user equals user property comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
bgiori committed Mar 14, 2024
1 parent de347f9 commit 0e66823
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Sources/Experiment/ExperimentUser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,14 @@ import Foundation
if let userPropertiesAnyValue = self.userPropertiesAnyValue, let otherUserPropertiesAnyValue = other.userPropertiesAnyValue {
userPropertiesAnyValueEqual = NSDictionary(dictionary: userPropertiesAnyValue).isEqual(to: otherUserPropertiesAnyValue)
} else {
userPropertiesAnyValueEqual = userProperties == nil && other.userProperties == nil
userPropertiesAnyValueEqual = userPropertiesAnyValue == nil && other.userPropertiesAnyValue == nil
}

var userPropertiesEqual = false
if let userProperties = self.userProperties, let otherUserProperties = other.userProperties {
userPropertiesEqual = NSDictionary(dictionary: userProperties).isEqual(to: otherUserProperties)
} else {
userPropertiesEqual = userProperties == nil && other.userProperties == nil
}

var groupPropertiesEqual = false
Expand All @@ -159,6 +166,7 @@ import Foundation
self.carrier == other.carrier &&
self.library == other.library &&
userPropertiesAnyValueEqual &&
userPropertiesEqual &&
self.groups == other.groups &&
groupPropertiesEqual
}
Expand Down
5 changes: 5 additions & 0 deletions Tests/ExperimentTests/ExperimentUserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,9 @@ class ExperimentUserTests: XCTestCase {
.build()
XCTAssert(expected == mergedUser)
}

func testEqualsOnlyUserProperties() {
let user = ExperimentUserBuilder().userProperty("test", value: "test").build()
XCTAssertTrue(user != ExperimentUser())
}
}

0 comments on commit 0e66823

Please sign in to comment.