chore(): Improve cart update line items (#11666)

**What**
Currently, we are potentially providing an array of selector/data leading to fetching data sequentially before running on update which will fetch data again in batch and perform the update. Now we can pass the data directly which includes the id already and only perform one bulk fetch + one bulk update.

This pr also include a fix on the inventory validation, currently, only the item to update inventory is being checked, with this pr we also check the inventory for the items that needs to be created
This commit is contained in:
Adrien de Peretti
2025-03-03 10:06:40 +00:00
committed by GitHub
parent 39597b6b52
commit d1efad9bf0
10 changed files with 188 additions and 60 deletions
@@ -676,6 +676,34 @@ moduleIntegrationTestRunner<ICartModuleService>({
expect(updatedItem.title).toBe("test2")
})
it("should update a line item in cart succesfully with data only approach", async () => {
const [createdCart] = await service.createCarts([
{
currency_code: "eur",
},
])
const [item] = await service.addLineItems(createdCart.id, [
{
quantity: 1,
unit_price: 100,
title: "test",
tax_lines: [],
},
])
expect(item.title).toBe("test")
const [updatedItem] = await service.updateLineItems([
{
id: item.id,
title: "test2",
},
])
expect(updatedItem.title).toBe("test2")
})
it("should update a line item in cart succesfully with id approach", async () => {
const [createdCart] = await service.createCarts([
{