Skip to content

Commit a50b14f

Browse files
Merge pull request #24 from Iterable/itbl-5475-refactor-consts
[Itbl-5475] - refactor consts
2 parents b0a4036 + 7b945f8 commit a50b14f

18 files changed

+337
-408
lines changed

Tests/swift-sdk-swift-tests/DeferredDeeplinkTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ class DeferredDeeplinkTests: XCTestCase {
3333
"messageId" : "1"
3434
]
3535
let networkSession = MockNetworkSession(statusCode: 200, json: json)
36-
36+
3737
let config = IterableConfig()
3838
config.checkForDeferredDeeplink = true
3939
let urlDelegate = MockUrlDelegate(returnValue: true)
4040
urlDelegate.callback = {(url, context) in
41+
TestUtils.validate(request: networkSession.request!, apiEndPoint: .ITBL_ENDPOINT_LINKS, path: .ITBL_PATH_DDL_MATCH)
4142
expectation.fulfill()
4243
XCTAssertEqual(url.absoluteString, "zeeDestinationUrl")
4344
}

Tests/swift-sdk-swift-tests/IterableAPIResponseTests.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class IterableAPIResponseTests: XCTestCase {
2424
let xpectation = expectation(description: "response code 200")
2525
let networkSession = MockNetworkSession(statusCode: 200)
2626
let apiInternal = IterableAPIInternal.initialize(apiKey: "", networkSession: networkSession)
27-
let request = apiInternal.createPostRequest(forAction: "", withBody: [:])!
27+
let request = apiInternal.createPostRequest(forPath: "", withBody: [:])!
2828
apiInternal.sendRequest(request,
2929
onSuccess: { (result) in
3030
xpectation.fulfill()
@@ -37,7 +37,7 @@ class IterableAPIResponseTests: XCTestCase {
3737
let xpectation = expectation(description: "no data")
3838
let networkSession = MockNetworkSession(statusCode: 200, data: nil)
3939
let apiInternal = IterableAPIInternal.initialize(apiKey: "", networkSession: networkSession)
40-
let request = apiInternal.createPostRequest(forAction: "", withBody: [:])!
40+
let request = apiInternal.createPostRequest(forPath: "", withBody: [:])!
4141
apiInternal.sendRequest(request, onSuccess: nil) { (reason, data) in
4242
xpectation.fulfill()
4343
XCTAssert(reason!.lowercased().contains("no data"))
@@ -50,7 +50,7 @@ class IterableAPIResponseTests: XCTestCase {
5050
let data = "{'''}}".data(using: .utf8)!
5151
let networkSession = MockNetworkSession(statusCode: 200, data: data)
5252
let apiInternal = IterableAPIInternal.initialize(apiKey: "", networkSession: networkSession)
53-
let request = apiInternal.createPostRequest(forAction: "", withBody: [:])!
53+
let request = apiInternal.createPostRequest(forPath: "", withBody: [:])!
5454
apiInternal.sendRequest(request, onSuccess: nil) { (reason, data) in
5555
xpectation.fulfill()
5656
XCTAssert(reason!.lowercased().contains("could not parse json"))
@@ -62,7 +62,7 @@ class IterableAPIResponseTests: XCTestCase {
6262
let xpectation = expectation(description: "400 without message")
6363
let networkSession = MockNetworkSession(statusCode: 400)
6464
let apiInternal = IterableAPIInternal.initialize(apiKey: "", networkSession: networkSession)
65-
let request = apiInternal.createPostRequest(forAction: "", withBody: [:])!
65+
let request = apiInternal.createPostRequest(forPath: "", withBody: [:])!
6666
apiInternal.sendRequest(request, onSuccess: nil) { (reason, data) in
6767
xpectation.fulfill()
6868
XCTAssert(reason!.lowercased().contains("invalid request"))
@@ -74,7 +74,7 @@ class IterableAPIResponseTests: XCTestCase {
7474
let xpectation = expectation(description: "400 with message")
7575
let networkSession = MockNetworkSession(statusCode: 400, json: ["msg" : "Test error"])
7676
let apiInternal = IterableAPIInternal.initialize(apiKey: "", networkSession: networkSession)
77-
let request = apiInternal.createPostRequest(forAction: "", withBody: [:])!
77+
let request = apiInternal.createPostRequest(forPath: "", withBody: [:])!
7878
apiInternal.sendRequest(request, onSuccess: nil) { (reason, data) in
7979
xpectation.fulfill()
8080
XCTAssert(reason!.lowercased().contains("test error"))
@@ -86,7 +86,7 @@ class IterableAPIResponseTests: XCTestCase {
8686
let xpectation = expectation(description: "401")
8787
let networkSession = MockNetworkSession(statusCode: 401)
8888
let apiInternal = IterableAPIInternal.initialize(apiKey: "", networkSession: networkSession)
89-
let request = apiInternal.createPostRequest(forAction: "", withBody: [:])!
89+
let request = apiInternal.createPostRequest(forPath: "", withBody: [:])!
9090
apiInternal.sendRequest(request, onSuccess: nil) { (reason, data) in
9191
xpectation.fulfill()
9292
XCTAssert(reason!.lowercased().contains("invalid api key"))
@@ -98,7 +98,7 @@ class IterableAPIResponseTests: XCTestCase {
9898
let xpectation = expectation(description: "500")
9999
let networkSession = MockNetworkSession(statusCode: 500)
100100
let apiInternal = IterableAPIInternal.initialize(apiKey: "", networkSession: networkSession)
101-
let request = apiInternal.createPostRequest(forAction: "", withBody: [:])!
101+
let request = apiInternal.createPostRequest(forPath: "", withBody: [:])!
102102
apiInternal.sendRequest(request, onSuccess: nil) { (reason, data) in
103103
xpectation.fulfill()
104104
XCTAssert(reason!.lowercased().contains("internal server error"))
@@ -110,7 +110,7 @@ class IterableAPIResponseTests: XCTestCase {
110110
let xpectation = expectation(description: "non 200")
111111
let networkSession = MockNetworkSession(statusCode: 302)
112112
let apiInternal = IterableAPIInternal.initialize(apiKey: "", networkSession: networkSession)
113-
let request = apiInternal.createPostRequest(forAction: "", withBody: [:])!
113+
let request = apiInternal.createPostRequest(forPath: "", withBody: [:])!
114114
apiInternal.sendRequest(request, onSuccess: nil) { (reason, data) in
115115
xpectation.fulfill()
116116
XCTAssert(reason!.lowercased().contains("non-200 response"))
@@ -122,7 +122,7 @@ class IterableAPIResponseTests: XCTestCase {
122122
let xpectation = expectation(description: "no network response")
123123
let networkSession = NoNetworkNetworkSession()
124124
let apiInternal = IterableAPIInternal.initialize(apiKey: "", networkSession: networkSession)
125-
let request = apiInternal.createPostRequest(forAction: "", withBody: [:])!
125+
let request = apiInternal.createPostRequest(forPath: "", withBody: [:])!
126126
apiInternal.sendRequest(request, onSuccess: nil) { (reason, data) in
127127
xpectation.fulfill()
128128
XCTAssert(reason!.lowercased().contains("nsurlerrordomain"))
@@ -143,7 +143,7 @@ class IterableAPIResponseTests: XCTestCase {
143143
}
144144

145145
let apiInternal = IterableAPIInternal.initialize(apiKey: "")
146-
var request = apiInternal.createPostRequest(forAction: "", withBody: [:])!
146+
var request = apiInternal.createPostRequest(forPath: "", withBody: [:])!
147147
request.timeoutInterval = 0.1
148148
apiInternal.sendRequest(request, onSuccess: nil) { (reason, data) in
149149
xpectation.fulfill()

Tests/swift-sdk-swift-tests/IterableAPITests.swift

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ class IterableAPITests: XCTestCase {
4343
IterableAPI.initialize(apiKey: IterableAPITests.apiKey, networkSession: networkSession)
4444
IterableAPI.email = IterableAPITests.email
4545
IterableAPI.track(event: eventName, dataFields: nil, onSuccess: { (json) in
46-
TestUtils.validate(request: networkSession.request!, requestType: .post, apiEndPoint: ITBConsts.apiEndpoint, path: ENDPOINT_TRACK, queryParams: [(name: "api_key", IterableAPITests.apiKey)])
46+
TestUtils.validate(request: networkSession.request!, requestType: .post, apiEndPoint: .ITBL_ENDPOINT_API, path: .ITBL_PATH_TRACK, queryParams: [(name: "api_key", IterableAPITests.apiKey)])
4747
let body = networkSession.getRequestBody()
48-
TestUtils.validateElementPresent(withName: ITBL_KEY_EVENT_NAME, andValue: eventName, inDictionary: body)
49-
TestUtils.validateElementPresent(withName: ITBL_KEY_EMAIL, andValue: IterableAPITests.email, inDictionary: body)
48+
TestUtils.validateElementPresent(withName: AnyHashable.ITBL_KEY_EVENT_NAME, andValue: eventName, inDictionary: body)
49+
TestUtils.validateElementPresent(withName: AnyHashable.ITBL_KEY_EMAIL, andValue: IterableAPITests.email, inDictionary: body)
5050
expectation.fulfill()
5151
}) { (reason, data) in
5252
expectation.fulfill()
@@ -88,11 +88,11 @@ class IterableAPITests: XCTestCase {
8888
IterableAPI.email = IterableAPITests.email
8989
let dataFields: Dictionary<String, String> = ["var1" : "val1", "var2" : "val2"]
9090
IterableAPI.updateUser(dataFields, mergeNestedObjects: true, onSuccess: {(json) in
91-
TestUtils.validate(request: networkSession.request!, requestType: .post, apiEndPoint: ITBConsts.apiEndpoint, path: ENDPOINT_UPDATE_USER, queryParams: [(name: "api_key", IterableAPITests.apiKey)])
91+
TestUtils.validate(request: networkSession.request!, requestType: .post, apiEndPoint: .ITBL_ENDPOINT_API, path: .ITBL_PATH_UPDATE_USER, queryParams: [(name: "api_key", IterableAPITests.apiKey)])
9292
let body = networkSession.getRequestBody()
93-
TestUtils.validateElementPresent(withName: ITBL_KEY_EMAIL, andValue: IterableAPITests.email, inDictionary: body)
94-
TestUtils.validateElementPresent(withName: ITBL_KEY_MERGE_NESTED, andValue: true, inDictionary: body)
95-
TestUtils.validateElementPresent(withName: ITBL_KEY_DATA_FIELDS, andValue: dataFields, inDictionary: body)
93+
TestUtils.validateElementPresent(withName: AnyHashable.ITBL_KEY_EMAIL, andValue: IterableAPITests.email, inDictionary: body)
94+
TestUtils.validateElementPresent(withName: AnyHashable.ITBL_KEY_MERGE_NESTED, andValue: true, inDictionary: body)
95+
TestUtils.validateElementPresent(withName: AnyHashable.ITBL_KEY_DATA_FIELDS, andValue: dataFields, inDictionary: body)
9696
expectation.fulfill()
9797
}) {(reason, _) in
9898
if let reason = reason {
@@ -117,12 +117,12 @@ class IterableAPITests: XCTestCase {
117117
onSuccess: {json in
118118
TestUtils.validate(request: networkSession.request!,
119119
requestType: .post,
120-
apiEndPoint: ITBConsts.apiEndpoint,
121-
path: ENDPOINT_UPDATE_EMAIL,
120+
apiEndPoint: .ITBL_ENDPOINT_API,
121+
path: .ITBL_PATH_UPDATE_EMAIL,
122122
queryParams: [(name: "api_key", value: IterableAPITests.apiKey)])
123123
let body = networkSession.getRequestBody()
124-
TestUtils.validateElementPresent(withName: ITBL_KEY_NEW_EMAIL, andValue: newEmail, inDictionary: body)
125-
TestUtils.validateElementPresent(withName: ITBL_KEY_CURRENT_EMAIL, andValue: IterableAPITests.email, inDictionary: body)
124+
TestUtils.validateElementPresent(withName: AnyHashable.ITBL_KEY_NEW_EMAIL, andValue: newEmail, inDictionary: body)
125+
TestUtils.validateElementPresent(withName: AnyHashable.ITBL_KEY_CURRENT_EMAIL, andValue: IterableAPITests.email, inDictionary: body)
126126
XCTAssertEqual(IterableAPI.email, newEmail)
127127
expectation.fulfill()
128128
},
@@ -189,7 +189,7 @@ class IterableAPITests: XCTestCase {
189189
let body = networkSession.getRequestBody() as! [String : Any]
190190
TestUtils.validateElementPresent(withName: "email", andValue: "[email protected]", inDictionary: body)
191191
TestUtils.validateMatch(keyPath: KeyPath("device.applicationName"), value: "my-push-integration", inDictionary: body)
192-
TestUtils.validateMatch(keyPath: KeyPath("device.platform"), value: ITBL_KEY_APNS_SANDBOX, inDictionary: body)
192+
TestUtils.validateMatch(keyPath: KeyPath("device.platform"), value: String.ITBL_KEY_APNS_SANDBOX, inDictionary: body)
193193
TestUtils.validateMatch(keyPath: KeyPath("device.token"), value: (token as NSData).iteHexadecimalString(), inDictionary: body)
194194

195195
// more device fields
@@ -249,9 +249,9 @@ class IterableAPITests: XCTestCase {
249249
networkSession.callback = nil
250250
IterableAPI.disableDeviceForCurrentUser(withOnSuccess: { (json) in
251251
let body = networkSession.getRequestBody() as! [String : Any]
252-
TestUtils.validate(request: networkSession.request!, requestType: .post, apiEndPoint: ITBConsts.apiEndpoint, path: ENDPOINT_DISABLE_DEVICE, queryParams: [(name: ITBL_KEY_API_KEY, value: IterableAPITests.apiKey)])
253-
TestUtils.validateElementPresent(withName: ITBL_KEY_TOKEN, andValue: (token as NSData).iteHexadecimalString(), inDictionary: body)
254-
TestUtils.validateElementPresent(withName: ITBL_KEY_EMAIL, andValue: "[email protected]", inDictionary: body)
252+
TestUtils.validate(request: networkSession.request!, requestType: .post, apiEndPoint: .ITBL_ENDPOINT_API, path: .ITBL_PATH_DISABLE_DEVICE, queryParams: [(name: AnyHashable.ITBL_KEY_API_KEY, value: IterableAPITests.apiKey)])
253+
TestUtils.validateElementPresent(withName: AnyHashable.ITBL_KEY_TOKEN, andValue: (token as NSData).iteHexadecimalString(), inDictionary: body)
254+
TestUtils.validateElementPresent(withName: AnyHashable.ITBL_KEY_EMAIL, andValue: "[email protected]", inDictionary: body)
255255
expectation.fulfill()
256256
}) { (errorMessage, data) in
257257
expectation.fulfill()
@@ -275,10 +275,10 @@ class IterableAPITests: XCTestCase {
275275
networkSession.callback = nil
276276
IterableAPI.disableDeviceForAllUsers(withOnSuccess: { (json) in
277277
let body = networkSession.getRequestBody() as! [String : Any]
278-
TestUtils.validate(request: networkSession.request!, requestType: .post, apiEndPoint: ITBConsts.apiEndpoint, path: ENDPOINT_DISABLE_DEVICE, queryParams: [(name: ITBL_KEY_API_KEY, value: IterableAPITests.apiKey)])
279-
TestUtils.validateElementPresent(withName: ITBL_KEY_TOKEN, andValue: (token as NSData).iteHexadecimalString(), inDictionary: body)
280-
TestUtils.validateElementNotPresent(withName: ITBL_KEY_EMAIL, inDictionary: body)
281-
TestUtils.validateElementNotPresent(withName: ITBL_KEY_USER_ID, inDictionary: body)
278+
TestUtils.validate(request: networkSession.request!, requestType: .post, apiEndPoint: .ITBL_ENDPOINT_API, path: .ITBL_PATH_DISABLE_DEVICE, queryParams: [(name: AnyHashable.ITBL_KEY_API_KEY, value: IterableAPITests.apiKey)])
279+
TestUtils.validateElementPresent(withName: AnyHashable.ITBL_KEY_TOKEN, andValue: (token as NSData).iteHexadecimalString(), inDictionary: body)
280+
TestUtils.validateElementNotPresent(withName: AnyHashable.ITBL_KEY_EMAIL, inDictionary: body)
281+
TestUtils.validateElementNotPresent(withName: AnyHashable.ITBL_KEY_USER_ID, inDictionary: body)
282282
expectation.fulfill()
283283
}) { (errorMessage, data) in
284284
expectation.fulfill()
@@ -320,9 +320,9 @@ class IterableAPITests: XCTestCase {
320320

321321
IterableAPI.track(purchase: 10.55, items: [], dataFields: nil, onSuccess: { (json) in
322322
let body = networkSession.getRequestBody() as! [String : Any]
323-
TestUtils.validate(request: networkSession.request!, requestType: .post, apiEndPoint: ITBConsts.apiEndpoint, path: ENDPOINT_COMMERCE_TRACK_PURCHASE, queryParams: [(name: ITBL_KEY_API_KEY, value: IterableAPITests.apiKey)])
324-
TestUtils.validateMatch(keyPath: KeyPath("\(ITBL_KEY_USER).\(ITBL_KEY_USER_ID)"), value: "zeeUserId", inDictionary: body)
325-
TestUtils.validateElementPresent(withName: ITBL_KEY_TOTAL, andValue: 10.55, inDictionary: body)
323+
TestUtils.validate(request: networkSession.request!, requestType: .post, apiEndPoint: .ITBL_ENDPOINT_API, path: .ITBL_PATH_COMMERCE_TRACK_PURCHASE, queryParams: [(name: AnyHashable.ITBL_KEY_API_KEY, value: IterableAPITests.apiKey)])
324+
TestUtils.validateMatch(keyPath: KeyPath("\(AnyHashable.ITBL_KEY_USER).\(AnyHashable.ITBL_KEY_USER_ID)"), value: "zeeUserId", inDictionary: body)
325+
TestUtils.validateElementPresent(withName: AnyHashable.ITBL_KEY_TOTAL, andValue: 10.55, inDictionary: body)
326326

327327
expectation.fulfill()
328328
}) { (reason, _) in
@@ -350,10 +350,10 @@ class IterableAPITests: XCTestCase {
350350

351351
IterableAPI.track(purchase: total, items: items, dataFields: nil, onSuccess: { (json) in
352352
let body = networkSession.getRequestBody() as! [String : Any]
353-
TestUtils.validate(request: networkSession.request!, requestType: .post, apiEndPoint: ITBConsts.apiEndpoint, path: ENDPOINT_COMMERCE_TRACK_PURCHASE, queryParams: [(name: ITBL_KEY_API_KEY, value: IterableAPITests.apiKey)])
354-
TestUtils.validateMatch(keyPath: KeyPath("\(ITBL_KEY_USER).\(ITBL_KEY_EMAIL)"), value: "[email protected]", inDictionary: body)
355-
TestUtils.validateElementPresent(withName: ITBL_KEY_TOTAL, andValue: total, inDictionary: body)
356-
let itemsElement = body[ITBL_KEY_ITEMS] as! [[AnyHashable : Any]]
353+
TestUtils.validate(request: networkSession.request!, requestType: .post, apiEndPoint: .ITBL_ENDPOINT_API, path: .ITBL_PATH_COMMERCE_TRACK_PURCHASE, queryParams: [(name: AnyHashable.ITBL_KEY_API_KEY, value: IterableAPITests.apiKey)])
354+
TestUtils.validateMatch(keyPath: KeyPath("\(AnyHashable.ITBL_KEY_USER).\(AnyHashable.ITBL_KEY_EMAIL)"), value: "[email protected]", inDictionary: body)
355+
TestUtils.validateElementPresent(withName: AnyHashable.ITBL_KEY_TOTAL, andValue: total, inDictionary: body)
356+
let itemsElement = body[AnyHashable.ITBL_KEY_ITEMS] as! [[AnyHashable : Any]]
357357
XCTAssertEqual(itemsElement.count, 1)
358358
let firstElement = itemsElement[0]
359359
TestUtils.validateElementPresent(withName: "id", andValue: "id1", inDictionary: firstElement)

0 commit comments

Comments
 (0)