Skip to content

Commit 919387f

Browse files
committed
Due to changes in Ordering/Fulfillment the previous error class no longer exists. A new error has to be rescued in case of payment attempt for non-submitted order.
1 parent ccd89d0 commit 919387f

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

rails_application/app/controllers/orders_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ def pay
105105
flash[:alert] = "Payment was already captured"
106106
rescue Payments::Payment::NotAuthorized
107107
flash[:alert] = "Payment wasn't yet authorized"
108-
rescue Ordering::Order::NotPlaced
109-
flash[:alert] = "You can't pay for an order which is not submitted"
108+
rescue Fulfillment::Order::InvalidState
109+
flash[:alert] = "Order is not in a valid state for payment"
110110
end
111111
redirect_to orders_path
112112
end

rails_application/test/integration/orders_test.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,45 @@ def test_current_time_promotion_is_applied
267267
assert_select("td", "50.0%")
268268
end
269269

270+
def test_unable_to_pay_for_not_submitted_order
271+
shopify_id = register_customer("Shopify")
272+
273+
order_id = SecureRandom.uuid
274+
another_order_id = SecureRandom.uuid
275+
276+
async_remote_id = register_product("Async Remote", 39, 10)
277+
fearless_id = register_product("Fearless Refactoring", 49, 10)
278+
279+
post "/orders",
280+
params: {
281+
"authenticity_token" => "[FILTERED]",
282+
"order_id" => another_order_id,
283+
"customer_id" => shopify_id,
284+
"commit" => "Submit order"
285+
}
286+
287+
get "/"
288+
get "/orders/new"
289+
follow_redirect!
290+
291+
assert_remove_buttons_not_visible(async_remote_id, fearless_id)
292+
293+
post "/orders/#{order_id}/add_item?product_id=#{async_remote_id}"
294+
post "/orders/#{order_id}/add_item?product_id=#{fearless_id}"
295+
post "/orders/#{order_id}/add_item?product_id=#{fearless_id}"
296+
get "/orders/#{order_id}/edit"
297+
assert_remove_buttons_visible(async_remote_id, fearless_id, order_id)
298+
299+
apply_discount_10_percent(order_id)
300+
301+
post "/orders/#{order_id}/pay"
302+
303+
follow_redirect!
304+
assert_select "#alert", "Order is not in a valid state for payment"
305+
assert_select("td", text: "Not submitted")
306+
end
307+
308+
270309
private
271310

272311
def assert_remove_buttons_visible(async_remote_id, fearless_id, order_id)

0 commit comments

Comments
 (0)