Skip to content

Commit 2b00983

Browse files
committed
add tests for setEmail/setUserId callback
1 parent 6a14f63 commit 2b00983

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

tests/unit-tests/IterableAPITests.swift

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,67 @@ class IterableAPITests: XCTestCase {
165165

166166
wait(for: [expectation], timeout: testExpectationTimeout)
167167
}
168+
169+
func testSetEmailWithCallbackSuccess() {
170+
let expectation = XCTestExpectation(description: "Set email with callback success")
171+
172+
let config = IterableConfig()
173+
let networkSession = MockNetworkSession(statusCode: 200)
174+
let internalAPI = InternalIterableAPI.initializeForTesting(apiKey: IterableAPITests.apiKey, config: config, networkSession: mockNetworkSession)
175+
176+
internalAPI.setEmail("[email protected]") { error in
177+
XCTAssertNil(error)
178+
expectation.fulfill()
179+
}
180+
181+
wait(for: [expectation], timeout: testExpectationTimeout)
182+
}
183+
184+
func testSetEmailWithCallbackFailure() {
185+
let expectation = XCTestExpectation(description: "Set email with callback failure")
186+
187+
let config = IterableConfig()
188+
let networkSession = MockNetworkSession(statusCode: 400, responseData: nil)
189+
let internalAPI = InternalIterableAPI.initializeForTesting(apiKey: IterableAPITests.apiKey, config: config, networkSession: networkSession)
190+
191+
internalAPI.setEmail("invalid_email") { error in
192+
XCTAssertNotNil(error)
193+
XCTAssertEqual(error?.localizedDescription, "Invalid email address")
194+
expectation.fulfill()
195+
}
196+
197+
wait(for: [expectation], timeout: testExpectationTimeout)
198+
}
199+
200+
func testSetUserIdWithCallbackSuccess() {
201+
let expectation = XCTestExpectation(description: "Set user ID with callback success")
202+
203+
let config = IterableConfig()
204+
let networkSession = MockNetworkSession(statusCode: 200)
205+
let internalAPI = InternalIterableAPI.initializeForTesting(apiKey: IterableAPITests.apiKey, config: config, networkSession: mockNetworkSession)
206+
207+
internalAPI.setUserId("user123") { error in
208+
XCTAssertNil(error)
209+
expectation.fulfill()
210+
}
211+
212+
wait(for: [expectation], timeout: testExpectationTimeout)
213+
}
214+
215+
func testSetUserIdWithCallbackFailure() {
216+
let expectation = XCTestExpectation(description: "Set user ID with callback failure")
217+
218+
let config = IterableConfig()
219+
let networkSession = MockNetworkSession(statusCode: 400)
220+
let internalAPI = InternalIterableAPI.initializeForTesting(apiKey: IterableAPITests.apiKey, config: config, networkSession: mockNetworkSession)
221+
222+
internalAPI.setUserId("user123") { error in
223+
XCTAssertNotNil(error)
224+
expectation.fulfill()
225+
}
226+
227+
wait(for: [expectation], timeout: testExpectationTimeout)
228+
}
168229

169230
func testEmailPersistence() {
170231
let internalAPI = InternalIterableAPI.initializeForTesting()

0 commit comments

Comments
 (0)