From 5869ec076b4ec9b1dfeb4d6ba5069106e83920a0 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Thu, 20 Oct 2022 15:35:28 +0900 Subject: [PATCH 01/16] fill Customer fields on Order screen --- .../Address Edit/EditOrderAddressForm.swift | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressForm.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressForm.swift index fcce4552a1c..af7a1a589c9 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressForm.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressForm.swift @@ -93,6 +93,20 @@ struct EditOrderAddressForm: View { let isSearchCustomersEnabled = DefaultFeatureFlagService().isFeatureFlagEnabled(.orderCreationSearchCustomers) + private func fillCustomerFields(customer: Customer) { + self.viewModel.fields.firstName = customer.firstName ?? "" + self.viewModel.fields.lastName = customer.lastName ?? "" + self.viewModel.fields.email = customer.email + self.viewModel.fields.phone = customer.billing?.phone ?? "" + self.viewModel.fields.company = customer.billing?.company ?? "" + self.viewModel.fields.address1 = customer.billing?.address1 ?? "" + self.viewModel.fields.address2 = customer.billing?.address2 ?? "" + self.viewModel.fields.city = customer.billing?.city ?? "" + self.viewModel.fields.postcode = customer.billing?.postcode ?? "" + self.viewModel.fields.country = customer.billing?.country ?? "" + self.viewModel.fields.state = customer.billing?.state ?? "" + } + var body: some View { Group { ScrollView { @@ -172,9 +186,8 @@ struct EditOrderAddressForm: View { .notice($viewModel.notice) .sheet(isPresented: $showingCustomerSearch, content: { OrderCustomerListView(siteID: viewModel.siteID, onCustomerTapped: { customer in - // Not implemented yet. - print("3 - Customer Callback. Fill Order data with Customer details") - print("4 - Customer ID: \(customer.customerID) - Name: \(customer.firstName ?? ""))") + fillCustomerFields(customer: customer) + showingCustomerSearch = false }) }) } From e05a33d1742dbb92399e9a31bc3dd00e45232c71 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Wed, 26 Oct 2022 21:00:31 +0900 Subject: [PATCH 02/16] Add shipping fields to EditAddressOrderForm --- .../Address Edit/EditOrderAddressForm.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressForm.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressForm.swift index af7a1a589c9..afb620d5b41 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressForm.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressForm.swift @@ -94,6 +94,7 @@ struct EditOrderAddressForm: View { let isSearchCustomersEnabled = DefaultFeatureFlagService().isFeatureFlagEnabled(.orderCreationSearchCustomers) private func fillCustomerFields(customer: Customer) { + // Primary fields: self.viewModel.fields.firstName = customer.firstName ?? "" self.viewModel.fields.lastName = customer.lastName ?? "" self.viewModel.fields.email = customer.email @@ -105,6 +106,19 @@ struct EditOrderAddressForm: View { self.viewModel.fields.postcode = customer.billing?.postcode ?? "" self.viewModel.fields.country = customer.billing?.country ?? "" self.viewModel.fields.state = customer.billing?.state ?? "" + // Common secondary fields: + self.viewModel.secondaryFields.firstName = customer.firstName ?? "" + self.viewModel.secondaryFields.lastName = customer.lastName ?? "" + self.viewModel.secondaryFields.email = customer.email + // Secondary fields: + self.viewModel.secondaryFields.phone = customer.shipping?.phone ?? "" + self.viewModel.secondaryFields.company = customer.shipping?.company ?? "" + self.viewModel.secondaryFields.address1 = customer.shipping?.address1 ?? "" + self.viewModel.secondaryFields.address2 = customer.shipping?.address2 ?? "" + self.viewModel.secondaryFields.city = customer.shipping?.city ?? "" + self.viewModel.secondaryFields.postcode = customer.shipping?.postcode ?? "" + self.viewModel.secondaryFields.country = customer.shipping?.country ?? "" + self.viewModel.secondaryFields.state = customer.shipping?.state ?? "" } var body: some View { From db2fb24fe1d9c27ef19f3062b331561ce7771279 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Wed, 26 Oct 2022 22:21:32 +0900 Subject: [PATCH 03/16] Add CustomerSearchUICommand unit tests --- .../WooCommerce.xcodeproj/project.pbxproj | 12 +++++ .../CustomerSearchUICommandTests.swift | 47 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 WooCommerce/WooCommerceTests/ViewRelated/Search/Customer/CustomerSearchUICommandTests.swift diff --git a/WooCommerce/WooCommerce.xcodeproj/project.pbxproj b/WooCommerce/WooCommerce.xcodeproj/project.pbxproj index 7f4a31ac970..233ecbb7776 100644 --- a/WooCommerce/WooCommerce.xcodeproj/project.pbxproj +++ b/WooCommerce/WooCommerce.xcodeproj/project.pbxproj @@ -991,6 +991,7 @@ 57F2C6CD246DECC10074063B /* SummaryTableViewCellViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F2C6CC246DECC10074063B /* SummaryTableViewCellViewModelTests.swift */; }; 57F42E40253768D600EA87F7 /* TitleAndEditableValueTableViewCellViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F42E3F253768D600EA87F7 /* TitleAndEditableValueTableViewCellViewModelTests.swift */; }; 581D5052274AA2480089B6AD /* View+AutofocusTextModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 581D5051274AA2480089B6AD /* View+AutofocusTextModifier.swift */; }; + 682210ED2909666600814E14 /* CustomerSearchUICommandTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 682210EC2909666600814E14 /* CustomerSearchUICommandTests.swift */; }; 6827140F28A3988300E6E3F6 /* DismissableNoticeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6827140E28A3988300E6E3F6 /* DismissableNoticeView.swift */; }; 6827141128A5410D00E6E3F6 /* NewSimplePaymentsLocationNoticeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6827141028A5410D00E6E3F6 /* NewSimplePaymentsLocationNoticeViewModel.swift */; }; 6827141528A671B900E6E3F6 /* NewSimplePaymentsLocationNoticeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6827141428A671B900E6E3F6 /* NewSimplePaymentsLocationNoticeViewController.swift */; }; @@ -2890,6 +2891,7 @@ 57F2C6CC246DECC10074063B /* SummaryTableViewCellViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SummaryTableViewCellViewModelTests.swift; sourceTree = ""; }; 57F42E3F253768D600EA87F7 /* TitleAndEditableValueTableViewCellViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleAndEditableValueTableViewCellViewModelTests.swift; sourceTree = ""; }; 581D5051274AA2480089B6AD /* View+AutofocusTextModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+AutofocusTextModifier.swift"; sourceTree = ""; }; + 682210EC2909666600814E14 /* CustomerSearchUICommandTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomerSearchUICommandTests.swift; sourceTree = ""; }; 6827140E28A3988300E6E3F6 /* DismissableNoticeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DismissableNoticeView.swift; sourceTree = ""; }; 6827141028A5410D00E6E3F6 /* NewSimplePaymentsLocationNoticeViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewSimplePaymentsLocationNoticeViewModel.swift; sourceTree = ""; }; 6827141428A671B900E6E3F6 /* NewSimplePaymentsLocationNoticeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewSimplePaymentsLocationNoticeViewController.swift; sourceTree = ""; }; @@ -5990,6 +5992,7 @@ 573D0ACC2458665C004DE614 /* Search */ = { isa = PBXGroup; children = ( + 682210EB2909664800814E14 /* Customer */, 020C908224C84638001E2BEB /* Product */, ); path = Search; @@ -6165,6 +6168,14 @@ path = TitleAndEditableValueTableViewCell; sourceTree = ""; }; + 682210EB2909664800814E14 /* Customer */ = { + isa = PBXGroup; + children = ( + 682210EC2909666600814E14 /* CustomerSearchUICommandTests.swift */, + ); + path = Customer; + sourceTree = ""; + }; 6856D6E9B1C3C89938DCAD5C /* Testing */ = { isa = PBXGroup; children = ( @@ -10593,6 +10604,7 @@ 03FBDAFD263EE4E800ACE257 /* CouponListViewModelTests.swift in Sources */, 036F6EA6281847D5006D84F8 /* PaymentCaptureOrchestratorTests.swift in Sources */, B555531321B57E8800449E71 /* MockUserNotificationsCenterAdapter.swift in Sources */, + 682210ED2909666600814E14 /* CustomerSearchUICommandTests.swift in Sources */, 4590B652261C8D1E00A6FCE0 /* WeightFormatterTests.swift in Sources */, D8C11A6022E2479800D4A88D /* OrderPaymentDetailsViewModelTests.swift in Sources */, B622BC74289CF19400B10CEC /* WaitingTimeTrackerTests.swift in Sources */, diff --git a/WooCommerce/WooCommerceTests/ViewRelated/Search/Customer/CustomerSearchUICommandTests.swift b/WooCommerce/WooCommerceTests/ViewRelated/Search/Customer/CustomerSearchUICommandTests.swift new file mode 100644 index 00000000000..11a852d3d21 --- /dev/null +++ b/WooCommerce/WooCommerceTests/ViewRelated/Search/Customer/CustomerSearchUICommandTests.swift @@ -0,0 +1,47 @@ +import XCTest + +@testable import WooCommerce +import Yosemite + +final class CustomerSearchUICommandTests: XCTestCase { + private let sampleSiteID: Int64 = 123 + + override func setUp() { + super.setUp() + } + + override func tearDown() { + super.tearDown() + } + + func test_searchResultsPredicate_includes_siteID_and_keyword_when_keyword() { + // Given + let command = CustomerSearchUICommand(siteID: sampleSiteID) { _ in } + + // When + let predicate = command.searchResultsPredicate(keyword: "some") + let expectedQuery = "siteID == 123 AND ANY searchResults.keyword == \"some\"" + + // Then + XCTAssertEqual(predicate?.predicateFormat, expectedQuery) + } + + func test_cellViewModel_display_correct_customer_details() { + let command = CustomerSearchUICommand(siteID: sampleSiteID) { _ in } + let customer = Customer( + siteID: sampleSiteID, + customerID: 1, + email: "john.w@email.com", + firstName: "John", + lastName: "W", + billing: nil, + shipping: nil + ) + + let cellViewModel = command.createCellViewModel(model: customer) + + XCTAssertEqual(cellViewModel.id, String(customer.customerID)) + XCTAssertEqual(cellViewModel.title, "\(customer.firstName ?? "") \(customer.lastName ?? "")") + XCTAssertEqual(cellViewModel.subtitle, String(customer.email)) + } +} From 54192985e997d3aea308ab07af54eb1a8487a7af Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Wed, 26 Oct 2022 22:31:57 +0900 Subject: [PATCH 04/16] Hound: trailing_newline --- .../Search/Customer/CustomerSearchUICommandTests.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/WooCommerce/WooCommerceTests/ViewRelated/Search/Customer/CustomerSearchUICommandTests.swift b/WooCommerce/WooCommerceTests/ViewRelated/Search/Customer/CustomerSearchUICommandTests.swift index 11a852d3d21..934c5fca421 100644 --- a/WooCommerce/WooCommerceTests/ViewRelated/Search/Customer/CustomerSearchUICommandTests.swift +++ b/WooCommerce/WooCommerceTests/ViewRelated/Search/Customer/CustomerSearchUICommandTests.swift @@ -1,5 +1,4 @@ import XCTest - @testable import WooCommerce import Yosemite From fae8db5c49dc1b7b6a0038c547212e1bebcaba1c Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Wed, 26 Oct 2022 22:35:01 +0900 Subject: [PATCH 05/16] Internal comment cleanup --- .../CustomerSection/OrderCustomerListView.swift | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Creation/CustomerSection/OrderCustomerListView.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Creation/CustomerSection/OrderCustomerListView.swift index 2dc0468d988..206373be6fa 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Creation/CustomerSection/OrderCustomerListView.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Creation/CustomerSection/OrderCustomerListView.swift @@ -3,7 +3,7 @@ import Yosemite import SwiftUI /// `SwiftUI` wrapper for `SearchViewController` using `CustomerSearchUICommand` -/// TODO: Make it generic +/// struct OrderCustomerListView: UIViewControllerRepresentable { let siteID: Int64 @@ -16,8 +16,6 @@ struct OrderCustomerListView: UIViewControllerRepresentable { storeID: siteID, command: CustomerSearchUICommand(siteID: siteID, onDidSelectSearchResult: onCustomerTapped), cellType: TitleAndSubtitleAndStatusTableViewCell.self, - // Must conform to SearchResultCell. - // TODO: Proper cell for this cellType. cellSeparator: .none ) let navigationController = WooNavigationController(rootViewController: viewController) @@ -25,6 +23,6 @@ struct OrderCustomerListView: UIViewControllerRepresentable { } func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) { - // nope + // not implemented } } From dff4aed4a62f5bcb39fee26a5ecf85da0a6036f3 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Thu, 27 Oct 2022 11:00:05 +0900 Subject: [PATCH 06/16] Skip searchCustomer request for customerID = 0 --- Yosemite/Yosemite/Stores/CustomerStore.swift | 6 ++++++ .../Stores/CustomerStoreTests.swift | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/Yosemite/Yosemite/Stores/CustomerStore.swift b/Yosemite/Yosemite/Stores/CustomerStore.swift index 1cd6bdd6be9..4e2a797dacf 100644 --- a/Yosemite/Yosemite/Stores/CustomerStore.swift +++ b/Yosemite/Yosemite/Stores/CustomerStore.swift @@ -119,6 +119,12 @@ public final class CustomerStore: Store { var customers = [Customer]() let group = DispatchGroup() for result in searchResults { + // At the moment, we're not searching through non-registered customers + // As we only search by customer ID, calls to /wc/v3/customers/0 will always fail + // https://github.com/woocommerce/woocommerce-ios/issues/7741 + if result.userID == 0 { + continue + } group.enter() self.retrieveCustomer(for: siteID, with: result.userID, onCompletion: { result in if let customer = try? result.get() { diff --git a/Yosemite/YosemiteTests/Stores/CustomerStoreTests.swift b/Yosemite/YosemiteTests/Stores/CustomerStoreTests.swift index 458020ef3a6..3103d5d41d9 100644 --- a/Yosemite/YosemiteTests/Stores/CustomerStoreTests.swift +++ b/Yosemite/YosemiteTests/Stores/CustomerStoreTests.swift @@ -184,4 +184,23 @@ final class CustomerStoreTests: XCTestCase { XCTAssertEqual(storedCustomer?.customerID, dummyCustomerID) XCTAssertEqual(storedCustomer?.firstName, "John") } + + func test_searchCustomers_returns_no_customers_when_customer_is_not_registered() throws { + // Given + let customerID = 0 + network.simulateResponse(requestUrlSuffix: "customers", filename: "wc-analytics-customers") + network.simulateResponse(requestUrlSuffix: "customers/\(customerID)", filename: "customer") + + // When + let response: Result<[Networking.Customer], Error> = waitFor { promise in + let action = CustomerAction.searchCustomers(siteID: self.dummySiteID, keyword: self.dummyKeyword) { result in + promise(result) + } + self.dispatcher.dispatch(action) + } + + // Then + let customers = try response.get() + XCTAssertEqual(customers.count, 0) + } } From 64cb6fe868d10fb868f898dc44b059969ef40f20 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Thu, 27 Oct 2022 11:08:03 +0900 Subject: [PATCH 07/16] Remove unnecessary method --- .../CreateOrderAddressFormViewModel.swift | 18 ------------------ .../AddressFormViewModelProtocol.swift | 4 ---- .../EditOrderAddressFormViewModel.swift | 2 -- 3 files changed, 24 deletions(-) diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Creation/CustomerSection/CreateOrderAddressFormViewModel.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Creation/CustomerSection/CreateOrderAddressFormViewModel.swift index 8257f3214fe..da51c1dd233 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Creation/CustomerSection/CreateOrderAddressFormViewModel.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Creation/CustomerSection/CreateOrderAddressFormViewModel.swift @@ -97,24 +97,6 @@ final class CreateOrderAddressFormViewModel: AddressFormViewModel, AddressFormVi override func trackOnLoad() { } func userDidCancelFlow() { } - - /// Dispatches the searchCustomers action when the Search button is tapped. - /// The hardcoded `keyword` is temporary until we implement the rest of the feature: - /// https://github.com/woocommerce/woocommerce-ios/issues/7741 - /// - func customerSearchTapped() { - let action = CustomerAction.searchCustomers( - siteID: siteID, - keyword: "hello") { result in - switch result { - case .success(_): - print("Success") - case .failure(let error): - print(error) - } - } - stores.dispatch(action) - } } private extension CreateOrderAddressFormViewModel { diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/AddressFormViewModelProtocol.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/AddressFormViewModelProtocol.swift index 120575655b1..f47773ec325 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/AddressFormViewModelProtocol.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/AddressFormViewModelProtocol.swift @@ -103,10 +103,6 @@ protocol AddressFormViewModelProtocol: ObservableObject { /// Creates a view model to be used when selecting a state for secondary fields /// func createSecondaryStateViewModel() -> StateSelectorViewModel - - /// Callback method when the Customer Search button is tapped - /// - func customerSearchTapped() } /// Type to hold values from all the form fields diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressFormViewModel.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressFormViewModel.swift index 48475fec3ff..1644f52465d 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressFormViewModel.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressFormViewModel.swift @@ -164,8 +164,6 @@ final class EditOrderAddressFormViewModel: AddressFormViewModel, AddressFormView func userDidCancelFlow() { analytics.track(event: WooAnalyticsEvent.OrderDetailsEdit.orderDetailEditFlowCanceled(subject: self.analyticsFlowType())) } - - func customerSearchTapped() {} } extension EditOrderAddressFormViewModel { From c5fbc9007570ab4fa6def46a5a70f13f6a015602 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Thu, 27 Oct 2022 11:37:23 +0900 Subject: [PATCH 08/16] Add empty view for empty search results --- .../CustomerSearchUICommand.swift | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Creation/CustomerSection/CustomerSearchUICommand.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Creation/CustomerSection/CustomerSearchUICommand.swift index 9cbb069975e..2623290f586 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Creation/CustomerSection/CustomerSearchUICommand.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Creation/CustomerSection/CustomerSearchUICommand.swift @@ -37,6 +37,16 @@ final class CustomerSearchUICommand: SearchUICommand { nil } + func configureEmptyStateViewControllerBeforeDisplay(viewController: EmptyStateViewController, searchKeyword: String) { + let boldSearchKeyword = NSAttributedString(string: searchKeyword, + attributes: [.font: EmptyStateViewController.Config.messageFont.bold]) + let format = Localization.emptySearchResults + let message = NSMutableAttributedString(string: format) + + message.replaceFirstOccurrence(of: "%@", with: boldSearchKeyword) + viewController.configure(.simple(message: message, image: .emptySearchResultsImage)) + } + func createCellViewModel(model: Customer) -> TitleAndSubtitleAndStatusTableViewCell.ViewModel { return CellViewModel( id: "\(model.customerID)", @@ -61,10 +71,6 @@ final class CustomerSearchUICommand: SearchUICommand { } func didSelectSearchResult(model: Customer, from viewController: UIViewController, reloadData: () -> Void, updateActionButton: () -> Void) { - // Not implemented yet - print("1 - Customer tapped") - print("2 - Customer ID: \(model.customerID) - Name: \(model.firstName ?? ""))") - // Customer data will go up to EditOrderAddressForm, via OrderCustomerListView completion handler onDidSelectSearchResult(model) } @@ -75,7 +81,11 @@ final class CustomerSearchUICommand: SearchUICommand { private extension CustomerSearchUICommand { enum Localization { - static let searchBarPlaceHolder = NSLocalizedString("Search all customers", - comment: "Customer Search Placeholder") + static let searchBarPlaceHolder = NSLocalizedString( + "Search all customers", + comment: "Customer Search Placeholder") + static let emptySearchResults = NSLocalizedString( + "We're sorry, we couldn't find results for “%@”", + comment: "Message for empty Customers search results. %@ is a placeholder for the text entered by the user.") } } From 173398437350c0000903e5683bfe36b29a5e80e2 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Thu, 27 Oct 2022 13:13:24 +0900 Subject: [PATCH 09/16] Set empty state for new keyword searches --- .../CustomerSection/CustomerSearchUICommand.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Creation/CustomerSection/CustomerSearchUICommand.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Creation/CustomerSection/CustomerSearchUICommand.swift index 2623290f586..eeed2279bd2 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Creation/CustomerSection/CustomerSearchUICommand.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Creation/CustomerSection/CustomerSearchUICommand.swift @@ -34,7 +34,7 @@ final class CustomerSearchUICommand: SearchUICommand { } func createStarterViewController() -> UIViewController? { - nil + createEmptyStateViewController() } func configureEmptyStateViewControllerBeforeDisplay(viewController: EmptyStateViewController, searchKeyword: String) { From 9cf838809632b5a1b4e785a10e8993fe4021d23b Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Fri, 28 Oct 2022 11:21:14 +0900 Subject: [PATCH 10/16] Extract fillCustomerFields method to viewModel --- .../AddressFormViewModelProtocol.swift | 29 ++++++++++++++++++ .../Address Edit/EditOrderAddressForm.swift | 30 +------------------ 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/AddressFormViewModelProtocol.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/AddressFormViewModelProtocol.swift index f47773ec325..9088fcbc3d3 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/AddressFormViewModelProtocol.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/AddressFormViewModelProtocol.swift @@ -103,6 +103,10 @@ protocol AddressFormViewModelProtocol: ObservableObject { /// Creates a view model to be used when selecting a state for secondary fields /// func createSecondaryStateViewModel() -> StateSelectorViewModel + + /// Fills AddressForm fields with Customer details + /// + func fillCustomerFields(customer: Customer) } /// Type to hold values from all the form fields @@ -397,6 +401,31 @@ open class AddressFormViewModel: ObservableObject { let secondaryEmailIsValid = secondaryFields.email.isEmpty || EmailFormatValidator.validate(string: fields.email) return primaryEmailIsValid && secondaryEmailIsValid } + + /// Fills AddressForm fields with Customer details + /// + func fillCustomerFields(customer: Customer) { + fields = populate(fields: fields, with: customer, address: customer.billing) + secondaryFields = populate(fields: secondaryFields, with: customer, address: customer.shipping) + } + + private func populate(fields: AddressFormFields, with customer: Customer, address: Address?) -> AddressFormFields { + var fields = fields + + fields.firstName = customer.firstName ?? "" + fields.lastName = customer.lastName ?? "" + fields.email = customer.email + fields.phone = address?.phone ?? "" + fields.company = address?.company ?? "" + fields.address1 = address?.address1 ?? "" + fields.address2 = address?.address2 ?? "" + fields.city = address?.city ?? "" + fields.postcode = address?.postcode ?? "" + fields.country = address?.country ?? "" + fields.state = address?.state ?? "" + + return fields + } } extension AddressFormViewModel { diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressForm.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressForm.swift index afb620d5b41..5365779ac24 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressForm.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressForm.swift @@ -93,34 +93,6 @@ struct EditOrderAddressForm: View { let isSearchCustomersEnabled = DefaultFeatureFlagService().isFeatureFlagEnabled(.orderCreationSearchCustomers) - private func fillCustomerFields(customer: Customer) { - // Primary fields: - self.viewModel.fields.firstName = customer.firstName ?? "" - self.viewModel.fields.lastName = customer.lastName ?? "" - self.viewModel.fields.email = customer.email - self.viewModel.fields.phone = customer.billing?.phone ?? "" - self.viewModel.fields.company = customer.billing?.company ?? "" - self.viewModel.fields.address1 = customer.billing?.address1 ?? "" - self.viewModel.fields.address2 = customer.billing?.address2 ?? "" - self.viewModel.fields.city = customer.billing?.city ?? "" - self.viewModel.fields.postcode = customer.billing?.postcode ?? "" - self.viewModel.fields.country = customer.billing?.country ?? "" - self.viewModel.fields.state = customer.billing?.state ?? "" - // Common secondary fields: - self.viewModel.secondaryFields.firstName = customer.firstName ?? "" - self.viewModel.secondaryFields.lastName = customer.lastName ?? "" - self.viewModel.secondaryFields.email = customer.email - // Secondary fields: - self.viewModel.secondaryFields.phone = customer.shipping?.phone ?? "" - self.viewModel.secondaryFields.company = customer.shipping?.company ?? "" - self.viewModel.secondaryFields.address1 = customer.shipping?.address1 ?? "" - self.viewModel.secondaryFields.address2 = customer.shipping?.address2 ?? "" - self.viewModel.secondaryFields.city = customer.shipping?.city ?? "" - self.viewModel.secondaryFields.postcode = customer.shipping?.postcode ?? "" - self.viewModel.secondaryFields.country = customer.shipping?.country ?? "" - self.viewModel.secondaryFields.state = customer.shipping?.state ?? "" - } - var body: some View { Group { ScrollView { @@ -200,7 +172,7 @@ struct EditOrderAddressForm: View { .notice($viewModel.notice) .sheet(isPresented: $showingCustomerSearch, content: { OrderCustomerListView(siteID: viewModel.siteID, onCustomerTapped: { customer in - fillCustomerFields(customer: customer) + viewModel.fillCustomerFields(customer: customer) showingCustomerSearch = false }) }) From ed043176432e6aebb2605f173c0fd09cbb72056b Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Fri, 28 Oct 2022 11:36:17 +0900 Subject: [PATCH 11/16] Add Unit Test for fillCustomerFields() --- .../EditOrderAddressFormViewModelTests.swift | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/WooCommerce/WooCommerceTests/ViewRelated/Orders/Order Details/Addresses/EditOrderAddressFormViewModelTests.swift b/WooCommerce/WooCommerceTests/ViewRelated/Orders/Order Details/Addresses/EditOrderAddressFormViewModelTests.swift index 1e64378949f..aad6a50c3ea 100644 --- a/WooCommerce/WooCommerceTests/ViewRelated/Orders/Order Details/Addresses/EditOrderAddressFormViewModelTests.swift +++ b/WooCommerce/WooCommerceTests/ViewRelated/Orders/Order Details/Addresses/EditOrderAddressFormViewModelTests.swift @@ -716,6 +716,62 @@ final class EditOrderAddressFormViewModelTests: XCTestCase { // Then XCTAssertEqual(notice, AddressFormViewModel.NoticeFactory.createInvalidEmailNotice()) } + + func test_fillCustomerFields_updates_billing_customer_fields() { + // Given + let viewModel = EditOrderAddressFormViewModel(order: Order.fake(), type: .billing) + let customer = Customer.fake().copy( + email: "scrambled@scrambled.com", + firstName: "Johnny", + lastName: "Appleseed", + billing: sampleAddressWithEmptyNullableFields(), + shipping: sampleAddressWithEmptyNullableFields() + ) + + // When + viewModel.fillCustomerFields(customer: customer) + + // Then + XCTAssertEqual(viewModel.fields.email, customer.email) + XCTAssertEqual(viewModel.fields.firstName, customer.firstName) + XCTAssertEqual(viewModel.fields.lastName, customer.lastName) + XCTAssertEqual(viewModel.fields.company, customer.billing?.company) + XCTAssertEqual(viewModel.fields.address1, customer.billing?.address1) + XCTAssertEqual(viewModel.fields.address2, customer.billing?.address2) + XCTAssertEqual(viewModel.fields.city, customer.billing?.city) + XCTAssertEqual(viewModel.fields.state, customer.billing?.state) + XCTAssertEqual(viewModel.fields.postcode, customer.billing?.postcode) + XCTAssertEqual(viewModel.fields.country, customer.billing?.country) + XCTAssertEqual(viewModel.fields.phone, customer.billing?.phone) + } + + func test_fillCustomerFields_updates_shipping_customer_fields() { + // Given + let viewModel = EditOrderAddressFormViewModel(order: Order.fake(), type: .shipping) + let customer = Customer.fake().copy( + email: "scrambled@scrambled.com", + firstName: "Johnny", + lastName: "Appleseed", + billing: sampleAddressWithEmptyNullableFields(), + shipping: sampleAddressWithEmptyNullableFields() + ) + + // When + viewModel.fillCustomerFields(customer: customer) + + // Then + XCTAssertEqual(viewModel.fields.email, customer.email) + XCTAssertEqual(viewModel.fields.firstName, customer.firstName) + XCTAssertEqual(viewModel.fields.lastName, customer.lastName) + XCTAssertEqual(viewModel.fields.company, customer.shipping?.company) + XCTAssertEqual(viewModel.fields.address1, customer.shipping?.address1) + XCTAssertEqual(viewModel.fields.address2, customer.shipping?.address2) + XCTAssertEqual(viewModel.fields.city, customer.shipping?.city) + XCTAssertEqual(viewModel.fields.state, customer.shipping?.state) + XCTAssertEqual(viewModel.fields.postcode, customer.shipping?.postcode) + XCTAssertEqual(viewModel.fields.country, customer.shipping?.country) + XCTAssertEqual(viewModel.fields.phone, customer.shipping?.phone) + } } private extension EditOrderAddressFormViewModelTests { From 5dffa9738ce7182ab10a65f5bacc772e06709fe7 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Fri, 28 Oct 2022 12:12:28 +0900 Subject: [PATCH 12/16] Display shipping details form if addresses differ --- .../AddressFormViewModelProtocol.swift | 14 ++++++++---- .../Address Edit/EditOrderAddressForm.swift | 2 +- .../EditOrderAddressFormViewModelTests.swift | 22 +++++++++++++++---- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/AddressFormViewModelProtocol.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/AddressFormViewModelProtocol.swift index 9088fcbc3d3..1f37958bdb5 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/AddressFormViewModelProtocol.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/AddressFormViewModelProtocol.swift @@ -104,9 +104,9 @@ protocol AddressFormViewModelProtocol: ObservableObject { /// func createSecondaryStateViewModel() -> StateSelectorViewModel - /// Fills AddressForm fields with Customer details + /// Triggers the logic to fill Customer Order details when a Customer is selected /// - func fillCustomerFields(customer: Customer) + func customerSelectedFromSearch(customer: Customer) } /// Type to hold values from all the form fields @@ -402,9 +402,15 @@ open class AddressFormViewModel: ObservableObject { return primaryEmailIsValid && secondaryEmailIsValid } - /// Fills AddressForm fields with Customer details + /// Fills Order AddressFormFields with Customer details /// - func fillCustomerFields(customer: Customer) { + func customerSelectedFromSearch(customer: Customer) { + fillCustomerFields(customer: customer) + let addressesDiffer = customer.billing != customer.shipping + showDifferentAddressForm = addressesDiffer + } + + private func fillCustomerFields(customer: Customer) { fields = populate(fields: fields, with: customer, address: customer.billing) secondaryFields = populate(fields: secondaryFields, with: customer, address: customer.shipping) } diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressForm.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressForm.swift index 5365779ac24..51bf0069510 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressForm.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressForm.swift @@ -172,7 +172,7 @@ struct EditOrderAddressForm: View { .notice($viewModel.notice) .sheet(isPresented: $showingCustomerSearch, content: { OrderCustomerListView(siteID: viewModel.siteID, onCustomerTapped: { customer in - viewModel.fillCustomerFields(customer: customer) + viewModel.customerSelectedFromSearch(customer: customer) showingCustomerSearch = false }) }) diff --git a/WooCommerce/WooCommerceTests/ViewRelated/Orders/Order Details/Addresses/EditOrderAddressFormViewModelTests.swift b/WooCommerce/WooCommerceTests/ViewRelated/Orders/Order Details/Addresses/EditOrderAddressFormViewModelTests.swift index aad6a50c3ea..db957c1ebb4 100644 --- a/WooCommerce/WooCommerceTests/ViewRelated/Orders/Order Details/Addresses/EditOrderAddressFormViewModelTests.swift +++ b/WooCommerce/WooCommerceTests/ViewRelated/Orders/Order Details/Addresses/EditOrderAddressFormViewModelTests.swift @@ -717,7 +717,7 @@ final class EditOrderAddressFormViewModelTests: XCTestCase { XCTAssertEqual(notice, AddressFormViewModel.NoticeFactory.createInvalidEmailNotice()) } - func test_fillCustomerFields_updates_billing_customer_fields() { + func test_OrderAddressForm_billing_fields_are_updated_when_customerSelectedFromSearch() { // Given let viewModel = EditOrderAddressFormViewModel(order: Order.fake(), type: .billing) let customer = Customer.fake().copy( @@ -729,7 +729,7 @@ final class EditOrderAddressFormViewModelTests: XCTestCase { ) // When - viewModel.fillCustomerFields(customer: customer) + viewModel.customerSelectedFromSearch(customer: customer) // Then XCTAssertEqual(viewModel.fields.email, customer.email) @@ -745,7 +745,7 @@ final class EditOrderAddressFormViewModelTests: XCTestCase { XCTAssertEqual(viewModel.fields.phone, customer.billing?.phone) } - func test_fillCustomerFields_updates_shipping_customer_fields() { + func test_OrderAddressForm_shipping_fields_are_updated_when_customerSelectedFromSearch() { // Given let viewModel = EditOrderAddressFormViewModel(order: Order.fake(), type: .shipping) let customer = Customer.fake().copy( @@ -757,7 +757,7 @@ final class EditOrderAddressFormViewModelTests: XCTestCase { ) // When - viewModel.fillCustomerFields(customer: customer) + viewModel.customerSelectedFromSearch(customer: customer) // Then XCTAssertEqual(viewModel.fields.email, customer.email) @@ -772,6 +772,20 @@ final class EditOrderAddressFormViewModelTests: XCTestCase { XCTAssertEqual(viewModel.fields.country, customer.shipping?.country) XCTAssertEqual(viewModel.fields.phone, customer.shipping?.phone) } + + func test_OrderAddressForm_shows_different_address_form_fields_when_addresses_differ_and_customerSelectedFromSearch() { + // Given + let viewModel = EditOrderAddressFormViewModel(order: Order.fake(), type: .billing) + let billing = sampleAddressWithEmptyNullableFields() + let shipping = Address.fake().copy(address1: "123 different fake street") + let customer = Customer.fake().copy(billing: billing, shipping: shipping) + + // When + viewModel.customerSelectedFromSearch(customer: customer) + + // Then + XCTAssertTrue(viewModel.showDifferentAddressForm) + } } private extension EditOrderAddressFormViewModelTests { From 7b58531d1272643fddc848ed904c820ef2b2b7e4 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Tue, 1 Nov 2022 09:08:00 +0900 Subject: [PATCH 13/16] Add/improve test case for unregistered customer --- .../WCAnalyticsCustomerRemoteTests.swift | 16 +++++++++------- .../Responses/wc-analytics-customers.json | 19 +++++++++++++++++++ .../CustomerSearchUICommandTests.swift | 8 -------- .../Stores/CustomerStoreTests.swift | 12 ++++++------ 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/Networking/NetworkingTests/Remote/WCAnalyticsCustomerRemoteTests.swift b/Networking/NetworkingTests/Remote/WCAnalyticsCustomerRemoteTests.swift index b8a400a1042..0d7ee9c1401 100644 --- a/Networking/NetworkingTests/Remote/WCAnalyticsCustomerRemoteTests.swift +++ b/Networking/NetworkingTests/Remote/WCAnalyticsCustomerRemoteTests.swift @@ -45,13 +45,15 @@ class WCAnalyticsCustomerRemoteTests: XCTestCase { let customers = try XCTUnwrap(result.get()) let hasSearchParameter = network.queryParameters?.contains(where: { $0 == "search=John" }) ?? false XCTAssertTrue(hasSearchParameter) - assertEqual(3, customers.count) - assertEqual(1, customers[0].userID) - assertEqual(2, customers[1].userID) - assertEqual(3, customers[2].userID) - assertEqual("John", customers[0].name) - assertEqual("Paul", customers[1].name) - assertEqual("John Doe", customers[2].name) + assertEqual(4, customers.count) + assertEqual(0, customers[0].userID) + assertEqual(1, customers[1].userID) + assertEqual(2, customers[2].userID) + assertEqual(3, customers[3].userID) + assertEqual("Matt The Unregistered", customers[0].name) + assertEqual("John", customers[1].name) + assertEqual("Paul", customers[2].name) + assertEqual("John Doe", customers[3].name) } func test_WCAnalyticsCustomerRemote_when_calls_retrieveCustomersByName_fails_then_returns_result_isFailure() { diff --git a/Networking/NetworkingTests/Responses/wc-analytics-customers.json b/Networking/NetworkingTests/Responses/wc-analytics-customers.json index 3988a0f1aab..7c92958649b 100644 --- a/Networking/NetworkingTests/Responses/wc-analytics-customers.json +++ b/Networking/NetworkingTests/Responses/wc-analytics-customers.json @@ -1,5 +1,24 @@ { "data": [ + { + "id":0, + "user_id":0, + "username":"Matt.the.unregistered", + "name":"Matt The Unregistered", + "email":"matt.t.u@example.com", + "country":"US", + "city":"San Francisco", + "state":"CA", + "postcode":"94103", + "date_registered":null, + "date_last_active":"2022-07-12T08:36:54", + "date_last_order":"2022-07-12 08:36:54", + "orders_count":1, + "total_spend":10, + "avg_order_value":10, + "date_registered_gmt":null, + "date_last_active_gmt":"2022-07-12T08:36:54" + }, { "id":1, "user_id":1, diff --git a/WooCommerce/WooCommerceTests/ViewRelated/Search/Customer/CustomerSearchUICommandTests.swift b/WooCommerce/WooCommerceTests/ViewRelated/Search/Customer/CustomerSearchUICommandTests.swift index 934c5fca421..5281cc97c35 100644 --- a/WooCommerce/WooCommerceTests/ViewRelated/Search/Customer/CustomerSearchUICommandTests.swift +++ b/WooCommerce/WooCommerceTests/ViewRelated/Search/Customer/CustomerSearchUICommandTests.swift @@ -5,14 +5,6 @@ import Yosemite final class CustomerSearchUICommandTests: XCTestCase { private let sampleSiteID: Int64 = 123 - override func setUp() { - super.setUp() - } - - override func tearDown() { - super.tearDown() - } - func test_searchResultsPredicate_includes_siteID_and_keyword_when_keyword() { // Given let command = CustomerSearchUICommand(siteID: sampleSiteID) { _ in } diff --git a/Yosemite/YosemiteTests/Stores/CustomerStoreTests.swift b/Yosemite/YosemiteTests/Stores/CustomerStoreTests.swift index 3103d5d41d9..9f0aada3a15 100644 --- a/Yosemite/YosemiteTests/Stores/CustomerStoreTests.swift +++ b/Yosemite/YosemiteTests/Stores/CustomerStoreTests.swift @@ -187,20 +187,20 @@ final class CustomerStoreTests: XCTestCase { func test_searchCustomers_returns_no_customers_when_customer_is_not_registered() throws { // Given - let customerID = 0 network.simulateResponse(requestUrlSuffix: "customers", filename: "wc-analytics-customers") - network.simulateResponse(requestUrlSuffix: "customers/\(customerID)", filename: "customer") // When - let response: Result<[Networking.Customer], Error> = waitFor { promise in + () = waitFor { promise in let action = CustomerAction.searchCustomers(siteID: self.dummySiteID, keyword: self.dummyKeyword) { result in - promise(result) + promise(()) } self.dispatcher.dispatch(action) } // Then - let customers = try response.get() - XCTAssertEqual(customers.count, 0) + let requests = network.requestsForResponseData.compactMap { $0 as? JetpackRequest } + XCTAssertFalse(requests.contains(where: { request in + request.path == "customers/0" + })) } } From 121ba8a10f18fa7b0f78f998df81c82d6b186544 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Tue, 1 Nov 2022 09:53:46 +0900 Subject: [PATCH 14/16] Populate fields with Address details, not Customer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We’ll be populating the fields using the Address data rather than Customer data for these 3 fields, for consistency with Android. There’s some inconsistency with the API though, reported here: https://github.com/woocommerce/woocommerce-ios/issues/7993 --- .../AddressFormViewModelProtocol.swift | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/AddressFormViewModelProtocol.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/AddressFormViewModelProtocol.swift index 1f37958bdb5..aa27e5d518c 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/AddressFormViewModelProtocol.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/AddressFormViewModelProtocol.swift @@ -411,16 +411,19 @@ open class AddressFormViewModel: ObservableObject { } private func fillCustomerFields(customer: Customer) { - fields = populate(fields: fields, with: customer, address: customer.billing) - secondaryFields = populate(fields: secondaryFields, with: customer, address: customer.shipping) + fields = populate(fields: fields, with: customer.billing) + secondaryFields = populate(fields: secondaryFields, with: customer.shipping) } - private func populate(fields: AddressFormFields, with customer: Customer, address: Address?) -> AddressFormFields { + private func populate(fields: AddressFormFields, with address: Address?) -> AddressFormFields { var fields = fields - fields.firstName = customer.firstName ?? "" - fields.lastName = customer.lastName ?? "" - fields.email = customer.email + fields.firstName = address?.firstName ?? "" + fields.lastName = address?.lastName ?? "" + // Email is declared optional because we're using the same property from the Address model + // for both Shipping and Billing details: + // https://github.com/woocommerce/woocommerce-ios/issues/7993 + fields.email = address?.email ?? "" fields.phone = address?.phone ?? "" fields.company = address?.company ?? "" fields.address1 = address?.address1 ?? "" From d3438630cfd929a64d6a3b03fd2fd291aa197073 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Tue, 1 Nov 2022 10:27:57 +0900 Subject: [PATCH 15/16] Update WCAnalyticsCustomerMapperTests --- .../Mapper/WCAnalyticsCustomerMapperTests.swift | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Networking/NetworkingTests/Mapper/WCAnalyticsCustomerMapperTests.swift b/Networking/NetworkingTests/Mapper/WCAnalyticsCustomerMapperTests.swift index dc5247597d6..057f949da45 100644 --- a/Networking/NetworkingTests/Mapper/WCAnalyticsCustomerMapperTests.swift +++ b/Networking/NetworkingTests/Mapper/WCAnalyticsCustomerMapperTests.swift @@ -35,7 +35,7 @@ class WCAnalyticsCustomerMapperTests: XCTestCase { customers = try! mapper.map(response: data) // Then - XCTAssertEqual(customers.count, 3) + XCTAssertEqual(customers.count, 4) } func test_WCAnalyticsCustomer_array_response_values_are_correctly_parsed() { @@ -50,11 +50,13 @@ class WCAnalyticsCustomerMapperTests: XCTestCase { let customers = try! mapper.map(response: data) // Then - XCTAssertEqual(customers[0].userID, 1) - XCTAssertEqual(customers[0].name, "John") - XCTAssertEqual(customers[1].userID, 2) - XCTAssertEqual(customers[1].name, "Paul") - XCTAssertEqual(customers[2].userID, 3) - XCTAssertEqual(customers[2].name, "John Doe") + XCTAssertEqual(customers[0].userID, 0) + XCTAssertEqual(customers[0].name, "Matt The Unregistered") + XCTAssertEqual(customers[1].userID, 1) + XCTAssertEqual(customers[1].name, "John") + XCTAssertEqual(customers[2].userID, 2) + XCTAssertEqual(customers[2].name, "Paul") + XCTAssertEqual(customers[3].userID, 3) + XCTAssertEqual(customers[3].name, "John Doe") } } From 2b772b72819cecfec641ffd973c996588da71cc0 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Tue, 1 Nov 2022 11:35:59 +0900 Subject: [PATCH 16/16] Update EdirOrderAddressFormViewModel tests --- .../Addresses/EditOrderAddressFormViewModelTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WooCommerce/WooCommerceTests/ViewRelated/Orders/Order Details/Addresses/EditOrderAddressFormViewModelTests.swift b/WooCommerce/WooCommerceTests/ViewRelated/Orders/Order Details/Addresses/EditOrderAddressFormViewModelTests.swift index db957c1ebb4..3947050db71 100644 --- a/WooCommerce/WooCommerceTests/ViewRelated/Orders/Order Details/Addresses/EditOrderAddressFormViewModelTests.swift +++ b/WooCommerce/WooCommerceTests/ViewRelated/Orders/Order Details/Addresses/EditOrderAddressFormViewModelTests.swift @@ -732,7 +732,7 @@ final class EditOrderAddressFormViewModelTests: XCTestCase { viewModel.customerSelectedFromSearch(customer: customer) // Then - XCTAssertEqual(viewModel.fields.email, customer.email) + XCTAssertEqual(viewModel.fields.email, customer.billing?.email) XCTAssertEqual(viewModel.fields.firstName, customer.firstName) XCTAssertEqual(viewModel.fields.lastName, customer.lastName) XCTAssertEqual(viewModel.fields.company, customer.billing?.company) @@ -760,7 +760,7 @@ final class EditOrderAddressFormViewModelTests: XCTestCase { viewModel.customerSelectedFromSearch(customer: customer) // Then - XCTAssertEqual(viewModel.fields.email, customer.email) + XCTAssertEqual(viewModel.fields.email, customer.shipping?.email) XCTAssertEqual(viewModel.fields.firstName, customer.firstName) XCTAssertEqual(viewModel.fields.lastName, customer.lastName) XCTAssertEqual(viewModel.fields.company, customer.shipping?.company)