@@ -292,11 +292,15 @@ class ProductStoreTests: XCTestCase {
292292 /// Verifies that `ProductAction.retrieveProduct` returns the expected `Product`.
293293 ///
294294 func testRetrieveSingleProductReturnsExpectedFields( ) {
295+ // The shipping class ID should match the `shipping_class_id` field in `product.json`.
296+ let expectedShippingClass = sampleProductShippingClass ( remoteID: 134 , siteID: sampleSiteID)
297+ storageManager. insertSampleProductShippingClass ( readOnlyProductShippingClass: expectedShippingClass)
298+
295299 let expectation = self . expectation ( description: " Retrieve single product " )
296300 let productStore = ProductStore ( dispatcher: dispatcher, storageManager: storageManager, network: network)
297- let remoteProduct = sampleProduct ( )
301+ let remoteProduct = sampleProduct ( productShippingClass : expectedShippingClass )
298302
299- network. simulateResponse ( requestUrlSuffix: " products/282 " , filename: " product " )
303+ network. simulateResponse ( requestUrlSuffix: " products/ \( sampleProductID ) " , filename: " product " )
300304 let action = ProductAction . retrieveProduct ( siteID: sampleSiteID, productID: sampleProductID) { ( product, error) in
301305 XCTAssertNil ( error)
302306 XCTAssertNotNil ( product)
@@ -335,7 +339,12 @@ class ProductStoreTests: XCTestCase {
335339 func testRetrieveSingleProductEffectivelyPersistsProductFieldsAndRelatedObjects( ) {
336340 let expectation = self . expectation ( description: " Persist single product " )
337341 let productStore = ProductStore ( dispatcher: dispatcher, storageManager: storageManager, network: network)
338- let remoteProduct = sampleProduct ( )
342+
343+ // The shipping class ID should match the `shipping_class_id` field in `product.json`.
344+ let expectedShippingClass = sampleProductShippingClass ( remoteID: 134 , siteID: sampleSiteID)
345+ storageManager. insertSampleProductShippingClass ( readOnlyProductShippingClass: expectedShippingClass)
346+
347+ let remoteProduct = sampleProduct ( productShippingClass: expectedShippingClass)
339348
340349 network. simulateResponse ( requestUrlSuffix: " products/282 " , filename: " product " )
341350 XCTAssertEqual ( viewStorage. countObjects ( ofType: Storage . Product. self) , 0 )
@@ -772,6 +781,7 @@ class ProductStoreTests: XCTestCase {
772781 let expectedProductDescription = " Learn something! "
773782 let expectedProductShippingClassID : Int64 = 96987515
774783 let expectedProductShippingClassSlug = " two-days "
784+ let expectedProductShippingClass = sampleProductShippingClass ( remoteID: expectedProductShippingClassID, siteID: sampleSiteID)
775785 let expectedProductSKU = " 94115 "
776786 let expectedProductManageStock = true
777787 let expectedProductSoldIndividually = false
@@ -788,6 +798,11 @@ class ProductStoreTests: XCTestCase {
788798 network. simulateResponse ( requestUrlSuffix: " products/ \( expectedProductID) " , filename: " product-update " )
789799 let product = sampleProduct ( productID: expectedProductID)
790800
801+ // Saves an existing shipping class into storage, so that it can be linked to the updated product.
802+ // The shipping class ID should match the `shipping_class_id` field in `product.json`.
803+ storageManager. insertSampleProductShippingClass ( readOnlyProductShippingClass: expectedProductShippingClass)
804+ XCTAssertEqual ( viewStorage. countObjects ( ofType: StorageProductShippingClass . self) , 1 )
805+
791806 // Saves an existing Product into storage.
792807 // Note: the fields to be tested should be different in the sample model and network response.
793808 storageManager. insertSampleProduct ( readOnlyProduct: product)
@@ -802,6 +817,7 @@ class ProductStoreTests: XCTestCase {
802817 // Shipping settings.
803818 XCTAssertEqual ( product? . shippingClassID, expectedProductShippingClassID)
804819 XCTAssertEqual ( product? . shippingClass, expectedProductShippingClassSlug)
820+ XCTAssertEqual ( product? . productShippingClass, expectedProductShippingClass)
805821 // Inventory settings.
806822 XCTAssertEqual ( product? . sku, expectedProductSKU)
807823 XCTAssertEqual ( product? . manageStock, expectedProductManageStock)
@@ -944,7 +960,7 @@ class ProductStoreTests: XCTestCase {
944960//
945961private extension ProductStoreTests {
946962
947- func sampleProduct( _ siteID: Int64 ? = nil , productID: Int64 ? = nil ) -> Networking . Product {
963+ func sampleProduct( _ siteID: Int64 ? = nil , productID: Int64 ? = nil , productShippingClass : Networking . ProductShippingClass ? = nil ) -> Networking . Product {
948964 let testSiteID = siteID ?? sampleSiteID
949965 let testProductID = productID ?? sampleProductID
950966 return Product ( siteID: testSiteID,
@@ -993,9 +1009,9 @@ private extension ProductStoreTests {
9931009 dimensions: sampleDimensions ( ) ,
9941010 shippingRequired: false ,
9951011 shippingTaxable: false ,
996- shippingClass: " " ,
997- shippingClassID: 0 ,
998- productShippingClass: nil ,
1012+ shippingClass: productShippingClass ? . slug ?? " " ,
1013+ shippingClassID: productShippingClass ? . shippingClassID ?? 0 ,
1014+ productShippingClass: productShippingClass ,
9991015 reviewsAllowed: true ,
10001016 averageRating: " 4.30 " ,
10011017 ratingCount: 23 ,
@@ -1208,6 +1224,15 @@ private extension ProductStoreTests {
12081224 return [ defaultAttribute1]
12091225 }
12101226
1227+ func sampleProductShippingClass( remoteID: Int64 , siteID: Int64 ) -> Yosemite . ProductShippingClass {
1228+ return ProductShippingClass ( count: 3 ,
1229+ descriptionHTML: " Limited offer! " ,
1230+ name: " Free Shipping " ,
1231+ shippingClassID: remoteID,
1232+ siteID: siteID,
1233+ slug: " " )
1234+ }
1235+
12111236 func sampleVariationTypeProduct( _ siteID: Int64 ? = nil ) -> Networking . Product {
12121237 let testSiteID = siteID ?? sampleSiteID
12131238 return Product ( siteID: testSiteID,
0 commit comments