From fa89a78b9dcb53e0bde3ef95fc4b1196b4e4afd2 Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 4 Oct 2023 15:56:54 +0100 Subject: [PATCH] Add how to fix --- app/mailers/csv_download_mailer.rb | 31 +++++++++++++++--------- spec/mailers/csv_download_mailer_spec.rb | 16 +++++++++--- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/app/mailers/csv_download_mailer.rb b/app/mailers/csv_download_mailer.rb index f35d1f271..473e012c3 100644 --- a/app/mailers/csv_download_mailer.rb +++ b/app/mailers/csv_download_mailer.rb @@ -15,7 +15,7 @@ class CsvDownloadMailer < NotifyMailer send_email( user.email, CSV_MISSING_LETTINGS_ADDRESSES_DOWNLOAD_TEMPLATE_ID, - { name: user.name, link:, issue_explanation: issue_explanation(issue_types), duration: ActiveSupport::Duration.build(duration).inspect }, + { name: user.name, issue_explanation: issue_explanation(issue_types), how_to_fix: how_to_fix(issue_types, link, "lettings"), duration: ActiveSupport::Duration.build(duration).inspect }, ) end @@ -23,7 +23,7 @@ class CsvDownloadMailer < NotifyMailer send_email( user.email, CSV_MISSING_SALES_ADDRESSES_DOWNLOAD_TEMPLATE_ID, - { name: user.name, link:, issue_explanation: issue_explanation(issue_types), duration: ActiveSupport::Duration.build(duration).inspect }, + { name: user.name, issue_explanation: issue_explanation(issue_types), how_to_fix: how_to_fix(issue_types, link, "sales"), duration: ActiveSupport::Duration.build(duration).inspect }, ) end @@ -31,16 +31,25 @@ private def issue_explanation(issue_types) issue_type_explanations = { - "missing_address" => "- Full address required: The UPRN in some logs is incorrect, so address data was not imported.", - "missing_town" => "- Missing town or city: The town or city in some logs is missing. This data is required in the new version of CORE.", - "wrong_uprn" => "- UPRN may be incorrect: The UPRN in some logs may be incorrect, so - wrong address data was imported. We think this is an issue because in - some logs the UPRN is the same as the tenant code or property reference, - and because your organisation has submitted logs for properties in Bristol - for the first time.", + "missing_address" => "- Full address required: The UPRN in some logs is incorrect, so address data was not imported.\n", + "missing_town" => "- Missing town or city: The town or city in some logs is missing. This data is required in the new version of CORE.\n", + "wrong_uprn" => "- UPRN may be incorrect: The UPRN in some logs may be incorrect, so wrong address data was imported. We think this is an issue because in some logs the UPRN is the same as the tenant code or property reference, and because your organisation has submitted logs for properties in Bristol for the first time.\n", } - "Some address data is missing or incorrect. We've detected the following issues in - your logs imported to the new version of CORE:\n\n" + issue_types.map { |issue_type| issue_type_explanations[issue_type] }.join("\n") + "Some address data is missing or incorrect. We've detected the following issues in your logs imported to the new version of CORE:\n\n#{issue_types.map { |issue_type| issue_type_explanations[issue_type] }.join('')}" + end + + def how_to_fix(issue_types, link, log_type) + [ + "You need to:\n\n", + "- download [this spreadsheet for #{log_type} logs](#{link})\n", + issue_types.include?("missing_address") || issue_types.include?("missing_town") ? "- fill in the missing address data\n" : "", + if issue_types == %w[wrong_uprn] + "- check the address data\n" + else + !issue_types.include?("wrong_uprn") ? "- check that the existing address data is correct\n" : "- check the existing address data\n" + end, + issue_types.include?("wrong_uprn") ? "- correct any errors\n" : "", + ].join("") end end diff --git a/spec/mailers/csv_download_mailer_spec.rb b/spec/mailers/csv_download_mailer_spec.rb index 20ea2f1a0..92ab4c304 100644 --- a/spec/mailers/csv_download_mailer_spec.rb +++ b/spec/mailers/csv_download_mailer_spec.rb @@ -38,12 +38,16 @@ RSpec.describe CsvDownloadMailer do template_id: described_class::CSV_MISSING_LETTINGS_ADDRESSES_DOWNLOAD_TEMPLATE_ID, personalisation: { name: user.name, - link:, + issue_explanation: "Some address data is missing or incorrect. We've detected the following issues in your logs imported to the new version of CORE:\n\n- Missing town or city: The town or city in some logs is missing. This data is required in the new version of CORE.\n", + how_to_fix: "You need to:\n +- download [this spreadsheet for lettings logs](#{link}) +- fill in the missing address data +- check that the existing address data is correct\n", duration: "20 minutes", }, ) - described_class.new.send_missing_lettings_addresses_csv_download_mail(user, link, duration) + described_class.new.send_missing_lettings_addresses_csv_download_mail(user, link, duration, %w[missing_town]) end end @@ -57,12 +61,16 @@ RSpec.describe CsvDownloadMailer do template_id: described_class::CSV_MISSING_SALES_ADDRESSES_DOWNLOAD_TEMPLATE_ID, personalisation: { name: user.name, - link:, + issue_explanation: "Some address data is missing or incorrect. We've detected the following issues in your logs imported to the new version of CORE:\n\n- UPRN may be incorrect: The UPRN in some logs may be incorrect, so wrong address data was imported. We think this is an issue because in some logs the UPRN is the same as the tenant code or property reference, and because your organisation has submitted logs for properties in Bristol for the first time.\n", + how_to_fix: "You need to:\n +- download [this spreadsheet for sales logs](#{link}) +- check the address data +- correct any errors\n", duration: "20 minutes", }, ) - described_class.new.send_missing_sales_addresses_csv_download_mail(user, link, duration) + described_class.new.send_missing_sales_addresses_csv_download_mail(user, link, duration, %w[wrong_uprn]) end end end