From e7bb6869512a2e064096482c7d135f9f16f53f04 Mon Sep 17 00:00:00 2001 From: Ajay Subramanya Date: Tue, 4 Jun 2024 15:36:35 -0500 Subject: [PATCH] Lowercasing when comparing tokens --- Sources/KlaviyoSwift/KlaviyoState.swift | 7 +++++++ .../KlaviyoSwiftTests/KlaviyoStateTests.swift | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/Sources/KlaviyoSwift/KlaviyoState.swift b/Sources/KlaviyoSwift/KlaviyoState.swift index dbf6a907..58014bf8 100644 --- a/Sources/KlaviyoSwift/KlaviyoState.swift +++ b/Sources/KlaviyoSwift/KlaviyoState.swift @@ -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 { diff --git a/Tests/KlaviyoSwiftTests/KlaviyoStateTests.swift b/Tests/KlaviyoSwiftTests/KlaviyoStateTests.swift index a59445c8..83073daa 100644 --- a/Tests/KlaviyoSwiftTests/KlaviyoStateTests.swift +++ b/Tests/KlaviyoSwiftTests/KlaviyoStateTests.swift @@ -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!) + } }