From 46733d0c0da7cb373d4fe3d2f8044fbb2e8fc6c1 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 22 Sep 2020 21:44:00 +0100 Subject: [PATCH] Add feature spec to cover T&Cs ticked by default if customer has already accepted them --- .../consumer/shopping/checkout_spec.rb | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb index d34c37bff6..094847a71f 100644 --- a/spec/features/consumer/shopping/checkout_spec.rb +++ b/spec/features/consumer/shopping/checkout_spec.rb @@ -126,7 +126,7 @@ feature "As a consumer I want to check out my cart", js: true do end end - context "when distributor has terms and conditions" do + context "when distributor has T&Cs" do let(:fake_terms_and_conditions_path) { Rails.root.join("app/assets/images/logo-white.png") } let(:terms_and_conditions_file) { Rack::Test::UploadedFile.new(fake_terms_and_conditions_path, "application/pdf") } @@ -135,14 +135,29 @@ feature "As a consumer I want to check out my cart", js: true do order.distributor.save end - it "shows a link to the terms and conditions" do - visit checkout_path - expect(page).to have_link("Terms and Conditions", href: order.distributor.terms_and_conditions.url) + describe "when customer has not accepted T&Cs before" do + it "shows a link to the T&Cs and disabled checkout button until terms are accepted" do + visit checkout_path + expect(page).to have_link("Terms and Conditions", href: order.distributor.terms_and_conditions.url) - expect(page).to have_button("Place order now", disabled: true) + expect(page).to have_button("Place order now", disabled: true) - check "accept_terms" - expect(page).to have_button("Place order now", disabled: false) + check "accept_terms" + expect(page).to have_button("Place order now", disabled: false) + end + end + + describe "when customer has already accepted T&Cs before" do + before do + customer = create(:customer, enterprise: order.distributor, user: user) + customer.update terms_and_conditions_accepted_at: Time.zone.now + end + + it "enables checkout because T&Cs are accepted by default" do + visit checkout_path + + expect(page).to have_button("Place order now", disabled: false) + end end end