From 85096a997fe2623ba5364e1d901c46d6233326e1 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Sat, 5 Sep 2020 19:33:27 +0100 Subject: [PATCH 01/24] Add a checkbox to checkout to tick for Terms and Conditions Checkout button should be disabled if checkbox is not ticked --- app/views/checkout/_form.html.haml | 2 +- app/views/checkout/_terms_and_conditions.html.haml | 7 +++++-- lib/tasks/sample_data/order_factory.rb | 2 +- spec/features/consumer/shopping/checkout_spec.rb | 5 +++++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/views/checkout/_form.html.haml b/app/views/checkout/_form.html.haml index f341a666d9..e755af01e4 100644 --- a/app/views/checkout/_form.html.haml +++ b/app/views/checkout/_form.html.haml @@ -16,6 +16,6 @@ = render "checkout/already_ordered", f: f if show_bought_items? = render "checkout/terms_and_conditions", f: f %p - %button.button.primary{type: :submit} + %button.button.primary{ type: :submit, ng: { disabled: "terms_and_conditions_activated && !terms_and_conditions_accepted" } } = t :checkout_send / {{ checkout.$valid }} diff --git a/app/views/checkout/_terms_and_conditions.html.haml b/app/views/checkout/_terms_and_conditions.html.haml index a99cf44785..bf301139b0 100644 --- a/app/views/checkout/_terms_and_conditions.html.haml +++ b/app/views/checkout/_terms_and_conditions.html.haml @@ -1,2 +1,5 @@ -%p.small - = t('.message_html', terms_and_conditions_link: link_to( t( '.link_text' ), current_order.distributor.terms_and_conditions.url, target: '_blank')) if current_order.distributor.terms_and_conditions.file? +- terms_and_conditions_activated = current_order.distributor.terms_and_conditions.file? +- if terms_and_conditions_activated + %p.small + %input{ type: 'checkbox', id: 'accept_terms', ng: { model: "terms_and_conditions_accepted", init: "terms_and_conditions_activated=#{terms_and_conditions_activated}" } } + %label{for: "accept_terms"}= t('.message_html', terms_and_conditions_link: link_to( t( '.link_text' ), current_order.distributor.terms_and_conditions.url, target: '_blank')) diff --git a/lib/tasks/sample_data/order_factory.rb b/lib/tasks/sample_data/order_factory.rb index 9614f685a0..cdb2dfcc4e 100644 --- a/lib/tasks/sample_data/order_factory.rb +++ b/lib/tasks/sample_data/order_factory.rb @@ -57,7 +57,7 @@ class OrderFactory bill_address: order_address, ship_address: order_address ) - order.line_items.create( variant_id: first_variant.id, quantity: 5 ) + order.line_items.create(variant_id: first_variant.id, quantity: 5) order.payments.create(payment_method_id: first_payment_method_id) order end diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb index 26be7c62a5..23e0386078 100644 --- a/spec/features/consumer/shopping/checkout_spec.rb +++ b/spec/features/consumer/shopping/checkout_spec.rb @@ -138,6 +138,11 @@ feature "As a consumer I want to check out my cart", js: true do it "shows a link to the terms and conditions" do visit checkout_path expect(page).to have_link("Terms of Service", href: order.distributor.terms_and_conditions.url) + + expect(page).to have_button("Place order now", disabled: true) + + check "accept_terms" + expect(page).to have_button("Place order now", disabled: false) end end From 806c8b943d049e184dd871fddea4059afb038087 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Mon, 7 Sep 2020 12:44:45 +0100 Subject: [PATCH 02/24] Move small class to label so that rule is actually applied --- app/views/checkout/_terms_and_conditions.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/checkout/_terms_and_conditions.html.haml b/app/views/checkout/_terms_and_conditions.html.haml index bf301139b0..6bafd6bbb7 100644 --- a/app/views/checkout/_terms_and_conditions.html.haml +++ b/app/views/checkout/_terms_and_conditions.html.haml @@ -1,5 +1,5 @@ - terms_and_conditions_activated = current_order.distributor.terms_and_conditions.file? - if terms_and_conditions_activated - %p.small + %p %input{ type: 'checkbox', id: 'accept_terms', ng: { model: "terms_and_conditions_accepted", init: "terms_and_conditions_activated=#{terms_and_conditions_activated}" } } - %label{for: "accept_terms"}= t('.message_html', terms_and_conditions_link: link_to( t( '.link_text' ), current_order.distributor.terms_and_conditions.url, target: '_blank')) + %label.small{for: "accept_terms"}= t('.message_html', terms_and_conditions_link: link_to( t( '.link_text' ), current_order.distributor.terms_and_conditions.url, target: '_blank')) From 78a8f53d8ded1094872b25838803035dfcc9391b Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Thu, 17 Sep 2020 18:38:38 +0100 Subject: [PATCH 03/24] Change default translations to what's been requested on the issue --- config/locales/en.yml | 4 ++-- spec/features/consumer/shopping/checkout_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 8b9786f1e9..5eb5b40892 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1235,8 +1235,8 @@ en: cart: "cart" message_html: "You have an order for this order cycle already. Check the %{cart} to see the items you ordered before. You can also cancel items as long as the order cycle is open." terms_and_conditions: - message_html: "By placing this order you agree to the %{terms_and_conditions_link}." - link_text: "Terms of Service" + message_html: "I agree to the seller's %{terms_and_conditions_link}." + link_text: "Terms and Conditions" failed: "The checkout failed. Please let us know so that we can process your order." shops: hubs: diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb index 23e0386078..d34c37bff6 100644 --- a/spec/features/consumer/shopping/checkout_spec.rb +++ b/spec/features/consumer/shopping/checkout_spec.rb @@ -122,7 +122,7 @@ feature "As a consumer I want to check out my cart", js: true do end it "doesn't show link to terms and conditions" do - expect(page).to have_no_link("Terms of Service") + expect(page).to have_no_link("Terms and Conditions") end end @@ -137,7 +137,7 @@ feature "As a consumer I want to check out my cart", js: true do it "shows a link to the terms and conditions" do visit checkout_path - expect(page).to have_link("Terms of Service", href: order.distributor.terms_and_conditions.url) + 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) From 3c9c5862d11b843f668962503289ef6cef41008d Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Mon, 7 Sep 2020 13:32:32 +0100 Subject: [PATCH 04/24] Verify terms and conditions updated_at timestamp is touched every time the file name changes. We will need this to check if user already accepted the terms and conditions of this enterprise. --- .../admin/enterprises/terms_and_conditions_spec.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spec/features/admin/enterprises/terms_and_conditions_spec.rb b/spec/features/admin/enterprises/terms_and_conditions_spec.rb index ced7c5deea..3f862403d4 100644 --- a/spec/features/admin/enterprises/terms_and_conditions_spec.rb +++ b/spec/features/admin/enterprises/terms_and_conditions_spec.rb @@ -43,7 +43,11 @@ feature "Uploading Terms and Conditions PDF" do # Add PDF attach_file "enterprise[terms_and_conditions]", white_pdf_file_name - click_button "Update" + + Timecop.freeze(run_time = Time.zone.local(2002, 4, 13, 0, 0, 0)) do + click_button "Update" + expect(distributor.reload.terms_and_conditions_updated_at).to eq run_time + end expect(page). to have_content("Enterprise \"#{distributor.name}\" has been successfully updated!") @@ -55,6 +59,7 @@ feature "Uploading Terms and Conditions PDF" do click_button "Update" expect(page). to have_content("Enterprise \"#{distributor.name}\" has been successfully updated!") + expect(distributor.reload.terms_and_conditions_updated_at).to_not eq run_time go_to_business_details expect(page).to have_selector("a[href*='logo-black.pdf']") From 4d64bf6ecefd918d4a1873e47ab4f7c5b63e0c77 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Mon, 7 Sep 2020 14:58:23 +0100 Subject: [PATCH 05/24] Add column to customers table to register last time enterprise terms and conditions were accepted so customer doesnt have to accept terms on all checkouts but only when the enterprise updates the terms file --- app/views/checkout/_terms_and_conditions.html.haml | 4 +++- ...0555_add_customer_terms_and_conditions_accepted.rb | 5 +++++ db/schema.rb | 11 ++++++----- 3 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20200907140555_add_customer_terms_and_conditions_accepted.rb diff --git a/app/views/checkout/_terms_and_conditions.html.haml b/app/views/checkout/_terms_and_conditions.html.haml index 6bafd6bbb7..0352ce804f 100644 --- a/app/views/checkout/_terms_and_conditions.html.haml +++ b/app/views/checkout/_terms_and_conditions.html.haml @@ -1,5 +1,7 @@ - terms_and_conditions_activated = current_order.distributor.terms_and_conditions.file? +- customer_terms_and_conditions_accepted_at = spree_current_user.customer_of(current_order.distributor).andand.terms_and_conditions_accepted_at +- terms_and_conditions_already_accepted = customer_terms_and_conditions_accepted_at.present? && (customer_terms_and_conditions_accepted_at > current_order.distributor.terms_and_conditions_updated_at) - if terms_and_conditions_activated %p - %input{ type: 'checkbox', id: 'accept_terms', ng: { model: "terms_and_conditions_accepted", init: "terms_and_conditions_activated=#{terms_and_conditions_activated}" } } + %input{ type: 'checkbox', id: 'accept_terms', ng: { model: "terms_and_conditions_accepted", init: "terms_and_conditions_activated=#{terms_and_conditions_activated}; terms_and_conditions_accepted=#{terms_and_conditions_already_accepted}" } } %label.small{for: "accept_terms"}= t('.message_html', terms_and_conditions_link: link_to( t( '.link_text' ), current_order.distributor.terms_and_conditions.url, target: '_blank')) diff --git a/db/migrate/20200907140555_add_customer_terms_and_conditions_accepted.rb b/db/migrate/20200907140555_add_customer_terms_and_conditions_accepted.rb new file mode 100644 index 0000000000..c48b1c19f2 --- /dev/null +++ b/db/migrate/20200907140555_add_customer_terms_and_conditions_accepted.rb @@ -0,0 +1,5 @@ +class AddCustomerTermsAndConditionsAccepted < ActiveRecord::Migration + def change + add_column :customers, :terms_and_conditions_accepted_at, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 5f982a1216..30247daf3a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -47,16 +47,17 @@ ActiveRecord::Schema.define(version: 20200912190210) do add_index "coordinator_fees", ["order_cycle_id"], name: "index_coordinator_fees_on_order_cycle_id", using: :btree create_table "customers", force: true do |t| - t.string "email", null: false - t.integer "enterprise_id", null: false + t.string "email", null: false + t.integer "enterprise_id", null: false t.string "code" t.integer "user_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.integer "bill_address_id" t.integer "ship_address_id" t.string "name" - t.boolean "allow_charges", default: false, null: false + t.boolean "allow_charges", default: false, null: false + t.datetime "terms_and_conditions_accepted_at" end add_index "customers", ["bill_address_id"], name: "index_customers_on_bill_address_id", using: :btree From f3ba0ebdbb05280032132cfa5a4ef916c3765490 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 22 Sep 2020 18:37:51 +0100 Subject: [PATCH 06/24] Move code to a new helper --- app/helpers/terms_and_conditions_helper.rb | 16 ++++++++++++++++ .../checkout/_terms_and_conditions.html.haml | 3 --- 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 app/helpers/terms_and_conditions_helper.rb diff --git a/app/helpers/terms_and_conditions_helper.rb b/app/helpers/terms_and_conditions_helper.rb new file mode 100644 index 0000000000..70b497af61 --- /dev/null +++ b/app/helpers/terms_and_conditions_helper.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module TermsAndConditionsHelper + def terms_and_conditions_activated + current_order.distributor.terms_and_conditions.file? + end + + def terms_and_conditions_already_accepted + customer_terms_and_conditions_accepted_at = spree_current_user. + customer_of(current_order.distributor)&.terms_and_conditions_accepted_at + + customer_terms_and_conditions_accepted_at.present? && + (customer_terms_and_conditions_accepted_at > + current_order.distributor.terms_and_conditions_updated_at) + end +end diff --git a/app/views/checkout/_terms_and_conditions.html.haml b/app/views/checkout/_terms_and_conditions.html.haml index 0352ce804f..9ac1e1e3f4 100644 --- a/app/views/checkout/_terms_and_conditions.html.haml +++ b/app/views/checkout/_terms_and_conditions.html.haml @@ -1,6 +1,3 @@ -- terms_and_conditions_activated = current_order.distributor.terms_and_conditions.file? -- customer_terms_and_conditions_accepted_at = spree_current_user.customer_of(current_order.distributor).andand.terms_and_conditions_accepted_at -- terms_and_conditions_already_accepted = customer_terms_and_conditions_accepted_at.present? && (customer_terms_and_conditions_accepted_at > current_order.distributor.terms_and_conditions_updated_at) - if terms_and_conditions_activated %p %input{ type: 'checkbox', id: 'accept_terms', ng: { model: "terms_and_conditions_accepted", init: "terms_and_conditions_activated=#{terms_and_conditions_activated}; terms_and_conditions_accepted=#{terms_and_conditions_already_accepted}" } } From ad592785cf9b3f36c04801b3e0918317c5345a6a Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 22 Sep 2020 18:39:54 +0100 Subject: [PATCH 07/24] Rename methods to follwo ruby convention and improve readability --- app/helpers/terms_and_conditions_helper.rb | 4 ++-- app/views/checkout/_terms_and_conditions.html.haml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/helpers/terms_and_conditions_helper.rb b/app/helpers/terms_and_conditions_helper.rb index 70b497af61..e748b520ec 100644 --- a/app/helpers/terms_and_conditions_helper.rb +++ b/app/helpers/terms_and_conditions_helper.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true module TermsAndConditionsHelper - def terms_and_conditions_activated + def terms_and_conditions_activated? current_order.distributor.terms_and_conditions.file? end - def terms_and_conditions_already_accepted + def terms_and_conditions_already_accepted? customer_terms_and_conditions_accepted_at = spree_current_user. customer_of(current_order.distributor)&.terms_and_conditions_accepted_at diff --git a/app/views/checkout/_terms_and_conditions.html.haml b/app/views/checkout/_terms_and_conditions.html.haml index 9ac1e1e3f4..05e0122ae7 100644 --- a/app/views/checkout/_terms_and_conditions.html.haml +++ b/app/views/checkout/_terms_and_conditions.html.haml @@ -1,4 +1,4 @@ -- if terms_and_conditions_activated +- if terms_and_conditions_activated? %p - %input{ type: 'checkbox', id: 'accept_terms', ng: { model: "terms_and_conditions_accepted", init: "terms_and_conditions_activated=#{terms_and_conditions_activated}; terms_and_conditions_accepted=#{terms_and_conditions_already_accepted}" } } + %input{ type: 'checkbox', id: 'accept_terms', ng: { model: "terms_and_conditions_accepted", init: "terms_and_conditions_activated=#{terms_and_conditions_activated?}; terms_and_conditions_accepted=#{terms_and_conditions_already_accepted?}" } } %label.small{for: "accept_terms"}= t('.message_html', terms_and_conditions_link: link_to( t( '.link_text' ), current_order.distributor.terms_and_conditions.url, target: '_blank')) From 57a9d6e1e28499dc358b69d9dde7823509f141cf Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 22 Sep 2020 19:48:52 +0100 Subject: [PATCH 08/24] Make customer terms_and_conditions_accepted_at be set to current time after a successful checkout --- .../darkswarm/services/checkout.js.coffee | 1 + app/services/checkout/post_checkout_actions.rb | 5 +++++ .../checkout/post_checkout_actions_spec.rb | 15 +++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/app/assets/javascripts/darkswarm/services/checkout.js.coffee b/app/assets/javascripts/darkswarm/services/checkout.js.coffee index 69c484ccb4..265588cd41 100644 --- a/app/assets/javascripts/darkswarm/services/checkout.js.coffee +++ b/app/assets/javascripts/darkswarm/services/checkout.js.coffee @@ -46,6 +46,7 @@ Darkswarm.factory 'Checkout', ($injector, CurrentOrder, ShippingMethods, StripeE munged_order = default_bill_address: !!@default_bill_address default_ship_address: !!@default_ship_address + terms_and_conditions_accepted: true for name, value of @order # Clone all data from the order JSON object switch name diff --git a/app/services/checkout/post_checkout_actions.rb b/app/services/checkout/post_checkout_actions.rb index f595ab0537..fbd51b7dac 100644 --- a/app/services/checkout/post_checkout_actions.rb +++ b/app/services/checkout/post_checkout_actions.rb @@ -8,6 +8,7 @@ module Checkout end def success(controller, params, current_user) + set_customer_terms_and_conditions_accepted_at(params) save_order_addresses_as_user_default(params, current_user) OrderCompletionReset.new(controller, @order).call end @@ -26,5 +27,9 @@ module Checkout user_default_address_setter.set_default_bill_address if params[:order][:default_bill_address] user_default_address_setter.set_default_ship_address if params[:order][:default_ship_address] end + + def set_customer_terms_and_conditions_accepted_at(params) + @order.customer.update(terms_and_conditions_accepted_at: Time.zone.now) if params[:order][:terms_and_conditions_accepted] + end end end diff --git a/spec/services/checkout/post_checkout_actions_spec.rb b/spec/services/checkout/post_checkout_actions_spec.rb index 916cff69fb..e1a27a20fb 100644 --- a/spec/services/checkout/post_checkout_actions_spec.rb +++ b/spec/services/checkout/post_checkout_actions_spec.rb @@ -23,6 +23,21 @@ describe Checkout::PostCheckoutActions do postCheckoutActions.success(controller, params, current_user) end + describe "setting customer terms_and_conditions_accepted_at" do + before { order.customer = build_stubbed(:customer) } + + it "does not set customer's terms_and_conditions to the current time if terms have not been accepted" do + postCheckoutActions.success(controller, params, current_user) + expect(order.customer.terms_and_conditions_accepted_at).to be_nil + end + + it "sets customer's terms_and_conditions to the current time if terms have been accepted" do + params = { order: { terms_and_conditions_accepted: true } } + postCheckoutActions.success(controller, params, current_user) + expect(order.customer.terms_and_conditions_accepted_at).to_not be_nil + end + end + describe "setting the user default address" do let(:user_default_address_setter) { instance_double(UserDefaultAddressSetter) } From 46733d0c0da7cb373d4fe3d2f8044fbb2e8fc6c1 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 22 Sep 2020 21:44:00 +0100 Subject: [PATCH 09/24] 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 From dd31cbe014a59433f806f65eecb7abc67b3df48b Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 22 Sep 2020 21:54:20 +0100 Subject: [PATCH 10/24] Cover case where enterprise uploads new T&Cs file and customer has already accepted before --- spec/features/consumer/shopping/checkout_spec.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb index 094847a71f..bedabaa2c3 100644 --- a/spec/features/consumer/shopping/checkout_spec.rb +++ b/spec/features/consumer/shopping/checkout_spec.rb @@ -136,7 +136,7 @@ feature "As a consumer I want to check out my cart", js: true do end 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 + it "shows a link to the T&Cs and disables 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) @@ -153,11 +153,19 @@ feature "As a consumer I want to check out my cart", js: true do customer.update terms_and_conditions_accepted_at: Time.zone.now end - it "enables checkout because T&Cs are accepted by default" do + it "enables checkout button (because T&Cs are accepted by default)" do visit checkout_path - expect(page).to have_button("Place order now", disabled: false) end + + describe "but afterwards the enterprise has uploaded a new T&Cs file" do + before { order.distributor.update terms_and_conditions_updated_at: Time.zone.now } + + it "disables checkout button until terms are accepted" do + visit checkout_path + expect(page).to have_button("Place order now", disabled: true) + end + end end end From 26946ec102a103201767d6a1da082103c146d2dc Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Mon, 28 Sep 2020 13:27:45 +0100 Subject: [PATCH 11/24] Fix edge case and some specs in post checkout actions --- app/services/checkout/post_checkout_actions.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/services/checkout/post_checkout_actions.rb b/app/services/checkout/post_checkout_actions.rb index fbd51b7dac..c9defcc9ca 100644 --- a/app/services/checkout/post_checkout_actions.rb +++ b/app/services/checkout/post_checkout_actions.rb @@ -29,6 +29,8 @@ module Checkout end def set_customer_terms_and_conditions_accepted_at(params) + return unless params[:order] + @order.customer.update(terms_and_conditions_accepted_at: Time.zone.now) if params[:order][:terms_and_conditions_accepted] end end From a94221870872c01aecced6f76941ed3e01f13aa2 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Mon, 28 Sep 2020 13:31:00 +0100 Subject: [PATCH 12/24] Fix post checkout actions spec --- spec/services/checkout/post_checkout_actions_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/services/checkout/post_checkout_actions_spec.rb b/spec/services/checkout/post_checkout_actions_spec.rb index e1a27a20fb..4c5ee6a1c2 100644 --- a/spec/services/checkout/post_checkout_actions_spec.rb +++ b/spec/services/checkout/post_checkout_actions_spec.rb @@ -24,7 +24,7 @@ describe Checkout::PostCheckoutActions do end describe "setting customer terms_and_conditions_accepted_at" do - before { order.customer = build_stubbed(:customer) } + before { order.customer = build(:customer) } it "does not set customer's terms_and_conditions to the current time if terms have not been accepted" do postCheckoutActions.success(controller, params, current_user) From ceee89fad0bdfb407b15b7963b9dbc51784eb72e Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Mon, 28 Sep 2020 14:44:41 +0100 Subject: [PATCH 13/24] Make Checkout form submit read terms_and_conditions_accepted from the checkout form checkbox --- .../javascripts/darkswarm/services/checkout.js.coffee | 9 ++++++++- .../unit/darkswarm/services/checkout_spec.js.coffee | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/darkswarm/services/checkout.js.coffee b/app/assets/javascripts/darkswarm/services/checkout.js.coffee index 265588cd41..ef865012c2 100644 --- a/app/assets/javascripts/darkswarm/services/checkout.js.coffee +++ b/app/assets/javascripts/darkswarm/services/checkout.js.coffee @@ -46,7 +46,6 @@ Darkswarm.factory 'Checkout', ($injector, CurrentOrder, ShippingMethods, StripeE munged_order = default_bill_address: !!@default_bill_address default_ship_address: !!@default_ship_address - terms_and_conditions_accepted: true for name, value of @order # Clone all data from the order JSON object switch name @@ -96,6 +95,10 @@ Darkswarm.factory 'Checkout', ($injector, CurrentOrder, ShippingMethods, StripeE last_name: @order.bill_address.lastname save_requested_by_customer: @secrets.save_requested_by_customer } + + if @terms_and_conditions_accepted() + munged_order["terms_and_conditions_accepted"] = true + munged_order shippingMethod: -> @@ -115,3 +118,7 @@ Darkswarm.factory 'Checkout', ($injector, CurrentOrder, ShippingMethods, StripeE cartTotal: -> @order.display_total + @shippingPrice() + @paymentPrice() + + terms_and_conditions_accepted: -> + terms_and_conditions_checkbox = angular.element("#accept_terms")[0] + terms_and_conditions_checkbox? && terms_and_conditions_checkbox.checked diff --git a/spec/javascripts/unit/darkswarm/services/checkout_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/checkout_spec.js.coffee index 8caacdc531..8c5d49633b 100644 --- a/spec/javascripts/unit/darkswarm/services/checkout_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/checkout_spec.js.coffee @@ -65,6 +65,7 @@ describe 'Checkout service', -> inject ($injector, _$httpBackend_, $rootScope)-> $httpBackend = _$httpBackend_ Checkout = $injector.get("Checkout") + spyOn(Checkout, "terms_and_conditions_accepted") scope = $rootScope.$new() scope.Checkout = Checkout Navigation = $injector.get("Navigation") From c980d22826cc9026ef297a34c16493d7d89e9901 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Mon, 28 Sep 2020 18:14:18 +0100 Subject: [PATCH 14/24] Make TCs link open in a new tab in the backoffice --- app/views/admin/enterprises/form/_business_details.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/enterprises/form/_business_details.html.haml b/app/views/admin/enterprises/form/_business_details.html.haml index d15e3803c0..f215dc9a68 100644 --- a/app/views/admin/enterprises/form/_business_details.html.haml +++ b/app/views/admin/enterprises/form/_business_details.html.haml @@ -37,7 +37,7 @@ = f.label :terms_and_conditions, t('.terms_and_conditions') .omega.eight.columns - %a{ href: '{{ Enterprise.terms_and_conditions }}', ng: { if: 'Enterprise.terms_and_conditions' } } + %a{ href: '{{ Enterprise.terms_and_conditions }}', target: "_blank", ng: { if: 'Enterprise.terms_and_conditions' } } = '{{ Enterprise.terms_and_conditions_file_name }}' .pad-top = f.file_field :terms_and_conditions From 9f17e4fd8fb79c71ef69bb0b7151010bff930e50 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Mon, 28 Sep 2020 18:51:07 +0100 Subject: [PATCH 15/24] Add upload timestamp to TCs upload form in enterprise business details --- app/serializers/api/admin/enterprise_serializer.rb | 11 ++++++++--- .../enterprises/form/_business_details.html.haml | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/serializers/api/admin/enterprise_serializer.rb b/app/serializers/api/admin/enterprise_serializer.rb index 2385d996d6..399284d132 100644 --- a/app/serializers/api/admin/enterprise_serializer.rb +++ b/app/serializers/api/admin/enterprise_serializer.rb @@ -6,7 +6,8 @@ class Api::Admin::EnterpriseSerializer < ActiveModel::Serializer :preferred_product_selection_from_inventory_only, :preferred_show_customer_names_to_suppliers, :owner, :contact, :users, :tag_groups, :default_tag_group, :require_login, :allow_guest_orders, :allow_order_changes, - :logo, :promo_image, :terms_and_conditions, :terms_and_conditions_file_name + :logo, :promo_image, :terms_and_conditions, + :terms_and_conditions_file_name, :terms_and_conditions_updated_at has_one :owner, serializer: Api::Admin::UserSerializer has_many :users, serializer: Api::Admin::UserSerializer @@ -21,9 +22,13 @@ class Api::Admin::EnterpriseSerializer < ActiveModel::Serializer end def terms_and_conditions - return unless @object.terms_and_conditions.file? + return unless object.terms_and_conditions.file? - @object.terms_and_conditions.url + object.terms_and_conditions.url + end + + def terms_and_conditions_updated_at + object.terms_and_conditions_updated_at&.to_s end def tag_groups diff --git a/app/views/admin/enterprises/form/_business_details.html.haml b/app/views/admin/enterprises/form/_business_details.html.haml index f215dc9a68..48be57a8ef 100644 --- a/app/views/admin/enterprises/form/_business_details.html.haml +++ b/app/views/admin/enterprises/form/_business_details.html.haml @@ -37,8 +37,8 @@ = f.label :terms_and_conditions, t('.terms_and_conditions') .omega.eight.columns - %a{ href: '{{ Enterprise.terms_and_conditions }}', target: "_blank", ng: { if: 'Enterprise.terms_and_conditions' } } - = '{{ Enterprise.terms_and_conditions_file_name }}' + %a{ href: '{{ Enterprise.terms_and_conditions }}', target: '_blank', ng: { if: 'Enterprise.terms_and_conditions' } } + = '{{ Enterprise.terms_and_conditions_file_name }}' " uploaded on " '{{ Enterprise.terms_and_conditions_updated_at }}' .pad-top = f.file_field :terms_and_conditions .pad-top From f7c07f492c3fc34ede548d0bb3d9bd8a4394c276 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Mon, 28 Sep 2020 18:52:08 +0100 Subject: [PATCH 16/24] Make TCs file input onoy accept pdf files --- app/views/admin/enterprises/form/_business_details.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/enterprises/form/_business_details.html.haml b/app/views/admin/enterprises/form/_business_details.html.haml index 48be57a8ef..8615d81321 100644 --- a/app/views/admin/enterprises/form/_business_details.html.haml +++ b/app/views/admin/enterprises/form/_business_details.html.haml @@ -40,7 +40,7 @@ %a{ href: '{{ Enterprise.terms_and_conditions }}', target: '_blank', ng: { if: 'Enterprise.terms_and_conditions' } } = '{{ Enterprise.terms_and_conditions_file_name }}' " uploaded on " '{{ Enterprise.terms_and_conditions_updated_at }}' .pad-top - = f.file_field :terms_and_conditions + = f.file_field :terms_and_conditions, accept: 'application/pdf' .pad-top %a.button.red{ href: '', ng: {click: 'removeTermsAndConditions()', if: 'Enterprise.terms_and_conditions'} } = t('.remove_terms_and_conditions') From 2cf7b1b36cd9be82ea07863a09d63c9435fe358a Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Mon, 28 Sep 2020 18:54:25 +0100 Subject: [PATCH 17/24] Make label translatable --- app/views/admin/enterprises/form/_business_details.html.haml | 4 +++- config/locales/en.yml | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/views/admin/enterprises/form/_business_details.html.haml b/app/views/admin/enterprises/form/_business_details.html.haml index 8615d81321..4f46fcf464 100644 --- a/app/views/admin/enterprises/form/_business_details.html.haml +++ b/app/views/admin/enterprises/form/_business_details.html.haml @@ -38,7 +38,9 @@ .omega.eight.columns %a{ href: '{{ Enterprise.terms_and_conditions }}', target: '_blank', ng: { if: 'Enterprise.terms_and_conditions' } } - = '{{ Enterprise.terms_and_conditions_file_name }}' " uploaded on " '{{ Enterprise.terms_and_conditions_updated_at }}' + = '{{ Enterprise.terms_and_conditions_file_name }}' + = t('.uploaded_on') + = '{{ Enterprise.terms_and_conditions_updated_at }}' .pad-top = f.file_field :terms_and_conditions, accept: 'application/pdf' .pad-top diff --git a/config/locales/en.yml b/config/locales/en.yml index 5eb5b40892..9691b851ed 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -705,6 +705,7 @@ en: invoice_text: Add customized text at the end of invoices terms_and_conditions: "Terms and Conditions" remove_terms_and_conditions: "Remove File" + uploaded_on: "uploaded on" contact: name: Name name_placeholder: eg. Gustav Plum From ca79270ba369aedcf09bb4eedfd811ce3c498a6f Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Mon, 28 Sep 2020 19:14:28 +0100 Subject: [PATCH 18/24] Show T&Cs warning when uploading a new file --- .../enterprises/controllers/enterprise_controller.js.coffee | 4 ++++ app/views/admin/enterprises/form/_business_details.html.haml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee b/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee index 51c38d0a3f..55698d9e5f 100644 --- a/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee +++ b/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee @@ -90,3 +90,7 @@ angular.module("admin.enterprises") $scope.translation = (key) -> t('js.admin.enterprises.form.images.' + key) + + $scope.show_terms_and_conditions_warning = (event) -> + unless confirm("All your buyers will have to agree to the Terms and Conditions again at checkout. Are you sure?") + event.preventDefault() diff --git a/app/views/admin/enterprises/form/_business_details.html.haml b/app/views/admin/enterprises/form/_business_details.html.haml index 4f46fcf464..41bf8c6f2c 100644 --- a/app/views/admin/enterprises/form/_business_details.html.haml +++ b/app/views/admin/enterprises/form/_business_details.html.haml @@ -42,7 +42,7 @@ = t('.uploaded_on') = '{{ Enterprise.terms_and_conditions_updated_at }}' .pad-top - = f.file_field :terms_and_conditions, accept: 'application/pdf' + = f.file_field :terms_and_conditions, accept: 'application/pdf', 'ng-click' => 'show_terms_and_conditions_warning($event)' .pad-top %a.button.red{ href: '', ng: {click: 'removeTermsAndConditions()', if: 'Enterprise.terms_and_conditions'} } = t('.remove_terms_and_conditions') From be35f9762209f02ffbde5fb48c4cfecc0c98f886 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 29 Sep 2020 11:42:45 +0100 Subject: [PATCH 19/24] Add tooltip icon to terms and conditions --- .../modals/terms_and_conditions_info.html.haml | 13 +++++++++++++ .../enterprises/form/_business_details.html.haml | 1 + config/locales/en.yml | 6 +++++- 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/templates/admin/modals/terms_and_conditions_info.html.haml diff --git a/app/assets/javascripts/templates/admin/modals/terms_and_conditions_info.html.haml b/app/assets/javascripts/templates/admin/modals/terms_and_conditions_info.html.haml new file mode 100644 index 0000000000..5a3568085e --- /dev/null +++ b/app/assets/javascripts/templates/admin/modals/terms_and_conditions_info.html.haml @@ -0,0 +1,13 @@ +%div + .margin-bottom-30.text-center + .text-big + {{ 'js.admin.modals.terms_and_conditions_info.title' | t }} + .margin-bottom-30 + %p + {{ 'js.admin.modals.terms_and_conditions_info.message_1' | t }} + .margin-bottom-30 + %p + {{ 'js.admin.modals.terms_and_conditions_info.message_2' | t }} + + .text-center + %input.button.red.icon-plus{ type: 'button', value: t('js.admin.modals.got_it'), ng: { click: 'close()' } } diff --git a/app/views/admin/enterprises/form/_business_details.html.haml b/app/views/admin/enterprises/form/_business_details.html.haml index 41bf8c6f2c..7c72b1a4b2 100644 --- a/app/views/admin/enterprises/form/_business_details.html.haml +++ b/app/views/admin/enterprises/form/_business_details.html.haml @@ -35,6 +35,7 @@ .row .alpha.three.columns = f.label :terms_and_conditions, t('.terms_and_conditions') + %i.text-big.icon-question-sign.help-modal{ template: 'admin/modals/terms_and_conditions_info.html' } .omega.eight.columns %a{ href: '{{ Enterprise.terms_and_conditions }}', target: '_blank', ng: { if: 'Enterprise.terms_and_conditions' } } diff --git a/config/locales/en.yml b/config/locales/en.yml index 9691b851ed..42f6edcf2a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2518,7 +2518,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using admin: enterprise_limit_reached: "You have reached the standard limit of enterprises per account. Write to %{contact_email} if you need to increase it." modals: - got_it: Got it + got_it: "Got it" close: "Close" invite: "Invite" invite_title: "Invite an unregistered user" @@ -2538,6 +2538,10 @@ See the %{link} to find out more about %{sitename}'s features and to start using customer_tagged_rules_text: > By creating rules related to a specific customer tag, you can override the default behaviour (whether it be to show or to hide items) for customers with the specified tag. + terms_and_conditions_info: + title: "Uploading Terms and Conditions" + message_1: "Terms and Conditions are the contract between you, the seller, and the shopper. If you upload a file here shoppers must accept your Terms and Conditions in order to complete checkout. For the shopper this will appear as a checkbox at checkout that must be checked in order to proceed with checkout. We highly recommend you upload Terms and Conditions in alignment with national legislation." + message_2: "Shoppers will only be required to accept Terms and Conditions once. However if you change you Terms and Conditions shoppers will again be required to accept them before they can checkout." panels: save: SAVE saved: SAVED From 3b682bc47ffbf5b66c48e080cf0e4986bc7e4cb4 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 29 Sep 2020 11:43:14 +0100 Subject: [PATCH 20/24] Add warning when uploading a file --- .../enterprise_controller.js.coffee | 4 --- .../terms_and_conditions_warning.js.coffee | 29 +++++++++++++++++++ .../terms_and_conditions_warning.html.haml | 14 +++++++++ .../form/_business_details.html.haml | 2 +- config/locales/en.yml | 5 ++++ 5 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 app/assets/javascripts/admin/enterprises/directives/terms_and_conditions_warning.js.coffee create mode 100644 app/assets/javascripts/templates/admin/modals/terms_and_conditions_warning.html.haml diff --git a/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee b/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee index 55698d9e5f..51c38d0a3f 100644 --- a/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee +++ b/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee @@ -90,7 +90,3 @@ angular.module("admin.enterprises") $scope.translation = (key) -> t('js.admin.enterprises.form.images.' + key) - - $scope.show_terms_and_conditions_warning = (event) -> - unless confirm("All your buyers will have to agree to the Terms and Conditions again at checkout. Are you sure?") - event.preventDefault() diff --git a/app/assets/javascripts/admin/enterprises/directives/terms_and_conditions_warning.js.coffee b/app/assets/javascripts/admin/enterprises/directives/terms_and_conditions_warning.js.coffee new file mode 100644 index 0000000000..1072839def --- /dev/null +++ b/app/assets/javascripts/admin/enterprises/directives/terms_and_conditions_warning.js.coffee @@ -0,0 +1,29 @@ +angular.module("admin.enterprises").directive 'termsAndConditionsWarning', ($compile, $templateCache, DialogDefaults, $timeout) -> + restrict: 'A' + scope: true + + link: (scope, element, attr) -> + # This file input click handler will hold the browser file input dialog and show a warning modal + scope.hold_file_input_and_show_warning_modal = (event) -> + event.preventDefault() + scope.template = $compile($templateCache.get('admin/modals/terms_and_conditions_warning.html'))(scope) + scope.template.dialog(DialogDefaults) + scope.template.dialog('open') + scope.$apply() + + element.bind 'click', scope.hold_file_input_and_show_warning_modal + + # When the user presses continue in the warning modal, we open the browser file input dialog + scope.continue = -> + scope.template.dialog('close') + + # unbind warning modal handler and click file input again to open the browser file input dialog + element.unbind('click').trigger('click') + # afterwards, bind warning modal handler again so that the warning is shown the next time + $timeout -> + element.bind 'click', scope.hold_file_input_and_show_warning_modal + return + + scope.close = -> + scope.template.dialog('close') + return diff --git a/app/assets/javascripts/templates/admin/modals/terms_and_conditions_warning.html.haml b/app/assets/javascripts/templates/admin/modals/terms_and_conditions_warning.html.haml new file mode 100644 index 0000000000..13eed6fe85 --- /dev/null +++ b/app/assets/javascripts/templates/admin/modals/terms_and_conditions_warning.html.haml @@ -0,0 +1,14 @@ +%div + .margin-bottom-30.text-center + .text-big + {{ 'js.admin.modals.terms_and_conditions_warning.title' | t }} + .margin-bottom-30 + %p + {{ 'js.admin.modals.terms_and_conditions_warning.message_1' | t }} + .margin-bottom-30 + %p + {{ 'js.admin.modals.terms_and_conditions_warning.message_2' | t }} + + .text-center + %input.button.red{ type: 'button', value: t('js.admin.modals.close'), ng: { click: 'close()' } } + %input.button.red{ type: 'button', value: t('js.admin.modals.continue'), ng: { click: 'continue()' } } diff --git a/app/views/admin/enterprises/form/_business_details.html.haml b/app/views/admin/enterprises/form/_business_details.html.haml index 7c72b1a4b2..1bade5b580 100644 --- a/app/views/admin/enterprises/form/_business_details.html.haml +++ b/app/views/admin/enterprises/form/_business_details.html.haml @@ -43,7 +43,7 @@ = t('.uploaded_on') = '{{ Enterprise.terms_and_conditions_updated_at }}' .pad-top - = f.file_field :terms_and_conditions, accept: 'application/pdf', 'ng-click' => 'show_terms_and_conditions_warning($event)' + = f.file_field :terms_and_conditions, accept: 'application/pdf', 'terms-and-conditions-warning' => 'true' .pad-top %a.button.red{ href: '', ng: {click: 'removeTermsAndConditions()', if: 'Enterprise.terms_and_conditions'} } = t('.remove_terms_and_conditions') diff --git a/config/locales/en.yml b/config/locales/en.yml index 42f6edcf2a..014cfe36f5 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2520,6 +2520,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using modals: got_it: "Got it" close: "Close" + continue: "Continue" invite: "Invite" invite_title: "Invite an unregistered user" tag_rule_help: @@ -2542,6 +2543,10 @@ See the %{link} to find out more about %{sitename}'s features and to start using title: "Uploading Terms and Conditions" message_1: "Terms and Conditions are the contract between you, the seller, and the shopper. If you upload a file here shoppers must accept your Terms and Conditions in order to complete checkout. For the shopper this will appear as a checkbox at checkout that must be checked in order to proceed with checkout. We highly recommend you upload Terms and Conditions in alignment with national legislation." message_2: "Shoppers will only be required to accept Terms and Conditions once. However if you change you Terms and Conditions shoppers will again be required to accept them before they can checkout." + terms_and_conditions_warning: + title: "Uploading Terms and Conditions" + message_1: "All your buyers will have to agree to them again at checkout." + message_2: "For buyers with subscriptions, you need to email them the changes for now, nothing will notify them about this change." panels: save: SAVE saved: SAVED From bd4d0ba5d3ce1fd10d89279a7df9d16a62326cf5 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Wed, 30 Sep 2020 12:30:26 +0100 Subject: [PATCH 21/24] Make the warning message work for first upload and for changes --- config/locales/en.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 014cfe36f5..ed2261fcf4 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2545,8 +2545,8 @@ See the %{link} to find out more about %{sitename}'s features and to start using message_2: "Shoppers will only be required to accept Terms and Conditions once. However if you change you Terms and Conditions shoppers will again be required to accept them before they can checkout." terms_and_conditions_warning: title: "Uploading Terms and Conditions" - message_1: "All your buyers will have to agree to them again at checkout." - message_2: "For buyers with subscriptions, you need to email them the changes for now, nothing will notify them about this change." + message_1: "All your buyers will have to agree to them once at checkout. If you update the file, all your buyers will have to agree to them again at checkout." + message_2: "For buyers with subscriptions, you need to email them the Terms and Conditions (or the changes to them) for now, nothing will notify them about these new Terms and Conditions." panels: save: SAVE saved: SAVED From 1d1067ebc12e0bfc70d090b7571fc189f11272c2 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Thu, 1 Oct 2020 18:10:34 +0100 Subject: [PATCH 22/24] Add coverage to T&Cs file opening on a new tab and also for the upload timestamp now displayed in the page --- .../admin/enterprises/terms_and_conditions_spec.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/spec/features/admin/enterprises/terms_and_conditions_spec.rb b/spec/features/admin/enterprises/terms_and_conditions_spec.rb index 3f862403d4..476ea6eaad 100644 --- a/spec/features/admin/enterprises/terms_and_conditions_spec.rb +++ b/spec/features/admin/enterprises/terms_and_conditions_spec.rb @@ -16,7 +16,7 @@ feature "Uploading Terms and Conditions PDF" do visit edit_admin_enterprise_path(distributor) end - describe "images for an enterprise" do + describe "with terms and conditions to upload" do def go_to_business_details within(".side_menu") do click_link "Business Details" @@ -49,20 +49,21 @@ feature "Uploading Terms and Conditions PDF" do expect(distributor.reload.terms_and_conditions_updated_at).to eq run_time end expect(page). - to have_content("Enterprise \"#{distributor.name}\" has been successfully updated!") + to have_content "Enterprise \"#{distributor.name}\" has been successfully updated!" go_to_business_details - expect(page).to have_selector("a[href*='logo-white.pdf']") + expect(page).to have_selector "a[href*='logo-white.pdf'][target=\"_blank\"]" + expect(page).to have_content "2002-04-13 00:00:00 +1000" # Replace PDF attach_file "enterprise[terms_and_conditions]", black_pdf_file_name click_button "Update" expect(page). - to have_content("Enterprise \"#{distributor.name}\" has been successfully updated!") + to have_content "Enterprise \"#{distributor.name}\" has been successfully updated!" expect(distributor.reload.terms_and_conditions_updated_at).to_not eq run_time go_to_business_details - expect(page).to have_selector("a[href*='logo-black.pdf']") + expect(page).to have_selector "a[href*='logo-black.pdf']" end end end From cf3f511f4d4c3682dca6e7789c219a5d23ea511c Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Thu, 1 Oct 2020 23:04:11 +0100 Subject: [PATCH 23/24] Add directive spec to validate the dialog template is loaded on element click --- .../terms_and_conditions_warning.js.coffee | 5 +++-- ...terms_and_conditions_warning_spec.js.coffee | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 spec/javascripts/unit/admin/enterprises/directives/terms_and_conditions_warning_spec.js.coffee diff --git a/app/assets/javascripts/admin/enterprises/directives/terms_and_conditions_warning.js.coffee b/app/assets/javascripts/admin/enterprises/directives/terms_and_conditions_warning.js.coffee index 1072839def..d8aafe113d 100644 --- a/app/assets/javascripts/admin/enterprises/directives/terms_and_conditions_warning.js.coffee +++ b/app/assets/javascripts/admin/enterprises/directives/terms_and_conditions_warning.js.coffee @@ -7,8 +7,9 @@ angular.module("admin.enterprises").directive 'termsAndConditionsWarning', ($com scope.hold_file_input_and_show_warning_modal = (event) -> event.preventDefault() scope.template = $compile($templateCache.get('admin/modals/terms_and_conditions_warning.html'))(scope) - scope.template.dialog(DialogDefaults) - scope.template.dialog('open') + if scope.template.dialog + scope.template.dialog(DialogDefaults) + scope.template.dialog('open') scope.$apply() element.bind 'click', scope.hold_file_input_and_show_warning_modal diff --git a/spec/javascripts/unit/admin/enterprises/directives/terms_and_conditions_warning_spec.js.coffee b/spec/javascripts/unit/admin/enterprises/directives/terms_and_conditions_warning_spec.js.coffee new file mode 100644 index 0000000000..b7647024e2 --- /dev/null +++ b/spec/javascripts/unit/admin/enterprises/directives/terms_and_conditions_warning_spec.js.coffee @@ -0,0 +1,18 @@ +describe "termsAndConditionsWarning", -> + element = null + templatecache = null + + beforeEach -> + module('admin.enterprises') + + inject ($rootScope, $compile, $templateCache) -> + templatecache = $templateCache + el = angular.element("") + element = $compile(el)($rootScope) + $rootScope.$digest() + + describe "terms and conditions warning", -> + it "should load template", -> + spyOn(templatecache, 'get') + element.triggerHandler('click'); + expect(templatecache.get).toHaveBeenCalledWith('admin/modals/terms_and_conditions_warning.html') From 71a181341b48bde6dc640d164137567e1c78dcf0 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Thu, 29 Oct 2020 15:56:41 +0000 Subject: [PATCH 24/24] Fix bug in terms_and_conditions_helper related to guest checkout where current_user is nil and T&Cs must be shown all the time --- app/helpers/terms_and_conditions_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/terms_and_conditions_helper.rb b/app/helpers/terms_and_conditions_helper.rb index e748b520ec..ef50459edb 100644 --- a/app/helpers/terms_and_conditions_helper.rb +++ b/app/helpers/terms_and_conditions_helper.rb @@ -6,7 +6,7 @@ module TermsAndConditionsHelper end def terms_and_conditions_already_accepted? - customer_terms_and_conditions_accepted_at = spree_current_user. + customer_terms_and_conditions_accepted_at = spree_current_user&. customer_of(current_order.distributor)&.terms_and_conditions_accepted_at customer_terms_and_conditions_accepted_at.present? &&