diff --git a/Fakes/Fakes/Networking.generated.swift b/Fakes/Fakes/Networking.generated.swift index a00b4d148dd..b834f81cbfc 100644 --- a/Fakes/Fakes/Networking.generated.swift +++ b/Fakes/Fakes/Networking.generated.swift @@ -871,7 +871,8 @@ extension Networking.Order { customFields: .fake(), renewalSubscriptionID: .fake(), appliedGiftCards: .fake(), - attributionInfo: .fake() + attributionInfo: .fake(), + shippingLabels: .fake() ) } } diff --git a/Networking/Networking.xcodeproj/project.pbxproj b/Networking/Networking.xcodeproj/project.pbxproj index 1c934bf6913..104ceba58a5 100644 --- a/Networking/Networking.xcodeproj/project.pbxproj +++ b/Networking/Networking.xcodeproj/project.pbxproj @@ -464,6 +464,11 @@ 453954D22C90D84200A3E64A /* meta-data-products-and-orders.json in Resources */ = {isa = PBXBuildFile; fileRef = 453954D12C90D84200A3E64A /* meta-data-products-and-orders.json */; }; 453954D42C90E81300A3E64A /* MetaDataRemoteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 453954D32C90E81300A3E64A /* MetaDataRemoteTests.swift */; }; 453954D62C9193BC00A3E64A /* meta-data-products-orders-update.json in Resources */ = {isa = PBXBuildFile; fileRef = 453954D52C9193BC00A3E64A /* meta-data-products-orders-update.json */; }; + 453B33FD2D47F1F4005C05B0 /* ShippingLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02C254A7256373AB00A04423 /* ShippingLabel.swift */; }; + 453B33FE2D47F1FB005C05B0 /* ShippingLabelStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02C254AB2563781800A04423 /* ShippingLabelStatus.swift */; }; + 453B33FF2D47F203005C05B0 /* ShippingLabelRefund.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02C2549F25636F6900A04423 /* ShippingLabelRefund.swift */; }; + 453B34002D47F20A005C05B0 /* ShippingLabelRefundStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02C254AF256378D000A04423 /* ShippingLabelRefundStatus.swift */; }; + 453B34012D47F22C005C05B0 /* ShippingLabelAddress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02C2549925636E1500A04423 /* ShippingLabelAddress.swift */; }; 45551F122523E7F1007EF104 /* UserAgent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45551F112523E7F1007EF104 /* UserAgent.swift */; }; 45551F142523E7FF007EF104 /* UserAgentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45551F132523E7FF007EF104 /* UserAgentTests.swift */; }; 4568E2222459ADC60007E478 /* SitePostsRemote.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4568E2212459ADC60007E478 /* SitePostsRemote.swift */; }; @@ -4892,11 +4897,13 @@ 2680B0D22BED5A4C00E7F1D8 /* AuthenticatedRESTRequest.swift in Sources */, 2680B0D02BED5A1900E7F1D8 /* WooConstants.swift in Sources */, 2680B0CF2BED59CE00E7F1D8 /* ApplicationPasswordStorage.swift in Sources */, + 453B34002D47F20A005C05B0 /* ShippingLabelRefundStatus.swift in Sources */, 2680B0CB2BED58B200E7F1D8 /* ApplicationPasswordNameAndUUID.swift in Sources */, 26373E0A2BFCEAAF008E6735 /* OrderItemTax.swift in Sources */, 2680B0CC2BED58B200E7F1D8 /* ApplicationPassword.swift in Sources */, 26373E122BFCEDB7008E6735 /* OrderFeeLine.swift in Sources */, 26F2CADD2BED579100F9A5E7 /* ApplicationPasswordUseCase.swift in Sources */, + 453B33FF2D47F203005C05B0 /* ShippingLabelRefund.swift in Sources */, 26F2CADA2BED578200F9A5E7 /* RequestProcessor.swift in Sources */, 26F2CADB2BED578200F9A5E7 /* RequestAuthenticator.swift in Sources */, 26F2CADC2BED578200F9A5E7 /* RequestConverter.swift in Sources */, @@ -4909,6 +4916,7 @@ 263A6DBC2BEAA49B00C292B2 /* AnyDecodable.swift in Sources */, 263A6DBD2BEAA49B00C292B2 /* AnyEncodable.swift in Sources */, 263A6DB92BEAA46F00C292B2 /* SiteSummaryStatsMapper.swift in Sources */, + 453B33FD2D47F1F4005C05B0 /* ShippingLabel.swift in Sources */, 26373E112BFCEDAE008E6735 /* OrderRefundCondensed.swift in Sources */, 263A6DBA2BEAA46F00C292B2 /* SiteSummaryStats.swift in Sources */, 263A6DB62BEAA46000C292B2 /* SiteVisitStatsMapper.swift in Sources */, @@ -4967,6 +4975,7 @@ 26CFDEE12C0295EA005ABC31 /* MetaContainer.swift in Sources */, 26373E152BFCEDE9008E6735 /* OrderGiftCard.swift in Sources */, 269014CB2BEA9253006056E0 /* JetpackRequest.swift in Sources */, + 453B34012D47F22C005C05B0 /* ShippingLabelAddress.swift in Sources */, 269014CA2BEA924B006056E0 /* NetworkError.swift in Sources */, 26373E092BFCEA90008E6735 /* OrderItemProductAddOn.swift in Sources */, 26373E162BFCEDFD008E6735 /* OrderAttributionInfo.swift in Sources */, @@ -4979,6 +4988,7 @@ 269014C32BEA9134006056E0 /* Mapper.swift in Sources */, 269014C22BEA912D006056E0 /* Request.swift in Sources */, 26373E182BFCEF79008E6735 /* KeyedDecodingContainer+Woo.swift in Sources */, + 453B33FE2D47F1FB005C05B0 /* ShippingLabelStatus.swift in Sources */, 26373E202BFCF6A7008E6735 /* EntityDateModifiedMapper.swift in Sources */, 26CFDEE02C0295E1005ABC31 /* NoteRange.swift in Sources */, 26CFDEDE2C0295CB005ABC31 /* NoteBlock.swift in Sources */, diff --git a/Networking/Networking/Model/Copiable/Models+Copiable.generated.swift b/Networking/Networking/Model/Copiable/Models+Copiable.generated.swift index addec7afc76..bce088fb3e7 100644 --- a/Networking/Networking/Model/Copiable/Models+Copiable.generated.swift +++ b/Networking/Networking/Model/Copiable/Models+Copiable.generated.swift @@ -1348,7 +1348,8 @@ extension Networking.Order { customFields: CopiableProp<[MetaData]> = .copy, renewalSubscriptionID: NullableCopiableProp = .copy, appliedGiftCards: CopiableProp<[OrderGiftCard]> = .copy, - attributionInfo: NullableCopiableProp = .copy + attributionInfo: NullableCopiableProp = .copy, + shippingLabels: CopiableProp<[ShippingLabel]> = .copy ) -> Networking.Order { let siteID = siteID ?? self.siteID let orderID = orderID ?? self.orderID @@ -1388,6 +1389,7 @@ extension Networking.Order { let renewalSubscriptionID = renewalSubscriptionID ?? self.renewalSubscriptionID let appliedGiftCards = appliedGiftCards ?? self.appliedGiftCards let attributionInfo = attributionInfo ?? self.attributionInfo + let shippingLabels = shippingLabels ?? self.shippingLabels return Networking.Order( siteID: siteID, @@ -1427,7 +1429,8 @@ extension Networking.Order { customFields: customFields, renewalSubscriptionID: renewalSubscriptionID, appliedGiftCards: appliedGiftCards, - attributionInfo: attributionInfo + attributionInfo: attributionInfo, + shippingLabels: shippingLabels ) } } diff --git a/Networking/Networking/Model/Order.swift b/Networking/Networking/Model/Order.swift index d11767bf3a5..e0f48aaf72e 100644 --- a/Networking/Networking/Model/Order.swift +++ b/Networking/Networking/Model/Order.swift @@ -61,6 +61,10 @@ public struct Order: Decodable, Sendable, GeneratedCopiable, GeneratedFakeable { /// public let attributionInfo: OrderAttributionInfo? + /// Shipping labels associated with the order + /// + public let shippingLabels: [ShippingLabel] + /// Order struct initializer. /// public init(siteID: Int64, @@ -100,7 +104,8 @@ public struct Order: Decodable, Sendable, GeneratedCopiable, GeneratedFakeable { customFields: [MetaData], renewalSubscriptionID: String?, appliedGiftCards: [OrderGiftCard], - attributionInfo: OrderAttributionInfo?) { + attributionInfo: OrderAttributionInfo?, + shippingLabels: [ShippingLabel]) { self.siteID = siteID self.orderID = orderID @@ -145,6 +150,7 @@ public struct Order: Decodable, Sendable, GeneratedCopiable, GeneratedFakeable { self.renewalSubscriptionID = renewalSubscriptionID self.appliedGiftCards = appliedGiftCards self.attributionInfo = attributionInfo + self.shippingLabels = shippingLabels } @@ -239,6 +245,11 @@ public struct Order: Decodable, Sendable, GeneratedCopiable, GeneratedFakeable { return OrderAttributionInfo(metaData: allOrderMetaData) }() + // Shipping labels + /// This will be an empty array by default because it's not directly parsed from the Order details, so it won't be decoded. + /// It's fetched with a specific API request, while at the same time it has a relationship in Core Data with Order. + let shippingLabels: [ShippingLabel] = [] + self.init(siteID: siteID, orderID: orderID, parentID: parentID, @@ -276,7 +287,8 @@ public struct Order: Decodable, Sendable, GeneratedCopiable, GeneratedFakeable { customFields: customFields, renewalSubscriptionID: renewalSubscriptionID, appliedGiftCards: appliedGiftCards, - attributionInfo: attributionInfo) + attributionInfo: attributionInfo, + shippingLabels: shippingLabels) } public static var empty: Order { @@ -317,7 +329,8 @@ public struct Order: Decodable, Sendable, GeneratedCopiable, GeneratedFakeable { customFields: [], renewalSubscriptionID: nil, appliedGiftCards: [], - attributionInfo: nil) + attributionInfo: nil, + shippingLabels: []) } } @@ -365,6 +378,7 @@ internal extension Order { case taxLines = "tax_lines" case metadata = "meta_data" case giftCards = "gift_cards" + case shippingLabels = "shipping_labels" } } @@ -407,7 +421,8 @@ extension Order: Equatable { lhs.items.count == rhs.items.count && lhs.items.sorted() == rhs.items.sorted() && lhs.customerNote == rhs.customerNote && - lhs.attributionInfo == rhs.attributionInfo + lhs.attributionInfo == rhs.attributionInfo && + lhs.shippingLabels == rhs.shippingLabels } } diff --git a/Networking/Networking/Model/ShippingLabel/Enums/ShippingLabelRefundStatus.swift b/Networking/Networking/Model/ShippingLabel/Enums/ShippingLabelRefundStatus.swift index ea94b1f0d1f..d743edd9251 100644 --- a/Networking/Networking/Model/ShippingLabel/Enums/ShippingLabelRefundStatus.swift +++ b/Networking/Networking/Model/ShippingLabel/Enums/ShippingLabelRefundStatus.swift @@ -2,7 +2,7 @@ import Foundation import Codegen /// The status of shipping label refund. -public enum ShippingLabelRefundStatus: GeneratedFakeable { +public enum ShippingLabelRefundStatus: Sendable, GeneratedFakeable { case pending case unknown } diff --git a/Networking/Networking/Model/ShippingLabel/Enums/ShippingLabelStatus.swift b/Networking/Networking/Model/ShippingLabel/Enums/ShippingLabelStatus.swift index 549d9c727e5..6c48eb4e849 100644 --- a/Networking/Networking/Model/ShippingLabel/Enums/ShippingLabelStatus.swift +++ b/Networking/Networking/Model/ShippingLabel/Enums/ShippingLabelStatus.swift @@ -2,7 +2,7 @@ import Foundation import Codegen /// The status of shipping label. -public enum ShippingLabelStatus: GeneratedFakeable { +public enum ShippingLabelStatus: Sendable, GeneratedFakeable { case purchased case purchaseError case purchaseInProgress diff --git a/Networking/Networking/Model/ShippingLabel/ShippingLabel.swift b/Networking/Networking/Model/ShippingLabel/ShippingLabel.swift index dd76e7088e1..3a7d5b36156 100644 --- a/Networking/Networking/Model/ShippingLabel/ShippingLabel.swift +++ b/Networking/Networking/Model/ShippingLabel/ShippingLabel.swift @@ -3,7 +3,7 @@ import Codegen /// Represents a Shipping Label. /// -public struct ShippingLabel: Equatable, GeneratedCopiable, GeneratedFakeable { +public struct ShippingLabel: Equatable, Sendable, GeneratedCopiable, GeneratedFakeable { /// The remote ID of the site that owns this shipping label. public let siteID: Int64 diff --git a/Networking/Networking/Model/ShippingLabel/ShippingLabelAddress.swift b/Networking/Networking/Model/ShippingLabel/ShippingLabelAddress.swift index cdda6f641fb..bfe44a91be9 100644 --- a/Networking/Networking/Model/ShippingLabel/ShippingLabelAddress.swift +++ b/Networking/Networking/Model/ShippingLabel/ShippingLabelAddress.swift @@ -3,7 +3,7 @@ import Codegen /// Represents a Shipping Label Address. /// -public struct ShippingLabelAddress: GeneratedCopiable, Equatable, GeneratedFakeable { +public struct ShippingLabelAddress: GeneratedCopiable, Equatable, Sendable, GeneratedFakeable { /// The name of the company at the address. public let company: String diff --git a/Networking/Networking/Model/ShippingLabel/ShippingLabelRefund.swift b/Networking/Networking/Model/ShippingLabel/ShippingLabelRefund.swift index a499f1b6894..d914cc5f91a 100644 --- a/Networking/Networking/Model/ShippingLabel/ShippingLabelRefund.swift +++ b/Networking/Networking/Model/ShippingLabel/ShippingLabelRefund.swift @@ -3,7 +3,7 @@ import Codegen /// Represents a Shipping Label Refund. /// -public struct ShippingLabelRefund: Equatable, GeneratedFakeable { +public struct ShippingLabelRefund: Equatable, Sendable, GeneratedFakeable { /// The date of refund request. public let dateRequested: Date diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index dd233f28386..7a67319086b 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -6,6 +6,7 @@ - [*] Product Details: Display cover tag on the first product image [https://github.com/woocommerce/woocommerce-ios/pull/15041] - [*] Payments: Update learn more links to open Stripe-specific docs when using that gateway [https://github.com/woocommerce/woocommerce-ios/pull/15035] - [*] Now, usernames and emails in text fields across multiple login views are no longer capitalized. [https://github.com/woocommerce/woocommerce-ios/pull/15002] +- [internal] Improve data fetching in Order Details, to avoid I/O performance on the main thread. [https://github.com/woocommerce/woocommerce-ios/pull/14999] 21.6 ----- @@ -13,6 +14,7 @@ - [*] Payments: Improved error handling during card payments and refunds [https://github.com/woocommerce/woocommerce-ios/pull/14980] - [***] Updated the app look and feel to match the new WooCommerce branding [https://github.com/woocommerce/woocommerce-ios/pull/14825] + 21.5 ----- - [*] Blaze: if the AI is unable to provide suggestions in the creation form, the form will now automatically use product information to ensure all fields of the preview are populated. [https://github.com/woocommerce/woocommerce-ios/pull/14868] diff --git a/WooCommerce/Classes/ViewModels/Order Details/OrderDetailsResultsControllers.swift b/WooCommerce/Classes/ViewModels/Order Details/OrderDetailsResultsControllers.swift index 85fc4f0189a..4270b4f4934 100644 --- a/WooCommerce/Classes/ViewModels/Order Details/OrderDetailsResultsControllers.swift +++ b/WooCommerce/Classes/ViewModels/Order Details/OrderDetailsResultsControllers.swift @@ -34,15 +34,6 @@ final class OrderDetailsResultsControllers { /// private lazy var productVariationResultsController: ResultsController = getProductVariationResultsController() - /// Fee lines Results Controller. - /// - private lazy var feeLinesResultsController: ResultsController = { - let predicate = NSPredicate(format: "order.orderID == %ld", order.orderID) - let descriptor = NSSortDescriptor(key: "feeID", ascending: true) - - return ResultsController(storageManager: storageManager, matching: predicate, sortedBy: [descriptor]) - }() - /// Status Results Controller. /// private lazy var statusResultsController: ResultsController = { @@ -63,17 +54,6 @@ final class OrderDetailsResultsControllers { return ResultsController(storageManager: storageManager, matching: predicate, sortedBy: [descriptor]) }() - /// ShippingLabel Results Controller. - /// - private lazy var shippingLabelResultsController: ResultsController = { - let predicate = NSPredicate(format: "siteID = %ld AND orderID = %ld", order.siteID, order.orderID) - let dateCreatedDescriptor = NSSortDescriptor(keyPath: \StorageShippingLabel.dateCreated, ascending: false) - let shippingLabelIDDescriptor = NSSortDescriptor(keyPath: \StorageShippingLabel.shippingLabelID, ascending: false) - return ResultsController(storageManager: storageManager, - matching: predicate, - sortedBy: [dateCreatedDescriptor, shippingLabelIDDescriptor]) - }() - /// AddOnGroup ResultsController. /// private lazy var addOnGroupResultsController: ResultsController = { @@ -128,7 +108,7 @@ final class OrderDetailsResultsControllers { /// Shipping labels for an Order /// var shippingLabels: [ShippingLabel] { - return shippingLabelResultsController.fetchedObjects + return order.shippingLabels } /// Site's add-on groups. @@ -142,7 +122,7 @@ final class OrderDetailsResultsControllers { } var feeLines: [OrderFeeLine] { - return feeLinesResultsController.fetchedObjects + return order.fees } /// Shipping methods list @@ -169,10 +149,8 @@ final class OrderDetailsResultsControllers { configureProductResultsController(onReload: onReload) configureProductVariationResultsController(onReload: onReload) configureRefundResultsController(onReload: onReload) - configureShippingLabelResultsController(onReload: onReload) configureAddOnGroupResultsController(onReload: onReload) configureSitePluginsResultsController(onReload: onReload) - configureFeeLinesResultsController(onReload: onReload) configureShippingMethodsResultsController(onReload: onReload) } @@ -286,24 +264,6 @@ private extension OrderDetailsResultsControllers { } } - private func configureShippingLabelResultsController(onReload: @escaping () -> Void) { - shippingLabelResultsController.onDidChangeContent = { - onReload() - } - - shippingLabelResultsController.onDidResetContent = { [weak self] in - guard let self = self else { return } - self.refetchAllResultsControllers() - onReload() - } - - do { - try shippingLabelResultsController.performFetch() - } catch { - DDLogError("⛔️ Unable to fetch ShippingLabels for Site \(siteID) and Order \(order.orderID): \(error)") - } - } - private func configureAddOnGroupResultsController(onReload: @escaping () -> Void) { addOnGroupResultsController.onDidChangeContent = { onReload() @@ -340,24 +300,6 @@ private extension OrderDetailsResultsControllers { } } - private func configureFeeLinesResultsController(onReload: @escaping () -> Void) { - feeLinesResultsController.onDidChangeContent = { - onReload() - } - - feeLinesResultsController.onDidResetContent = { [weak self] in - guard let self = self else { return } - self.refetchAllResultsControllers() - onReload() - } - - do { - try feeLinesResultsController.performFetch() - } catch { - DDLogError("⛔️ Unable to fetch Order Fee lines for Site \(siteID): \(error)") - } - } - private func configureShippingMethodsResultsController(onReload: @escaping () -> Void) { shippingMethodsResultsController.onDidChangeContent = { onReload() @@ -384,7 +326,6 @@ private extension OrderDetailsResultsControllers { try? refundResultsController.performFetch() try? trackingResultsController.performFetch() try? statusResultsController.performFetch() - try? shippingLabelResultsController.performFetch() try? addOnGroupResultsController.performFetch() try? sitePluginsResultsController.performFetch() try? shippingMethodsResultsController.performFetch() 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 195f5cda300..f31497cf63f 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressForm.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressForm.swift @@ -505,7 +505,8 @@ struct EditAddressForm_Previews: PreviewProvider { customFields: [], renewalSubscriptionID: nil, appliedGiftCards: [], - attributionInfo: nil) + attributionInfo: nil, + shippingLabels: []) static let sampleAddress = Address(firstName: "Johnny", lastName: "Appleseed", diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/Create Shipping Label Form/Package Details/Multi-package/ShippingLabelPackagesFormViewModel.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/Create Shipping Label Form/Package Details/Multi-package/ShippingLabelPackagesFormViewModel.swift index 883930a78b6..9ea468b73db 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/Create Shipping Label Form/Package Details/Multi-package/ShippingLabelPackagesFormViewModel.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/Create Shipping Label Form/Package Details/Multi-package/ShippingLabelPackagesFormViewModel.swift @@ -488,7 +488,8 @@ extension ShippingLabelPackagesFormViewModel { customFields: [], renewalSubscriptionID: nil, appliedGiftCards: [], - attributionInfo: nil) + attributionInfo: nil, + shippingLabels: []) } static func sampleAddress() -> Address { diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/Create Shipping Label Form/Package Details/ShippingLabelSampleData.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/Create Shipping Label Form/Package Details/ShippingLabelSampleData.swift index 899eb94f7db..b2382e66b29 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/Create Shipping Label Form/Package Details/ShippingLabelSampleData.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/Create Shipping Label Form/Package Details/ShippingLabelSampleData.swift @@ -43,7 +43,8 @@ enum ShippingLabelSampleData { customFields: [], renewalSubscriptionID: nil, appliedGiftCards: [], - attributionInfo: nil) + attributionInfo: nil, + shippingLabels: []) } static func samplePackageDetails() -> ShippingLabelPackagesResponse { diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Package and Rate Selection/WooShippingPackageAndRatePlaceholder.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Package and Rate Selection/WooShippingPackageAndRatePlaceholder.swift index 7c03abb2e98..ab431646783 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Package and Rate Selection/WooShippingPackageAndRatePlaceholder.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Package and Rate Selection/WooShippingPackageAndRatePlaceholder.swift @@ -110,6 +110,7 @@ extension Order { customFields: [], renewalSubscriptionID: nil, appliedGiftCards: [], - attributionInfo: nil) + attributionInfo: nil, + shippingLabels: []) } #endif diff --git a/WooCommerce/WooCommerceTests/ViewRelated/Orders/Order Details/OrderDetailsDataSourceTests.swift b/WooCommerce/WooCommerceTests/ViewRelated/Orders/Order Details/OrderDetailsDataSourceTests.swift index efe4c2bd4ac..bdfa248bd82 100644 --- a/WooCommerce/WooCommerceTests/ViewRelated/Orders/Order Details/OrderDetailsDataSourceTests.swift +++ b/WooCommerce/WooCommerceTests/ViewRelated/Orders/Order Details/OrderDetailsDataSourceTests.swift @@ -289,7 +289,7 @@ final class OrderDetailsDataSourceTests: XCTestCase { // Given let order = makeOrder() let refundedShippingLabel = ShippingLabel.fake().copy(siteID: order.siteID, orderID: order.orderID, refund: ShippingLabelRefund.fake()) - insert(shippingLabel: refundedShippingLabel) + insert(shippingLabel: refundedShippingLabel, order: order) let dataSource = OrderDetailsDataSource(order: order, storageManager: storageManager, cardPresentPaymentsConfiguration: Mocks.configuration) dataSource.isEligibleForShippingLabelCreation = true @@ -306,9 +306,10 @@ final class OrderDetailsDataSourceTests: XCTestCase { func test_create_shipping_label_button_is_not_visible_for_eligible_order_with_labels() throws { // Given - let order = makeOrder() + var order = makeOrder() let shippingLabel = ShippingLabel.fake().copy(siteID: order.siteID, orderID: order.orderID) - insert(shippingLabel: shippingLabel) + order = order.copy(shippingLabels: [shippingLabel]) + insert(shippingLabel: shippingLabel, order: order) let dataSource = OrderDetailsDataSource(order: order, storageManager: storageManager, cardPresentPaymentsConfiguration: Mocks.configuration) dataSource.isEligibleForShippingLabelCreation = true @@ -356,9 +357,10 @@ final class OrderDetailsDataSourceTests: XCTestCase { func test_more_button_is_visible_in_product_section_for_eligible_order_without_refunded_labels() throws { // Given - let order = makeOrder() + var order = makeOrder() let shippingLabel = ShippingLabel.fake().copy(siteID: order.siteID, orderID: order.orderID) - insert(shippingLabel: shippingLabel) + order = order.copy(shippingLabels: [shippingLabel]) + insert(shippingLabel: shippingLabel, order: order) let dataSource = OrderDetailsDataSource(order: order, storageManager: storageManager, cardPresentPaymentsConfiguration: Mocks.configuration) dataSource.isEligibleForShippingLabelCreation = true @@ -451,9 +453,10 @@ final class OrderDetailsDataSourceTests: XCTestCase { func test_more_button_is_visible_in_product_section_for_eligible_order_with_refunded_labels() throws { // Given - let order = makeOrder() + var order = makeOrder() let refundedShippingLabel = ShippingLabel.fake().copy(siteID: order.siteID, orderID: order.orderID, refund: ShippingLabelRefund.fake()) - insert(shippingLabel: refundedShippingLabel) + order = order.copy(shippingLabels: [refundedShippingLabel]) + insert(shippingLabel: refundedShippingLabel, order: order) let dataSource = OrderDetailsDataSource(order: order, storageManager: storageManager, cardPresentPaymentsConfiguration: Mocks.configuration) dataSource.isEligibleForShippingLabelCreation = true @@ -944,9 +947,12 @@ private extension OrderDetailsDataSourceTests { storageFee.order = storageOrder } - /// Inserts the shipping label into storage + /// Inserts the shipping label into storage, and then shipping label into order /// - func insert(shippingLabel: ShippingLabel) { + func insert(shippingLabel: ShippingLabel, order: Order) { + let storageOrder = storage.insertNewObject(ofType: StorageOrder.self) + storageOrder.update(with: order) + let storageShippingLabel = storage.insertNewObject(ofType: StorageShippingLabel.self) storageShippingLabel.update(with: shippingLabel) if let shippingLabelRefund = shippingLabel.refund { @@ -954,6 +960,7 @@ private extension OrderDetailsDataSourceTests { storageRefund.update(with: shippingLabelRefund) storageShippingLabel.refund = storageRefund } + storageShippingLabel.order = storageOrder } func insert(_ readOnlyPlugin: Yosemite.SitePlugin) { diff --git a/Yosemite/Yosemite/Model/Mocks/MockObjectGraph.swift b/Yosemite/Yosemite/Model/Mocks/MockObjectGraph.swift index 9474193a9ff..ab2875fd576 100644 --- a/Yosemite/Yosemite/Model/Mocks/MockObjectGraph.swift +++ b/Yosemite/Yosemite/Model/Mocks/MockObjectGraph.swift @@ -385,7 +385,8 @@ extension MockObjectGraph { customFields: [], renewalSubscriptionID: nil, appliedGiftCards: [], - attributionInfo: nil + attributionInfo: nil, + shippingLabels: [] ) } } diff --git a/Yosemite/Yosemite/Model/Storage/Order+ReadOnlyConvertible.swift b/Yosemite/Yosemite/Model/Storage/Order+ReadOnlyConvertible.swift index ab39c16d9d2..7f1338eefde 100644 --- a/Yosemite/Yosemite/Model/Storage/Order+ReadOnlyConvertible.swift +++ b/Yosemite/Yosemite/Model/Storage/Order+ReadOnlyConvertible.swift @@ -79,6 +79,7 @@ extension Storage.Order: ReadOnlyConvertible { let orderTaxLines = taxes?.map { $0.toReadOnly() } ?? [Yosemite.OrderTaxLine]() let orderCustomFields = customFields?.map { $0.toReadOnly() } ?? [Yosemite.MetaData]() let orderGiftCards = appliedGiftCards?.map { $0.toReadOnly() } ?? [Yosemite.OrderGiftCard]() + let orderShippingLabels = shippingLabels?.map { $0.toReadOnly() } ?? [Yosemite.ShippingLabel]() return Order(siteID: siteID, orderID: orderID, @@ -117,7 +118,8 @@ extension Storage.Order: ReadOnlyConvertible { customFields: orderCustomFields, renewalSubscriptionID: renewalSubscriptionID, appliedGiftCards: orderGiftCards, - attributionInfo: attributionInfo?.toReadOnly()) + attributionInfo: attributionInfo?.toReadOnly(), + shippingLabels: orderShippingLabels) } diff --git a/Yosemite/Yosemite/Stores/Order/OrderFactory.swift b/Yosemite/Yosemite/Stores/Order/OrderFactory.swift index a1756460ab5..0c34ed87be4 100644 --- a/Yosemite/Yosemite/Stores/Order/OrderFactory.swift +++ b/Yosemite/Yosemite/Stores/Order/OrderFactory.swift @@ -46,7 +46,8 @@ public enum OrderFactory { customFields: [], renewalSubscriptionID: nil, appliedGiftCards: [], - attributionInfo: nil) + attributionInfo: nil, + shippingLabels: []) } /// Creates a fee line suitable to be used within a simple payments order.