-
Notifications
You must be signed in to change notification settings - Fork 121
Update OrdersRemote with async/throws network methods to parse orders response in a background thread
#15982
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
Changes from 2 commits
f7e16d5
de902e5
aa00e4c
8377aba
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 |
|---|---|---|
|
|
@@ -60,57 +60,42 @@ final class OrdersRemoteTests: XCTestCase { | |
|
|
||
| /// Verifies that loadAllOrders properly parses the `orders-load-all` sample response. | ||
| /// | ||
| func testLoadAllOrdersProperlyReturnsParsedOrders() throws { | ||
| func testLoadAllOrdersProperlyReturnsParsedOrders() async throws { | ||
|
||
| // Given | ||
| let remote = OrdersRemote(network: network) | ||
|
|
||
| network.simulateResponse(requestUrlSuffix: "orders", filename: "orders-load-all") | ||
|
|
||
| // When | ||
| var result: Result<[Order], Error>? | ||
| waitForExpectation { expectation in | ||
| remote.loadAllOrders(for: sampleSiteID) { aResult in | ||
| result = aResult | ||
| expectation.fulfill() | ||
| } | ||
| } | ||
| let orders = try await remote.loadAllOrders(for: sampleSiteID) | ||
|
|
||
| // Then | ||
| let orders = try XCTUnwrap(result?.get()) | ||
| XCTAssert(orders.count == 4) | ||
| } | ||
|
|
||
| /// Verifies that loadAllOrders properly relays Networking Layer errors. | ||
| /// | ||
| func testLoadAllOrdersProperlyRelaysNetworkingErrors() throws { | ||
| func testLoadAllOrdersProperlyRelaysNetworkingErrors() async throws { | ||
| // Given | ||
| let remote = OrdersRemote(network: network) | ||
|
|
||
| // When | ||
| var result: Result<[Order], Error>? | ||
| waitForExpectation { expectation in | ||
| remote.loadAllOrders(for: sampleSiteID) { aResult in | ||
| result = aResult | ||
| expectation.fulfill() | ||
| } | ||
| // When & Then | ||
| do { | ||
| _ = try await remote.loadAllOrders(for: sampleSiteID) | ||
| XCTFail("Expected error to be thrown") | ||
| } catch { | ||
| XCTAssertEqual(error as? NetworkError, .notFound(response: nil)) | ||
| } | ||
|
|
||
| // Then | ||
| XCTAssertTrue(try XCTUnwrap(result).isFailure) | ||
| } | ||
|
|
||
| func test_loadAllOrders_includes_modifiedAfter_parameter_when_provided() { | ||
| func test_loadAllOrders_includes_modifiedAfter_parameter_when_provided() async throws { | ||
| // Given | ||
| let remote = OrdersRemote(network: network) | ||
| let modifiedAfter = Date() | ||
| network.simulateResponse(requestUrlSuffix: "orders", filename: "orders-load-all") | ||
|
|
||
| // When | ||
| _ = waitFor { promise in | ||
| remote.loadAllOrders(for: self.sampleSiteID, modifiedAfter: modifiedAfter) { result in | ||
| promise(result) | ||
| } | ||
| } | ||
| _ = try await remote.loadAllOrders(for: sampleSiteID, modifiedAfter: modifiedAfter) | ||
|
|
||
| // Then | ||
| guard let queryParameters = network.queryParameters else { | ||
|
|
@@ -123,18 +108,14 @@ final class OrdersRemoteTests: XCTestCase { | |
| XCTAssertTrue(queryParameters.contains(expectedParam), "Expected to have param: \(expectedParam)") | ||
| } | ||
|
|
||
| func test_loadAllOrders_includes_customer_parameter_when_provided() { | ||
| func test_loadAllOrders_includes_customer_parameter_when_provided() async throws { | ||
| // Given | ||
| let remote = OrdersRemote(network: network) | ||
| network.simulateResponse(requestUrlSuffix: "orders", filename: "orders-load-all") | ||
| let expectedCustomerID: Int64 = 123 | ||
|
|
||
| // When | ||
| _ = waitFor { promise in | ||
| remote.loadAllOrders(for: self.sampleSiteID, customerID: expectedCustomerID) { result in | ||
| promise(result) | ||
| } | ||
| } | ||
| _ = try await remote.loadAllOrders(for: sampleSiteID, customerID: expectedCustomerID) | ||
|
|
||
| // Then | ||
| guard let queryParameters = network.queryParameters else { | ||
|
|
@@ -146,18 +127,14 @@ final class OrdersRemoteTests: XCTestCase { | |
| XCTAssertTrue(queryParameters.contains(expectedParam), "Expected to have param: \(expectedParam)") | ||
| } | ||
|
|
||
| func test_loadAllOrders_includes_product_parameter_when_provided() { | ||
| func test_loadAllOrders_includes_product_parameter_when_provided() async throws { | ||
| // Given | ||
| let remote = OrdersRemote(network: network) | ||
| network.simulateResponse(requestUrlSuffix: "orders", filename: "orders-load-all") | ||
| let expectedProductID: Int64 = 13 | ||
|
|
||
| // When | ||
| _ = waitFor { promise in | ||
| remote.loadAllOrders(for: self.sampleSiteID, productID: expectedProductID) { result in | ||
| promise(result) | ||
| } | ||
| } | ||
| _ = try await remote.loadAllOrders(for: sampleSiteID, productID: expectedProductID) | ||
|
|
||
| // Then | ||
| guard let queryParameters = network.queryParameters else { | ||
|
|
@@ -243,35 +220,33 @@ final class OrdersRemoteTests: XCTestCase { | |
|
|
||
| /// Verifies that searchOrders properly parses the `orders-load-all` sample response. | ||
| /// | ||
| func testSearchOrdersProperlyReturnsParsedOrders() { | ||
| func test_searchOrders_properly_returns_parsed_orders() async throws { | ||
| // Given | ||
| let remote = OrdersRemote(network: network) | ||
| let expectation = self.expectation(description: "Load All Orders") | ||
|
|
||
| network.simulateResponse(requestUrlSuffix: "orders", filename: "orders-load-all") | ||
|
|
||
| remote.searchOrders(for: sampleSiteID, keyword: String()) { (orders, error) in | ||
| XCTAssertNil(error) | ||
| XCTAssertNotNil(orders) | ||
| XCTAssert(orders!.count == 4) | ||
| expectation.fulfill() | ||
| } | ||
| // When | ||
| let orders = try await remote.searchOrders(for: sampleSiteID, keyword: String()) | ||
|
|
||
| wait(for: [expectation], timeout: Constants.expectationTimeout) | ||
| // Then | ||
| XCTAssert(orders.count == 4) | ||
| } | ||
|
|
||
| /// Verifies that searchOrders properly relays Networking Layer errors. | ||
| /// | ||
| func testSearchOrdersProperlyRelaysNetworkingErrors() { | ||
| func test_searchOrders_properly_relays_networking_error() async throws { | ||
| // Given | ||
| let remote = OrdersRemote(network: network) | ||
| let expectation = self.expectation(description: "Load All Orders") | ||
|
|
||
| remote.searchOrders(for: sampleSiteID, keyword: String()) { (orders, error) in | ||
| XCTAssertNil(orders) | ||
| XCTAssertNotNil(error) | ||
| expectation.fulfill() | ||
| do { | ||
| // When | ||
| _ = try await remote.searchOrders(for: sampleSiteID, keyword: String()) | ||
| XCTFail("Expected error to be thrown") | ||
| } catch { | ||
| // Then | ||
| XCTAssertEqual(error as? NetworkError, .notFound(response: nil)) | ||
| } | ||
|
|
||
| wait(for: [expectation], timeout: Constants.expectationTimeout) | ||
| } | ||
|
|
||
|
|
||
|
|
||
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: The alignment of these props seems to be off!
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.
Fixed the alignment in 8377aba.