From adff27182aa4c8181f932c669c02201bedbb89e2 Mon Sep 17 00:00:00 2001 From: Ajay Subramanya Date: Wed, 10 Apr 2024 11:04:29 -0500 Subject: [PATCH] trimming white spaces in identifiers --- Sources/KlaviyoSwift/KlaviyoState.swift | 2 +- .../StateManagementEdgeCaseTests.swift | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Sources/KlaviyoSwift/KlaviyoState.swift b/Sources/KlaviyoSwift/KlaviyoState.swift index 6f9a72d4..dbf6a907 100644 --- a/Sources/KlaviyoSwift/KlaviyoState.swift +++ b/Sources/KlaviyoSwift/KlaviyoState.swift @@ -506,7 +506,7 @@ extension Profile { extension String { fileprivate func isNotEmptyOrSame(as state: String?, identifier: String) -> Bool { - let incoming = self + let incoming = trimmingCharacters(in: .whitespacesAndNewlines) if incoming.isEmpty || incoming == state { logDevWarning(for: identifier) } diff --git a/Tests/KlaviyoSwiftTests/StateManagementEdgeCaseTests.swift b/Tests/KlaviyoSwiftTests/StateManagementEdgeCaseTests.swift index 09449939..6acf4426 100644 --- a/Tests/KlaviyoSwiftTests/StateManagementEdgeCaseTests.swift +++ b/Tests/KlaviyoSwiftTests/StateManagementEdgeCaseTests.swift @@ -158,6 +158,13 @@ class StateManagementEdgeCaseTests: XCTestCase { _ = await store.send(.setEmail("")) } + func testSetEmailWithWhiteSpace() async throws { + let initialState = INITIALIZED_TEST_STATE() + let store = TestStore(initialState: initialState, reducer: KlaviyoReducer()) + + _ = await store.send(.setEmail(" ")) + } + // MARK: - Set External Id @MainActor @@ -196,6 +203,13 @@ class StateManagementEdgeCaseTests: XCTestCase { _ = await store.send(.setExternalId("")) } + func testSetExternalIdWithWhiteSpaces() async throws { + let initialState = INITIALIZED_TEST_STATE() + let store = TestStore(initialState: initialState, reducer: KlaviyoReducer()) + + _ = await store.send(.setExternalId("")) + } + // MARK: - Set Phone number @MainActor @@ -233,6 +247,13 @@ class StateManagementEdgeCaseTests: XCTestCase { _ = await store.send(.setPhoneNumber("")) } + func testSetPhoneNumberWithWhiteSpaces() async throws { + let initialState = INITIALIZED_TEST_STATE() + let store = TestStore(initialState: initialState, reducer: KlaviyoReducer()) + + _ = await store.send(.setPhoneNumber("")) + } + // MARK: - Set Push Token @MainActor