diff --git a/app/controllers/split_checkout_controller.rb b/app/controllers/split_checkout_controller.rb index b00f42b980..5202673270 100644 --- a/app/controllers/split_checkout_controller.rb +++ b/app/controllers/split_checkout_controller.rb @@ -203,9 +203,12 @@ class SplitCheckoutController < ::BaseController return false end - # Create adjustment - # TODO add tax part of adjustement - voucher.create_adjustment(voucher.code, @order) + adjustment = voucher.create_adjustment(voucher.code, @order) + + if adjustment.nil? + @order.errors.add(:voucher, I18n.t('split_checkout.errors.add_voucher_error')) + return false + end true end diff --git a/config/locales/en.yml b/config/locales/en.yml index 40a5c5c043..b4913ecb9f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2095,6 +2095,7 @@ en: select_a_payment_method: Select a payment method no_shipping_methods_available: Checkout is not possible due to absence of shipping options. Please contact the shop owner. voucher_not_found: Not found + add_voucher_error: There was an error while adding the voucher order_paid: PAID order_not_paid: NOT PAID order_total: Total order diff --git a/spec/controllers/split_checkout_controller_spec.rb b/spec/controllers/split_checkout_controller_spec.rb index 86750668d4..e441e12854 100644 --- a/spec/controllers/split_checkout_controller_spec.rb +++ b/spec/controllers/split_checkout_controller_spec.rb @@ -279,7 +279,16 @@ describe SplitCheckoutController, type: :controller do end context "when adding fails" do - pending "returns 422 and an error message" + it "returns 422 and an error message" do + # Makes adding the voucher fails + allow(voucher).to receive(:compute_amount).and_return(0) + allow(Voucher).to receive(:find_by).and_return(voucher) + + put :update, params: params + + expect(response.status).to eq 422 + expect(flash[:error]).to match "There was an error while adding the voucher" + end end end