Skip to content

Commit 4ed5694

Browse files
committed
Update test for ShippingLabelPurchaseMapper
1 parent 3712990 commit 4ed5694

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

Networking/Networking.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,7 @@
726726
DE66C55F2977C67D00DAA978 /* shipping-label-account-settings-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C55E2977C67D00DAA978 /* shipping-label-account-settings-without-data.json */; };
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 */; };
729+
DE66C5652977CC4300DAA978 /* shipping-label-purchase-success-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C5642977CC4300DAA978 /* shipping-label-purchase-success-without-data.json */; };
729730
DE6F308727966FEF004E1C9A /* CouponReportListMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE6F308627966FEF004E1C9A /* CouponReportListMapperTests.swift */; };
730731
DE74F29A27E08F5A0002FE59 /* SiteSettingMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE74F29927E08F5A0002FE59 /* SiteSettingMapper.swift */; };
731732
DE74F29C27E0A1D00002FE59 /* setting-coupon.json in Resources */ = {isa = PBXBuildFile; fileRef = DE74F29B27E0A1D00002FE59 /* setting-coupon.json */; };
@@ -1565,6 +1566,7 @@
15651566
DE66C55E2977C67D00DAA978 /* shipping-label-account-settings-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "shipping-label-account-settings-without-data.json"; sourceTree = "<group>"; };
15661567
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>"; };
15671568
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>"; };
1569+
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>"; };
15681570
DE6F308627966FEF004E1C9A /* CouponReportListMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponReportListMapperTests.swift; sourceTree = "<group>"; };
15691571
DE74F29927E08F5A0002FE59 /* SiteSettingMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiteSettingMapper.swift; sourceTree = "<group>"; };
15701572
DE74F29B27E0A1D00002FE59 /* setting-coupon.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "setting-coupon.json"; sourceTree = "<group>"; };
@@ -2184,6 +2186,7 @@
21842186
B559EBA820A0B5B100836CD4 /* Responses */ = {
21852187
isa = PBXGroup;
21862188
children = (
2189+
DE66C5642977CC4300DAA978 /* shipping-label-purchase-success-without-data.json */,
21872190
DE66C5622977CBC700DAA978 /* shipping-label-eligibility-failure-without-data.json */,
21882191
DE66C5602977CB5F00DAA978 /* shipping-label-eligibility-success-without-data.json */,
21892192
DE66C55E2977C67D00DAA978 /* shipping-label-account-settings-without-data.json */,
@@ -3104,6 +3107,7 @@
31043107
DEF13C5A296571150024A02B /* leaderboards-year-without-data.json in Resources */,
31053108
2683D70E24456DB8002A1589 /* categories-empty.json in Resources */,
31063109
D865CE67278CA225002C8520 /* stripe-payment-intent-succeeded.json in Resources */,
3110+
DE66C5652977CC4300DAA978 /* shipping-label-purchase-success-without-data.json in Resources */,
31073111
DE74F2A027E3137F0002FE59 /* setting-analytics.json in Resources */,
31083112
0272E3F5254AA48F00436277 /* order-with-line-item-attributes.json in Resources */,
31093113
3105471C262E2F8000C5C02B /* wcpay-payment-intent-requires-action.json in Resources */,

Networking/NetworkingTests/Mapper/ShippingLabelPurchaseMapperTests.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,29 @@ class ShippingLabelPurchaseMapperTests: XCTestCase {
3333
XCTAssertEqual(shippingLabel.productIDs, [])
3434
XCTAssertEqual(shippingLabel.productNames, ["Beanie"])
3535
}
36+
37+
/// Verifies that the Shipping Label Purchase is parsed correctly.
38+
///
39+
func test_ShippingLabelPurchase_is_properly_parsed_when_response_has_no_data_envelope() {
40+
guard let shippingLabelList = mapLoadShippingLabelPurchaseWithoutDataEnvelope(),
41+
let shippingLabel = shippingLabelList.first else {
42+
XCTFail()
43+
return
44+
}
45+
46+
XCTAssertEqual(shippingLabel.siteID, sampleSiteID)
47+
XCTAssertEqual(shippingLabel.orderID, sampleOrderID)
48+
XCTAssertEqual(shippingLabel.shippingLabelID, 733)
49+
XCTAssertNil(shippingLabel.carrierID)
50+
XCTAssertEqual(shippingLabel.dateCreated, Date(timeIntervalSince1970: 1584549793.938))
51+
XCTAssertEqual(shippingLabel.packageName, "Test")
52+
XCTAssertNil(shippingLabel.trackingNumber)
53+
XCTAssertEqual(shippingLabel.serviceName, "USPS - First Class Mail")
54+
XCTAssertEqual(shippingLabel.refundableAmount, 0)
55+
XCTAssertEqual(shippingLabel.status, ShippingLabelStatus.purchaseInProgress)
56+
XCTAssertEqual(shippingLabel.productIDs, [])
57+
XCTAssertEqual(shippingLabel.productNames, ["Beanie"])
58+
}
3659
}
3760

3861
/// Private Helpers
@@ -54,4 +77,10 @@ private extension ShippingLabelPurchaseMapperTests {
5477
func mapLoadShippingLabelPurchase() -> [ShippingLabelPurchase]? {
5578
return mapShippingLabelPurchase(from: "shipping-label-purchase-success")
5679
}
80+
81+
/// Returns the ShippingLabelPurchaseMapper output upon receiving `shipping-label-purchase-success-without-data`
82+
///
83+
func mapLoadShippingLabelPurchaseWithoutDataEnvelope() -> [ShippingLabelPurchase]? {
84+
return mapShippingLabelPurchase(from: "shipping-label-purchase-success-without-data")
85+
}
5786
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"labels": [{
3+
"label_id": 733,
4+
"tracking": null,
5+
"refundable_amount": 0,
6+
"created": 1584549793938,
7+
"carrier_id": null,
8+
"service_name": "USPS - First Class Mail",
9+
"status": "PURCHASE_IN_PROGRESS",
10+
"package_name": "Test",
11+
"product_names": ["Beanie"]
12+
}],
13+
"success": true
14+
}

0 commit comments

Comments
 (0)