From 0671e52a2921e681d8af69c6ca787d5e2eab2ed6 Mon Sep 17 00:00:00 2001 From: Cillian O'Ruanaidh Date: Fri, 17 Jun 2022 11:28:53 +0100 Subject: [PATCH] Undo changes to tests, now that order cycle returns all shipping methods by default and doesn't explicitly require OrderCycleShippingMethods anymore --- .../enterprises_controller_spec.rb | 19 +++-------- spec/controllers/shop_controller_spec.rb | 33 ++++++++----------- spec/factories/order_cycle_factory.rb | 25 -------------- spec/factories/order_factory.rb | 2 +- .../order_cycle_permissions_spec.rb | 6 ++-- spec/models/order_cycle_spec.rb | 13 ++++---- spec/models/spree/order_spec.rb | 10 +++--- .../consumer/caching/shops_caching_spec.rb | 5 +-- .../consumer/shopping/checkout_auth_spec.rb | 4 +-- .../consumer/shopping/checkout_paypal_spec.rb | 1 - .../system/consumer/shopping/checkout_spec.rb | 6 ++-- .../consumer/shopping/checkout_stripe_spec.rb | 4 +-- .../system/consumer/shopping/products_spec.rb | 4 +-- .../system/consumer/shopping/shopping_spec.rb | 8 ++--- .../consumer/shopping/unit_price_spec.rb | 4 +-- .../shopping/variant_overrides_spec.rb | 3 +- spec/system/consumer/split_checkout_spec.rb | 3 +- 17 files changed, 46 insertions(+), 104 deletions(-) diff --git a/spec/controllers/enterprises_controller_spec.rb b/spec/controllers/enterprises_controller_spec.rb index 13f3209436..c9ee7b4437 100644 --- a/spec/controllers/enterprises_controller_spec.rb +++ b/spec/controllers/enterprises_controller_spec.rb @@ -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 diff --git a/spec/controllers/shop_controller_spec.rb b/spec/controllers/shop_controller_spec.rb index d55d88b603..b072152e72 100644 --- a/spec/controllers/shop_controller_spec.rb +++ b/spec/controllers/shop_controller_spec.rb @@ -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) diff --git a/spec/factories/order_cycle_factory.rb b/spec/factories/order_cycle_factory.rb index 3ad85ef7e5..1962475a8d 100644 --- a/spec/factories/order_cycle_factory.rb +++ b/spec/factories/order_cycle_factory.rb @@ -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 diff --git a/spec/factories/order_factory.rb b/spec/factories/order_factory.rb index b1b2b3e66c..6f38184372 100644 --- a/spec/factories/order_factory.rb +++ b/spec/factories/order_factory.rb @@ -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) diff --git a/spec/lib/open_food_network/order_cycle_permissions_spec.rb b/spec/lib/open_food_network/order_cycle_permissions_spec.rb index cc7a33c91a..4cabc5d3ac 100644 --- a/spec/lib/open_food_network/order_cycle_permissions_spec.rb +++ b/spec/lib/open_food_network/order_cycle_permissions_spec.rb @@ -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 diff --git a/spec/models/order_cycle_spec.rb b/spec/models/order_cycle_spec.rb index 0da971b524..e6b3ff54a1 100644 --- a/spec/models/order_cycle_spec.rb +++ b/spec/models/order_cycle_spec.rb @@ -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 diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index 43738baa40..c490457aa3 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -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 diff --git a/spec/system/consumer/caching/shops_caching_spec.rb b/spec/system/consumer/caching/shops_caching_spec.rb index 89d70edb5b..aa5bc79141 100644 --- a/spec/system/consumer/caching/shops_caching_spec.rb +++ b/spec/system/consumer/caching/shops_caching_spec.rb @@ -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 diff --git a/spec/system/consumer/shopping/checkout_auth_spec.rb b/spec/system/consumer/shopping/checkout_auth_spec.rb index 1ab5e93436..747a6d2413 100644 --- a/spec/system/consumer/shopping/checkout_auth_spec.rb +++ b/spec/system/consumer/shopping/checkout_auth_spec.rb @@ -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) } diff --git a/spec/system/consumer/shopping/checkout_paypal_spec.rb b/spec/system/consumer/shopping/checkout_paypal_spec.rb index 0f3e46556f..950d2153b7 100644 --- a/spec/system/consumer/shopping/checkout_paypal_spec.rb +++ b/spec/system/consumer/shopping/checkout_paypal_spec.rb @@ -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 diff --git a/spec/system/consumer/shopping/checkout_spec.rb b/spec/system/consumer/shopping/checkout_spec.rb index 249b76d694..04015ae715 100644 --- a/spec/system/consumer/shopping/checkout_spec.rb +++ b/spec/system/consumer/shopping/checkout_spec.rb @@ -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 diff --git a/spec/system/consumer/shopping/checkout_stripe_spec.rb b/spec/system/consumer/shopping/checkout_stripe_spec.rb index f1ea41192b..c91d64de10 100644 --- a/spec/system/consumer/shopping/checkout_stripe_spec.rb +++ b/spec/system/consumer/shopping/checkout_stripe_spec.rb @@ -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 diff --git a/spec/system/consumer/shopping/products_spec.rb b/spec/system/consumer/shopping/products_spec.rb index 52e2787036..c310d6ef3e 100644 --- a/spec/system/consumer/shopping/products_spec.rb +++ b/spec/system/consumer/shopping/products_spec.rb @@ -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") diff --git a/spec/system/consumer/shopping/shopping_spec.rb b/spec/system/consumer/shopping/shopping_spec.rb index 57867455a4..823018143b 100644 --- a/spec/system/consumer/shopping/shopping_spec.rb +++ b/spec/system/consumer/shopping/shopping_spec.rb @@ -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 } diff --git a/spec/system/consumer/shopping/unit_price_spec.rb b/spec/system/consumer/shopping/unit_price_spec.rb index a1c998887e..c134dd4f4d 100644 --- a/spec/system/consumer/shopping/unit_price_spec.rb +++ b/spec/system/consumer/shopping/unit_price_spec.rb @@ -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 } diff --git a/spec/system/consumer/shopping/variant_overrides_spec.rb b/spec/system/consumer/shopping/variant_overrides_spec.rb index 26ed5c2955..5fbb24de3e 100644 --- a/spec/system/consumer/shopping/variant_overrides_spec.rb +++ b/spec/system/consumer/shopping/variant_overrides_spec.rb @@ -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 } diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index cfd01afb2f..ab6568c2f0 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -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