From d4db9f1598eab79df1f2d970e6cdfc8aed77b6b7 Mon Sep 17 00:00:00 2001 From: Povilas Staskus <4062343+staskus@users.noreply.github.com> Date: Wed, 11 Sep 2024 15:16:33 +0300 Subject: [PATCH] Change a default sorting of POS products to "menu_order" --- Networking/Networking/Remote/ProductsRemote.swift | 5 ++++- .../NetworkingTests/Remote/ProductsRemoteTests.swift | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Networking/Networking/Remote/ProductsRemote.swift b/Networking/Networking/Remote/ProductsRemote.swift index 10d74e3c527..482bab4dc4d 100644 --- a/Networking/Networking/Remote/ProductsRemote.swift +++ b/Networking/Networking/Remote/ProductsRemote.swift @@ -190,7 +190,7 @@ public final class ProductsRemote: Remote, ProductsRemoteProtocol { ParameterKey.page: POSConstants.page, ParameterKey.perPage: POSConstants.productsPerPage, ParameterKey.productType: POSConstants.productType, - ParameterKey.orderBy: OrderKey.name.value, + ParameterKey.orderBy: OrderKey.menuOrder.value, ParameterKey.order: Order.ascending.value, ParameterKey.productStatus: POSConstants.productStatus, ] @@ -541,6 +541,7 @@ public extension ProductsRemote { case name // available for use in `GET wc-analytics/reports/products/stats` only. case itemsSold + case menuOrder } enum Order { @@ -625,6 +626,8 @@ private extension ProductsRemote.OrderKey { return "title" case .itemsSold: return "items_sold" + case .menuOrder: + return "menu_order" } } } diff --git a/Networking/NetworkingTests/Remote/ProductsRemoteTests.swift b/Networking/NetworkingTests/Remote/ProductsRemoteTests.swift index b827494674b..868cee7d1dd 100644 --- a/Networking/NetworkingTests/Remote/ProductsRemoteTests.swift +++ b/Networking/NetworkingTests/Remote/ProductsRemoteTests.swift @@ -867,6 +867,18 @@ final class ProductsRemoteTests: XCTestCase { } } + func test_loadAllSimpleProductsForPointOfSale_called_with_menu_order() async throws { + // Given + let remote = ProductsRemote(network: network) + + // When + network.simulateResponse(requestUrlSuffix: "products", filename: "products-load-all-type-simple") + let _ = try await remote.loadAllSimpleProductsForPointOfSale(for: sampleSiteID) + + // Then + XCTAssertTrue((network.queryParameters ?? []).contains("orderby=menu_order")) + } + func test_loadAllSimpleProductsForPointOfSale_relays_networking_error() async throws { // Given let remote = ProductsRemote(network: network)