From 38edde5f84dc5e6c55520433a98cfedbb9738871 Mon Sep 17 00:00:00 2001 From: Jack S Date: Mon, 10 Jul 2023 17:01:18 +0200 Subject: [PATCH] Do not show invalid emails --- app/helpers/data_sharing_agreement_helper.rb | 6 ++- .../data_sharing_agreement.html.erb_spec.rb | 44 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/app/helpers/data_sharing_agreement_helper.rb b/app/helpers/data_sharing_agreement_helper.rb index e79819ffb..c6a088461 100644 --- a/app/helpers/data_sharing_agreement_helper.rb +++ b/app/helpers/data_sharing_agreement_helper.rb @@ -61,7 +61,11 @@ module DataSharingAgreementHelper end end - "12.2. For #{@org_name}: Name: #{@dpo_name}, Postal Address: #{@org_address}, E-mail address: #{@dpo_email}, Telephone number: #{@org_phone}" + if data_protection_confirmation&.confirmed? && @dpo_email.exclude?("@") # Do not show invalid email addresses + "12.2. For #{@org_name}: Name: #{@dpo_name}, Postal Address: #{@org_address}, Telephone number: #{@org_phone}" + else + "12.2. For #{@org_name}: Name: #{@dpo_name}, Postal Address: #{@org_address}, E-mail address: #{@dpo_email}, Telephone number: #{@org_phone}" + end end # rubocop:enable Rails/HelperInstanceVariable diff --git a/spec/views/organisations/data_sharing_agreement.html.erb_spec.rb b/spec/views/organisations/data_sharing_agreement.html.erb_spec.rb index b20cecf4d..9fda45274 100644 --- a/spec/views/organisations/data_sharing_agreement.html.erb_spec.rb +++ b/spec/views/organisations/data_sharing_agreement.html.erb_spec.rb @@ -65,6 +65,50 @@ RSpec.describe "organisations/data_sharing_agreement.html.erb", :aggregate_failu # Shows DPO and org details in 12.2 expect(fragment).to have_content("12.2. For #{organisation.name}: Name: #{dpo.name}, Postal Address: #{organisation.address_row}, E-mail address: #{dpo.email}, Telephone number: #{organisation.phone}") end + + context "when user email not valid" do + let(:dpo) do + u = User.new( + name: "test", + organisation:, + is_dpo: true, + encrypted_password: SecureRandom.hex(10), + email: SecureRandom.uuid, + confirmed_at: Time.zone.now, + active: false, + ) + u.save!(validate: false) + u + end + + let(:data_protection_confirmation) do + create( + :data_protection_confirmation, + organisation:, + created_at: Time.zone.now - 1.day, + data_protection_officer: dpo, + ) + end + + it "renders dynamic content" do + render + + # dpo name + expect(fragment).to have_content("Name: #{dpo.name}") + + # org details + expect(fragment).to have_content("#{organisation.name} of #{organisation.address_row} (“CORE Data Provider”)") + # header + expect(fragment).to have_css("h2", text: "#{organisation.name} and Department for Levelling Up, Housing and Communities") + # does not show action buttons + expect(fragment).not_to have_button(text: "Accept this agreement") + expect(fragment).not_to have_link(text: "Cancel", href: "/organisations/#{organisation.id}/details") + # sees signed_at date + expect(fragment).to have_content("9th day of January 2023") + # Shows DPO and org details in 12.2 + expect(fragment).to have_content("12.2. For #{organisation.name}: Name: #{dpo.name}, Postal Address: #{organisation.address_row}, Telephone number: #{organisation.phone}") + end + end end end