Improve coverage in orders_controller_spec

This commit is contained in:
Matt-Yorkley
2021-02-19 00:02:16 +00:00
parent d4750b9f26
commit cc55e9eeda

View File

@@ -257,16 +257,19 @@ describe Spree::OrdersController, type: :controller do
context "with enterprise fees" do
let(:user) { create(:user) }
let(:variant) { create(:variant) }
let(:variant1) { create(:variant) }
let(:variant2) { create(:variant) }
let(:distributor) { create(:distributor_enterprise, allow_order_changes: true) }
let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor]) }
let(:enterprise_fee) { create(:enterprise_fee, calculator: build(:calculator_per_item) ) }
let!(:exchange) { create(:exchange, incoming: true, sender: variant.product.supplier, receiver: order_cycle.coordinator, variants: [variant], enterprise_fees: [enterprise_fee]) }
let!(:exchange) { create(:exchange, incoming: true, sender: variant1.product.supplier, receiver: order_cycle.coordinator, variants: [variant1, variant2], enterprise_fees: [enterprise_fee]) }
let!(:order) do
order = create(:completed_order_with_totals, line_items_count: 1, user: user, distributor: distributor, order_cycle: order_cycle)
order.reload.line_items.first.update(variant_id: variant.id)
order = create(:completed_order_with_totals, line_items_count: 2, user: user, distributor: distributor, order_cycle: order_cycle)
order.reload.line_items.first.update(variant_id: variant1.id)
order.reload.line_items.last.update(variant_id: variant2.id)
while !order.completed? do break unless order.next! end
order.recreate_all_fees!
order.update!
order
end
let(:params) {
@@ -281,12 +284,34 @@ describe Spree::OrdersController, type: :controller do
end
it "updates the fees" do
expect(order.reload.adjustment_total).to eq enterprise_fee.calculator.preferred_amount
expect(order.total).to eq order.item_total + (enterprise_fee.calculator.preferred_amount * 2)
expect(order.adjustment_total).to eq enterprise_fee.calculator.preferred_amount * 2
allow(controller).to receive_messages spree_current_user: user
spree_post :update, params
expect(order.reload.adjustment_total).to eq enterprise_fee.calculator.preferred_amount * 2
expect(order.total).to eq order.item_total + (enterprise_fee.calculator.preferred_amount * 3)
expect(order.adjustment_total).to eq enterprise_fee.calculator.preferred_amount * 3
end
context "when a line item is removed" do
let(:params) {
{ order: { line_items_attributes: {
"0" => { id: order.line_items.first.id, quantity: 0 },
"1" => { id: order.line_items.last.id, quantity: 1 }
} } }
}
it "updates the fees" do
expect(order.total).to eq order.item_total + (enterprise_fee.calculator.preferred_amount * 2)
expect(order.adjustment_total).to eq enterprise_fee.calculator.preferred_amount * 2
allow(controller).to receive_messages spree_current_user: user
spree_post :update, params
expect(order.total).to eq order.item_total + (enterprise_fee.calculator.preferred_amount * 1)
expect(order.adjustment_total).to eq enterprise_fee.calculator.preferred_amount * 1
end
end
end
end