mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Undo changes to tests, now that order cycle returns all shipping methods by default and doesn't explicitly require OrderCycleShippingMethods anymore
This commit is contained in:
committed by
Filipe
parent
9296686384
commit
0671e52a29
@@ -9,17 +9,13 @@ 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,
|
||||
shipping_methods: [shipping_method],
|
||||
variants: [line_item.variant] )
|
||||
orders_close_at: 3.days.from_now, 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,
|
||||
shipping_methods: [shipping_method])
|
||||
orders_close_at: 4.days.from_now )
|
||||
}
|
||||
|
||||
before do
|
||||
@@ -59,10 +55,8 @@ 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,
|
||||
shipping_methods: [shipping_method])
|
||||
create(:simple_order_cycle, distributors: [distributor], orders_open_at: 3.days.ago,
|
||||
orders_close_at: 4.days.from_now)
|
||||
}
|
||||
let!(:oc3_exchange) { order_cycle3.exchanges.outgoing.to_enterprise(distributor).first }
|
||||
let(:customer) { create(:customer, user: user, enterprise: distributor) }
|
||||
@@ -122,10 +116,7 @@ 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],
|
||||
shipping_methods: [current_distributor.shipping_methods.first],
|
||||
variants: [variant])
|
||||
create(:simple_order_cycle, distributors: [current_distributor], 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], shipping_methods: [sm])
|
||||
oc1 = create(:simple_order_cycle, distributors: [distributor])
|
||||
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], shipping_methods: [sm])
|
||||
oc2 = create(:simple_order_cycle, distributors: [distributor], shipping_methods: [sm])
|
||||
oc1 = create(:simple_order_cycle, distributors: [distributor])
|
||||
oc2 = create(:simple_order_cycle, distributors: [distributor])
|
||||
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], shipping_methods: [sm])
|
||||
oc2 = create(:simple_order_cycle, distributors: [distributor], shipping_methods: [sm])
|
||||
oc1 = create(:simple_order_cycle, distributors: [distributor])
|
||||
oc2 = create(:simple_order_cycle, distributors: [distributor])
|
||||
|
||||
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], shipping_methods: [sm])
|
||||
oc2 = create(:simple_order_cycle, distributors: [distributor], shipping_methods: [sm])
|
||||
oc1 = create(:simple_order_cycle, distributors: [distributor])
|
||||
oc2 = create(:simple_order_cycle, distributors: [distributor])
|
||||
|
||||
spree_post :order_cycle, order_cycle_id: oc2.id
|
||||
expect(response.status).to eq 200
|
||||
@@ -55,19 +55,15 @@ 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], shipping_methods: [sm])
|
||||
oc1 = create(:simple_order_cycle, distributors: [distributor])
|
||||
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) 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(:oc1) { create(:simple_order_cycle, distributors: [distributor]) }
|
||||
let(:oc2) { create(:simple_order_cycle, distributors: [distributor]) }
|
||||
let(:order) { create(:order, order_cycle: oc1) }
|
||||
|
||||
before { allow(controller).to receive(:current_order) { order } }
|
||||
@@ -81,12 +77,9 @@ 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], 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])
|
||||
oc1 = create(:simple_order_cycle, distributors: [distributor])
|
||||
oc2 = create(:simple_order_cycle, distributors: [distributor])
|
||||
oc3 = create(:simple_order_cycle, distributors: [create(:distributor_enterprise)])
|
||||
|
||||
spree_post :order_cycle, order_cycle_id: oc3.id
|
||||
expect(response.status).to eq(404)
|
||||
|
||||
@@ -76,7 +76,6 @@ FactoryBot.define do
|
||||
suppliers { [] }
|
||||
distributors { [] }
|
||||
variants { [] }
|
||||
with_distributor_and_shipping_method { false }
|
||||
end
|
||||
|
||||
after(:create) do |oc, proxy|
|
||||
@@ -91,10 +90,6 @@ FactoryBot.define do
|
||||
proxy.variants.each { |v| ex.variants << v }
|
||||
end
|
||||
|
||||
if proxy.with_distributor_and_shipping_method
|
||||
proxy.distributors << oc.coordinator if proxy.distributors.empty?
|
||||
end
|
||||
|
||||
# Outgoing Exchanges
|
||||
proxy.distributors.each.with_index do |distributor, i|
|
||||
ex = create(:exchange, order_cycle: oc,
|
||||
@@ -105,26 +100,6 @@ FactoryBot.define do
|
||||
pickup_instructions: "instructions #{i}")
|
||||
proxy.variants.each { |v| ex.variants << v }
|
||||
end
|
||||
|
||||
if proxy.with_distributor_and_shipping_method || proxy.shipping_methods.any?
|
||||
oc.reload # so outgoing exchanges/distributors attached above are present
|
||||
distributor = oc.distributors.first
|
||||
if proxy.shipping_methods.empty?
|
||||
proxy.shipping_methods << create(:shipping_method, distributors: [distributor])
|
||||
else
|
||||
proxy.shipping_methods.each do |shipping_method|
|
||||
# ensure shipping methods belong to a distributor on the order cycle
|
||||
if !shipping_method.distributors.include?(distributor)
|
||||
shipping_method.distributors << distributor
|
||||
end
|
||||
end
|
||||
end
|
||||
oc.shipping_methods = proxy.shipping_methods
|
||||
end
|
||||
|
||||
if proxy.distributors.any? || proxy.shipping_methods.any?
|
||||
oc.reload # so shipping methods attached above are present
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ FactoryBot.define do
|
||||
|
||||
factory :order_ready_for_details do
|
||||
distributor { create(:distributor_enterprise, with_payment_and_shipping: true) }
|
||||
order_cycle { create(:order_cycle, distributors: [distributor], shipping_methods: [shipping_method]) }
|
||||
order_cycle { create(:order_cycle, distributors: [distributor]) }
|
||||
|
||||
after(:create) do |order|
|
||||
order.line_items << build(:line_item, order: order)
|
||||
|
||||
@@ -10,7 +10,7 @@ module OpenFoodNetwork
|
||||
let(:producer) { create(:supplier_enterprise) }
|
||||
let(:user) { double(:user) }
|
||||
let(:oc) { create(:simple_order_cycle, coordinator: coordinator) }
|
||||
let(:permissions) { OrderCyclePermissions.new(user, oc.reload) }
|
||||
let(:permissions) { OrderCyclePermissions.new(user, oc) }
|
||||
|
||||
describe "finding enterprises that can be viewed in the order cycle interface" do
|
||||
context "when permissions are initialized without an order_cycle" do
|
||||
@@ -53,7 +53,7 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
context "where the coordinator sells 'own'" do
|
||||
before { allow(oc.coordinator).to receive(:sells) { 'own' } }
|
||||
before { allow(coordinator).to receive(:sells) { 'own' } }
|
||||
it "returns just the coordinator" do
|
||||
enterprises = permissions.visible_enterprises
|
||||
expect(enterprises).to_not include hub, producer
|
||||
@@ -80,7 +80,7 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
context "where the coordinator sells 'own'" do
|
||||
before { allow(oc.coordinator).to receive(:sells) { 'own' } }
|
||||
before { allow(coordinator).to receive(:sells) { 'own' } }
|
||||
it "returns just the coordinator" do
|
||||
enterprises = permissions.visible_enterprises
|
||||
expect(enterprises).to_not include hub, producer
|
||||
|
||||
@@ -582,7 +582,7 @@ describe OrderCycle do
|
||||
end
|
||||
|
||||
describe "version tracking", versioning: true do
|
||||
let!(:oc) { create(:sells_own_order_cycle, name: "Original") }
|
||||
let!(:oc) { create(:order_cycle, name: "Original") }
|
||||
|
||||
it "remembers old versions" do
|
||||
expect {
|
||||
@@ -627,12 +627,11 @@ describe OrderCycle do
|
||||
end
|
||||
|
||||
describe "syncing subscriptions" do
|
||||
let!(:subscription) { create(:subscription, with_items: true) }
|
||||
let!(:oc) { subscription.order_cycles.first }
|
||||
|
||||
before do
|
||||
oc.update_columns(orders_open_at: 1.week.ago, orders_close_at: 1.day.ago)
|
||||
end
|
||||
let!(:oc) {
|
||||
create(:simple_order_cycle, orders_open_at: 1.week.ago, orders_close_at: 1.day.ago)
|
||||
}
|
||||
let(:schedule) { create(:schedule, order_cycles: [oc]) }
|
||||
let!(:subscription) { create(:subscription, schedule: schedule, with_items: true) }
|
||||
|
||||
it "syncs subscriptions when transitioning from closed to open" do
|
||||
expect(OrderManagement::Subscriptions::ProxyOrderSyncer).to receive(:new).and_call_original
|
||||
|
||||
@@ -711,8 +711,9 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
it "keeps the order cycle when it is available at the new distributor" do
|
||||
oc = create(:distributor_order_cycle, with_distributor_and_shipping_method: true)
|
||||
d = oc.distributors.first
|
||||
d = create(:distributor_enterprise)
|
||||
oc = create(:simple_order_cycle)
|
||||
create(:exchange, order_cycle: oc, sender: oc.coordinator, receiver: d, incoming: false)
|
||||
|
||||
subject.order_cycle = oc
|
||||
subject.set_distributor! d
|
||||
@@ -758,7 +759,7 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
describe "setting the order cycle" do
|
||||
let(:oc) { create(:distributor_order_cycle, with_distributor_and_shipping_method: true) }
|
||||
let(:oc) { create(:simple_order_cycle) }
|
||||
|
||||
it "empties the cart when changing the order cycle" do
|
||||
expect(subject).to receive(:empty!)
|
||||
@@ -776,7 +777,8 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
it "keeps the distributor when it is available in the new order cycle" do
|
||||
d = oc.distributors.first
|
||||
d = create(:distributor_enterprise)
|
||||
create(:exchange, order_cycle: oc, sender: oc.coordinator, receiver: d, incoming: false)
|
||||
|
||||
subject.distributor = d
|
||||
subject.set_order_cycle! oc
|
||||
|
||||
@@ -10,10 +10,7 @@ describe "Shops caching", js: true, caching: true do
|
||||
create(:distributor_enterprise, with_payment_and_shipping: true, is_primary_producer: true)
|
||||
}
|
||||
let!(:order_cycle) {
|
||||
create(:open_order_cycle,
|
||||
distributors: [distributor],
|
||||
coordinator: distributor,
|
||||
shipping_methods: [distributor.shipping_methods.first])
|
||||
create(:open_order_cycle, distributors: [distributor], coordinator: distributor)
|
||||
}
|
||||
|
||||
describe "caching enterprises AMS data" do
|
||||
|
||||
@@ -14,9 +14,7 @@ describe "As a consumer I want to check out my cart", js: true do
|
||||
let(:supplier) { create(:supplier_enterprise) }
|
||||
let!(:order_cycle) {
|
||||
create(:simple_order_cycle, distributors: [distributor],
|
||||
coordinator: create(:distributor_enterprise),
|
||||
shipping_methods: [distributor.shipping_methods.first],
|
||||
variants: [product.variants.first])
|
||||
coordinator: create(:distributor_enterprise), variants: [product.variants.first])
|
||||
}
|
||||
let(:product) { create(:simple_product, supplier: supplier) }
|
||||
let(:order) { create(:order, order_cycle: order_cycle, distributor: distributor) }
|
||||
|
||||
@@ -42,7 +42,6 @@ describe "Check out with Paypal", js: true do
|
||||
|
||||
before do
|
||||
distributor.shipping_methods << free_shipping
|
||||
order_cycle.shipping_methods << free_shipping
|
||||
set_order order
|
||||
add_product_to_cart order, product
|
||||
end
|
||||
|
||||
@@ -65,9 +65,9 @@ describe "As a consumer I want to check out my cart", js: true do
|
||||
set_order order
|
||||
add_product_to_cart order, product
|
||||
|
||||
shipping_methods = [free_shipping, shipping_with_fee, tagged_shipping]
|
||||
distributor.shipping_methods << shipping_methods
|
||||
order_cycle.shipping_methods << shipping_methods
|
||||
distributor.shipping_methods << free_shipping
|
||||
distributor.shipping_methods << shipping_with_fee
|
||||
distributor.shipping_methods << tagged_shipping
|
||||
end
|
||||
|
||||
describe "when I have an out of stock product in my cart" do
|
||||
|
||||
@@ -34,9 +34,7 @@ describe "Check out with Stripe", js: true do
|
||||
setup_stripe
|
||||
set_order order
|
||||
add_product_to_cart order, product
|
||||
shipping_methods = [shipping_with_fee, free_shipping]
|
||||
distributor.shipping_methods << shipping_methods
|
||||
order_cycle.shipping_methods << shipping_methods
|
||||
distributor.shipping_methods << [shipping_with_fee, free_shipping]
|
||||
end
|
||||
|
||||
describe "using Stripe SCA" do
|
||||
|
||||
@@ -18,9 +18,7 @@ describe "As a consumer I want to view products", js: true do
|
||||
let(:supplier) { create(:supplier_enterprise) }
|
||||
let(:oc1) {
|
||||
create(:simple_order_cycle, distributors: [distributor],
|
||||
coordinator: create(:distributor_enterprise),
|
||||
orders_close_at: 2.days.from_now,
|
||||
shipping_methods: [distributor.shipping_methods.first])
|
||||
coordinator: create(:distributor_enterprise), orders_close_at: 2.days.from_now)
|
||||
}
|
||||
let(:product) {
|
||||
create(:simple_product, supplier: supplier, primary_taxon: taxon, properties: [property], name: "Beans")
|
||||
|
||||
@@ -14,15 +14,11 @@ describe "As a consumer I want to shop with a distributor", js: true do
|
||||
let(:supplier) { create(:supplier_enterprise) }
|
||||
let(:oc1) {
|
||||
create(:simple_order_cycle, distributors: [distributor],
|
||||
coordinator: create(:distributor_enterprise),
|
||||
orders_close_at: 2.days.from_now,
|
||||
shipping_methods: [distributor.shipping_methods.first])
|
||||
coordinator: create(:distributor_enterprise), orders_close_at: 2.days.from_now)
|
||||
}
|
||||
let(:oc2) {
|
||||
create(:simple_order_cycle, distributors: [distributor],
|
||||
coordinator: create(:distributor_enterprise),
|
||||
orders_close_at: 3.days.from_now,
|
||||
shipping_methods: [distributor.shipping_methods.first])
|
||||
coordinator: create(:distributor_enterprise), orders_close_at: 3.days.from_now)
|
||||
}
|
||||
let(:product) { create(:simple_product, supplier: supplier, meta_keywords: "Domestic") }
|
||||
let(:variant) { product.variants.first }
|
||||
|
||||
@@ -12,9 +12,7 @@ describe "As a consumer, I want to check unit price information for a product",
|
||||
let(:supplier) { create(:supplier_enterprise) }
|
||||
let(:oc1) {
|
||||
create(:simple_order_cycle, distributors: [distributor],
|
||||
coordinator: create(:distributor_enterprise),
|
||||
orders_close_at: 2.days.from_now,
|
||||
shipping_methods: [distributor.shipping_methods.first])
|
||||
coordinator: create(:distributor_enterprise), orders_close_at: 2.days.from_now)
|
||||
}
|
||||
let(:product) { create(:simple_product, supplier: supplier) }
|
||||
let(:variant) { product.variants.first }
|
||||
|
||||
@@ -12,8 +12,7 @@ describe "shopping with variant overrides defined", js: true do
|
||||
let(:hub) { create(:distributor_enterprise, with_payment_and_shipping: true) }
|
||||
let(:producer) { create(:supplier_enterprise) }
|
||||
let(:oc) {
|
||||
create(:simple_order_cycle,
|
||||
suppliers: [producer], coordinator: hub, distributors: [hub], shipping_methods: [sm])
|
||||
create(:simple_order_cycle, suppliers: [producer], coordinator: hub, distributors: [hub])
|
||||
}
|
||||
let(:outgoing_exchange) { oc.exchanges.outgoing.first }
|
||||
let(:sm) { hub.shipping_methods.first }
|
||||
|
||||
@@ -71,8 +71,7 @@ describe "As a consumer, I want to checkout my order", js: true do
|
||||
add_enterprise_fee enterprise_fee
|
||||
set_order order
|
||||
|
||||
distributor.shipping_methods << shipping_methods
|
||||
order_cycle.shipping_methods << shipping_methods
|
||||
distributor.shipping_methods.push(shipping_methods)
|
||||
end
|
||||
|
||||
context "guest checkout when distributor doesn't allow guest orders" do
|
||||
|
||||
Reference in New Issue
Block a user