mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-11 23:17:48 +00:00
Get tests broken because of new order cycle shipping method validations working again
This commit is contained in:
committed by
Filipe
parent
a46b77d10c
commit
4e0bf75ecf
@@ -9,13 +9,17 @@ describe EnterprisesController, type: :controller do
|
||||
let(:line_item) { create(:line_item) }
|
||||
let!(:current_distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) }
|
||||
let!(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) }
|
||||
let!(:shipping_method) { distributor.shipping_methods.first }
|
||||
let!(:order_cycle1) {
|
||||
create(:simple_order_cycle, distributors: [distributor], orders_open_at: 2.days.ago,
|
||||
orders_close_at: 3.days.from_now, variants: [line_item.variant] )
|
||||
orders_close_at: 3.days.from_now,
|
||||
shipping_methods: [shipping_method],
|
||||
variants: [line_item.variant] )
|
||||
}
|
||||
let!(:order_cycle2) {
|
||||
create(:simple_order_cycle, distributors: [distributor], orders_open_at: 3.days.ago,
|
||||
orders_close_at: 4.days.from_now )
|
||||
orders_close_at: 4.days.from_now,
|
||||
shipping_methods: [shipping_method])
|
||||
}
|
||||
|
||||
before do
|
||||
@@ -55,8 +59,10 @@ describe EnterprisesController, type: :controller do
|
||||
|
||||
context "using FilterOrderCycles tag rules" do
|
||||
let!(:order_cycle3) {
|
||||
create(:simple_order_cycle, distributors: [distributor], orders_open_at: 3.days.ago,
|
||||
orders_close_at: 4.days.from_now)
|
||||
create(:simple_order_cycle, distributors: [distributor],
|
||||
orders_open_at: 3.days.ago,
|
||||
orders_close_at: 4.days.from_now,
|
||||
shipping_methods: [shipping_method])
|
||||
}
|
||||
let!(:oc3_exchange) { order_cycle3.exchanges.outgoing.to_enterprise(distributor).first }
|
||||
let(:customer) { create(:customer, user: user, enterprise: distributor) }
|
||||
@@ -116,7 +122,10 @@ describe EnterprisesController, type: :controller do
|
||||
let(:variant) { create(:variant, on_demand: false, on_hand: 10) }
|
||||
let(:line_item) { create(:line_item, variant: variant) }
|
||||
let(:order_cycle) {
|
||||
create(:simple_order_cycle, distributors: [current_distributor], variants: [variant])
|
||||
create(:simple_order_cycle,
|
||||
distributors: [current_distributor],
|
||||
shipping_methods: [current_distributor.shipping_methods.first],
|
||||
variants: [variant])
|
||||
}
|
||||
|
||||
before do
|
||||
|
||||
@@ -21,21 +21,21 @@ describe ShopController, type: :controller do
|
||||
|
||||
describe "selecting an order cycle" do
|
||||
it "should select an order cycle when only one order cycle is open" do
|
||||
oc1 = create(:simple_order_cycle, distributors: [distributor])
|
||||
oc1 = create(:simple_order_cycle, distributors: [distributor], shipping_methods: [sm])
|
||||
get :show
|
||||
expect(controller.current_order_cycle).to eq(oc1)
|
||||
end
|
||||
|
||||
it "should not set an order cycle when multiple order cycles are open" do
|
||||
oc1 = create(:simple_order_cycle, distributors: [distributor])
|
||||
oc2 = create(:simple_order_cycle, distributors: [distributor])
|
||||
oc1 = create(:simple_order_cycle, distributors: [distributor], shipping_methods: [sm])
|
||||
oc2 = create(:simple_order_cycle, distributors: [distributor], shipping_methods: [sm])
|
||||
get :show
|
||||
expect(controller.current_order_cycle).to be_nil
|
||||
end
|
||||
|
||||
it "should allow the user to post to select the current order cycle" do
|
||||
oc1 = create(:simple_order_cycle, distributors: [distributor])
|
||||
oc2 = create(:simple_order_cycle, distributors: [distributor])
|
||||
oc1 = create(:simple_order_cycle, distributors: [distributor], shipping_methods: [sm])
|
||||
oc2 = create(:simple_order_cycle, distributors: [distributor], shipping_methods: [sm])
|
||||
|
||||
spree_post :order_cycle, order_cycle_id: oc2.id
|
||||
expect(response.status).to eq 200
|
||||
@@ -46,8 +46,8 @@ describe ShopController, type: :controller do
|
||||
render_views
|
||||
|
||||
it "should return the order cycle details when the OC is selected" do
|
||||
oc1 = create(:simple_order_cycle, distributors: [distributor])
|
||||
oc2 = create(:simple_order_cycle, distributors: [distributor])
|
||||
oc1 = create(:simple_order_cycle, distributors: [distributor], shipping_methods: [sm])
|
||||
oc2 = create(:simple_order_cycle, distributors: [distributor], shipping_methods: [sm])
|
||||
|
||||
spree_post :order_cycle, order_cycle_id: oc2.id
|
||||
expect(response.status).to eq 200
|
||||
@@ -55,15 +55,19 @@ describe ShopController, type: :controller do
|
||||
end
|
||||
|
||||
it "should return the current order cycle when hit with GET" do
|
||||
oc1 = create(:simple_order_cycle, distributors: [distributor])
|
||||
oc1 = create(:simple_order_cycle, distributors: [distributor], shipping_methods: [sm])
|
||||
allow(controller).to receive(:current_order_cycle).and_return oc1
|
||||
get :order_cycle
|
||||
expect(response.body).to have_content oc1.id
|
||||
end
|
||||
|
||||
context "when the order cycle has already been set" do
|
||||
let(:oc1) { create(:simple_order_cycle, distributors: [distributor]) }
|
||||
let(:oc2) { create(:simple_order_cycle, distributors: [distributor]) }
|
||||
let(:oc1) do
|
||||
create(:simple_order_cycle, distributors: [distributor], shipping_methods: [sm])
|
||||
end
|
||||
let(:oc2) do
|
||||
create(:simple_order_cycle, distributors: [distributor], shipping_methods: [sm])
|
||||
end
|
||||
let(:order) { create(:order, order_cycle: oc1) }
|
||||
|
||||
before { allow(controller).to receive(:current_order) { order } }
|
||||
@@ -77,9 +81,12 @@ describe ShopController, type: :controller do
|
||||
end
|
||||
|
||||
it "should not allow the user to select an invalid order cycle" do
|
||||
oc1 = create(:simple_order_cycle, distributors: [distributor])
|
||||
oc2 = create(:simple_order_cycle, distributors: [distributor])
|
||||
oc3 = create(:simple_order_cycle, distributors: [create(:distributor_enterprise)])
|
||||
oc1 = create(:simple_order_cycle, distributors: [distributor], shipping_methods: [sm])
|
||||
oc2 = create(:simple_order_cycle, distributors: [distributor], shipping_methods: [sm])
|
||||
other_distributor = create(:distributor_enterprise, with_payment_and_shipping: true)
|
||||
oc3 = create(:simple_order_cycle,
|
||||
distributors: [other_distributor],
|
||||
shipping_methods: [other_distributor.shipping_methods.first])
|
||||
|
||||
spree_post :order_cycle, order_cycle_id: oc3.id
|
||||
expect(response.status).to eq(404)
|
||||
|
||||
Reference in New Issue
Block a user