mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Simplify and speed up service tests
This commit is contained in:
@@ -4,14 +4,6 @@ describe RestartCheckout do
|
||||
let(:order) { create(:order) }
|
||||
|
||||
describe "#restart_checkout" do
|
||||
let!(:shipment_pending) { create(:shipment, order: order, state: 'pending') }
|
||||
let!(:payment_checkout) { create(:payment, order: order, state: 'checkout') }
|
||||
let!(:payment_failed) { create(:payment, order: order, state: 'failed') }
|
||||
|
||||
before do
|
||||
order.update_attribute(:shipping_method_id, shipment_pending.shipping_method_id)
|
||||
end
|
||||
|
||||
context "when the order is already in the 'cart' state" do
|
||||
it "does nothing" do
|
||||
expect(order).to_not receive(:restart_checkout!)
|
||||
@@ -20,23 +12,22 @@ describe RestartCheckout do
|
||||
end
|
||||
|
||||
context "when the order is in a subsequent state" do
|
||||
let!(:shipment_pending) { create(:shipment, order: order, state: 'pending') }
|
||||
let!(:payment_checkout) { create(:payment, order: order, state: 'checkout') }
|
||||
let!(:payment_failed) { create(:payment, order: order, state: 'failed') }
|
||||
|
||||
before do
|
||||
order.shipping_method_id = shipment_pending.shipping_method_id
|
||||
order.update_attribute(:state, "payment")
|
||||
end
|
||||
|
||||
# NOTE: at the time of writing, it was not possible to create a shipment with a state other than
|
||||
# 'pending' when the order has not been completed, so this is not a case that requires testing.
|
||||
# NOTE: at the time of writing, it was not possible to create a shipment
|
||||
# with a state other than 'pending' when the order has not been
|
||||
# completed, so this is not a case that requires testing.
|
||||
it "resets the order state, and clears incomplete shipments and payments" do
|
||||
expect(order).to receive(:restart_checkout!).and_call_original
|
||||
expect(order.shipping_method_id).to_not eq nil
|
||||
expect(order.shipments.count).to eq 1
|
||||
expect(order.adjustments.shipping.count).to eq 1
|
||||
expect(order.payments.count).to eq 2
|
||||
expect(order.adjustments.payment_fee.count).to eq 2
|
||||
|
||||
RestartCheckout.new(order).restart_checkout
|
||||
|
||||
expect(order.reload.state).to eq 'cart'
|
||||
expect(order.state).to eq 'cart'
|
||||
expect(order.shipping_method_id).to eq nil
|
||||
expect(order.shipments.count).to eq 0
|
||||
expect(order.adjustments.shipping.count).to eq 0
|
||||
|
||||
Reference in New Issue
Block a user