Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vouchers] error moving between summary and cart pages #11117

Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
04bbea5
Move voucher processing out of checkout controller
Matt-Yorkley Jun 1, 2023
60c0c54
Update create_adjustment to create with an amount of 0
rioug Jun 26, 2023
87790b2
Fix VoucherAdjustmentsService.calculate so we can call it mutiple time
rioug Jun 26, 2023
366cca7
Prevent voucher adjustment from bein updated when update is called
rioug Jun 26, 2023
ca7dcb8
Apply voucher after transitionning to the confirmation step
rioug Jun 26, 2023
edabc56
Add voucher calculation after updating an order
rioug Jun 26, 2023
a8062e9
Add a scenario to make sure voucher adjustment a recalculated
rioug Jun 26, 2023
789ce39
Fixing Rubocop errors
rioug Jun 26, 2023
751056b
As per review comment, spell out voucher code when entering a voucher
rioug Jun 30, 2023
4127119
Per review, Makes quantity change more explicit
rioug Jun 30, 2023
3d9542f
Per review, rename amount to adjustment_amount
rioug Jun 30, 2023
5a59396
Remove call to VoucherAdjustmentService when creating a voucher
rioug Jun 30, 2023
0e0850e
Add specs to cover re calculation
rioug Jun 30, 2023
a584f9a
Refactor VoucherAdjustmentsService
rioug Jul 18, 2023
a5b2bc6
Per review, Refactor VoucherAdjustmentsService
rioug Jul 18, 2023
895f534
Remove unnecessary extra page load
dacook Jul 27, 2023
be1a727
Pending spec: vouchers should not require payment
dacook Jul 27, 2023
ef62fb8
Check if record actually saved
dacook Jul 27, 2023
f35001d
Update voucher adjustment and order total when adding a voucher
rioug Jul 28, 2023
33ef8de
Update order total after removing a voucher
rioug Jul 28, 2023
089d2b9
Clear any existing payment and payment fees when adding a voucher
rioug Jul 31, 2023
2857930
Fix voucher adjustment request spec
rioug Jul 31, 2023
85adb9f
Fix rubocop warning
rioug Jul 31, 2023
6ed35f4
Per review, delete only incomplete payments
rioug Aug 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 66 additions & 5 deletions spec/system/consumer/split_checkout_tax_incl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
let!(:order_within_zone) {
create(:order, order_cycle: order_cycle, distributor: distributor, user: user_within_zone,
bill_address: address_within_zone, ship_address: address_within_zone,
state: "cart", line_items: [create(:line_item, variant: variant_with_tax)])
state: "cart", line_items: [create(:line_item, variant: variant_with_tax, quantity: 1)])
}
let!(:order_outside_zone) {
create(:order, order_cycle: order_cycle, distributor: distributor, user: user_outside_zone,
Expand Down Expand Up @@ -139,11 +139,65 @@
end

# DB check
order_within_zone.reload
voucher_adjustment = order_within_zone.voucher_adjustments.first
assert_db_voucher_adjustment(-10.00, -1.15)
end

describe "moving between summary to summary via edit cart" do
let!(:voucher) do
create(:voucher, code: 'good_code', enterprise: distributor, amount: 15)
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
rioug marked this conversation as resolved.
Show resolved Hide resolved
click_button("Apply")

proceed_to_summary

assert_db_voucher_adjustment(-10.00, -1.15)

# 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
rioug marked this conversation as resolved.
Show resolved Hide resolved
end

expect(voucher_adjustment.amount.to_f).to eq(-10)
expect(voucher_adjustment.included_tax.to_f).to eq(-1.15)
click_button("Update")

# Check adjustment has been recalculated
assert_db_voucher_adjustment(-15.00, -1.73)

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("$15.00 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 "-15"
end

# Check adjustment has been recalculated, we are not expecting any changes here
assert_db_voucher_adjustment(-15.00, -1.73)
end
end
end
end
Expand Down Expand Up @@ -190,4 +244,11 @@ def assert_db_no_tax_incl
expect(order_outside_zone.included_tax_total).to eq(0.0)
expect(order_outside_zone.additional_tax_total).to eq(0.0)
end

def assert_db_voucher_adjustment(amount, tax_amount)
adjustment = order_within_zone.voucher_adjustments.first
#adjustment.reload
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is removed in another commit.

expect(adjustment.amount.to_f).to eq(amount)
expect(adjustment.included_tax.to_f).to eq(tax_amount)
end
end