Repository navigation
fix(cart): verify cart remove only removes the target line #41 - #49
Merged
Merged
Conversation
| ctx.logger.info(`➖ Removing SKU ${skuId}…`); | ||
| await ctx.client.removeCartItem(skuId); | ||
| const cart = await ctx.client.getCart(); | ||
| const unexpectedRemovals = changedLines(before, cart, skuId, null); |
There was a problem hiding this comment.
🛡️ High Passing null as targetQuantity disables verification that the target SKU was actually removed. If removeCartItem is a no-op and the SKU remains, unexpectedRemovals stays empty and the function reports success.
Suggested change
| const unexpectedRemovals = changedLines(before, cart, skuId, null); | |
| const unexpectedRemovals = changedLines(before, cart, skuId, 0); |
| : `takealot cart add --sku ${line.skuId} --qty ${line.quantity} --confirm --yes`; | ||
| ctx.logger.warn(`Restore ${line.title}: ${command}`); | ||
| } | ||
| } |
There was a problem hiding this comment.
🛡️ Medium Restore commands use line.quantity, but changedLines deduplicates by SKU and keeps only one representative line. For duplicated SKUs, this quantity is not the original per-SKU total, so the suggested set-qty command can restore the wrong amount.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cart remove / set-qty read the cart before and after the write. A sku not in the cart is refused (exit 4, no DELETE). If any other line disappears or changes quantity (per-SKU summed quantities, so duplicate lines are covered) the command prints unexpectedRemovals plus restore commands and exits 1; it never auto-writes. Dry run lists the lines that would remain; --verbose logs customerId, auth generation and the DELETE body.
The DELETE body already matches the 4.3.0 app, so no body defect was found for the original report.
Live on the real account: added sku 83379710 to a 3-line cart and removed it, cart back to exactly the original 3 lines; absent sku exits 4. 357 tests. Oracle signed off (2 rounds).
Closes #41