Get tests broken because of new order cycle shipping method validations working again

This commit is contained in:
Cillian O'Ruanaidh
2022-06-08 21:28:37 +01:00
committed by Filipe
parent a46b77d10c
commit 4e0bf75ecf
17 changed files with 134 additions and 70 deletions

View File

@@ -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

View File

@@ -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