mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-06 22:36:07 +00:00
Fix timing issue: change in client-side value during server update
This commit is contained in:
@@ -130,21 +130,24 @@ describe 'Cart service', ->
|
||||
describe "when an item is out of stock", ->
|
||||
it "reduces the quantity in the cart", ->
|
||||
li = {variant: {id: 1}, quantity: 5}
|
||||
stockLevels = {1: {quantity: 0, max_quantity: 0, on_hand: 0}}
|
||||
spyOn(Cart, 'line_items_present').andReturn [li]
|
||||
Cart.compareAndNotifyStockLevels {}
|
||||
Cart.compareAndNotifyStockLevels stockLevels
|
||||
expect(li.quantity).toEqual 0
|
||||
expect(li.max_quantity).toBeUndefined()
|
||||
|
||||
it "reduces the max_quantity in the cart", ->
|
||||
li = {variant: {id: 1}, quantity: 5, max_quantity: 6}
|
||||
stockLevels = {1: {quantity: 0, max_quantity: 0, on_hand: 0}}
|
||||
spyOn(Cart, 'line_items_present').andReturn [li]
|
||||
Cart.compareAndNotifyStockLevels {}
|
||||
Cart.compareAndNotifyStockLevels stockLevels
|
||||
expect(li.max_quantity).toEqual 0
|
||||
|
||||
it "resets the count on hand available", ->
|
||||
li = {variant: {id: 1, count_on_hand: 10}, quantity: 5}
|
||||
stockLevels = {1: {quantity: 0, max_quantity: 0, on_hand: 0}}
|
||||
spyOn(Cart, 'line_items_present').andReturn [li]
|
||||
Cart.compareAndNotifyStockLevels {}
|
||||
Cart.compareAndNotifyStockLevels stockLevels
|
||||
expect(li.variant.count_on_hand).toEqual 0
|
||||
|
||||
describe "when the quantity available is less than that requested", ->
|
||||
@@ -170,6 +173,38 @@ describe 'Cart service', ->
|
||||
Cart.compareAndNotifyStockLevels stockLevels
|
||||
expect(li.variant.count_on_hand).toEqual 6
|
||||
|
||||
describe "when the client-side quantity has been increased during the request", ->
|
||||
it "does not reset the quantity", ->
|
||||
li = {variant: {id: 1}, quantity: 6}
|
||||
stockLevels = {1: {quantity: 5, on_hand: 6}}
|
||||
spyOn(Cart, 'line_items_present').andReturn [li]
|
||||
Cart.compareAndNotifyStockLevels stockLevels
|
||||
expect(li.quantity).toEqual 6
|
||||
expect(li.max_quantity).toBeUndefined()
|
||||
|
||||
it "does not reset the max_quantity", ->
|
||||
li = {variant: {id: 1}, quantity: 5, max_quantity: 7}
|
||||
stockLevels = {1: {quantity: 5, max_quantity: 6, on_hand: 7}}
|
||||
spyOn(Cart, 'line_items_present').andReturn [li]
|
||||
Cart.compareAndNotifyStockLevels stockLevels
|
||||
expect(li.quantity).toEqual 5
|
||||
expect(li.max_quantity).toEqual 7
|
||||
|
||||
describe "when the client-side quantity has been changed from 0 to 1 during the request", ->
|
||||
it "does not reset the quantity", ->
|
||||
li = {variant: {id: 1}, quantity: 1}
|
||||
spyOn(Cart, 'line_items_present').andReturn [li]
|
||||
Cart.compareAndNotifyStockLevels {}
|
||||
expect(li.quantity).toEqual 1
|
||||
expect(li.max_quantity).toBeUndefined()
|
||||
|
||||
it "does not reset the max_quantity", ->
|
||||
li = {variant: {id: 1}, quantity: 1, max_quantity: 1}
|
||||
spyOn(Cart, 'line_items_present').andReturn [li]
|
||||
Cart.compareAndNotifyStockLevels {}
|
||||
expect(li.quantity).toEqual 1
|
||||
expect(li.max_quantity).toEqual 1
|
||||
|
||||
it "pops the queue", ->
|
||||
Cart.update_enqueued = true
|
||||
spyOn(Cart, 'scheduleUpdate')
|
||||
|
||||
Reference in New Issue
Block a user