Skip to content

Commit

Permalink
Add tests to simulate load packages responses
Browse files Browse the repository at this point in the history
  • Loading branch information
bozidarsevo committed Nov 14, 2024
1 parent bcadc0e commit f199265
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Fakes/Fakes/Networking.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2768,7 +2768,8 @@ extension Networking.WooShippingPackagesResponse {
.init(
storeOptions: .fake(),
customPackages: .fake(),
predefinedOptions: .fake()
savedPredefinedOptions: .fake(),
allPredefinedOptions: .fake()
)
}
}
Expand Down
4 changes: 4 additions & 0 deletions Networking/Networking.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,7 @@
DAF367982CE4AA0400D1B327 /* WooShippingPackagesResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAF367972CE4A9FC00D1B327 /* WooShippingPackagesResponse.swift */; };
DAF3679A2CE6480600D1B327 /* WooShippingPredefinedPackage.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAF367992CE647FA00D1B327 /* WooShippingPredefinedPackage.swift */; };
DAF3679C2CE6557E00D1B327 /* WooShippingPredefinedSavedOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAF3679B2CE6557C00D1B327 /* WooShippingPredefinedSavedOption.swift */; };
DAF367A02CE65A8B00D1B327 /* wooshipping-get-packages-success.json in Resources */ = {isa = PBXBuildFile; fileRef = DAF3679E2CE65A8B00D1B327 /* wooshipping-get-packages-success.json */; };
DE02ABB12B5636FC008E0AC4 /* BlazePaymentInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE02ABB02B5636FC008E0AC4 /* BlazePaymentInfo.swift */; };
DE02ABB32B563E61008E0AC4 /* blaze-payment-info.json in Resources */ = {isa = PBXBuildFile; fileRef = DE02ABB22B563E61008E0AC4 /* blaze-payment-info.json */; };
DE02ABB52B563E96008E0AC4 /* BlazePaymentInfoMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE02ABB42B563E96008E0AC4 /* BlazePaymentInfoMapper.swift */; };
Expand Down Expand Up @@ -2127,6 +2128,7 @@
DAF367972CE4A9FC00D1B327 /* WooShippingPackagesResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WooShippingPackagesResponse.swift; sourceTree = "<group>"; };
DAF367992CE647FA00D1B327 /* WooShippingPredefinedPackage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WooShippingPredefinedPackage.swift; sourceTree = "<group>"; };
DAF3679B2CE6557C00D1B327 /* WooShippingPredefinedSavedOption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WooShippingPredefinedSavedOption.swift; sourceTree = "<group>"; };
DAF3679E2CE65A8B00D1B327 /* wooshipping-get-packages-success.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "wooshipping-get-packages-success.json"; sourceTree = "<group>"; };
DE02ABB02B5636FC008E0AC4 /* BlazePaymentInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlazePaymentInfo.swift; sourceTree = "<group>"; };
DE02ABB22B563E61008E0AC4 /* blaze-payment-info.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "blaze-payment-info.json"; sourceTree = "<group>"; };
DE02ABB42B563E96008E0AC4 /* BlazePaymentInfoMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlazePaymentInfoMapper.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3507,6 +3509,7 @@
453954D52C9193BC00A3E64A /* meta-data-products-orders-update.json */,
95122E3D2CB82C0A0079FF0A /* generate-product-success-wrapped.json */,
CE0F4EC82CE3753F006339BD /* wooshipping-get-label-rates-success.json */,
DAF3679E2CE65A8B00D1B327 /* wooshipping-get-packages-success.json */,
CE0F4ECC2CE375DD006339BD /* wooshipping-get-label-rates-error.json */,
);
path = Responses;
Expand Down Expand Up @@ -4482,6 +4485,7 @@
EE9826902B17189B00A3F57E /* product-subscription-sync-renewals-day-month-format.json in Resources */,
DEB387902C2D71A10025256E /* gla-campaign-list-with-data-envelope.json in Resources */,
7492FAE3217FBDBC00ED2C69 /* settings-general-alt.json in Resources */,
DAF367A02CE65A8B00D1B327 /* wooshipping-get-packages-success.json in Resources */,
93D8BBFF226BC1DA00AD2EB3 /* me-settings.json in Resources */,
74C947842193A6C70024CB60 /* comment-moderate-approved.json in Resources */,
DEC51AED2768A0AD009F3DF4 /* systemStatusWithPluginsOnly.json in Resources */,
Expand Down
35 changes: 35 additions & 0 deletions Networking/NetworkingTests/Remote/WooShippingRemoteTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,41 @@ final class WooShippingRemoteTests: XCTestCase {
// Then
XCTAssertNotNil(result.failure)
}

