From a113b5ba01bd9760573f3b9e9749987274e80dca Mon Sep 17 00:00:00 2001 From: prateek0411999 Date: Fri, 20 Oct 2023 18:11:57 +0530 Subject: [PATCH] add condition on warning_forfeit_remaining_amount note --- .../split_checkout/_voucher_section.html.haml | 2 +- .../_voucher_section.html.haml_spec.rb | 52 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 spec/views/split_checkout/_voucher_section.html.haml_spec.rb diff --git a/app/views/split_checkout/_voucher_section.html.haml b/app/views/split_checkout/_voucher_section.html.haml index fcbebda20b..917c75fe98 100644 --- a/app/views/split_checkout/_voucher_section.html.haml +++ b/app/views/split_checkout/_voucher_section.html.haml @@ -11,7 +11,7 @@ = link_to t("split_checkout.step2.voucher.remove_code"), voucher_adjustment_path(id: voucher_adjustment.id), method: "delete", data: { confirm: t("split_checkout.step2.voucher.confirm_delete") } - # This might not be true, ie payment method including a fee which wouldn't be covered by voucher or tax implication raising total to be bigger than the voucher amount ? - - if voucher_adjustment.originator.amount > order.pre_discount_total + - if voucher_adjustment.originator.amount > order.pre_discount_total && voucher_adjustment.originator.is_a?(Vouchers::FlatRate) .checkout-input %span.formError.standalone = t("split_checkout.step2.voucher.warning_forfeit_remaining_amount") diff --git a/spec/views/split_checkout/_voucher_section.html.haml_spec.rb b/spec/views/split_checkout/_voucher_section.html.haml_spec.rb new file mode 100644 index 0000000000..be940910ce --- /dev/null +++ b/spec/views/split_checkout/_voucher_section.html.haml_spec.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe "split_checkout/_voucher_section.html.haml" do + let(:order) { create(:order_with_distributor, total: 10) } + let(:flat_voucher) { + create(:voucher_flat_rate, code: "flat_code", + enterprise: order.distributor, amount: 20) + } + let(:percent_voucher) { + create(:voucher_percentage_rate, code: 'percent_code', + enterprise: order.distributor, amount: 20) + } + let(:note) { + ["Note: if your order total is less than your voucher", + "you may not be able to spend the remaining value."].join(" ") + } + + it "should display warning_forfeit_remaining_amount note" do + add_voucher(flat_voucher, order) + + allow(view).to receive_messages( + order:, + voucher_adjustment: order.voucher_adjustments.first + ) + assign(:order, order) + + render + expect(rendered).to have_content(note) + end + + it "should not display warning_forfeit_remaining_amount note" do + add_voucher(percent_voucher, order) + + allow(view).to receive_messages( + order:, + voucher_adjustment: order.voucher_adjustments.first + ) + assign(:order, order) + + render + expect(rendered).to_not have_content(note) + end + + def add_voucher(voucher, order) + voucher.create_adjustment(voucher.code, order) + order.update_order! + + VoucherAdjustmentsService.new(order).update + end +end