Skip to content

Commit

Permalink
Rename updateProduct to updateProductDescription.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaclync committed Nov 5, 2019
1 parent dfe0591 commit 3e303ad
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Networking/Networking/Remote/ProductsRemote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public class ProductsRemote: Remote {
/// - description: Description of the Product.
/// - completion: Closure to be executed upon completion.
///
public func updateProduct(for siteID: Int, productID: Int, description: String, completion: @escaping (Product?, Error?) -> Void) {
public func updateProductDescription(for siteID: Int, productID: Int, description: String, completion: @escaping (Product?, Error?) -> Void) {
let parameters = [
"description": description
]
Expand Down
8 changes: 4 additions & 4 deletions Networking/NetworkingTests/Remote/ProductsRemoteTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class ProductsRemoteTests: XCTestCase {

// MARK: - Update Product Description

/// Verifies that updateProduct description properly parses the `product-update-description` sample response.
/// Verifies that updateProductDescription description properly parses the `product-update-description` sample response.
///
func testUpdateProductDescriptionProperlyReturnsParsedProduct() {
let remote = ProductsRemote(network: network)
Expand All @@ -148,7 +148,7 @@ class ProductsRemoteTests: XCTestCase {
network.simulateResponse(requestUrlSuffix: "products/\(sampleProductID)", filename: "product-update-description")

let productDescription = "Learn something!"
remote.updateProduct(for: sampleSiteID, productID: sampleProductID, description: productDescription) { (product, error) in
remote.updateProductDescription(for: sampleSiteID, productID: sampleProductID, description: productDescription) { (product, error) in
XCTAssertNil(error)
XCTAssertNotNil(product)
XCTAssertEqual(product?.fullDescription, productDescription)
Expand All @@ -158,13 +158,13 @@ class ProductsRemoteTests: XCTestCase {
wait(for: [expectation], timeout: Constants.expectationTimeout)
}

/// Verifies that updateProduct description properly relays Networking Layer errors.
/// Verifies that updateProductDescription description properly relays Networking Layer errors.
///
func testUpdateProductDescriptionProperlyRelaysNetwokingErrors() {
let remote = ProductsRemote(network: network)
let expectation = self.expectation(description: "Wait for product description update")

remote.updateProduct(for: sampleSiteID, productID: sampleProductID, description: "") { (product, error) in
remote.updateProductDescription(for: sampleSiteID, productID: sampleProductID, description: "") { (product, error) in
XCTAssertNil(product)
XCTAssertNotNil(error)
expectation.fulfill()
Expand Down
2 changes: 1 addition & 1 deletion Yosemite/Yosemite/Actions/ProductAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ public enum ProductAction: Action {

/// Updates the description of a specified Product.
///
case updateProduct(siteID: Int, productID: Int, description: String?, onCompletion: (Product?, Error?) -> Void)
case updateProductDescription(siteID: Int, productID: Int, description: String?, onCompletion: (Product?, Error?) -> Void)
}
4 changes: 2 additions & 2 deletions Yosemite/Yosemite/Stores/ProductStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ProductStore: Store {
synchronizeProducts(siteID: siteID, pageNumber: pageNumber, pageSize: pageSize, onCompletion: onCompletion)
case .requestMissingProducts(let order, let onCompletion):
requestMissingProducts(for: order, onCompletion: onCompletion)
case .updateProduct(let siteID, let productID, let description, let onCompletion):
case .updateProductDescription(let siteID, let productID, let description, let onCompletion):
updateProduct(siteID: siteID, productID: productID, description: description, onCompletion: onCompletion)
}
}
Expand Down Expand Up @@ -171,7 +171,7 @@ private extension ProductStore {
func updateProduct(siteID: Int, productID: Int, description: String?, onCompletion: @escaping (Networking.Product?, Error?) -> Void) {
let remote = ProductsRemote(network: network)

remote.updateProduct(for: siteID, productID: productID, description: description ?? "") { [weak self] (product, error) in
remote.updateProductDescription(for: siteID, productID: productID, description: description ?? "") { [weak self] (product, error) in
guard let product = product else {
onCompletion(nil, error)
return
Expand Down
27 changes: 13 additions & 14 deletions Yosemite/YosemiteTests/Stores/ProductStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -613,9 +613,9 @@ class ProductStoreTests: XCTestCase {
wait(for: [expectation], timeout: Constants.expectationTimeout)
}

// MARK: - ProductAction.updateProduct
// MARK: - ProductAction.updateProductDescription

/// Verifies that `ProductAction.updateProduct` description returns the expected `Product`.
/// Verifies that `ProductAction.updateProductDescription` returns the expected `Product`.
///
func testUpdatingProductDescriptionReturnsExpectedFields() {
let expectation = self.expectation(description: "Update product description")
Expand All @@ -625,7 +625,7 @@ class ProductStoreTests: XCTestCase {
let expectedProductDescription = "Learn something!"

network.simulateResponse(requestUrlSuffix: "products/\(expectedProductID)", filename: "product-update-description")
let action = ProductAction.updateProduct(siteID: sampleSiteID,
let action = ProductAction.updateProductDescription(siteID: sampleSiteID,
productID: expectedProductID,
description: expectedProductDescription) { (product, error) in
XCTAssertNil(error)
Expand All @@ -647,7 +647,7 @@ class ProductStoreTests: XCTestCase {
wait(for: [expectation], timeout: Constants.expectationTimeout)
}

/// Verifies that `ProductAction.updateProduct` description effectively persists all of the remote product fields
/// Verifies that `ProductAction.updateProductDescription` effectively persists all of the remote product fields
/// correctly across all of the related `Product` entities (tags, categories, attributes, etc) for `variation` product types.
///
func testUpdatingProductDescriptionEffectivelyPersistsRelatedObjects() {
Expand All @@ -659,7 +659,7 @@ class ProductStoreTests: XCTestCase {
network.simulateResponse(requestUrlSuffix: "products/\(expectedProductID)", filename: "product-update-description")
XCTAssertEqual(viewStorage.countObjects(ofType: Storage.Product.self), 0)

let action = ProductAction.updateProduct(siteID: sampleSiteID, productID: expectedProductID, description: "") { (product, error) in
let action = ProductAction.updateProductDescription(siteID: sampleSiteID, productID: expectedProductID, description: "") { (product, error) in
XCTAssertNotNil(product)
XCTAssertNil(error)
XCTAssertEqual(self.viewStorage.countObjects(ofType: Storage.Product.self), 1)
Expand All @@ -682,14 +682,14 @@ class ProductStoreTests: XCTestCase {
wait(for: [expectation], timeout: Constants.expectationTimeout)
}

/// Verifies that `ProductAction.updateProduct` description returns an error whenever there is an error response from the backend.
/// Verifies that `ProductAction.updateProductDescription` returns an error whenever there is an error response from the backend.
///
func testUpdatingProductDescriptionReturnsErrorUponReponseError() {
let expectation = self.expectation(description: "Update product description")
let productStore = ProductStore(dispatcher: dispatcher, storageManager: storageManager, network: network)

network.simulateResponse(requestUrlSuffix: "products/\(sampleProductID)", filename: "generic_error")
let action = ProductAction.updateProduct(siteID: sampleSiteID, productID: sampleProductID, description: "") { (product, error) in
let action = ProductAction.updateProductDescription(siteID: sampleSiteID, productID: sampleProductID, description: "") { (product, error) in
XCTAssertNotNil(error)
expectation.fulfill()
}
Expand All @@ -698,13 +698,13 @@ class ProductStoreTests: XCTestCase {
wait(for: [expectation], timeout: Constants.expectationTimeout)
}

/// Verifies that `ProductAction.updateProduct` description returns an error whenever there is no backend response.
/// Verifies that `ProductAction.updateProductDescription` returns an error whenever there is no backend response.
///
func testUpdatingProductDescriptionReturnsErrorUponEmptyResponse() {
let expectation = self.expectation(description: "Retrieve single product empty response")
let expectation = self.expectation(description: "Update product description")
let productStore = ProductStore(dispatcher: dispatcher, storageManager: storageManager, network: network)

let action = ProductAction.updateProduct(siteID: sampleSiteID, productID: sampleProductID, description: "") { (product, error) in
let action = ProductAction.updateProductDescription(siteID: sampleSiteID, productID: sampleProductID, description: "") { (product, error) in
XCTAssertNotNil(error)
XCTAssertNil(product)
expectation.fulfill()
Expand All @@ -714,19 +714,18 @@ class ProductStoreTests: XCTestCase {
wait(for: [expectation], timeout: Constants.expectationTimeout)
}

/// Verifies that whenever a `ProductAction.updateProduct` description action results in a response with statusCode = 404, the local entity
/// is obliterated from existence.
/// Verifies that whenever a `ProductAction.updateProductDescription` action results in a response with statusCode = 404, the local entity is not deleted.
///
func testUpdatingProductDescriptionResultingInStatusCode404DoesNotCauseTheStoredProductToGetDeleted() {
let expectation = self.expectation(description: "Retrieve single product empty response")
let expectation = self.expectation(description: "Update product description")
let productStore = ProductStore(dispatcher: dispatcher, storageManager: storageManager, network: network)

XCTAssertEqual(viewStorage.countObjects(ofType: Storage.Product.self), 0)
productStore.upsertStoredProduct(readOnlyProduct: sampleProduct(), in: viewStorage)
XCTAssertEqual(viewStorage.countObjects(ofType: Storage.Product.self), 1)

network.simulateError(requestUrlSuffix: "products/\(sampleProductID)", error: NetworkError.notFound)
let action = ProductAction.updateProduct(siteID: sampleSiteID, productID: sampleProductID, description: "") { (product, error) in
let action = ProductAction.updateProductDescription(siteID: sampleSiteID, productID: sampleProductID, description: "") { (product, error) in
XCTAssertNotNil(error)
XCTAssertNil(product)
// The existing Product should not be deleted on 404 response.
Expand Down

0 comments on commit 3e303ad

Please sign in to comment.