mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-02 21:57:17 +00:00
Add a scenario to make sure voucher adjustment a recalculated
This is specificly for voucher with a tax component, but it will also become relevant for percentage based voucher.
This commit is contained in:
@@ -49,7 +49,7 @@ describe "As a consumer, I want to see adjustment breakdown" do
|
||||
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,
|
||||
@@ -139,11 +139,65 @@ describe "As a consumer, I want to see adjustment breakdown" do
|
||||
end
|
||||
|
||||
# DB check
|
||||
order_within_zone.reload
|
||||
voucher_adjustment = order_within_zone.voucher_adjustments.first
|
||||
assert_db_voucher_adjustment(-10.00, -1.15)
|
||||
end
|
||||
|
||||
expect(voucher_adjustment.amount.to_f).to eq(-10)
|
||||
expect(voucher_adjustment.included_tax.to_f).to eq(-1.15)
|
||||
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
|
||||
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
|
||||
end
|
||||
|
||||
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
|
||||
@@ -190,4 +244,11 @@ describe "As a consumer, I want to see adjustment breakdown" do
|
||||
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
|
||||
expect(adjustment.amount.to_f).to eq(amount)
|
||||
expect(adjustment.included_tax.to_f).to eq(tax_amount)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user