Skip to content

Commit 4f7d434

Browse files
adds unit tests and slight refactor
1 parent 391c617 commit 4f7d434

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

swift-sdk/Internal/InternalIterableAPI.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
7878
self.dependencyContainer.createAuthManager(config: self.config)
7979
}()
8080

81+
var apiEndPoint: String {
82+
get {
83+
_apiEndPoint
84+
}
85+
}
86+
8187
// MARK: - SDK Functions
8288

8389
@discardableResult func handleUniversalLink(_ url: URL) -> Bool {
@@ -400,7 +406,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
400406
// MARK: - Private/Internal
401407

402408
private var config: IterableConfig
403-
private var apiEndPoint: String
409+
private var _apiEndPoint: String
404410

405411
/// Following are needed for handling pending notification and deep link.
406412
static var pendingNotificationResponse: NotificationResponseProtocol?
@@ -555,7 +561,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
555561
}
556562
}
557563

558-
private static func getApiEndpoint(apiEndPointOverride: String?, config: IterableConfig) -> String {
564+
private static func setApiEndpoint(apiEndPointOverride: String?, config: IterableConfig) -> String {
559565
let apiEndPoint = config.dataRegion
560566
return apiEndPointOverride ?? apiEndPoint
561567
}
@@ -570,7 +576,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
570576
self.apiKey = apiKey
571577
self.launchOptions = launchOptions
572578
self.config = config
573-
apiEndPoint = InternalIterableAPI.getApiEndpoint(apiEndPointOverride: apiEndPointOverride, config: config)
579+
_apiEndPoint = InternalIterableAPI.setApiEndpoint(apiEndPointOverride: apiEndPointOverride, config: config)
574580
self.dependencyContainer = dependencyContainer
575581
dateProvider = dependencyContainer.dateProvider
576582
networkSession = dependencyContainer.networkSession

tests/unit-tests/IterableAPITests.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class IterableAPITests: XCTestCase {
1111
private static let apiKey = "zeeApiKey"
1212
private static let email = "[email protected]"
1313
private static let userId = "testUserId"
14+
private static let apiEndPointUS = "https://api.iterable.com"
15+
private static let apiEndPointEU = "https://api.eu.iterable.com"
1416

1517
override func setUp() {
1618
super.setUp()
@@ -34,6 +36,32 @@ class IterableAPITests: XCTestCase {
3436
XCTAssertEqual(internalAPI.apiKey, IterableAPITests.apiKey)
3537
}
3638

39+
func testInitializeWithDefaultDataRegion() {
40+
let prodIntegrationName = "the-best-app-ever"
41+
42+
let config = IterableConfig()
43+
config.pushIntegrationName = prodIntegrationName
44+
config.inAppDisplayInterval = 1.0
45+
config.dataRegion = IterableDataRegion.US
46+
47+
let internalAPI = InternalIterableAPI.initializeForTesting(apiKey: IterableAPITests.apiKey, config: config)
48+
49+
XCTAssertEqual(internalAPI.apiEndPoint, IterableAPITests.apiEndPointUS)
50+
}
51+
52+
func testInitializeWithEUDataRegion() {
53+
let prodIntegrationName = "the-best-app-ever"
54+
55+
let config = IterableConfig()
56+
config.pushIntegrationName = prodIntegrationName
57+
config.inAppDisplayInterval = 1.0
58+
config.dataRegion = IterableDataRegion.EU
59+
60+
let internalAPI = InternalIterableAPI.initializeForTesting(apiKey: IterableAPITests.apiKey, config: config)
61+
62+
XCTAssertEqual(internalAPI.apiEndPoint, IterableAPITests.apiEndPointEU)
63+
}
64+
3765
func testInitializeCheckEndpoint() {
3866
let expectation1 = XCTestExpectation(description: "api endpoint called")
3967

0 commit comments

Comments
 (0)