mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +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)
|
||||
|
||||
@@ -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]) }
|
||||
order_cycle { create(:order_cycle, distributors: [distributor], shipping_methods: [shipping_method]) }
|
||||
|
||||
after(:create) do |order|
|
||||
order.line_items << build(:line_item, order: order)
|
||||
|
||||
@@ -3,7 +3,13 @@
|
||||
FactoryBot.define do
|
||||
factory :subscription, class: Subscription do
|
||||
shop { create :enterprise }
|
||||
schedule { create(:schedule, order_cycles: [create(:simple_order_cycle, coordinator: shop)]) }
|
||||
schedule do
|
||||
order_cycle = create(:distributor_order_cycle,
|
||||
coordinator: shop,
|
||||
distributors: [shop],
|
||||
shipping_methods: [shipping_method])
|
||||
create(:schedule, order_cycles: [order_cycle])
|
||||
end
|
||||
customer { create(:customer, enterprise: shop) }
|
||||
bill_address { create(:address, :randomized) }
|
||||
ship_address { create(:address, :randomized) }
|
||||
|
||||
@@ -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) }
|
||||
let(:permissions) { OrderCyclePermissions.new(user, oc.reload) }
|
||||
|
||||
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(coordinator).to receive(:sells) { 'own' } }
|
||||
before { allow(oc.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(coordinator).to receive(:sells) { 'own' } }
|
||||
before { allow(oc.coordinator).to receive(:sells) { 'own' } }
|
||||
it "returns just the coordinator" do
|
||||
enterprises = permissions.visible_enterprises
|
||||
expect(enterprises).to_not include hub, producer
|
||||
|
||||
@@ -434,39 +434,65 @@ describe OrderCycle do
|
||||
end
|
||||
end
|
||||
|
||||
it "clones itself" do
|
||||
coordinator = create(:enterprise);
|
||||
oc = create(:simple_order_cycle,
|
||||
coordinator_fees: [create(:enterprise_fee, enterprise: coordinator)],
|
||||
preferred_product_selection_from_coordinator_inventory_only: true,
|
||||
automatic_notifications: true, processed_at: Time.zone.now, mails_sent: true)
|
||||
schedule = create(:schedule, order_cycles: [oc])
|
||||
ex1 = create(:exchange, order_cycle: oc)
|
||||
ex2 = create(:exchange, order_cycle: oc)
|
||||
oc.clone!
|
||||
describe "clone!" do
|
||||
it "clones itself" do
|
||||
coordinator = create(:enterprise);
|
||||
oc = create(:simple_order_cycle,
|
||||
coordinator_fees: [create(:enterprise_fee, enterprise: coordinator)],
|
||||
preferred_product_selection_from_coordinator_inventory_only: true,
|
||||
automatic_notifications: true, processed_at: Time.zone.now, mails_sent: true)
|
||||
schedule = create(:schedule, order_cycles: [oc])
|
||||
ex1 = create(:exchange, order_cycle: oc)
|
||||
ex2 = create(:exchange, order_cycle: oc)
|
||||
oc.clone!
|
||||
|
||||
occ = OrderCycle.last
|
||||
expect(occ.name).to eq("COPY OF #{oc.name}")
|
||||
expect(occ.orders_open_at).to be_nil
|
||||
expect(occ.orders_close_at).to be_nil
|
||||
expect(occ.coordinator).not_to be_nil
|
||||
expect(occ.preferred_product_selection_from_coordinator_inventory_only).to be true
|
||||
expect(occ.automatic_notifications).to eq(oc.automatic_notifications)
|
||||
expect(occ.processed_at).to eq(nil)
|
||||
expect(occ.mails_sent).to eq(nil)
|
||||
expect(occ.coordinator).to eq(oc.coordinator)
|
||||
occ = OrderCycle.last
|
||||
expect(occ.name).to eq("COPY OF #{oc.name}")
|
||||
expect(occ.orders_open_at).to be_nil
|
||||
expect(occ.orders_close_at).to be_nil
|
||||
expect(occ.coordinator).not_to be_nil
|
||||
expect(occ.preferred_product_selection_from_coordinator_inventory_only).to be true
|
||||
expect(occ.automatic_notifications).to eq(oc.automatic_notifications)
|
||||
expect(occ.processed_at).to eq(nil)
|
||||
expect(occ.mails_sent).to eq(nil)
|
||||
expect(occ.coordinator).to eq(oc.coordinator)
|
||||
|
||||
expect(occ.coordinator_fee_ids).not_to be_empty
|
||||
expect(occ.coordinator_fee_ids).to eq(oc.coordinator_fee_ids)
|
||||
expect(occ.preferred_product_selection_from_coordinator_inventory_only).to eq(oc.preferred_product_selection_from_coordinator_inventory_only)
|
||||
expect(occ.schedule_ids).not_to be_empty
|
||||
expect(occ.schedule_ids).to eq(oc.schedule_ids)
|
||||
expect(occ.coordinator_fee_ids).not_to be_empty
|
||||
expect(occ.coordinator_fee_ids).to eq(oc.coordinator_fee_ids)
|
||||
expect(occ.preferred_product_selection_from_coordinator_inventory_only).to eq(oc.preferred_product_selection_from_coordinator_inventory_only)
|
||||
expect(occ.schedule_ids).not_to be_empty
|
||||
expect(occ.schedule_ids).to eq(oc.schedule_ids)
|
||||
|
||||
# Check that the exchanges have been cloned.
|
||||
original_exchange_attributes = oc.exchanges.map { |ex| core_exchange_attributes(ex) }
|
||||
cloned_exchange_attributes = occ.exchanges.map { |ex| core_exchange_attributes(ex) }
|
||||
# Check that the exchanges have been cloned.
|
||||
original_exchange_attributes = oc.exchanges.map { |ex| core_exchange_attributes(ex) }
|
||||
cloned_exchange_attributes = occ.exchanges.map { |ex| core_exchange_attributes(ex) }
|
||||
|
||||
expect(cloned_exchange_attributes).to match_array original_exchange_attributes
|
||||
expect(cloned_exchange_attributes).to match_array original_exchange_attributes
|
||||
end
|
||||
|
||||
context "distributor order cycle created before the customisable shipping methods feature was available" do
|
||||
it "allows the clone to have customisable shipping methods" do
|
||||
order_cycle = create(:distributor_order_cycle, shipping_methods_customisable: false)
|
||||
|
||||
order_cycle.clone!
|
||||
|
||||
order_cycle_clone = OrderCycle.last
|
||||
expect(order_cycle_clone.shipping_methods_customisable).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
context "when it has shipping methods which can longer be applied validly e.g. shipping method is backoffice only" do
|
||||
it "raises an error (TODO: display a message to user explaining why clone failed)" do
|
||||
distributor = create(:distributor_enterprise)
|
||||
shipping_method = create(:shipping_method, distributors: [distributor])
|
||||
order_cycle = create(:distributor_order_cycle, distributors: [distributor], shipping_methods: [shipping_method])
|
||||
shipping_method.update_column(:display_on, "back_end")
|
||||
|
||||
expect {
|
||||
order_cycle.clone!
|
||||
}.to raise_error ActiveRecord::RecordInvalid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "finding recently closed order cycles" do
|
||||
|
||||
@@ -711,9 +711,8 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
it "keeps the order cycle when it is available at the new distributor" do
|
||||
d = create(:distributor_enterprise)
|
||||
oc = create(:simple_order_cycle)
|
||||
create(:exchange, order_cycle: oc, sender: oc.coordinator, receiver: d, incoming: false)
|
||||
oc = create(:distributor_order_cycle, with_distributor_and_shipping_method: true)
|
||||
d = oc.distributors.first
|
||||
|
||||
subject.order_cycle = oc
|
||||
subject.set_distributor! d
|
||||
@@ -759,7 +758,7 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
describe "setting the order cycle" do
|
||||
let(:oc) { create(:simple_order_cycle) }
|
||||
let(:oc) { create(:distributor_order_cycle, with_distributor_and_shipping_method: true) }
|
||||
|
||||
it "empties the cart when changing the order cycle" do
|
||||
expect(subject).to receive(:empty!)
|
||||
@@ -777,8 +776,7 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
it "keeps the distributor when it is available in the new order cycle" do
|
||||
d = create(:distributor_enterprise)
|
||||
create(:exchange, order_cycle: oc, sender: oc.coordinator, receiver: d, incoming: false)
|
||||
d = oc.distributors.first
|
||||
|
||||
subject.distributor = d
|
||||
subject.set_order_cycle! oc
|
||||
|
||||
@@ -10,7 +10,10 @@ 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)
|
||||
create(:open_order_cycle,
|
||||
distributors: [distributor],
|
||||
coordinator: distributor,
|
||||
shipping_methods: [distributor.shipping_methods.first])
|
||||
}
|
||||
|
||||
describe "caching enterprises AMS data" do
|
||||
|
||||
@@ -14,7 +14,9 @@ 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), variants: [product.variants.first])
|
||||
coordinator: create(:distributor_enterprise),
|
||||
shipping_methods: [distributor.shipping_methods.first],
|
||||
variants: [product.variants.first])
|
||||
}
|
||||
let(:product) { create(:simple_product, supplier: supplier) }
|
||||
let(:order) { create(:order, order_cycle: order_cycle, distributor: distributor) }
|
||||
|
||||
@@ -42,6 +42,7 @@ 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
|
||||
|
||||
distributor.shipping_methods << free_shipping
|
||||
distributor.shipping_methods << shipping_with_fee
|
||||
distributor.shipping_methods << tagged_shipping
|
||||
shipping_methods = [free_shipping, shipping_with_fee, tagged_shipping]
|
||||
distributor.shipping_methods << shipping_methods
|
||||
order_cycle.shipping_methods << shipping_methods
|
||||
end
|
||||
|
||||
describe "when I have an out of stock product in my cart" do
|
||||
|
||||
@@ -34,7 +34,9 @@ describe "Check out with Stripe", js: true do
|
||||
setup_stripe
|
||||
set_order order
|
||||
add_product_to_cart order, product
|
||||
distributor.shipping_methods << [shipping_with_fee, free_shipping]
|
||||
shipping_methods = [shipping_with_fee, free_shipping]
|
||||
distributor.shipping_methods << shipping_methods
|
||||
order_cycle.shipping_methods << shipping_methods
|
||||
end
|
||||
|
||||
describe "using Stripe SCA" do
|
||||
|
||||
@@ -18,7 +18,9 @@ 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)
|
||||
coordinator: create(:distributor_enterprise),
|
||||
orders_close_at: 2.days.from_now,
|
||||
shipping_methods: [distributor.shipping_methods.first])
|
||||
}
|
||||
let(:product) {
|
||||
create(:simple_product, supplier: supplier, primary_taxon: taxon, properties: [property], name: "Beans")
|
||||
|
||||
@@ -14,11 +14,15 @@ 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)
|
||||
coordinator: create(:distributor_enterprise),
|
||||
orders_close_at: 2.days.from_now,
|
||||
shipping_methods: [distributor.shipping_methods.first])
|
||||
}
|
||||
let(:oc2) {
|
||||
create(:simple_order_cycle, distributors: [distributor],
|
||||
coordinator: create(:distributor_enterprise), orders_close_at: 3.days.from_now)
|
||||
coordinator: create(:distributor_enterprise),
|
||||
orders_close_at: 3.days.from_now,
|
||||
shipping_methods: [distributor.shipping_methods.first])
|
||||
}
|
||||
let(:product) { create(:simple_product, supplier: supplier, meta_keywords: "Domestic") }
|
||||
let(:variant) { product.variants.first }
|
||||
|
||||
@@ -12,7 +12,9 @@ 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)
|
||||
coordinator: create(:distributor_enterprise),
|
||||
orders_close_at: 2.days.from_now,
|
||||
shipping_methods: [distributor.shipping_methods.first])
|
||||
}
|
||||
let(:product) { create(:simple_product, supplier: supplier) }
|
||||
let(:variant) { product.variants.first }
|
||||
|
||||
@@ -12,7 +12,8 @@ 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])
|
||||
create(:simple_order_cycle,
|
||||
suppliers: [producer], coordinator: hub, distributors: [hub], shipping_methods: [sm])
|
||||
}
|
||||
let(:outgoing_exchange) { oc.exchanges.outgoing.first }
|
||||
let(:sm) { hub.shipping_methods.first }
|
||||
|
||||
@@ -71,7 +71,8 @@ describe "As a consumer, I want to checkout my order", js: true do
|
||||
add_enterprise_fee enterprise_fee
|
||||
set_order order
|
||||
|
||||
distributor.shipping_methods.push(shipping_methods)
|
||||
distributor.shipping_methods << shipping_methods
|
||||
order_cycle.shipping_methods << shipping_methods
|
||||
end
|
||||
|
||||
context "guest checkout when distributor doesn't allow guest orders" do
|
||||
|
||||
Reference in New Issue
Block a user