Skip to content

Commit

Permalink
Add system specs for percentage based voucher
Browse files Browse the repository at this point in the history
Similar to tax included in price scenario, adds a test for percentage
based voucher to check the adjustments are recalculated when needed.
Plus fix tax incluced in price specs to use new factory
  • Loading branch information
rioug committed Jun 27, 2023
1 parent 79e2036 commit 60b4b0c
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 8 deletions.
4 changes: 2 additions & 2 deletions spec/system/consumer/split_checkout_tax_incl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
before { Flipper.enable :vouchers }

let!(:voucher) do
create(:voucher, code: 'some_code', enterprise: distributor, amount: 10)
create(:voucher_flat_rate, code: 'some_code', enterprise: distributor, amount: 10)
end

it "will include a tax included amount on the voucher adjustment" do
Expand Down Expand Up @@ -147,7 +147,7 @@

describe "moving between summary to summary via edit cart" do
let!(:voucher) do
create(:voucher, code: 'good_code', enterprise: distributor, amount: 15)
create(:voucher_flat_rate, code: 'good_code', enterprise: distributor, amount: 15)
end

it "recalculate the tax component properly" do
Expand Down
80 changes: 74 additions & 6 deletions spec/system/consumer/split_checkout_tax_not_incl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@

context "when using a voucher" do
let!(:voucher) do
create(:voucher, code: 'some_code', enterprise: distributor, amount: 10)
create(:voucher_flat_rate, code: 'some_code', enterprise: distributor, amount: 10)
end

it "will include a tax included amount on the voucher adjustment" do
Expand Down Expand Up @@ -151,12 +151,71 @@
end

# DB check
order_within_zone.reload
voucher_adjustment = order_within_zone.voucher_adjustments.first
voucher_tax_adjustment = order_within_zone.voucher_adjustments.second
#order_within_zone.reload
#voucher_adjustment = order_within_zone.voucher_adjustments.first
#voucher_tax_adjustment = order_within_zone.voucher_adjustments.second

expect(voucher_adjustment.amount.to_f).to eq(-8.85)
expect(voucher_tax_adjustment.amount.to_f).to eq(-1.15)
assert_db_voucher_adjustment(-8.85, -1.15)
end

describe "moving between summary to summary via edit cart" do
let!(:voucher) do
create(:voucher_percentage, code: 'good_code', enterprise: distributor, amount: 20)
end

it "recalculate the tax component properly" do
visit checkout_step_path(:details)
proceed_to_payment

# add Voucher
fill_in "Enter voucher code", with: voucher.code
click_button("Apply")

#pause
proceed_to_summary
assert_db_voucher_adjustment(-2.00, -0.26)

# Click on edit link
within "div", text: /Order details/ do
# It's a bit brittle, but the scoping doesn't seem to work
all(".summary-edit").last.click
end

# Update quantity
within ".cart-item-quantity" do
input = find(".line_item_quantity")
input.send_keys :up
end

click_button("Update")

# Check adjustment has been recalculated
assert_db_voucher_adjustment(-4.00, -0.52)

within "#cart-container" do
click_link("Checkout")
end

# Go back to payment step
proceed_to_payment

# Check voucher is still there
expect(page).to have_content("20.0 % Voucher")

# Go to summary
proceed_to_summary

# Check voucher value
within ".summary-right" do
expect(page).to have_content "good_code"
expect(page).to have_content "-4"
expect(page).to have_content "Tax good_code"
expect(page).to have_content "-0.52"
end

# Check adjustment has been recalculated, we are not expecting any changes here
assert_db_voucher_adjustment(-4.00, -0.52)
end
end
end
end
Expand Down Expand Up @@ -233,4 +292,13 @@
end
end
end

private

def assert_db_voucher_adjustment(amount, tax_amount)
adjustment = order_within_zone.voucher_adjustments.first
tax_adjustment = order_within_zone.voucher_adjustments.second
expect(adjustment.amount.to_f).to eq(amount)
expect(tax_adjustment.amount.to_f).to eq(tax_amount)
end
end

0 comments on commit 60b4b0c

Please sign in to comment.