diff --git a/spec/fixtures/vcr_cassettes/As_a_consumer_I_want_to_checkout_my_order/as_a_logged_in_user/summary_step/with_a_VINE_voucher/when_placing_the_order/completes_the_order.yml b/spec/fixtures/vcr_cassettes/As_a_consumer_I_want_to_checkout_my_order/as_a_logged_in_user/summary_step/with_a_VINE_voucher/when_placing_the_order/completes_the_order.yml new file mode 100644 index 0000000000..b3a5737dfb --- /dev/null +++ b/spec/fixtures/vcr_cassettes/As_a_consumer_I_want_to_checkout_my_order/as_a_logged_in_user/summary_step/with_a_VINE_voucher/when_placing_the_order/completes_the_order.yml @@ -0,0 +1,55 @@ +--- +http_interactions: +- request: + method: post + uri: https://vine-staging.openfoodnetwork.org.au/api/v1/voucher-redemptions + body: + encoding: UTF-8 + string: '{"voucher_id":"9d316d27-4e3c-4c8c-b3c8-8e23cc171f20","voucher_set_id":"9d314daa-0878-4b73-922d-698047640cf4","amount":1}' + headers: + X-Authorization: + - "" + Accept: + - application/json + User-Agent: + - Faraday v2.9.0 + Content-Type: + - application/json + Authorization: + - "" + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Vary: + - Accept-Encoding + Cache-Control: + - no-cache, private + Date: + - Wed, 23 Oct 2024 03:16:39 GMT + Access-Control-Allow-Origin: + - "*" + X-Frame-Options: + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + body: + encoding: ASCII-8BIT + string: '{"meta":{"responseCode":200,"limit":50,"offset":0,"message":"Redemption + successful. This was a test redemption. Do NOT provide the person with goods + or services."},"data":{"voucher_id":"9d316d27-4e3c-4c8c-b3c8-8e23cc171f20","voucher_set_id":"9d314daa-0878-4b73-922d-698047640cf4","redeemed_by_user_id":8,"redeemed_by_team_id":4,"redeemed_amount":1,"is_test":1,"updated_at":"2024-10-23T03:16:39.000000Z","created_at":"2024-10-23T03:16:39.000000Z","id":7}}' + recorded_at: Wed, 23 Oct 2024 03:16:39 GMT +recorded_with: VCR 6.2.0 diff --git a/spec/system/consumer/checkout/summary_spec.rb b/spec/system/consumer/checkout/summary_spec.rb index 6fc9a5028e..313c133947 100644 --- a/spec/system/consumer/checkout/summary_spec.rb +++ b/spec/system/consumer/checkout/summary_spec.rb @@ -344,6 +344,49 @@ RSpec.describe "As a consumer, I want to checkout my order" do end end end + + context "with a VINE voucher", feature: :connected_apps do + let!(:vine_connected_app) { + ConnectedApps::Vine.create( + enterprise: distributor, data: { api_key: "1234568", secret: "my_secret" } + ) + } + let(:vine_voucher) { + create(:voucher_flat_rate, voucher_type: "VINE", code: 'some_vine_code', + enterprise: distributor, amount: 0.01) + } + + before do + allow(ENV).to receive(:fetch).and_call_original + allow(ENV).to receive(:fetch).with("VINE_API_URL") + .and_return("https://vine-staging.openfoodnetwork.org.au/api/v1") + + add_voucher_to_order(vine_voucher, order) + end + + it "shows the applied voucher" do + visit checkout_step_path(:summary) + + within ".summary-right" do + expect(page).to have_content "some_vine_code" + expect(page).to have_content "-0.01" + end + end + + context "when placing the order" do + it "completes the order", :vcr do + visit checkout_step_path(:summary) + + place_order + + within "#line-items" do + expect(page).to have_content "Voucher: some_vine_code" + expect(page).to have_content "$-0.01" + end + expect(order.reload.state).to eq "complete" + end + end + end end context "with previous open orders" do @@ -400,7 +443,7 @@ RSpec.describe "As a consumer, I want to checkout my order" do expect(page).to have_selector('h5', text: "Balance Due") expect(page).to have_selector('h5', text: with_currency(10)) - confirmation_page_expect_paid(paid_state: "NOT PAID" ,paid_amount: 40) + confirmation_page_expect_paid(paid_state: "NOT PAID", paid_amount: 40) end end @@ -411,7 +454,7 @@ RSpec.describe "As a consumer, I want to checkout my order" do expect(page).to have_selector('h5', text: "Credit Owed") expect(page).to have_selector('h5', text: with_currency(-10)) - confirmation_page_expect_paid(paid_state: "PAID" ,paid_amount: 60) + confirmation_page_expect_paid(paid_state: "PAID", paid_amount: 60) end end @@ -422,13 +465,13 @@ RSpec.describe "As a consumer, I want to checkout my order" do expect(page).not_to have_selector('h5', text: "Credit Owed") expect(page).not_to have_selector('h5', text: "Balance Due") - confirmation_page_expect_paid(paid_state: "PAID" ,paid_amount: 50) + confirmation_page_expect_paid(paid_state: "PAID", paid_amount: 50) end end end end - def confirmation_page_expect_paid(paid_state: ,paid_amount:) + def confirmation_page_expect_paid(paid_state:, paid_amount:) expect(page).to have_content paid_state.to_s expect(page).to have_selector('strong', text: "Amount Paid") expect(page).to have_selector('strong', text: with_currency(paid_amount))