func test_loadPackages_parses_success_response() throws {
// Given
let remote = WooShippingRemote(network: network)
network.simulateResponse(requestUrlSuffix: "packages", filename: "wooshipping-get-packages-success")

// When
let result: Result<WooShippingPackagesResponse, Error> = waitFor { promise in
remote.loadPackages(siteID: self.sampleSiteID) { result in
promise(result)
}
}

// Then
let successResponse = try XCTUnwrap(result.get())
XCTAssertEqual(successResponse.savedPredefinedOptions.count, 1)
XCTAssertEqual(successResponse.savedPredefinedOptions.first?.id, "usps")
XCTAssertEqual(successResponse.savedPredefinedOptions.first?.predefinedPackageIDs.count, 2)
}

func test_loadPackages_returns_error_on_failure() throws {
// Given
let remote = WooShippingRemote(network: network)
network.simulateResponse(requestUrlSuffix: "packages", filename: "generic_error")

// When
let result: Result<WooShippingPackagesResponse, Error> = waitFor { promise in
remote.loadPackages(siteID: self.sampleSiteID) { result in
promise(result)
}
}

// Then
XCTAssertNotNil(result.failure)
}
}

private extension WooShippingRemoteTests {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"data": {
"storeOptions": {
"currency_symbol": "$",
"dimension_unit": "cm",
"weight_unit": "kg",
"origin_country": "US"
},
"packages": {
"saved": {
"custom": [
{
"name": "12x12x12",
"boxWeight": 0.01,
"id": "849225dc153",
"type": "box",
"isLetter": false,
"dimensions": "12 x 12 x 12",
"is_user_defined": true
}
],
"predefined": {
"usps": [
"small_flat_box",
"medium_flat_box_top"
]
}
},
"predefined": {
"usps": {
"pri_flat_boxes": {
"title": "USPS Priority Mail Flat Rate Boxes",
"definitions": [
{
"inner_dimensions": "8.63 x 5.38 x 1.63",
"outer_dimensions": "8.63 x 5.38 x 1.63",
"box_weight": 0,
"is_flat_rate": true,
"id": "small_flat_box",
"name": "Small Flat Rate Box",
"dimensions": "8.63 x 5.38 x 1.63",
"max_weight": 70,
"is_letter": false,
"group_id": "pri_flat_boxes",
"can_ship_international": true
},
{
"inner_dimensions": "11 x 8.5 x 5.5",
"outer_dimensions": "11.25 x 8.75 x 6",
"box_weight": 0,
"is_flat_rate": true,
"id": "medium_flat_box_top",
"name": "Medium Flat Rate Box 1, Top Loading",
"max_weight": 70,
"is_letter": false,
"group_id": "pri_flat_boxes",
"can_ship_international": true
},
]
}
},
"fedex": {
"express": {
"title": "FedEx Express Packages",
"definitions": [
{
"inner_dimensions": "13.19 x 9.25 x 0.75",
"outer_dimensions": "13.19 x 9.25 x 0.75",
"box_weight": 0,
"is_flat_rate": false,
"id": "FedExEnvelope",
"name": "Envelope",
"dimensions": "13.19 x 9.25 x 0.75",
"max_weight": 10,
"is_letter": true,
"group_id": "express"
},
{
"inner_dimensions": "15.5 x 12 x 0.75",
"outer_dimensions": "15.5 x 12 x 0.75",
"box_weight": 0,
"is_flat_rate": false,
"id": "FedExPak",
"name": "Large Pak",
"dimensions": "15.5 x 12 x 0.75",
"max_weight": 20,
"is_letter": true,
"group_id": "express"
},
]
}
}
}
},
"success": true
}
}

0 comments on commit f199265

Please sign in to comment.