mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Add spec for OrderPopulator#attempt_cart_add
This commit is contained in:
@@ -7,12 +7,11 @@ module Spree
|
||||
let(:params) { double(:params) }
|
||||
let(:distributor) { double(:distributor) }
|
||||
let(:order_cycle) { double(:order_cycle) }
|
||||
let(:op) { OrderPopulator.new(order, currency) }
|
||||
|
||||
describe "populate" do
|
||||
|
||||
it "checks that distributor can supply all products in the cart" do
|
||||
op = OrderPopulator.new(order, currency)
|
||||
|
||||
op.should_receive(:load_distributor_and_order_cycle).with(params).
|
||||
and_return([distributor, order_cycle])
|
||||
op.should_receive(:distributor_can_supply_products_in_cart).with(distributor).
|
||||
@@ -25,8 +24,6 @@ module Spree
|
||||
end
|
||||
|
||||
it "doesn't set cart distributor and order cycle if populate fails" do
|
||||
op = OrderPopulator.new(order, currency)
|
||||
|
||||
op.should_receive(:load_distributor_and_order_cycle).with(params).
|
||||
and_return([distributor, order_cycle])
|
||||
op.should_receive(:distributor_can_supply_products_in_cart).with(distributor).
|
||||
@@ -45,8 +42,6 @@ module Spree
|
||||
end
|
||||
|
||||
it "sets cart distributor and order cycle when populate succeeds" do
|
||||
op = OrderPopulator.new(order, currency)
|
||||
|
||||
op.should_receive(:load_distributor_and_order_cycle).with(params).
|
||||
and_return([distributor, order_cycle])
|
||||
op.should_receive(:distributor_can_supply_products_in_cart).with(distributor).
|
||||
@@ -54,16 +49,38 @@ module Spree
|
||||
op.should_receive(:populate_without_distribution_validation).with(params)
|
||||
op.should_receive(:set_cart_distributor_and_order_cycle).with(distributor, order_cycle)
|
||||
|
||||
op.populate(params).should be_true
|
||||
op.populate(params).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe "attempt_cart_add" do
|
||||
it "validates distribution is provided"
|
||||
it "validates variant is available under distributor"
|
||||
it "performs additional validations" do
|
||||
variant = double(:variant)
|
||||
quantity = 123
|
||||
Spree::Variant.stub(:find).and_return(variant)
|
||||
|
||||
op.should_receive(:check_stock_levels).with(variant, quantity).and_return(true)
|
||||
op.should_receive(:check_distribution_provided_for).with(variant).and_return(true)
|
||||
op.should_receive(:check_variant_available_under_distributor).with(variant).
|
||||
and_return(true)
|
||||
order.should_receive(:add_variant).with(variant, quantity, currency)
|
||||
|
||||
op.attempt_cart_add(333, quantity.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
describe "support" do
|
||||
it "loads distributor and order cycle from hash"
|
||||
it "sets cart distributor and order cycle"
|
||||
end
|
||||
|
||||
describe "validations" do
|
||||
describe "determining if distributor can supply products in cart" do
|
||||
it "returns true if no distributor is supplied"
|
||||
it "returns true if the order can be changed to that distributor"
|
||||
it "returns false otherwise"
|
||||
end
|
||||
|
||||
describe "checking distribution is provided for a variant" do
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user