Moved shipment and shipping_method factories with flat rate and shipping fees to traits

This commit is contained in:
luisramos0
2018-09-16 21:24:29 +01:00
parent 7b6e4825e7
commit fbd2d96b05
4 changed files with 31 additions and 33 deletions

View File

@@ -339,6 +339,20 @@ FactoryBot.define do
trait :delivery do
require_ship_address { true }
end
trait :flat_rate do
calculator { Spree::Calculator::FlatRate.new(preferred_amount: 50.0) }
end
trait :shipping_fee 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
end
factory :shipment_with, parent: :shipment do
@@ -350,15 +364,16 @@ FactoryBot.define do
shipment.add_shipping_method(evaluator.shipping_method, true)
end
end
end
factory :shipping_method_with_flat_rate, parent: :shipping_method do
calculator { Spree::Calculator::FlatRate.new(preferred_amount: 50.0) }
end
trait :shipping_fee do
transient do
shipping_fee 3
end
factory :shipment_with_flat_rate, parent: :shipment do
after(:create) do |shipment|
shipment.add_shipping_method(create(:shipping_method_with_flat_rate), true)
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
end
@@ -367,34 +382,13 @@ FactoryBot.define do
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
shipments { [ create(:shipment_with_shipping_fee, shipping_fee: shipping_fee) ] }
shipments { [ create(:shipment_with, :shipping_fee, shipping_fee: shipping_fee) ] }
after(:create) do |order, evaluator|
create(:line_item, order: order)

View File

@@ -12,7 +12,8 @@ describe OrderShippingMethod do
context 'when order has single shipment' do
it 'returns the shipments shipping_method' do
shipment = create(:shipment_with_flat_rate)
shipping_method = create(:shipping_method_with, :flat_rate)
shipment = create(:shipment_with, :shipping_method, shipping_method: shipping_method)
order.shipments = [shipment]
expect(order.shipping_method).to eq shipment.shipping_method

View File

@@ -59,7 +59,8 @@ module Spree
end
describe "Shipment adjustments" do
let!(:shipment) { create(:shipment_with_flat_rate) }
let(:shipping_method) { create(:shipping_method_with, :flat_rate) }
let(:shipment) { create(:shipment_with, :shipping_method, shipping_method: shipping_method) }
let!(:order) { create(:order, distributor: hub, shipments: [shipment]) }
let(:hub) { create(:distributor_enterprise, charges_sales_tax: true) }
let!(:line_item) { create(:line_item, order: order) }

View File

@@ -222,7 +222,8 @@ describe Spree::Order do
end
describe "getting the shipping tax" do
let(:shipment) { create(:shipment_with_flat_rate) }
let(:shipping_method) { create(:shipping_method_with, :flat_rate) }
let(:shipment) { create(:shipment_with, :shipping_method, shipping_method: shipping_method) }
let(:order) { create(:order, shipments: [shipment]) }
context "with a taxed shipment" do
@@ -254,7 +255,8 @@ describe Spree::Order do
end
describe "getting the total tax" do
let(:shipment) { create(:shipment_with_flat_rate) }
let(:shipping_method) { create(:shipping_method_with, :flat_rate) }
let(:shipment) { create(:shipment_with, :shipping_method, shipping_method: shipping_method) }
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) }