Compare commits

...

3 Commits

Author SHA1 Message Date
Matt-Yorkley
4be45303bf Reload order before updating in Payment callback 2021-04-27 13:17:18 +01:00
Matt-Yorkley
8d19bcdcf2 Add failing spec for payment and shipment states bug
The order was being left in an unexpected condition here, it's states are not set and there seem to be some weird issues.
2021-04-27 13:16:23 +01:00
Matt-Yorkley
f6f1cf9e41 Test payment and shipment states in checkout spec
If these aren't behaving correctly we need to know about it...
2021-04-27 13:16:23 +01:00
3 changed files with 54 additions and 11 deletions

View File

@@ -201,7 +201,7 @@ module Spree
end end
def update_order def update_order
order.update! order.reload.update!
end end
# Necessary because some payment gateways will refuse payments with # Necessary because some payment gateways will refuse payments with

View File

@@ -35,4 +35,33 @@ feature '
expect(page).to have_content I18n.t(:new_payment) expect(page).to have_content I18n.t(:new_payment)
end end
end end
context "creating an order's first payment via admin", js: true do
before do
order.update_columns(
state: "payment",
payment_state: nil,
shipment_state: nil,
completed_at: nil
)
end
it "creates the payment, completes the order, and updates payment and shipping states" do
login_as_admin_and_visit spree.new_admin_order_payment_path order
expect(page).to have_content "New Payment"
within "#new_payment" do
find('input[type="radio"]').click
end
click_button "Update"
expect(page).to have_content "Payments"
order.reload
expect(order.state).to eq "complete"
expect(order.payment_state).to eq "balance_due"
expect(order.shipment_state).to eq "pending"
end
end
end end

View File

@@ -255,6 +255,10 @@ feature "As a consumer I want to check out my cart", js: true do
place_order place_order
expect(page).to have_content "Your order has been processed successfully" expect(page).to have_content "Your order has been processed successfully"
end.to enqueue_job ConfirmOrderJob end.to enqueue_job ConfirmOrderJob
order = Spree::Order.complete.last
expect(order.payment_state).to eq "balance_due"
expect(order.shipment_state).to eq "pending"
end end
end end
end end
@@ -389,10 +393,10 @@ feature "As a consumer I want to check out my cart", js: true do
end.to enqueue_job ConfirmOrderJob end.to enqueue_job ConfirmOrderJob
# And the order's special instructions should be set # And the order's special instructions should be set
order = Spree::Order.complete.first order = Spree::Order.complete.last
expect(order.special_instructions).to eq "SpEcIaL NoTeS" expect(order.special_instructions).to eq "SpEcIaL NoTeS"
# Shipment and payments states should be set # Shipment and payments states should be set ###
expect(order.payment_state).to eq "balance_due" expect(order.payment_state).to eq "balance_due"
expect(order.shipment_state).to eq "pending" expect(order.shipment_state).to eq "pending"
@@ -421,6 +425,10 @@ feature "As a consumer I want to check out my cart", js: true do
it "takes us to the order confirmation page when submitted with 'same as billing address' checked" do it "takes us to the order confirmation page when submitted with 'same as billing address' checked" do
place_order place_order
expect(page).to have_content "Your order has been processed successfully" expect(page).to have_content "Your order has been processed successfully"
order = Spree::Order.complete.last
expect(order.payment_state).to eq "balance_due"
expect(order.shipment_state).to eq "pending"
end end
it "takes us to the cart page with an error when a product becomes out of stock just before we purchase", js: true do it "takes us to the cart page with an error when a product becomes out of stock just before we purchase", js: true do
@@ -443,9 +451,11 @@ feature "As a consumer I want to check out my cart", js: true do
expect(page).to have_content "Your order has been processed successfully" expect(page).to have_content "Your order has been processed successfully"
# There are two orders - our order and our new cart # There are two orders - our order and our new cart
o = Spree::Order.complete.first order = Spree::Order.complete.last
expect(o.shipment_adjustments.first.amount).to eq(4.56) expect(order.shipment_adjustments.first.amount).to eq(4.56)
expect(o.payments.first.amount).to eq(10 + 1.23 + 4.56) # items + fees + shipping expect(order.payments.first.amount).to eq(10 + 1.23 + 4.56) # items + fees + shipping
expect(order.payment_state).to eq "balance_due"
expect(order.shipment_state).to eq "pending"
end end
end end
@@ -464,9 +474,11 @@ feature "As a consumer I want to check out my cart", js: true do
expect(page).to have_content "Your order has been processed successfully" expect(page).to have_content "Your order has been processed successfully"
# There are two orders - our order and our new cart # There are two orders - our order and our new cart
o = Spree::Order.complete.first order = Spree::Order.complete.last
expect(o.all_adjustments.payment_fee.first.amount).to eq 5.67 expect(order.all_adjustments.payment_fee.first.amount).to eq 5.67
expect(o.payments.first.amount).to eq(10 + 1.23 + 5.67) # items + fees + transaction expect(order.payments.first.amount).to eq(10 + 1.23 + 5.67) # items + fees + transaction
expect(order.payment_state).to eq "balance_due"
expect(order.shipment_state).to eq "pending"
end end
end end
@@ -485,8 +497,10 @@ feature "As a consumer I want to check out my cart", js: true do
expect(page).to have_content "Your order has been processed successfully" expect(page).to have_content "Your order has been processed successfully"
# Order should have a payment with the correct amount # Order should have a payment with the correct amount
o = Spree::Order.complete.first order = Spree::Order.complete.last
expect(o.payments.first.amount).to eq(11.23) expect(order.payments.first.amount).to eq(11.23)
expect(order.payment_state).to eq "paid"
expect(order.shipment_state).to eq "ready"
end end
it "shows the payment processing failed message when submitted with an invalid credit card" do it "shows the payment processing failed message when submitted with an invalid credit card" do