Skip to content

Commit

Permalink
Lowercasing when comparing tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaysubra committed Jun 4, 2024
1 parent 176e395 commit e7bb686
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Sources/KlaviyoSwift/KlaviyoState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ struct KlaviyoState: Equatable, Codable {
case pushBackground
case deviceData
}

static func ==(lhs: PushTokenData, rhs: PushTokenData) -> Bool {
lhs.pushToken.lowercased() == rhs.pushToken.lowercased() &&
lhs.pushEnablement == rhs.pushEnablement &&
lhs.pushBackground == rhs.pushBackground &&
lhs.deviceData == rhs.deviceData
}
}

enum PushEnablement: String, Codable {
Expand Down
18 changes: 18 additions & 0 deletions Tests/KlaviyoSwiftTests/KlaviyoStateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,22 @@ final class KlaviyoStateTests: XCTestCase {
// Fake value to test availability
XCTAssertEqual(KlaviyoState.PushEnablement.create(from: UNAuthorizationStatus(rawValue: 50)!), .notDetermined)
}

func testPushTokenDataEquatableIgnoresCaseForPushToken() {
let pushTokenData = ["abcd", "ABCD"].map { tokens in
KlaviyoState.PushTokenData(pushToken: tokens, pushEnablement: .authorized, pushBackground: .available, deviceData: .init(context: environment.analytics.appContextInfo()))
}

XCTAssertEqual(pushTokenData.first!, pushTokenData.last!)
}

func testPushTokenDataEquatableWithDifferentEnablement() {
let pushTokenData = [
("abcd", KlaviyoState.PushEnablement.authorized),
("ABCD", KlaviyoState.PushEnablement.denied)
].map { tuple in
KlaviyoState.PushTokenData(pushToken: tuple.0, pushEnablement: tuple.1, pushBackground: .available, deviceData: .init(context: environment.analytics.appContextInfo()))
}
XCTAssertNotEqual(pushTokenData.first!, pushTokenData.last!)
}
}

0 comments on commit e7bb686

Please sign in to comment.