Skip to content

Commit 13d9151

Browse files
ShipmentTrackingProviderListMapper - Add unit tests.
1 parent 71344ae commit 13d9151

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import XCTest
2+
@testable import Networking
3+
4+
/// ShipmentTrackingProviderListMapper Unit Tests
5+
///
6+
final class ShipmentTrackingProviderListMapperTests: XCTestCase {
7+
8+
/// Dummy Site ID.
9+
///
10+
private let dummySiteID: Int64 = 424242
11+
12+
func test_provider_fields_are_properly_parsed() throws {
13+
let shipmentTrackingProviders = try mapLoadShipmentTrackingProviderResponse()
14+
XCTAssertEqual(shipmentTrackingProviders.count, 19)
15+
16+
let shipmentProviderGroup = try XCTUnwrap(shipmentTrackingProviders.first(where:) { $0.name == "Australia" })
17+
18+
XCTAssertEqual(shipmentProviderGroup.providers.count, 2)
19+
XCTAssertTrue(shipmentProviderGroup.providers.contains(where: { $0.name == "Australia Post" }))
20+
XCTAssertTrue(shipmentProviderGroup.providers.contains(where: { $0.name == "Fastway Couriers" }))
21+
}
22+
23+
func test_provider_fields_are_properly_parsed_when_response_has_no_data_envelope() throws {
24+
let shipmentTrackingProviders = try mapLoadShipmentTrackingProviderResponseWithoutDataEnvelope()
25+
XCTAssertEqual(shipmentTrackingProviders.count, 19)
26+
27+
let shipmentProviderGroup = try XCTUnwrap(shipmentTrackingProviders.first(where:) { $0.name == "Australia" })
28+
29+
XCTAssertEqual(shipmentProviderGroup.providers.count, 2)
30+
XCTAssertTrue(shipmentProviderGroup.providers.contains(where: { $0.name == "Australia Post" }))
31+
XCTAssertTrue(shipmentProviderGroup.providers.contains(where: { $0.name == "Fastway Couriers" }))
32+
}
33+
}
34+
35+
/// Private Methods.
36+
///
37+
private extension ShipmentTrackingProviderListMapperTests {
38+
39+
/// Returns the ShipmentTrackingProviderListMapper output upon receiving `filename` (Data Encoded)
40+
///
41+
func mapShipmentTrackingProvider(from filename: String) throws -> [ShipmentTrackingProviderGroup] {
42+
guard let response = Loader.contentsOf(filename) else {
43+
throw ParsingError.unableToLoadFile
44+
}
45+
46+
return try! ShipmentTrackingProviderListMapper(siteID: dummySiteID).map(response: response)
47+
}
48+
49+
/// Returns the ShipmentTrackingProviderListMapper output upon receiving `shipment_tracking_providers`
50+
///
51+
func mapLoadShipmentTrackingProviderResponse() throws -> [ShipmentTrackingProviderGroup] {
52+
try mapShipmentTrackingProvider(from: "shipment_tracking_providers")
53+
}
54+
55+
/// Returns the ShipmentTrackingProviderListMapper output upon receiving `shipment_tracking_providers_without_data`
56+
///
57+
func mapLoadShipmentTrackingProviderResponseWithoutDataEnvelope() throws -> [ShipmentTrackingProviderGroup] {
58+
try mapShipmentTrackingProvider(from: "shipment_tracking_providers_without_data")
59+
}
60+
}
61+
62+
private enum ParsingError: Error {
63+
case unableToLoadFile
64+
}

0 commit comments

Comments
 (0)