diff --git a/app/models/form/lettings/questions/address_selection.rb b/app/models/form/lettings/questions/address_selection.rb index acf8ef968..943dd24ac 100644 --- a/app/models/form/lettings/questions/address_selection.rb +++ b/app/models/form/lettings/questions/address_selection.rb @@ -29,6 +29,6 @@ class Form::Lettings::Questions::AddressSelection < ::Form::Question end def hidden_in_check_answers?(log, _current_user = nil) - (log.uprn_known == 1 || log.uprn_confirmed == 1) || !(1..10).cover?(log.address_options.count) + (log.uprn_known == 1 || log.uprn_confirmed == 1) || !(1..10).cover?(log.address_options&.count) end end diff --git a/app/models/form/lettings/questions/postcode_for_address_matcher.rb b/app/models/form/lettings/questions/postcode_for_address_matcher.rb index 81387c233..2cac3ce92 100644 --- a/app/models/form/lettings/questions/postcode_for_address_matcher.rb +++ b/app/models/form/lettings/questions/postcode_for_address_matcher.rb @@ -5,19 +5,7 @@ class Form::Lettings::Questions::PostcodeForAddressMatcher < ::Form::Question @header = "Postcode" @type = "text" @width = 5 - @inferred_check_answers_value = [{ - "condition" => { - "pcodenk" => 1, - }, - "value" => "Not known", - }] - @inferred_answers = { - "la" => { - "is_la_inferred" => true, - }, - } @plain_label = true - @check_answer_label = "Postcode" @disable_clearing_if_not_routed_or_dynamic_answer_options = true @hide_question_number_on_page = true @hidden_in_check_answers = true diff --git a/spec/models/form/lettings/questions/address_line1_for_address_matcher_spec.rb b/spec/models/form/lettings/questions/address_line1_for_address_matcher_spec.rb new file mode 100644 index 000000000..7c0baa66e --- /dev/null +++ b/spec/models/form/lettings/questions/address_line1_for_address_matcher_spec.rb @@ -0,0 +1,62 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Questions::AddressLine1ForAddressMatcher, type: :model do + subject(:question) { described_class.new(question_id, question_definition, page) } + + let(:question_id) { nil } + let(:question_definition) { nil } + let(:page) { instance_double(Form::Page) } + let(:log) { create(:lettings_log, :in_progress, address_line1_input: "Address line 1", postcode_full_input: "AA1 1AA") } + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("address_line1_input") + end + + it "has the correct header" do + expect(question.header).to eq("Address line 1") + end + + it "has the correct error label" do + expect(question.error_label).to eq("Address line 1") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Find address") + end + + it "has the correct question_number" do + expect(question.question_number).to eq(nil) + end + + it "has the correct type" do + expect(question.type).to eq("text") + end + + it "is not marked as derived" do + expect(question.derived?).to be false + end + + it "has the correct hint" do + expect(question.hint_text).to be_nil + end + + it "has the correct answer label" do + expect(question.answer_label(log)).to eq("Address line 1\nAA1 1AA") + end + + it "has the correct inferred check answers value" do + expect(question.inferred_check_answers_value).to be_nil + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to be_nil + end + + it "has the correct disable_clearing_if_not_routed_or_dynamic_answer_options value" do + expect(question.disable_clearing_if_not_routed_or_dynamic_answer_options).to eq(true) + end +end diff --git a/spec/models/form/lettings/questions/address_selection_spec.rb b/spec/models/form/lettings/questions/address_selection_spec.rb new file mode 100644 index 000000000..6669f5c46 --- /dev/null +++ b/spec/models/form/lettings/questions/address_selection_spec.rb @@ -0,0 +1,100 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Questions::AddressSelection, type: :model do + subject(:question) { described_class.new(question_id, question_definition, page) } + + let(:question_id) { nil } + let(:question_definition) { nil } + let(:page) { instance_double(Form::Page) } + let(:log) { create(:lettings_log, :in_progress, address_line1_input: "Address line 1", postcode_full_input: "AA1 1AA") } + + before do + allow_any_instance_of(AddressClient).to receive(:call) + allow_any_instance_of(AddressClient).to receive(:result).and_return([{ + "UPRN" => "UPRN", + "UDPRN" => "UDPRN", + "ADDRESS" => "full address", + "SUB_BUILDING_NAME" => "0", + "BUILDING_NAME" => "building name", + "THOROUGHFARE_NAME" => "thoroughfare", + "POST_TOWN" => "posttown", + "POSTCODE" => "postcode", + }]) + end + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("address_selection") + end + + it "has the correct header" do + expect(question.header).to eq("Select the correct address") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Select the correct address") + end + + it "has the correct question_number" do + expect(question.question_number).to eq(nil) + end + + it "has the correct type" do + expect(question.type).to eq("radio") + end + + it "is not marked as derived" do + expect(question.derived?).to be false + end + + it "has the correct hint" do + expect(question.hint_text).to be_nil + end + + it "has the correct answer options" do + stub_request(:get, /api.os.uk/) + .to_return(status: 200, body: "", headers: {}) + + expect(question.answer_options(log)).to eq({ "-1" => { "value" => "The address is not listed, I want to enter the address manually" }, "0" => { "value" => "full address" }, "divider" => { "value" => true } }) + end + + it "has the correct displayed answer options" do + stub_request(:get, /api.os.uk/) + .to_return(status: 200, body: "", headers: {}) + + expect(question.displayed_answer_options(log)).to eq({ "-1" => { "value" => "The address is not listed, I want to enter the address manually" }, "0" => { "value" => "full address" }, "divider" => { "value" => true } }) + end + + it "has the correct inferred check answers value" do + expect(question.inferred_check_answers_value).to be_nil + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to be_nil + end + + context "when the log has address options" do + it "has the correct hidden_in_check_answers?" do + stub_request(:get, /api.os.uk/) + .to_return(status: 200, body: '{"results": {"0": "address_0", "1": "address_1", "2": "address_2"}}', headers: {}) + + expect(question.hidden_in_check_answers?(log)).to eq(false) + end + end + + context "when the log does not have address options" do + before do + allow_any_instance_of(AddressClient).to receive(:result).and_return(nil) + end + + it "has the correct hidden_in_check_answers?" do + stub_request(:get, /api.os.uk/) + .to_return(status: 200, body: "", headers: {}) + + expect(question.hidden_in_check_answers?(log)).to eq(true) + end + end +end diff --git a/spec/models/form/lettings/questions/postcode_for_address_matcher_spec.rb b/spec/models/form/lettings/questions/postcode_for_address_matcher_spec.rb new file mode 100644 index 000000000..9d12cd59c --- /dev/null +++ b/spec/models/form/lettings/questions/postcode_for_address_matcher_spec.rb @@ -0,0 +1,62 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Questions::PostcodeForAddressMatcher, type: :model do + subject(:question) { described_class.new(question_id, question_definition, page) } + + let(:question_id) { nil } + let(:question_definition) { nil } + let(:page) { instance_double(Form::Page) } + let(:log) { create(:lettings_log, :in_progress, address_line1_input: "Address line 1", postcode_full_input: "AA1 1AA") } + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("postcode_full_input") + end + + it "has the correct header" do + expect(question.header).to eq("Postcode") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Postcode") + end + + it "has the correct question_number" do + expect(question.question_number).to eq(nil) + end + + it "has the correct type" do + expect(question.type).to eq("text") + end + + it "is not marked as derived" do + expect(question.derived?).to be false + end + + it "has the correct hint" do + expect(question.hint_text).to be_nil + end + + it "has the correct answer label" do + expect(question.answer_label(log)).to eq("AA1 1AA") + end + + it "has the correct inferred check answers value" do + expect(question.inferred_check_answers_value).to be_nil + end + + it "has the correct inferred_answers value" do + expect(question.inferred_answers).to be_nil + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to be_nil + end + + it "has the correct disable_clearing_if_not_routed_or_dynamic_answer_options value" do + expect(question.disable_clearing_if_not_routed_or_dynamic_answer_options).to eq(true) + end +end