mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-06 22:36:07 +00:00
Replaced order.shipping_method with order.shipments in models.order_spec.
Fixed factory completed_order_with_fees used in order_spec and also in line_items_controller_spec and orders_controller_spec.
This commit is contained in:
@@ -91,10 +91,9 @@ describe LineItemsController, type: :controller do
|
||||
end
|
||||
|
||||
context "where shipping and payment fees apply" do
|
||||
let(:distributor) { create(:distributor_enterprise, charges_sales_tax: true, allow_order_changes: true) }
|
||||
let(:shipping_fee) { 3 }
|
||||
let(:payment_fee) { 5 }
|
||||
let(:order) { create(:completed_order_with_fees, distributor: distributor, shipping_fee: shipping_fee, payment_fee: payment_fee) }
|
||||
let(:order) { create(:completed_order_with_fees, shipping_fee: shipping_fee, payment_fee: payment_fee) }
|
||||
|
||||
before do
|
||||
Spree::Config.shipment_inc_vat = true
|
||||
|
||||
@@ -94,8 +94,7 @@ describe Spree::OrdersController, type: :controller do
|
||||
|
||||
describe "removing items from a completed order" do
|
||||
context "with shipping and transaction fees" do
|
||||
let(:distributor) { create(:distributor_enterprise, charges_sales_tax: true, allow_order_changes: true) }
|
||||
let(:order) { create(:completed_order_with_fees, distributor: distributor, shipping_fee: shipping_fee, payment_fee: payment_fee) }
|
||||
let(:order) { create(:completed_order_with_fees, shipping_fee: shipping_fee, payment_fee: payment_fee) }
|
||||
let(:line_item1) { order.line_items.first }
|
||||
let(:line_item2) { order.line_items.second }
|
||||
let(:shipping_fee) { 3 }
|
||||
|
||||
@@ -335,16 +335,49 @@ FactoryBot.define do
|
||||
end
|
||||
end
|
||||
|
||||
factory :shipping_method_with_flat_rate, parent: :shipping_method do
|
||||
calculator { Spree::Calculator::FlatRate.new(preferred_amount: 50.0) }
|
||||
end
|
||||
|
||||
factory :shipment_with_flat_rate, parent: :shipment do
|
||||
after(:create) do |shipment|
|
||||
shipment.add_shipping_method(create(:shipping_method_with_flat_rate), true)
|
||||
end
|
||||
end
|
||||
|
||||
factory :distributor_enterprise_with_tax, parent: :distributor_enterprise do
|
||||
charges_sales_tax { true }
|
||||
allow_order_changes { true }
|
||||
end
|
||||
|
||||
factory :shipping_method_with_shipping_fee, parent: :shipping_method do
|
||||
transient do
|
||||
shipping_fee 3
|
||||
end
|
||||
|
||||
calculator { build(:calculator_per_item, preferred_amount: shipping_fee) }
|
||||
require_ship_address { false }
|
||||
distributors { [create(:distributor_enterprise_with_tax)] }
|
||||
end
|
||||
|
||||
factory :shipment_with_shipping_fee, parent: :shipment do
|
||||
transient do
|
||||
shipping_fee 3
|
||||
end
|
||||
|
||||
after(:create) do |shipment, evaluator|
|
||||
shipping_method = create(:shipping_method_with_shipping_fee, shipping_fee: evaluator.shipping_fee)
|
||||
shipment.add_shipping_method(shipping_method, true)
|
||||
end
|
||||
end
|
||||
|
||||
factory :completed_order_with_fees, parent: :order_with_totals_and_distribution do
|
||||
transient do
|
||||
shipping_fee 3
|
||||
payment_fee 5
|
||||
end
|
||||
|
||||
shipping_method do
|
||||
shipping_calculator = build(:calculator_per_item, preferred_amount: shipping_fee)
|
||||
create(:shipping_method, calculator: shipping_calculator, require_ship_address: false, distributors: [distributor])
|
||||
end
|
||||
shipments { [ create(:shipment_with_shipping_fee, shipping_fee: shipping_fee) ] }
|
||||
|
||||
after(:create) do |order, evaluator|
|
||||
create(:line_item, order: order)
|
||||
|
||||
@@ -181,8 +181,7 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
describe "an unpaid order with a shipment" do
|
||||
let(:order) { create(:order_with_totals, shipping_method: shipping_method) }
|
||||
let(:shipping_method) { create(:shipping_method) }
|
||||
let(:order) { create(:order_with_totals, shipments: [create(:shipment)]) }
|
||||
|
||||
before do
|
||||
order.reload
|
||||
@@ -209,8 +208,7 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
describe "a paid order with a shipment" do
|
||||
let(:order) { create(:order, shipping_method: shipping_method) }
|
||||
let(:shipping_method) { create(:shipping_method) }
|
||||
let(:order) { create(:order_with_line_items) }
|
||||
|
||||
before do
|
||||
order.payment_state = 'paid'
|
||||
@@ -224,8 +222,8 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
describe "getting the shipping tax" do
|
||||
let(:order) { create(:order, shipping_method: shipping_method) }
|
||||
let(:shipping_method) { create(:shipping_method, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 50.0)) }
|
||||
let(:shipment) { create(:shipment_with_flat_rate) }
|
||||
let(:order) { create(:order, shipments: [shipment]) }
|
||||
|
||||
context "with a taxed shipment" do
|
||||
before do
|
||||
@@ -256,10 +254,10 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
describe "getting the total tax" do
|
||||
let(:order) { create(:order, shipping_method: shipping_method) }
|
||||
let(:shipping_method) { create(:shipping_method, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 50.0)) }
|
||||
let(:enterprise_fee) { create(:enterprise_fee) }
|
||||
let!(:adjustment) { create(:adjustment, adjustable: order, originator: enterprise_fee, label: "EF", amount: 123, included_tax: 2) }
|
||||
let(:shipment) { create(:shipment_with_flat_rate) }
|
||||
let(:order) { create(:order, shipments: [shipment]) }
|
||||
let(:enterprise_fee) { create(:enterprise_fee) }
|
||||
let!(:adjustment) { create(:adjustment, adjustable: order, originator: enterprise_fee, label: "EF", amount: 123, included_tax: 2) }
|
||||
|
||||
before do
|
||||
Spree::Config.shipment_inc_vat = true
|
||||
@@ -287,14 +285,16 @@ describe Spree::Order do
|
||||
|
||||
let(:variant) { create(:variant, product: create(:product, tax_category: tax_category10)) }
|
||||
let(:shipping_method) { create(:shipping_method, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 46.0)) }
|
||||
let(:shipment) { create(:shipment) }
|
||||
let(:enterprise_fee) { create(:enterprise_fee, enterprise: coordinator, tax_category: tax_category20, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 48.0)) }
|
||||
let(:additional_adjustment) { create(:adjustment, amount: 50.0, included_tax: tax_rate25.compute_tax(50.0)) }
|
||||
|
||||
let(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator, coordinator_fees: [enterprise_fee], distributors: [coordinator], variants: [variant]) }
|
||||
let!(:order) { create(:order, shipping_method: shipping_method, bill_address: create(:address), order_cycle: order_cycle, distributor: coordinator, adjustments: [additional_adjustment]) }
|
||||
let!(:order) { create(:order, shipments: [shipment], bill_address: create(:address), order_cycle: order_cycle, distributor: coordinator, adjustments: [additional_adjustment]) }
|
||||
let!(:line_item) { create(:line_item, order: order, variant: variant, price: 44.0) }
|
||||
|
||||
before do
|
||||
shipment.add_shipping_method(shipping_method, true)
|
||||
Spree::Config.shipment_inc_vat = true
|
||||
Spree::Config.shipping_tax_rate = tax_rate15.amount
|
||||
Spree::TaxRate.adjust(order)
|
||||
@@ -386,7 +386,7 @@ describe Spree::Order do
|
||||
|
||||
describe "emptying the order" do
|
||||
it "removes shipping method" do
|
||||
subject.shipping_method = create(:shipping_method)
|
||||
subject.shipments = [create(:shipment)]
|
||||
subject.save!
|
||||
subject.empty!
|
||||
subject.shipping_method.should == nil
|
||||
@@ -655,8 +655,7 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
describe "a completed order with shipping and transaction fees" do
|
||||
let(:distributor) { create(:distributor_enterprise, charges_sales_tax: true, allow_order_changes: true) }
|
||||
let(:order) { create(:completed_order_with_fees, distributor: distributor, shipping_fee: shipping_fee, payment_fee: payment_fee) }
|
||||
let(:order) { create(:completed_order_with_fees, shipping_fee: shipping_fee, payment_fee: payment_fee) }
|
||||
let(:shipping_fee) { 3 }
|
||||
let(:payment_fee) { 5 }
|
||||
let(:item_num) { order.line_items.length }
|
||||
|
||||
Reference in New Issue
Block a user