Skip to content

Commit 507352d

Browse files
committed
Update test for ShippingLabelStatusMapper
1 parent 4ed5694 commit 507352d

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

Networking/Networking.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,7 @@
727727
DE66C5612977CB5F00DAA978 /* shipping-label-eligibility-success-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C5602977CB5F00DAA978 /* shipping-label-eligibility-success-without-data.json */; };
728728
DE66C5632977CBC700DAA978 /* shipping-label-eligibility-failure-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C5622977CBC700DAA978 /* shipping-label-eligibility-failure-without-data.json */; };
729729
DE66C5652977CC4300DAA978 /* shipping-label-purchase-success-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C5642977CC4300DAA978 /* shipping-label-purchase-success-without-data.json */; };
730+
DE66C5672977CEB800DAA978 /* shipping-label-status-success-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C5662977CEB800DAA978 /* shipping-label-status-success-without-data.json */; };
730731
DE6F308727966FEF004E1C9A /* CouponReportListMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE6F308627966FEF004E1C9A /* CouponReportListMapperTests.swift */; };
731732
DE74F29A27E08F5A0002FE59 /* SiteSettingMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE74F29927E08F5A0002FE59 /* SiteSettingMapper.swift */; };
732733
DE74F29C27E0A1D00002FE59 /* setting-coupon.json in Resources */ = {isa = PBXBuildFile; fileRef = DE74F29B27E0A1D00002FE59 /* setting-coupon.json */; };
@@ -1567,6 +1568,7 @@
15671568
DE66C5602977CB5F00DAA978 /* shipping-label-eligibility-success-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "shipping-label-eligibility-success-without-data.json"; sourceTree = "<group>"; };
15681569
DE66C5622977CBC700DAA978 /* shipping-label-eligibility-failure-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "shipping-label-eligibility-failure-without-data.json"; sourceTree = "<group>"; };
15691570
DE66C5642977CC4300DAA978 /* shipping-label-purchase-success-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "shipping-label-purchase-success-without-data.json"; sourceTree = "<group>"; };
1571+
DE66C5662977CEB800DAA978 /* shipping-label-status-success-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "shipping-label-status-success-without-data.json"; sourceTree = "<group>"; };
15701572
DE6F308627966FEF004E1C9A /* CouponReportListMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponReportListMapperTests.swift; sourceTree = "<group>"; };
15711573
DE74F29927E08F5A0002FE59 /* SiteSettingMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiteSettingMapper.swift; sourceTree = "<group>"; };
15721574
DE74F29B27E0A1D00002FE59 /* setting-coupon.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "setting-coupon.json"; sourceTree = "<group>"; };
@@ -2186,6 +2188,7 @@
21862188
B559EBA820A0B5B100836CD4 /* Responses */ = {
21872189
isa = PBXGroup;
21882190
children = (
2191+
DE66C5662977CEB800DAA978 /* shipping-label-status-success-without-data.json */,
21892192
DE66C5642977CC4300DAA978 /* shipping-label-purchase-success-without-data.json */,
21902193
DE66C5622977CBC700DAA978 /* shipping-label-eligibility-failure-without-data.json */,
21912194
DE66C5602977CB5F00DAA978 /* shipping-label-eligibility-success-without-data.json */,
@@ -3185,6 +3188,7 @@
31853188
74A1D264211898F000931DFA /* site-visits-week.json in Resources */,
31863189
B53EF53621813681003E146F /* generic_success.json in Resources */,
31873190
31054718262E2F5E00C5C02B /* wcpay-payment-intent-requires-confirmation.json in Resources */,
3191+
DE66C5672977CEB800DAA978 /* shipping-label-status-success-without-data.json in Resources */,
31883192
D8FBFF2922D52AFB006E3336 /* order-stats-v4-year.json in Resources */,
31893193
D865CE65278CA202002C8520 /* stripe-payment-intent-canceled.json in Resources */,
31903194
DE42F9672967F61D00D514C2 /* refunds-all-without-data.json in Resources */,

Networking/NetworkingTests/Mapper/ShippingLabelStatusMapperTests.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,40 @@ class ShippingLabelStatusMapperTests: XCTestCase {
4747
XCTAssertEqual(shippingLabel?.productNames, ["WordPress Pennant"])
4848
}
4949

50+
func test_ShippingLabelStatusPollingResponse_is_properly_parsed_for_purchased_label_when_response_has_no_data_envelope() {
51+
// Given
52+
guard let shippingLabelList = mapLoadShippingLabelStatusWithoutDataEnvelope(),
53+
let shippingLabelResponse = shippingLabelList.first else {
54+
XCTFail()
55+
return
56+
}
57+
58+
// Assert
59+
XCTAssertEqual(shippingLabelResponse.status, .purchased)
60+
61+
// Then
62+
let shippingLabel = shippingLabelResponse.getPurchasedLabel()
63+
64+
// Assert
65+
XCTAssertEqual(shippingLabel?.siteID, sampleSiteID)
66+
XCTAssertEqual(shippingLabel?.orderID, sampleOrderID)
67+
XCTAssertEqual(shippingLabel?.shippingLabelID, 1825)
68+
XCTAssertEqual(shippingLabel?.carrierID, "usps")
69+
XCTAssertEqual(shippingLabel?.dateCreated, Date(timeIntervalSince1970: 1623764362.682))
70+
XCTAssertEqual(shippingLabel?.packageName, "Small Flat Rate Box")
71+
XCTAssertEqual(shippingLabel?.rate, 7.9)
72+
XCTAssertEqual(shippingLabel?.currency, "USD")
73+
XCTAssertEqual(shippingLabel?.trackingNumber, "9405500205309072644962")
74+
XCTAssertEqual(shippingLabel?.serviceName, "USPS - Priority Mail")
75+
XCTAssertEqual(shippingLabel?.refundableAmount, 7.9)
76+
XCTAssertEqual(shippingLabel?.status, ShippingLabelStatus.purchased)
77+
XCTAssertNil(shippingLabel?.refund)
78+
XCTAssertEqual(shippingLabel?.originAddress, ShippingLabelAddress.fake())
79+
XCTAssertEqual(shippingLabel?.destinationAddress, ShippingLabelAddress.fake())
80+
XCTAssertEqual(shippingLabel?.productIDs, [89])
81+
XCTAssertEqual(shippingLabel?.productNames, ["WordPress Pennant"])
82+
}
83+
5084
/// Verifies that the Shipping Label Status Polling Response is parsed correctly when it receives a pending shipping label purchase.
5185
///
5286
func test_ShippingLabelStatusPollingResponse_is_properly_parsed_for_pending_label_purchase() {
@@ -81,6 +115,12 @@ private extension ShippingLabelStatusMapperTests {
81115
return mapShippingLabelStatus(from: "shipping-label-status-success")
82116
}
83117

118+
/// Returns the ShippingLabelStatusMapper output upon receiving `shipping-label-status-success-without-data`
119+
///
120+
func mapLoadShippingLabelStatusWithoutDataEnvelope() -> [ShippingLabelStatusPollingResponse]? {
121+
return mapShippingLabelStatus(from: "shipping-label-status-success-without-data")
122+
}
123+
84124
/// Returns the ShippingLabelStatusMapper output upon receiving `shipping-label-purchase-success`
85125
///
86126
func mapLoadShippingLabelPurchaseStatus() -> [ShippingLabelStatusPollingResponse]? {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"success":true,
3+
"labels":[{
4+
"label_id": 1825,
5+
"tracking": "9405500205309072644962",
6+
"refundable_amount": 7.9,
7+
"created": 1623764362682,
8+
"carrier_id": "usps",
9+
"service_name": "USPS - Priority Mail",
10+
"status": "PURCHASED",
11+
"commercial_invoice_url": null,
12+
"package_name": "Small Flat Rate Box",
13+
"is_letter": false,
14+
"product_names": ["WordPress Pennant"],
15+
"product_ids": [89],
16+
"receipt_item_id": 24601924,
17+
"created_date": 1623764367000,
18+
"expiry_date": 1639316366000,
19+
"main_receipt_id": 19991879,
20+
"rate": 7.9,
21+
"currency": "USD"
22+
}]
23+
}

0 commit comments

Comments
 (0)