Skip to content

Commit

Permalink
Change a default sorting of POS products to "menu_order"
Browse files Browse the repository at this point in the history
  • Loading branch information
staskus committed Sep 11, 2024
1 parent 79620bf commit d4db9f1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Networking/Networking/Remote/ProductsRemote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -625,6 +626,8 @@ private extension ProductsRemote.OrderKey {
return "title"
case .itemsSold:
return "items_sold"
case .menuOrder:
return "menu_order"
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions Networking/NetworkingTests/Remote/ProductsRemoteTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d4db9f1

Please sign in to comment.