Skip to content

Commit 1f4e53e

Browse files
authored
Dashboard: Fix workaround for stock card (#13648)
2 parents c1b56e0 + 78b1624 commit 1f4e53e

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

RELEASE-NOTES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
- [*] Payments: Fixed issue where new WooPayments accounts couldn't be used for In Person Payments while they were pending verification [https://github.com/woocommerce/woocommerce-ios/pull/13610]
2525
- [Internal] Custom Fields: Started effort to rename OrderMetaData to MetaData to share it with Products, starting with Networking layer. [https://github.com/woocommerce/woocommerce-ios/pull/13620]
2626
- [*] Login: Hid the site credential login option when entering a WPCom site address. [https://github.com/woocommerce/woocommerce-ios/pull/13623]
27+
- [Internal] Beta fix: Fixed unreliable states of the Inbox screen when navigated from the Hub Menu. [https://github.com/woocommerce/woocommerce-ios/pull/13645]
28+
- [Internal] Beta fix: Fixed navigation to variations in stock card for some stores. [https://github.com/woocommerce/woocommerce-ios/pull/13648]
2729

2830
19.9
2931
-----

WooCommerce/Classes/ViewRelated/Dashboard/ProductStock/ProductStockDashboardCardViewModel.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,12 @@ private extension ProductStockDashboardCardViewModel {
169169
return reports.map { report in
170170
guard let variationID = report.variationID,
171171
report.productID == 0,
172-
let parentID = stock.first(where: { $0.productID == variationID })?.productID else {
172+
let parentID = stock.first(where: { $0.productID == variationID })?.parentID else {
173173
return report
174174
}
175+
/// For some stores, the product ID is not found for variations returned from variation reports.
176+
/// We need to copy the parent ID from the stock report over to the variation reports
177+
/// to be able to show the details for the variation upon selection.
175178
return report.copy(productID: parentID)
176179
}
177180
}

WooCommerce/WooCommerceTests/ViewRelated/Dashboard/ProductStockDashboardCardViewModelTests.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,43 @@ final class ProductStockDashboardCardViewModelTests: XCTestCase {
7373
XCTAssertEqual(viewModel.reports, [variationReport, productReport])
7474
}
7575

76+
@MainActor
77+
func test_reloadData_updates_missing_parent_ids_for_variation_reports() async {
78+
// Given
79+
let siteID: Int64 = 123
80+
let stores = MockStoresManager(sessionManager: .makeForTesting())
81+
let viewModel = ProductStockDashboardCardViewModel(siteID: siteID, stores: stores)
82+
83+
let variation = ProductStock.fake().copy(siteID: siteID, productID: 44, parentID: 40)
84+
85+
let thumbnailURL = "https://example.com/image.jpg"
86+
let variationReport = ProductReport.fake().copy(productID: 0, // missing product ID happens to some stores
87+
variationID: variation.productID,
88+
name: "Pizza - Large, Seafood, Spicy",
89+
imageURL: nil,
90+
itemsSold: 8,
91+
stockQuantity: 3)
92+
XCTAssertTrue(viewModel.reports.isEmpty)
93+
94+
// When
95+
stores.whenReceivingAction(ofType: ProductAction.self) { action in
96+
switch action {
97+
case let .fetchStockReport(_, _, _, _, _, completion):
98+
completion(.success([variation]))
99+
case let .fetchVariationReports(_, productIDs, variationIDs, _, _, _, _, _, _, _, completion):
100+
XCTAssertEqual(productIDs, [variation.parentID])
101+
XCTAssertEqual(variationIDs, [variation.productID])
102+
completion(.success([variationReport]))
103+
default:
104+
break
105+
}
106+
}
107+
await viewModel.reloadData()
108+
109+
// Then
110+
XCTAssertEqual(viewModel.reports, [variationReport.copy(productID: variation.parentID)])
111+
}
112+
76113
@MainActor
77114
func test_reloadData_relays_error_when_one_of_the_requests_fail() async {
78115
// Given

0 commit comments

Comments
 (0)