mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-15 04:14:24 +00:00
Merge branch 'add-to-cart-robustness' into combined/vo-on-demand-stock-control_add-to-cart-robustness
This commit is contained in:
@@ -134,15 +134,20 @@ feature "As a consumer I want to shop with a distributor", js: true do
|
||||
end
|
||||
|
||||
it "should save group buy data to the cart" do
|
||||
# -- Quantity
|
||||
fill_in "variants[#{variant.id}]", with: 6
|
||||
fill_in "variant_attributes[#{variant.id}][max_quantity]", with: 7
|
||||
page.should have_in_cart product.name
|
||||
wait_until { !cart_dirty }
|
||||
|
||||
li = Spree::Order.order(:created_at).last.line_items.order(:created_at).last
|
||||
li.quantity.should == 6
|
||||
|
||||
# -- Max quantity
|
||||
fill_in "variant_attributes[#{variant.id}][max_quantity]", with: 7
|
||||
wait_until { !cart_dirty }
|
||||
|
||||
li = Spree::Order.order(:created_at).last.line_items.order(:created_at).last
|
||||
li.max_quantity.should == 7
|
||||
li.quantity.should == 6
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,6 +3,8 @@ describe 'Cart service', ->
|
||||
Variants = null
|
||||
variant = null
|
||||
order = null
|
||||
$httpBackend = null
|
||||
$timeout = null
|
||||
|
||||
beforeEach ->
|
||||
module 'Darkswarm'
|
||||
@@ -16,9 +18,11 @@ describe 'Cart service', ->
|
||||
]
|
||||
}
|
||||
angular.module('Darkswarm').value('currentOrder', order)
|
||||
inject ($injector)->
|
||||
inject ($injector, _$httpBackend_, _$timeout_)->
|
||||
Variants = $injector.get("Variants")
|
||||
Cart = $injector.get("Cart")
|
||||
$httpBackend = _$httpBackend_
|
||||
$timeout = _$timeout_
|
||||
|
||||
it "backreferences line items", ->
|
||||
expect(Cart.line_items[0].variant.line_item).toBe Cart.line_items[0]
|
||||
@@ -44,6 +48,29 @@ describe 'Cart service', ->
|
||||
order.line_items[0].quantity = 2
|
||||
expect(Cart.total_item_count()).toEqual 2
|
||||
|
||||
describe "updating the cart", ->
|
||||
data = {variants: {}}
|
||||
|
||||
it "marks the form as saved on success", ->
|
||||
spyOn(Cart, 'saved')
|
||||
$httpBackend.expectPOST("/orders/populate", data).respond 200, {}
|
||||
Cart.update()
|
||||
$httpBackend.flush()
|
||||
expect(Cart.saved).toHaveBeenCalled()
|
||||
|
||||
it "retries the update on failure", ->
|
||||
spyOn(Cart, 'scheduleRetry')
|
||||
$httpBackend.expectPOST("/orders/populate", data).respond 404, {}
|
||||
Cart.update()
|
||||
$httpBackend.flush()
|
||||
expect(Cart.scheduleRetry).toHaveBeenCalled()
|
||||
|
||||
it "schedules retries of updates", ->
|
||||
spyOn(Cart, 'orderChanged')
|
||||
Cart.scheduleRetry()
|
||||
$timeout.flush()
|
||||
expect(Cart.orderChanged).toHaveBeenCalled()
|
||||
|
||||
describe "generating an extended variant name", ->
|
||||
it "returns the product name when it is the same as the variant name", ->
|
||||
variant = {product_name: 'product_name', name_to_display: 'product_name'}
|
||||
|
||||
Reference in New Issue
Block a user