Test that payment_total is stored after payment

CustomerWithBalance totally relies on `spree_orders.payment_total` so we
better cover it with tests.
This commit is contained in:
Pau Perez
2020-11-25 16:07:48 +01:00
parent 93cdca85c6
commit 04930877dd

View File

@@ -201,16 +201,27 @@ describe Spree::Order do
let(:payment) { build(:payment) }
before { allow(order).to receive_messages pending_payments: [payment], total: 10 }
it "should process the payments" do
expect(payment).to receive(:process!)
expect(order.process_payments!).to be_truthy
end
it "should return false if no pending_payments available" do
allow(order).to receive_messages pending_payments: []
expect(order.process_payments!).to be_falsy
end
context "when the processing is sucessful" do
it "should process the payments" do
expect(payment).to receive(:process!)
expect(order.process_payments!).to be_truthy
end
it "stores the payment total on the order" do
allow(payment).to receive(:process!)
allow(payment).to receive(:completed?).and_return(true)
order.process_payments!
expect(order.payment_total).to eq(payment.amount)
end
end
context "when a payment raises a GatewayError" do
before { expect(payment).to receive(:process!).and_raise(Spree::Core::GatewayError) }