diff --git a/app/models/form/lettings/questions/scheme_id.rb b/app/models/form/lettings/questions/scheme_id.rb index a9147ba5f..487b1b2c4 100644 --- a/app/models/form/lettings/questions/scheme_id.rb +++ b/app/models/form/lettings/questions/scheme_id.rb @@ -9,6 +9,11 @@ class Form::Lettings::Questions::SchemeId < ::Form::Question @guidance_position = GuidancePosition::BOTTOM @guidance_partial = "scheme_selection" @question_number = 9 + @inferred_answers = { + "location.name": { + "scheme_has_multiple_locations?": false, + }, + } end def answer_options @@ -41,6 +46,10 @@ class Form::Lettings::Questions::SchemeId < ::Form::Question !supported_housing_selected?(lettings_log) end + def get_extra_check_answer_value(lettings_log) + lettings_log.form.get_question("postcode_full", nil).label_from_value(lettings_log.postcode_full) unless lettings_log.scheme_has_multiple_locations? + end + private def supported_housing_selected?(lettings_log) diff --git a/app/models/form/question.rb b/app/models/form/question.rb index 19b9de163..a2196a019 100644 --- a/app/models/form/question.rb +++ b/app/models/form/question.rb @@ -317,7 +317,11 @@ private end def enabled_inferred_answers(inferred_answers, log) - inferred_answers.filter { |_key, value| value.all? { |condition_key, condition_value| log[condition_key] == condition_value } } + inferred_answers.filter do |_attribute, condition| + condition.all? do |condition_key, condition_value| + log.public_send(condition_key) == condition_value + end + end end def inferred_answer_value(log) diff --git a/spec/models/form/lettings/questions/address_line1_spec.rb b/spec/models/form/lettings/questions/address_line1_spec.rb index e2600f0cc..2c13aef48 100644 --- a/spec/models/form/lettings/questions/address_line1_spec.rb +++ b/spec/models/form/lettings/questions/address_line1_spec.rb @@ -64,7 +64,7 @@ RSpec.describe Form::Lettings::Questions::AddressLine1, type: :model do end end - context "when la is present but inferred" do + context "when la is present and inferred" do let(:log) { create(:lettings_log, la: "E09000003") } before do diff --git a/spec/models/form/lettings/questions/scheme_id_spec.rb b/spec/models/form/lettings/questions/scheme_id_spec.rb index 7e88e3139..d16dc89dc 100644 --- a/spec/models/form/lettings/questions/scheme_id_spec.rb +++ b/spec/models/form/lettings/questions/scheme_id_spec.rb @@ -39,6 +39,45 @@ RSpec.describe Form::Lettings::Questions::SchemeId, type: :model do expect(question.derived?).to be false end + it "has the correct inferred_answers" do + expect(question.inferred_answers).to eq({ + "location.name": { + "scheme_has_multiple_locations?": false, + }, + }) + end + + describe "has the correct get_extra_check_answer_value" do + let(:scheme) { create(:scheme) } + + context "when locations are present but not inferred" do + let(:lettings_log) { create(:lettings_log) } + + before do + allow(lettings_log).to receive(:scheme_has_multiple_locations?).and_return(true) + end + + it "returns nil" do + expect(question.get_extra_check_answer_value(lettings_log)).to be_nil + end + end + + context "when location is present and inferred" do + let!(:location) { create(:location, scheme:) } + let!(:lettings_log) { create(:lettings_log, scheme:, location:) } + let(:real_2022_2023_form) { Form.new("config/forms/2022_2023.json") } + + before do + allow(lettings_log).to receive(:scheme_has_multiple_locations?).and_return(false) + allow(lettings_log).to receive(:form).and_return(real_2022_2023_form) + end + + it "returns the postcode" do + expect(question.get_extra_check_answer_value(lettings_log)).to eq(location.postcode) + end + end + end + context "when a user is signed in" do let(:organisation) { FactoryBot.create(:organisation) } let(:organisation_2) { FactoryBot.create(:organisation) } diff --git a/spec/models/form/sales/questions/address_line1_spec.rb b/spec/models/form/sales/questions/address_line1_spec.rb index f037f41cd..8c73feef2 100644 --- a/spec/models/form/sales/questions/address_line1_spec.rb +++ b/spec/models/form/sales/questions/address_line1_spec.rb @@ -64,7 +64,7 @@ RSpec.describe Form::Sales::Questions::AddressLine1, type: :model do end end - context "when la is present but inferred" do + context "when la is present and inferred" do let(:log) { create(:sales_log, la: "E09000003") } before do diff --git a/spec/models/lettings_log_spec.rb b/spec/models/lettings_log_spec.rb index 1e6fd3244..2d349f295 100644 --- a/spec/models/lettings_log_spec.rb +++ b/spec/models/lettings_log_spec.rb @@ -7,7 +7,6 @@ RSpec.describe LettingsLog do let(:created_by_user) { create(:user) } let(:owning_organisation) { created_by_user.organisation } let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") } - let(:fake_2022_2023_form) { Form.new("spec/fixtures/forms/2022_2023.json") } around do |example| Timecop.freeze(Time.utc(2022, 1, 1)) do