Do not trigger an orderChanged with null quantity

When loading the page $watchGroup calls the listener function for every
listed line item but with a set variant and null quantity and
max_quantity. There's no point on computing an order change when there
was none.

This saves an empty request on the second most used endpoint of the app,
specially busy when users are placing orders.
This commit is contained in:
Pau Perez
2020-04-07 09:18:21 +02:00
parent a8ca471cd2
commit c224df9b6a
2 changed files with 12 additions and 1 deletions

View File

@@ -45,6 +45,13 @@ describe 'Cart service', ->
Cart.adjust(order.line_items[0])
expect(Cart.line_items.length).toEqual 0
it "does not add an item in the cart without quantity", ->
Cart.line_items = []
spyOn(Cart, 'orderChanged')
order.line_items[0].max_quantity = 0
expect(Cart.orderChanged).not.toHaveBeenCalled()
it "sums the quantity of each line item for cart total", ->
order.line_items[0].quantity = 2
expect(Cart.total_item_count()).toEqual 2