From e2c52def47e460b44e2ec2fb5efd83eff1afe22b Mon Sep 17 00:00:00 2001 From: Jack S Date: Fri, 23 Jun 2023 15:55:00 +0100 Subject: [PATCH] Add test as a proof of the bug we have in prod --- ...ection_confirmation_import_service_spec.rb | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spec/services/imports/data_protection_confirmation_import_service_spec.rb b/spec/services/imports/data_protection_confirmation_import_service_spec.rb index 400822462..7c3d8f8b2 100644 --- a/spec/services/imports/data_protection_confirmation_import_service_spec.rb +++ b/spec/services/imports/data_protection_confirmation_import_service_spec.rb @@ -46,6 +46,26 @@ RSpec.describe Imports::DataProtectionConfirmationImportService do expect(confirmation.confirmed).to be_truthy expect(Time.zone.local_to_utc(confirmation.created_at)).to eq(Time.utc(2018, 0o6, 0o5, 10, 36, 49)) end + + context "when a user with empty email already exists" do + before do + User.new( + name: "Test McTest", + organisation: create(:organisation), + encrypted_password: SecureRandom.hex(10), + ).save!(validate: false) + allow(logger).to receive(:warn) + end + + it "does not create a data sharing confirmation because it thinks it exists already and logs a misleading message" do + expect(logger).to receive(:warn).with("Data protection confirmation 7c5bd5fb549c09a2c55d7cb90d7ba84927e64618 created by John Doe for DLUHC is already present, skipping.") + import_service.create_data_protection_confirmations("data_protection_directory") + end + + it "does add a data protection confirmation and the org still does not have it" do + expect { import_service.create_data_protection_confirmations("data_protection_directory") }.to not_change { organisation.reload.data_protection_confirmation }.from(nil) + end + end end context "when a data protection officer with matching name already exists for the organisation" do