diff --git a/app/models/form/lettings/questions/declaration.rb b/app/models/form/lettings/questions/declaration.rb index 7e1b0280d..0960e77cd 100644 --- a/app/models/form/lettings/questions/declaration.rb +++ b/app/models/form/lettings/questions/declaration.rb @@ -20,5 +20,13 @@ class Form::Lettings::Questions::Declaration < ::Form::Question { "declaration" => { "value" => declaration_text } }.freeze end + def unanswered_error_message + if form.start_year_after_2024? + I18n.t("validations.declaration.missing.post_2024") + else + I18n.t("validations.declaration.missing.pre_2024") + end + end + QUESTION_NUMBER_FROM_YEAR = { 2023 => 30, 2024 => 11 }.freeze end diff --git a/app/models/form/question.rb b/app/models/form/question.rb index 391771ad9..0a486b5bd 100644 --- a/app/models/form/question.rb +++ b/app/models/form/question.rb @@ -198,9 +198,6 @@ class Form::Question end def unanswered_error_message - return I18n.t("validations.declaration.missing") if id == "declaration" - return I18n.t("validations.privacynotice.missing") if id == "privacynotice" - I18n.t("validations.not_answered", question: error_display_label.downcase) end diff --git a/app/models/form/sales/questions/privacy_notice.rb b/app/models/form/sales/questions/privacy_notice.rb index 82c4c2a6c..ebb6b9434 100644 --- a/app/models/form/sales/questions/privacy_notice.rb +++ b/app/models/form/sales/questions/privacy_notice.rb @@ -20,6 +20,15 @@ class Form::Sales::Questions::PrivacyNotice < ::Form::Question { "privacynotice" => { "value" => declaration_text } }.freeze end + def unanswered_error_message + buyer_or_buyers = @joint_purchase ? "buyers" : "buyer" + if form.start_year_after_2024? + I18n.t("validations.privacynotice.missing.post_2024", buyer_or_buyers:) + else + I18n.t("validations.privacynotice.missing.pre_2024", buyer_or_buyers:) + end + end + def guidance if form.start_year_after_2024? @joint_purchase ? "privacy_notice_buyer_2024_joint_purchase" : "privacy_notice_buyer_2024" diff --git a/config/locales/en.yml b/config/locales/en.yml index 8612e0367..487ceed1a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -567,10 +567,14 @@ en: joint_more_than_one_member: "There must be more than one person in the household as you've told us this is a joint tenancy" declaration: - missing: "You must show the DLUHC privacy notice to the tenant before you can submit this log." + missing: + pre_2024: "You must show the DLUHC privacy notice to the tenant before you can submit this log." + post_2024: "You must show or give access to the DLUHC privacy notice to the tenant before you can submit this log." privacynotice: - missing: "You must show the DLUHC privacy notice to the buyer before you can submit this log." + missing: + pre_2024: "You must show the DLUHC privacy notice to the %{buyer_or_buyers} before you can submit this log." + post_2024: "You must show or give access to the DLUHC privacy notice to the %{buyer_or_buyers} before you can submit this log." scheme: toggle_date: diff --git a/spec/models/form/lettings/questions/declaration_spec.rb b/spec/models/form/lettings/questions/declaration_spec.rb index e61258893..fae18e5bc 100644 --- a/spec/models/form/lettings/questions/declaration_spec.rb +++ b/spec/models/form/lettings/questions/declaration_spec.rb @@ -61,6 +61,10 @@ RSpec.describe Form::Lettings::Questions::Declaration, type: :model do it "has check_answers_card_number = 0" do expect(question.check_answers_card_number).to eq(0) end + + it "returns correct unanswered_error_message" do + expect(question.unanswered_error_message).to eq("You must show the DLUHC privacy notice to the tenant before you can submit this log.") + end end context "when the form year is >= 2024" do @@ -81,9 +85,9 @@ RSpec.describe Form::Lettings::Questions::Declaration, type: :model do it "has check_answers_card_number nil" do expect(question.check_answers_card_number).to be_nil end - end - it "returns correct unanswered_error_message" do - expect(question.unanswered_error_message).to eq("You must show the DLUHC privacy notice to the tenant before you can submit this log.") + it "returns correct unanswered_error_message" do + expect(question.unanswered_error_message).to eq("You must show or give access to the DLUHC privacy notice to the tenant before you can submit this log.") + end end end diff --git a/spec/models/form/sales/questions/privacy_notice_spec.rb b/spec/models/form/sales/questions/privacy_notice_spec.rb index 95f2de544..879ca9a45 100644 --- a/spec/models/form/sales/questions/privacy_notice_spec.rb +++ b/spec/models/form/sales/questions/privacy_notice_spec.rb @@ -48,14 +48,38 @@ RSpec.describe Form::Sales::Questions::PrivacyNotice, type: :model do allow(form).to receive(:start_year_after_2024?).and_return(false) end - it "has the correct answer_options" do - expect(question.answer_options).to eq({ - "privacynotice" => { "value" => "The buyer has seen the DLUHC privacy notice" }, - }) + context "and there is a single buyer" do + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "privacynotice" => { "value" => "The buyer has seen the DLUHC privacy notice" }, + }) + end + + it "uses the expected top guidance partial" do + expect(question.top_guidance_partial).to eq("privacy_notice_buyer") + end + + it "returns correct unanswered_error_message" do + expect(question.unanswered_error_message).to eq("You must show the DLUHC privacy notice to the buyer before you can submit this log.") + end end - it "uses the expected top guidance partial" do - expect(question.top_guidance_partial).to eq("privacy_notice_buyer") + context "and there are joint buyers" do + subject(:question) { described_class.new(question_id, question_definition, page, joint_purchase: true) } + + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "privacynotice" => { "value" => "The buyers have seen the DLUHC privacy notice" }, + }) + end + + it "uses the expected top guidance partial" do + expect(question.top_guidance_partial).to eq("privacy_notice_buyer_joint_purchase") + end + + it "returns correct unanswered_error_message" do + expect(question.unanswered_error_message).to eq("You must show the DLUHC privacy notice to the buyers before you can submit this log.") + end end end @@ -64,18 +88,38 @@ RSpec.describe Form::Sales::Questions::PrivacyNotice, type: :model do allow(form).to receive(:start_year_after_2024?).and_return(true) end - it "has the correct answer_options" do - expect(question.answer_options).to eq({ - "privacynotice" => { "value" => "The buyer has seen or been given access to the DLUHC privacy notice" }, - }) - end + context "and there is a single buyer" do + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "privacynotice" => { "value" => "The buyer has seen or been given access to the DLUHC privacy notice" }, + }) + end + + it "uses the expected top guidance partial" do + expect(question.top_guidance_partial).to eq("privacy_notice_buyer_2024") + end - it "uses the expected top guidance partial" do - expect(question.top_guidance_partial).to eq("privacy_notice_buyer_2024") + it "returns correct unanswered_error_message" do + expect(question.unanswered_error_message).to eq("You must show or give access to the DLUHC privacy notice to the buyer before you can submit this log.") + end end - end - it "returns correct unanswered_error_message" do - expect(question.unanswered_error_message).to eq("You must show the DLUHC privacy notice to the buyer before you can submit this log.") + context "and there are joint buyers" do + subject(:question) { described_class.new(question_id, question_definition, page, joint_purchase: true) } + + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "privacynotice" => { "value" => "The buyers have seen or been given access to the DLUHC privacy notice" }, + }) + end + + it "uses the expected top guidance partial" do + expect(question.top_guidance_partial).to eq("privacy_notice_buyer_2024_joint_purchase") + end + + it "returns correct unanswered_error_message" do + expect(question.unanswered_error_message).to eq("You must show or give access to the DLUHC privacy notice to the buyers before you can submit this log.") + end + end end end