spec updates

This commit is contained in:
Andy Brett
2020-11-29 15:03:30 -08:00
parent c70ea44091
commit b713bd7aa7
3 changed files with 11 additions and 7 deletions

View File

@@ -12,7 +12,7 @@ class CartController < BaseController
cart_service = CartService.new(order)
errors = cart_service.populate(params.slice(:products, :variants, :quantity), true)[:errors]
if errors.blank?
if errors.empty?
order.update_distribution_charge!
order.cap_quantity_at_stock!
order.update!

View File

@@ -7,33 +7,37 @@ describe CartController, type: :controller do
describe "basic behaviour" do
let(:cart_service) { double }
let(:errors) { double }
before do
allow(CartService).to receive(:new).and_return(cart_service)
end
it "returns HTTP success when successful" do
allow(cart_service).to receive(:populate) { true }
allow(cart_service).to receive(:populate).and_return({ errors: {} })
allow(cart_service).to receive(:variants_h) { {} }
xhr :post, :populate, use_route: :spree, format: :json
expect(response.status).to eq(200)
end
it "returns failure when unsuccessful" do
allow(cart_service).to receive(:populate).and_return false
allow(errors).to receive(:empty?).and_return(false)
allow(errors).to receive(:full_messages).and_return(["Error: foo"])
allow(cart_service).to receive(:populate).and_return({ errors: errors })
xhr :post, :populate, use_route: :spree, format: :json
expect(response.status).to eq(412)
end
it "tells cart_service to overwrite" do
expect(cart_service).to receive(:populate).with({}, true)
allow(cart_service).to receive(:variants_h) { {} }
expect(cart_service).to receive(:populate).with({}, true).and_return({ errors: {} })
xhr :post, :populate, use_route: :spree, format: :json
end
it "returns stock levels as JSON on success" do
allow(controller).to receive(:variant_ids_in) { [123] }
allow_any_instance_of(VariantsStockLevels).to receive(:call).and_return("my_stock_levels")
allow(cart_service).to receive(:populate) { true }
allow(cart_service).to receive(:populate).and_return({ errors: {} })
allow(cart_service).to receive(:variants_h) { {} }
xhr :post, :populate, use_route: :spree, format: :json

View File

@@ -138,10 +138,10 @@ describe 'Cart service', ->
expect(Cart.popQueue).not.toHaveBeenCalled()
it "shows an error on cart update failure", ->
$httpBackend.expectPOST("/cart/populate", data).respond 404, {}
$httpBackend.expectPOST("/cart/populate", data).respond 412, {}
Cart.update()
$httpBackend.flush()
expect(RailsFlashLoader.loadFlash).toHaveBeenCalledWith({error: t('js.cart.add_to_cart_failed')})
expect(RailsFlashLoader.loadFlash).toHaveBeenCalled()
describe "verifying stock levels after update", ->
describe "when an item is out of stock", ->