-
Notifications
You must be signed in to change notification settings - Fork 294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Require Encodable
body for all GET
requests
#1166
Changes from all commits
ed9f715
6190fb3
eea36bf
908936b
fd5d2dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Foundation | ||
|
||
/// The GET parameters for `v1/payment_methods/amex_rewards_balance` | ||
struct BTAmexRewardsBalanceRequest: Encodable { | ||
|
||
private let currencyIsoCode: String | ||
private let paymentMethodNonce: String | ||
|
||
init(currencyIsoCode: String, paymentMethodNonce: String) { | ||
self.currencyIsoCode = currencyIsoCode | ||
self.paymentMethodNonce = paymentMethodNonce | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/// The POST body for `v1/configuration` | ||
struct BTConfigurationRequest: Encodable { | ||
|
||
private let configVersion = "3" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,11 +99,17 @@ class BTHTTP: NSObject, NSCopying, URLSessionDelegate { | |
|
||
// MARK: - HTTP Methods | ||
|
||
func get(_ path: String, parameters: [String: Any]? = nil, shouldCache: Bool = false, completion: @escaping RequestCompletion) { | ||
if shouldCache { | ||
httpRequestWithCaching(method: "GET", path: path, parameters: parameters, completion: completion) | ||
} else { | ||
httpRequest(method: "GET", path: path, parameters: parameters, completion: completion) | ||
func get(_ path: String, parameters: Encodable? = nil, shouldCache: Bool = false, completion: @escaping RequestCompletion) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In a future PR, we can make |
||
do { | ||
let dict = try parameters?.toDictionary() | ||
|
||
if shouldCache { | ||
httpRequestWithCaching(method: "GET", path: path, parameters: dict, completion: completion) | ||
} else { | ||
httpRequest(method: "GET", path: path, parameters: dict, completion: completion) | ||
} | ||
} catch let error { | ||
completion(nil, nil, error) | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,20 @@ class BTAmericanExpressClient_Tests: XCTestCase { | |
super.setUp() | ||
mockAPIClient = MockAPIClient(authorization: "development_tokenization_key")! | ||
amexClient = BTAmericanExpressClient(apiClient: mockAPIClient) | ||
} | ||
} | ||
|
||
func testGetRewardsBalance_formatsGETRequest() async { | ||
let result = try? await amexClient!.getRewardsBalance(forNonce: "fake-nonce", currencyISOCode: "fake-code") | ||
|
||
XCTAssertEqual(mockAPIClient.lastGETPath, "v1/payment_methods/amex_rewards_balance") | ||
|
||
guard let lastGetParameters = mockAPIClient.lastGETParameters else { | ||
XCTFail("Expected GET parameters") | ||
return | ||
} | ||
XCTAssertEqual(lastGetParameters["currencyIsoCode"] as! String, "fake-code") | ||
XCTAssertEqual(lastGetParameters["paymentMethodNonce"] as! String, "fake-nonce") | ||
Comment on lines
+26
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This work has been a good exercise, since it reveals that we aren't testing the formatting of most our JSON bodies for both GET & POST requests right now 😬 (as also evidenced in #1151) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't completely understand the example that reveals we aren't testing the formatting of JSON bodies. Maybe understanding it would give me the answer to my question. Q: Why do we care about the formatting of the JSON as long as the key value pairs are the same? |
||
} | ||
|
||
func testGetRewardsBalance_returnsSendsAnalyticsEventOnSuccess() { | ||
let responseBody = [ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit for a future PR but we should update this to
currencyISOCode
to match our style guide preferences. Same in theinit