From 1a5d9fc14b7a417a359cc95754a5c6768f2b4f3c Mon Sep 17 00:00:00 2001 From: Jack <113976590+bibblobcode@users.noreply.github.com> Date: Wed, 22 Mar 2023 13:00:03 +0000 Subject: [PATCH] [CLDC-2068] Add UPRN questions to lettings (#1432) * Update CYA page * Update UPRN derived fields * Update sales' UPRN questions * Add UPRN lettings questions * Fix spec --- ...swers_summary_list_card_component.html.erb | 16 +++- .../lettings_log_variables.rb | 21 +++++ app/models/form/lettings/pages/address.rb | 24 +++++ .../pages/property_local_authority.rb | 8 ++ app/models/form/lettings/pages/uprn.rb | 28 ++++++ .../form/lettings/pages/uprn_confirmation.rb | 17 ++++ app/models/form/lettings/pages/uprn_known.rb | 16 ++++ .../form/lettings/questions/address_line1.rb | 38 ++++++++ .../form/lettings/questions/address_line2.rb | 13 +++ app/models/form/lettings/questions/county.rb | 13 +++ app/models/form/lettings/questions/la.rb | 4 + .../questions/postcode_for_full_address.rb | 25 +++++ .../form/lettings/questions/town_or_city.rb | 13 +++ app/models/form/lettings/questions/uprn.rb | 35 +++++++ .../lettings/questions/uprn_confirmation.rb | 34 +++++++ .../form/lettings/questions/uprn_known.rb | 21 +++++ .../subsections/property_information.rb | 19 +++- .../form/sales/questions/address_line1.rb | 1 + app/models/form/sales/questions/uprn.rb | 1 + app/models/lettings_log.rb | 5 + app/models/log.rb | 1 + .../form/_check_answers_summary_list.html.erb | 2 +- .../form/lettings/pages/address_spec.rb | 73 +++++++++++++++ .../pages/property_local_authority_spec.rb | 77 ++++++++++++++++ .../lettings/pages/uprn_confirmation_spec.rb | 59 ++++++++++++ .../form/lettings/pages/uprn_known_spec.rb | 51 ++++++++++ spec/models/form/lettings/pages/uprn_spec.rb | 81 ++++++++++++++++ .../lettings/questions/address_line1_spec.rb | 79 ++++++++++++++++ .../lettings/questions/address_line2_spec.rb | 49 ++++++++++ .../form/lettings/questions/county_spec.rb | 49 ++++++++++ .../models/form/lettings/questions/la_spec.rb | 30 ++++++ .../postcode_for_full_address_spec.rb | 62 +++++++++++++ .../lettings/questions/town_or_city_spec.rb | 49 ++++++++++ .../questions/uprn_confirmation_spec.rb | 90 ++++++++++++++++++ .../lettings/questions/uprn_known_spec.rb | 59 ++++++++++++ .../form/lettings/questions/uprn_spec.rb | 92 +++++++++++++++++++ .../subsections/property_information_spec.rb | 83 ++++++++++++----- .../sales/questions/address_line1_spec.rb | 4 + spec/models/form/sales/questions/uprn_spec.rb | 4 + spec/models/lettings_log_spec.rb | 57 ++++++++++++ spec/models/sales_log_spec.rb | 10 +- 41 files changed, 1382 insertions(+), 31 deletions(-) create mode 100644 app/models/form/lettings/pages/address.rb create mode 100644 app/models/form/lettings/pages/uprn.rb create mode 100644 app/models/form/lettings/pages/uprn_confirmation.rb create mode 100644 app/models/form/lettings/pages/uprn_known.rb create mode 100644 app/models/form/lettings/questions/address_line1.rb create mode 100644 app/models/form/lettings/questions/address_line2.rb create mode 100644 app/models/form/lettings/questions/county.rb create mode 100644 app/models/form/lettings/questions/postcode_for_full_address.rb create mode 100644 app/models/form/lettings/questions/town_or_city.rb create mode 100644 app/models/form/lettings/questions/uprn.rb create mode 100644 app/models/form/lettings/questions/uprn_confirmation.rb create mode 100644 app/models/form/lettings/questions/uprn_known.rb create mode 100644 spec/models/form/lettings/pages/address_spec.rb create mode 100644 spec/models/form/lettings/pages/property_local_authority_spec.rb create mode 100644 spec/models/form/lettings/pages/uprn_confirmation_spec.rb create mode 100644 spec/models/form/lettings/pages/uprn_known_spec.rb create mode 100644 spec/models/form/lettings/pages/uprn_spec.rb create mode 100644 spec/models/form/lettings/questions/address_line1_spec.rb create mode 100644 spec/models/form/lettings/questions/address_line2_spec.rb create mode 100644 spec/models/form/lettings/questions/county_spec.rb create mode 100644 spec/models/form/lettings/questions/postcode_for_full_address_spec.rb create mode 100644 spec/models/form/lettings/questions/town_or_city_spec.rb create mode 100644 spec/models/form/lettings/questions/uprn_confirmation_spec.rb create mode 100644 spec/models/form/lettings/questions/uprn_known_spec.rb create mode 100644 spec/models/form/lettings/questions/uprn_spec.rb diff --git a/app/components/check_answers_summary_list_card_component.html.erb b/app/components/check_answers_summary_list_card_component.html.erb index 3b4c4978a..31c3bffac 100644 --- a/app/components/check_answers_summary_list_card_component.html.erb +++ b/app/components/check_answers_summary_list_card_component.html.erb @@ -12,16 +12,22 @@ <% summary_list.row do |row| %> <% row.key { get_question_label(question) } %> <% row.value do %> - <%= get_answer_label(question) %> + <%= simple_format( + get_answer_label(question), + wrapper_tag: "span", + class: "govuk-!-margin-right-4", + ) %> <% extra_value = question.get_extra_check_answer_value(log) %> - <% if extra_value %> - <%= extra_value %> + <% if extra_value && question.answer_label(log).present? %> + <%= simple_format( + extra_value, + wrapper_tag: "span", + class: "govuk-!-font-weight-regular app-!-colour-muted", + ) %> <% end %> -
- <% question.get_inferred_answers(log).each do |inferred_answer| %> <%= inferred_answer %> <% end %> diff --git a/app/models/derived_variables/lettings_log_variables.rb b/app/models/derived_variables/lettings_log_variables.rb index d42fb3903..aae49422d 100644 --- a/app/models/derived_variables/lettings_log_variables.rb +++ b/app/models/derived_variables/lettings_log_variables.rb @@ -94,6 +94,17 @@ module DerivedVariables::LettingsLogVariables self.vacdays = property_vacant_days set_housingneeds_fields if housingneeds? + + if uprn_known&.zero? + self.uprn = nil + end + + if uprn_confirmed&.zero? + self.uprn = nil + self.uprn_known = 0 + end + + reset_address_fields! if is_supported_housing? end private @@ -229,4 +240,14 @@ private self.housingneeds_g = 0 self.housingneeds_h = 0 end + + def reset_address_fields! + self.uprn = nil + self.uprn_known = nil + self.uprn_confirmed = nil + self.address_line1 = nil + self.address_line2 = nil + self.town_or_city = nil + self.county = nil + end end diff --git a/app/models/form/lettings/pages/address.rb b/app/models/form/lettings/pages/address.rb new file mode 100644 index 000000000..6f88bad0d --- /dev/null +++ b/app/models/form/lettings/pages/address.rb @@ -0,0 +1,24 @@ +class Form::Lettings::Pages::Address < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "address" + @header = "What is the property's address?" + end + + def questions + @questions ||= [ + Form::Lettings::Questions::AddressLine1.new(nil, nil, self), + Form::Lettings::Questions::AddressLine2.new(nil, nil, self), + Form::Lettings::Questions::TownOrCity.new(nil, nil, self), + Form::Lettings::Questions::County.new(nil, nil, self), + Form::Lettings::Questions::PostcodeForFullAddress.new(nil, nil, self), + ] + end + + def routed_to?(log, _current_user = nil) + return false if log.uprn_known.nil? + return false if log.is_supported_housing? + + log.uprn_confirmed != 1 || log.uprn_known.zero? + end +end diff --git a/app/models/form/lettings/pages/property_local_authority.rb b/app/models/form/lettings/pages/property_local_authority.rb index 2c64e3628..7692fd376 100644 --- a/app/models/form/lettings/pages/property_local_authority.rb +++ b/app/models/form/lettings/pages/property_local_authority.rb @@ -8,4 +8,12 @@ class Form::Lettings::Pages::PropertyLocalAuthority < ::Form::Page def questions @questions ||= [Form::Lettings::Questions::La.new(nil, nil, self)] end + + def routed_to?(log, _current_user = nil) + return false if log.uprn_known.nil? && form.start_date.year >= 2023 + return false if log.is_la_inferred? + return false if log.is_supported_housing? + + true + end end diff --git a/app/models/form/lettings/pages/uprn.rb b/app/models/form/lettings/pages/uprn.rb new file mode 100644 index 000000000..7b6b90f1a --- /dev/null +++ b/app/models/form/lettings/pages/uprn.rb @@ -0,0 +1,28 @@ +class Form::Lettings::Pages::Uprn < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "uprn" + end + + def questions + @questions ||= [ + Form::Lettings::Questions::Uprn.new(nil, nil, self), + ] + end + + def routed_to?(log, _current_user = nil) + return false if log.is_supported_housing? + + log.uprn_known == 1 + end + + def skip_text + "Enter address instead" + end + + def skip_href(log = nil) + return unless log + + "/#{log.model_name.param_key.dasherize}s/#{log.id}/address" + end +end diff --git a/app/models/form/lettings/pages/uprn_confirmation.rb b/app/models/form/lettings/pages/uprn_confirmation.rb new file mode 100644 index 000000000..26cde2d97 --- /dev/null +++ b/app/models/form/lettings/pages/uprn_confirmation.rb @@ -0,0 +1,17 @@ +class Form::Lettings::Pages::UprnConfirmation < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "uprn_confirmation" + @header = "We found an address that might be this property" + end + + def questions + @questions ||= [ + Form::Lettings::Questions::UprnConfirmation.new(nil, nil, self), + ] + end + + def routed_to?(log, _current_user = nil) + log.uprn.present? && log.uprn_known == 1 + end +end diff --git a/app/models/form/lettings/pages/uprn_known.rb b/app/models/form/lettings/pages/uprn_known.rb new file mode 100644 index 000000000..1ded1ba82 --- /dev/null +++ b/app/models/form/lettings/pages/uprn_known.rb @@ -0,0 +1,16 @@ +class Form::Lettings::Pages::UprnKnown < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "uprn_known" + end + + def questions + @questions ||= [ + Form::Lettings::Questions::UprnKnown.new(nil, nil, self), + ] + end + + def routed_to?(log, _current_user = nil) + !log.is_supported_housing? + end +end diff --git a/app/models/form/lettings/questions/address_line1.rb b/app/models/form/lettings/questions/address_line1.rb new file mode 100644 index 000000000..6f82edf45 --- /dev/null +++ b/app/models/form/lettings/questions/address_line1.rb @@ -0,0 +1,38 @@ +class Form::Lettings::Questions::AddressLine1 < ::Form::Question + def initialize(id, hsh, page) + super + @id = "address_line1" + @check_answer_label = "Address" + @header = "Address line 1" + @type = "text" + @plain_label = true + @question_number = 12 + end + + def hidden_in_check_answers?(log, _current_user = nil) + return true if log.uprn_known.nil? + return false if log.uprn_known&.zero? + return true if log.uprn_confirmed.nil? && log.uprn.present? + return true if log.uprn_known == 1 && log.uprn.blank? + + log.uprn_confirmed == 1 + end + + def answer_label(log, _current_user = nil) + [ + log.address_line1, + log.address_line2, + log.postcode_full, + log.town_or_city, + log.county, + ].select(&:present?).join("\n") + end + + def get_extra_check_answer_value(log) + return unless log.is_la_inferred? + + la = LocalAuthority.find_by(code: log.la)&.name + + la.presence + end +end diff --git a/app/models/form/lettings/questions/address_line2.rb b/app/models/form/lettings/questions/address_line2.rb new file mode 100644 index 000000000..16f7c8336 --- /dev/null +++ b/app/models/form/lettings/questions/address_line2.rb @@ -0,0 +1,13 @@ +class Form::Lettings::Questions::AddressLine2 < ::Form::Question + def initialize(id, hsh, page) + super + @id = "address_line2" + @header = "Address line 2 (optional)" + @type = "text" + @plain_label = true + end + + def hidden_in_check_answers?(_log = nil, _current_user = nil) + true + end +end diff --git a/app/models/form/lettings/questions/county.rb b/app/models/form/lettings/questions/county.rb new file mode 100644 index 000000000..360c0966c --- /dev/null +++ b/app/models/form/lettings/questions/county.rb @@ -0,0 +1,13 @@ +class Form::Lettings::Questions::County < ::Form::Question + def initialize(id, hsh, page) + super + @id = "county" + @header = "County (optional)" + @type = "text" + @plain_label = true + end + + def hidden_in_check_answers?(_log = nil, _current_user = nil) + true + end +end diff --git a/app/models/form/lettings/questions/la.rb b/app/models/form/lettings/questions/la.rb index 3cafda054..b70e7590b 100644 --- a/app/models/form/lettings/questions/la.rb +++ b/app/models/form/lettings/questions/la.rb @@ -13,4 +13,8 @@ class Form::Lettings::Questions::La < ::Form::Question def answer_options { "" => "Select an option" }.merge(LocalAuthority.active(form.start_date).england.map { |la| [la.code, la.name] }.to_h) end + + def hidden_in_check_answers?(log, _current_user = nil) + log.startdate && log.startdate.year >= 2023 && log.is_la_inferred? + end end diff --git a/app/models/form/lettings/questions/postcode_for_full_address.rb b/app/models/form/lettings/questions/postcode_for_full_address.rb new file mode 100644 index 000000000..015abc2e8 --- /dev/null +++ b/app/models/form/lettings/questions/postcode_for_full_address.rb @@ -0,0 +1,25 @@ +class Form::Lettings::Questions::PostcodeForFullAddress < ::Form::Question + def initialize(id, hsh, page) + super + @id = "postcode_full" + @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 + end + + def hidden_in_check_answers?(_log = nil, _current_user = nil) + true + end +end diff --git a/app/models/form/lettings/questions/town_or_city.rb b/app/models/form/lettings/questions/town_or_city.rb new file mode 100644 index 000000000..f1eac8dff --- /dev/null +++ b/app/models/form/lettings/questions/town_or_city.rb @@ -0,0 +1,13 @@ +class Form::Lettings::Questions::TownOrCity < ::Form::Question + def initialize(id, hsh, page) + super + @id = "town_or_city" + @header = "Town or city" + @type = "text" + @plain_label = true + end + + def hidden_in_check_answers?(_log = nil, _current_user = nil) + true + end +end diff --git a/app/models/form/lettings/questions/uprn.rb b/app/models/form/lettings/questions/uprn.rb new file mode 100644 index 000000000..efe9a4ea4 --- /dev/null +++ b/app/models/form/lettings/questions/uprn.rb @@ -0,0 +1,35 @@ +class Form::Lettings::Questions::Uprn < ::Form::Question + def initialize(id, hsh, page) + super + @id = "uprn" + @check_answer_label = "UPRN" + @header = "What is the property's UPRN" + @type = "text" + @hint_text = "The Unique Property Reference Number (UPRN) is a unique number system created by Ordnance Survey and used by housing providers and sectors UK-wide. For example 10010457355." + @width = 10 + @question_number = 11 + end + + def unanswered_error_message + I18n.t("validations.property.uprn.invalid") + end + + def get_extra_check_answer_value(log) + value = [ + log.address_line1, + log.address_line2, + log.town_or_city, + log.county, + log.postcode_full, + (LocalAuthority.find_by(code: log.la)&.name if log.la.present?), + ].select(&:present?) + + return unless value.any? + + "\n\n#{value.join("\n")}" + end + + def hidden_in_check_answers?(log, _current_user = nil) + log.uprn_known != 1 + end +end diff --git a/app/models/form/lettings/questions/uprn_confirmation.rb b/app/models/form/lettings/questions/uprn_confirmation.rb new file mode 100644 index 000000000..5b7bbd535 --- /dev/null +++ b/app/models/form/lettings/questions/uprn_confirmation.rb @@ -0,0 +1,34 @@ +class Form::Lettings::Questions::UprnConfirmation < ::Form::Question + def initialize(id, hsh, page) + super + @id = "uprn_confirmed" + @header = "Is this the property address?" + @type = "radio" + @answer_options = ANSWER_OPTIONS + @check_answer_label = "Is this the right address?" + end + + ANSWER_OPTIONS = { + "1" => { "value" => "Yes" }, + "0" => { "value" => "No, I want to enter the address manually" }, + }.freeze + + def notification_banner(log = nil) + return unless log&.uprn + + { + title: "UPRN: #{log.uprn}", + heading: [ + log.address_line1, + log.address_line2, + log.postcode_full, + log.town_or_city, + log.county, + ].select(&:present?).join("\n"), + } + end + + def hidden_in_check_answers?(log, _current_user = nil) + log.uprn_known != 1 || log.uprn_confirmed.present? + end +end diff --git a/app/models/form/lettings/questions/uprn_known.rb b/app/models/form/lettings/questions/uprn_known.rb new file mode 100644 index 000000000..6e3ce0302 --- /dev/null +++ b/app/models/form/lettings/questions/uprn_known.rb @@ -0,0 +1,21 @@ +class Form::Lettings::Questions::UprnKnown < ::Form::Question + def initialize(id, hsh, page) + super + @id = "uprn_known" + @check_answer_label = "UPRN known?" + @header = "Do you know the property UPRN?" + @type = "radio" + @answer_options = ANSWER_OPTIONS + @hint_text = "The Unique Property Reference Number (UPRN) is a unique number system created by Ordnance Survey and used by housing providers and sectors UK-wide. For example 10010457355.

+ You can continue without the UPRN, but it means we will need you to enter the address of the property." + end + + ANSWER_OPTIONS = { + "1" => { "value" => "Yes" }, + "0" => { "value" => "No" }, + }.freeze + + def unanswered_error_message + I18n.t("validations.property.uprn_known.invalid") + end +end diff --git a/app/models/form/lettings/subsections/property_information.rb b/app/models/form/lettings/subsections/property_information.rb index 6e20ea7cf..c20c2b27c 100644 --- a/app/models/form/lettings/subsections/property_information.rb +++ b/app/models/form/lettings/subsections/property_information.rb @@ -8,7 +8,7 @@ class Form::Lettings::Subsections::PropertyInformation < ::Form::Subsection def pages @pages ||= [ - Form::Lettings::Pages::PropertyPostcode.new(nil, nil, self), + uprn_questions, Form::Lettings::Pages::PropertyLocalAuthority.new(nil, nil, self), Form::Lettings::Pages::FirstTimePropertyLetAsSocialHousing.new(nil, nil, self), Form::Lettings::Pages::PropertyLetType.new(nil, nil, self), @@ -25,7 +25,22 @@ class Form::Lettings::Subsections::PropertyInformation < ::Form::Subsection Form::Lettings::Pages::NewBuildHandoverDate.new(nil, nil, self), Form::Lettings::Pages::PropertyMajorRepairs.new(nil, nil, self), Form::Lettings::Pages::PropertyMajorRepairsValueCheck.new(nil, nil, self), - ].compact + ].flatten.compact + end + + def uprn_questions + if form.start_date.year >= 2023 + [ + Form::Lettings::Pages::UprnKnown.new(nil, nil, self), + Form::Lettings::Pages::Uprn.new(nil, nil, self), + Form::Lettings::Pages::UprnConfirmation.new(nil, nil, self), + Form::Lettings::Pages::Address.new(nil, nil, self), + ] + else + [ + Form::Lettings::Pages::PropertyPostcode.new(nil, nil, self), + ] + end end def displayed_in_tasklist?(log) diff --git a/app/models/form/sales/questions/address_line1.rb b/app/models/form/sales/questions/address_line1.rb index e8ccb17c0..2dd3a734e 100644 --- a/app/models/form/sales/questions/address_line1.rb +++ b/app/models/form/sales/questions/address_line1.rb @@ -6,6 +6,7 @@ class Form::Sales::Questions::AddressLine1 < ::Form::Question @header = "Address line 1" @type = "text" @plain_label = true + @question_number = 15 end def hidden_in_check_answers?(log, _current_user = nil) diff --git a/app/models/form/sales/questions/uprn.rb b/app/models/form/sales/questions/uprn.rb index 2c0b66dc8..7967a2035 100644 --- a/app/models/form/sales/questions/uprn.rb +++ b/app/models/form/sales/questions/uprn.rb @@ -7,6 +7,7 @@ class Form::Sales::Questions::Uprn < ::Form::Question @type = "text" @hint_text = "The Unique Property Reference Number (UPRN) is a unique number system created by Ordnance Survey and used by housing providers and sectors UK-wide. For example 10010457355." @width = 10 + @question_number = 14 end def unanswered_error_message diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index f8c817c56..f96c41c88 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -32,6 +32,7 @@ class LettingsLog < Log before_validation :reset_location_fields!, unless: :postcode_known? before_validation :reset_previous_location_fields!, unless: :previous_postcode_known? before_validation :set_derived_fields! + after_validation :process_uprn_change!, if: :should_process_uprn_change? belongs_to :scheme, optional: true belongs_to :location, optional: true @@ -679,4 +680,8 @@ private def unknown_housingneeds? housingneeds == 3 end + + def should_process_uprn_change? + uprn_changed? && startdate && startdate.year >= 2023 + end end diff --git a/app/models/log.rb b/app/models/log.rb index 34c920bd5..3ecc02754 100644 --- a/app/models/log.rb +++ b/app/models/log.rb @@ -45,6 +45,7 @@ class Log < ApplicationRecord self.address_line2 = presenter.address_line2 self.town_or_city = presenter.town_or_city self.postcode_full = presenter.postcode + self.county = nil process_postcode_changes! end end diff --git a/app/views/form/_check_answers_summary_list.html.erb b/app/views/form/_check_answers_summary_list.html.erb index 71fe9cd97..653cd610d 100644 --- a/app/views/form/_check_answers_summary_list.html.erb +++ b/app/views/form/_check_answers_summary_list.html.erb @@ -9,7 +9,7 @@ class: "govuk-!-margin-right-4", ) %> <% extra_value = question.get_extra_check_answer_value(@log) %> - <% if extra_value && question.answer_label(lettings_log, current_user).present? %> + <% if extra_value && question.answer_label(@log, current_user).present? %> <%= simple_format( extra_value, wrapper_tag: "span", diff --git a/spec/models/form/lettings/pages/address_spec.rb b/spec/models/form/lettings/pages/address_spec.rb new file mode 100644 index 000000000..e4cf044b8 --- /dev/null +++ b/spec/models/form/lettings/pages/address_spec.rb @@ -0,0 +1,73 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Pages::Address, type: :model do + subject(:page) { described_class.new(page_id, page_definition, subsection) } + + let(:page_id) { nil } + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection) } + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[address_line1 address_line2 town_or_city county postcode_full]) + end + + it "has the correct id" do + expect(page.id).to eq("address") + end + + it "has the correct header" do + expect(page.header).to eq("What is the property's address?") + end + + it "has the correct description" do + expect(page.description).to be_nil + end + + it "has correct depends_on" do + expect(page.depends_on).to be_nil + end + + describe "has correct routed_to?" do + context "when uprn_known == nil" do + let(:log) { create(:lettings_log, uprn_known: nil) } + + it "returns false" do + expect(page.routed_to?(log)).to eq(false) + end + end + + context "when uprn_confirmed != 1" do + let(:log) do + create(:lettings_log, uprn_known: 1, uprn_confirmed: 0) + end + + it "returns true" do + expect(page.routed_to?(log)).to eq(true) + end + end + + context "when uprn_known == 0" do + let(:log) do + create(:lettings_log, uprn_known: 0, uprn_confirmed: 0) + end + + it "returns true" do + expect(page.routed_to?(log)).to eq(true) + end + end + + context "when uprn_confirmed == 1 && uprn_known != 0" do + let(:log) do + create(:lettings_log, uprn_known: 1, uprn_confirmed: 1) + end + + it "returns true" do + expect(page.routed_to?(log)).to eq(false) + end + end + end +end diff --git a/spec/models/form/lettings/pages/property_local_authority_spec.rb b/spec/models/form/lettings/pages/property_local_authority_spec.rb new file mode 100644 index 000000000..5b5ee95eb --- /dev/null +++ b/spec/models/form/lettings/pages/property_local_authority_spec.rb @@ -0,0 +1,77 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Pages::PropertyLocalAuthority, type: :model do + subject(:page) { described_class.new(page_id, page_definition, subsection) } + + let(:page_id) { nil } + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date:)) } + let(:start_date) { Time.utc(2022, 4, 1) } + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq( + %w[ + la + ], + ) + end + + it "has the correct id" do + expect(page.id).to eq("property_local_authority") + end + + it "has the correct header" do + expect(page.header).to be_nil + end + + it "has the correct description" do + expect(page.description).to be_nil + end + + it "has the correct depends_on" do + expect(page.depends_on).to match([{ "is_general_needs?" => true, "is_la_inferred" => false }]) + end + + describe "has correct routed_to?" do + context "when start_date < 2023" do + let(:log) { create(:lettings_log, uprn_known: 1) } + let(:start_date) { Time.utc(2022, 2, 8) } + + it "returns false" do + expect(page.routed_to?(log)).to eq(true) + end + end + + context "when start_date >= 2023" do + let(:log) { create(:lettings_log, uprn_known: 1) } + let(:start_date) { Time.utc(2023, 2, 8) } + + it "returns true" do + expect(page.routed_to?(log)).to eq(true) + end + end + + context "when start_date < 2023 and uprn_known: nil" do + let(:log) { create(:lettings_log, uprn_known: nil) } + let(:start_date) { Time.utc(2023, 2, 8) } + + it "returns true" do + expect(page.routed_to?(log)).to eq(false) + end + + context "when is_la_inferred: true" do + before do + allow(log).to receive(:is_la_inferred?).and_return(true) + end + + it "returns true" do + expect(page.routed_to?(log)).to eq(false) + end + end + end + end +end diff --git a/spec/models/form/lettings/pages/uprn_confirmation_spec.rb b/spec/models/form/lettings/pages/uprn_confirmation_spec.rb new file mode 100644 index 000000000..e1c6a587d --- /dev/null +++ b/spec/models/form/lettings/pages/uprn_confirmation_spec.rb @@ -0,0 +1,59 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Pages::UprnConfirmation, type: :model do + subject(:page) { described_class.new(page_id, page_definition, subsection) } + + let(:page_id) { nil } + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection) } + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[uprn_confirmed]) + end + + it "has the correct id" do + expect(page.id).to eq("uprn_confirmation") + end + + it "has the correct header" do + expect(page.header).to eq("We found an address that might be this property") + end + + it "has the correct description" do + expect(page.description).to be_nil + end + + it "has correct depends_on" do + expect(page.depends_on).to be_nil + end + + describe "has correct routed_to?" do + context "when uprn present && uprn_known == 1 " do + let(:log) { create(:lettings_log, uprn_known: 1, uprn: "123456789") } + + it "returns true" do + expect(page.routed_to?(log)).to eq(true) + end + end + + context "when uprn = nil" do + let(:log) { create(:lettings_log, uprn_known: 1, uprn: nil) } + + it "returns false" do + expect(page.routed_to?(log)).to eq(false) + end + end + + context "when uprn_known == 0" do + let(:log) { create(:lettings_log, uprn_known: 0, uprn: "123456789") } + + it "returns false" do + expect(page.routed_to?(log)).to eq(false) + end + end + end +end diff --git a/spec/models/form/lettings/pages/uprn_known_spec.rb b/spec/models/form/lettings/pages/uprn_known_spec.rb new file mode 100644 index 000000000..27b893a5c --- /dev/null +++ b/spec/models/form/lettings/pages/uprn_known_spec.rb @@ -0,0 +1,51 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Pages::UprnKnown, type: :model do + subject(:page) { described_class.new(page_id, page_definition, subsection) } + + let(:page_id) { nil } + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection) } + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[uprn_known]) + end + + it "has the correct id" do + expect(page.id).to eq("uprn_known") + end + + it "has the correct header" do + expect(page.header).to be_nil + end + + it "has the correct description" do + expect(page.description).to be_nil + end + + it "has correct depends_on" do + expect(page.depends_on).to be_nil + end + + describe "has correct routed_to?" do + context "when needstype != 2" do + let(:log) { create(:lettings_log, needstype: nil) } + + it "returns true" do + expect(page.routed_to?(log)).to eq(true) + end + end + + context "when needstype == 2" do + let(:log) { create(:lettings_log, needstype: 2) } + + it "returns true" do + expect(page.routed_to?(log)).to eq(false) + end + end + end +end diff --git a/spec/models/form/lettings/pages/uprn_spec.rb b/spec/models/form/lettings/pages/uprn_spec.rb new file mode 100644 index 000000000..7b480b6b2 --- /dev/null +++ b/spec/models/form/lettings/pages/uprn_spec.rb @@ -0,0 +1,81 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Pages::Uprn, type: :model do + subject(:page) { described_class.new(page_id, page_definition, subsection) } + + let(:page_id) { nil } + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection) } + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[uprn]) + end + + it "has the correct id" do + expect(page.id).to eq("uprn") + end + + it "has the correct header" do + expect(page.header).to be_nil + end + + it "has the correct description" do + expect(page.description).to be_nil + end + + it "has correct depends_on" do + expect(page.depends_on).to be_nil + end + + it "has correct skip_text" do + expect(page.skip_text).to eq("Enter address instead") + end + + describe "has correct routed_to?" do + context "when uprn_known != 1" do + let(:log) { create(:lettings_log, uprn_known: 0) } + + it "returns false" do + expect(page.routed_to?(log)).to eq(false) + end + end + + context "when uprn_known == 1" do + let(:log) { create(:lettings_log, uprn_known: 1) } + + it "returns true" do + expect(page.routed_to?(log)).to eq(true) + end + end + + context "when needstype == 2" do + let(:log) { create(:lettings_log, uprn_known: 1, needstype: 2) } + + it "returns true" do + expect(page.routed_to?(log)).to eq(false) + end + end + end + + describe "has correct skip_href" do + context "when log is nil" do + it "is nil" do + expect(page.skip_href).to be_nil + end + end + + context "when log is present" do + let(:log) { create(:lettings_log) } + + it "points to address page" do + expect(page.skip_href(log)).to eq( + "/lettings-logs/#{log.id}/address", + ) + end + end + end +end diff --git a/spec/models/form/lettings/questions/address_line1_spec.rb b/spec/models/form/lettings/questions/address_line1_spec.rb new file mode 100644 index 000000000..781b0a748 --- /dev/null +++ b/spec/models/form/lettings/questions/address_line1_spec.rb @@ -0,0 +1,79 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Questions::AddressLine1, 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) } + + 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") + end + + it "has the correct header" do + expect(question.header).to eq("Address line 1") + end + + it "has the correct question_number" do + expect(question.question_number).to eq(12) + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Address") + 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 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 + + describe "has the correct get_extra_check_answer_value" do + context "when la is not present" do + let(:log) { create(:lettings_log, la: nil) } + + it "returns nil" do + expect(question.get_extra_check_answer_value(log)).to be_nil + end + end + + context "when la is present but not inferred" do + let(:log) { create(:lettings_log, la: "E09000003", is_la_inferred: false) } + + it "returns nil" do + expect(question.get_extra_check_answer_value(log)).to be_nil + end + end + + context "when la is present but inferred" do + let(:log) { create(:lettings_log, la: "E09000003") } + + before do + allow(log).to receive(:is_la_inferred?).and_return(true) + end + + it "returns the la" do + expect(question.get_extra_check_answer_value(log)).to eq("Barnet") + end + end + end +end diff --git a/spec/models/form/lettings/questions/address_line2_spec.rb b/spec/models/form/lettings/questions/address_line2_spec.rb new file mode 100644 index 000000000..4ac51a231 --- /dev/null +++ b/spec/models/form/lettings/questions/address_line2_spec.rb @@ -0,0 +1,49 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Questions::AddressLine2, 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) } + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("address_line2") + end + + it "has the correct header" do + expect(question.header).to eq("Address line 2 (optional)") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to be_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 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 hidden_in_check_answers" do + expect(question.hidden_in_check_answers?).to eq(true) + end +end diff --git a/spec/models/form/lettings/questions/county_spec.rb b/spec/models/form/lettings/questions/county_spec.rb new file mode 100644 index 000000000..cf8f814e4 --- /dev/null +++ b/spec/models/form/lettings/questions/county_spec.rb @@ -0,0 +1,49 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Questions::County, 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) } + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("county") + end + + it "has the correct header" do + expect(question.header).to eq("County (optional)") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to be_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 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 hidden_in_check_answers" do + expect(question.hidden_in_check_answers?).to eq(true) + end +end diff --git a/spec/models/form/lettings/questions/la_spec.rb b/spec/models/form/lettings/questions/la_spec.rb index f73a29660..3b5e30977 100644 --- a/spec/models/form/lettings/questions/la_spec.rb +++ b/spec/models/form/lettings/questions/la_spec.rb @@ -315,4 +315,34 @@ RSpec.describe Form::Lettings::Questions::La, type: :model do "E06000065" => "North Yorkshire", }) end + + describe "has the correct hidden_in_check_answers" do + context "when saledate.year before 2023" do + let(:log) { build(:lettings_log, startdate: Time.zone.parse("2022-07-01")) } + + it "returns false" do + expect(question.hidden_in_check_answers?(log)).to eq(false) + end + end + + context "when saledate.year >= 2023" do + let(:log) { build(:lettings_log, startdate: Time.zone.parse("2023-07-01")) } + + it "returns true" do + expect(question.hidden_in_check_answers?(log)).to eq(false) + end + end + + context "when saledate.year >= 2023 and la inferred" do + let(:log) { build(:lettings_log, startdate: Time.zone.parse("2023-07-01")) } + + before do + allow(log).to receive(:is_la_inferred?).and_return(true) + end + + it "returns true" do + expect(question.hidden_in_check_answers?(log)).to eq(true) + end + end + end end diff --git a/spec/models/form/lettings/questions/postcode_for_full_address_spec.rb b/spec/models/form/lettings/questions/postcode_for_full_address_spec.rb new file mode 100644 index 000000000..ccb02ef07 --- /dev/null +++ b/spec/models/form/lettings/questions/postcode_for_full_address_spec.rb @@ -0,0 +1,62 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Questions::PostcodeForFullAddress, 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) } + + 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") + 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 be_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 width" do + expect(question.width).to eq(5) + end + + it "has the correct inferred_answers" do + expect(question.inferred_answers).to eq({ + "la" => { + "is_la_inferred" => true, + }, + }) + end + + it "has the correct inferred_check_answers_value" do + expect(question.inferred_check_answers_value).to eq([{ + "condition" => { + "pcodenk" => 1, + }, + "value" => "Not known", + }]) + end + + it "has the correct hidden_in_check_answers" do + expect(question.hidden_in_check_answers?).to eq(true) + end +end diff --git a/spec/models/form/lettings/questions/town_or_city_spec.rb b/spec/models/form/lettings/questions/town_or_city_spec.rb new file mode 100644 index 000000000..8741fb058 --- /dev/null +++ b/spec/models/form/lettings/questions/town_or_city_spec.rb @@ -0,0 +1,49 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Questions::TownOrCity, 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) } + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("town_or_city") + end + + it "has the correct header" do + expect(question.header).to eq("Town or city") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to be_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 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 hidden_in_check_answers" do + expect(question.hidden_in_check_answers?).to eq(true) + end +end diff --git a/spec/models/form/lettings/questions/uprn_confirmation_spec.rb b/spec/models/form/lettings/questions/uprn_confirmation_spec.rb new file mode 100644 index 000000000..3c409641d --- /dev/null +++ b/spec/models/form/lettings/questions/uprn_confirmation_spec.rb @@ -0,0 +1,90 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Questions::UprnConfirmation, 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) } + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("uprn_confirmed") + end + + it "has the correct header" do + expect(question.header).to eq("Is this the property address?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Is this the right address?") + 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 unanswered_error_message" do + expect(question.unanswered_error_message).to eq("You must answer is this the right address?") + end + + describe "notification_banner" do + context "when address is not present" do + it "returns nil" do + log = create(:lettings_log) + + expect(question.notification_banner(log)).to be_nil + end + end + + context "when address is present" do + it "returns formatted value" do + log = create(:lettings_log, address_line1: "1, Test Street", town_or_city: "Test Town", county: "Test County", postcode_full: "AA1 1AA", uprn: "1234") + + expect(question.notification_banner(log)).to eq( + { + heading: "1, Test Street\nAA1 1AA\nTest Town\nTest County", + title: "UPRN: 1234", + }, + ) + end + end + end + + describe "has the correct hidden_in_check_answers" do + context "when uprn_known != 1 && uprn_confirmed == nil" do + let(:log) { create(:lettings_log, uprn_known: 0, uprn_confirmed: nil) } + + it "returns true" do + expect(question.hidden_in_check_answers?(log)).to eq(true) + end + end + + context "when uprn_known == 1 && uprn_confirmed == nil" do + let(:log) { create(:lettings_log, uprn_known: 1, uprn_confirmed: nil) } + + it "returns false" do + expect(question.hidden_in_check_answers?(log)).to eq(false) + end + end + + context "when uprn_known != 1 && uprn_confirmed == 1" do + let(:log) { create(:lettings_log, uprn_known: 1, uprn_confirmed: 1) } + + it "returns true" do + expect(question.hidden_in_check_answers?(log)).to eq(true) + end + end + end +end diff --git a/spec/models/form/lettings/questions/uprn_known_spec.rb b/spec/models/form/lettings/questions/uprn_known_spec.rb new file mode 100644 index 000000000..1a0f810da --- /dev/null +++ b/spec/models/form/lettings/questions/uprn_known_spec.rb @@ -0,0 +1,59 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Questions::UprnKnown, 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) } + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("uprn_known") + end + + it "has the correct header" do + expect(question.header).to eq("Do you know the property UPRN?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("UPRN known?") + 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 answer_options" do + expect(question.answer_options).to eq({ + "0" => { "value" => "No" }, + "1" => { "value" => "Yes" }, + }) + end + + it "has correct conditional for" do + expect(question.conditional_for).to be_nil + end + + it "has the correct unanswered_error_message" do + expect(question.unanswered_error_message).to eq("You must answer UPRN known?") + end + + it "has the correct hint" do + expect(question.hint_text).to eq( + "The Unique Property Reference Number (UPRN) is a unique number system created by Ordnance Survey and used by housing providers and sectors UK-wide. For example 10010457355.

+ You can continue without the UPRN, but it means we will need you to enter the address of the property.", + ) + end + + it "has the correct hidden_in_check_answers" do + expect(question.hidden_in_check_answers).to be_nil + end +end diff --git a/spec/models/form/lettings/questions/uprn_spec.rb b/spec/models/form/lettings/questions/uprn_spec.rb new file mode 100644 index 000000000..8f6ba047a --- /dev/null +++ b/spec/models/form/lettings/questions/uprn_spec.rb @@ -0,0 +1,92 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Questions::Uprn, 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) } + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("uprn") + end + + it "has the correct header" do + expect(question.header).to eq("What is the property's UPRN") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("UPRN") + 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 question_number" do + expect(question.question_number).to eq(11) + end + + it "has the correct hint" do + expect(question.hint_text).to eq("The Unique Property Reference Number (UPRN) is a unique number system created by Ordnance Survey and used by housing providers and sectors UK-wide. For example 10010457355.") + end + + it "has the correct unanswered_error_message" do + expect(question.unanswered_error_message).to eq("UPRN must be 12 digits or less") + end + + describe "get_extra_check_answer_value" do + context "when address is not present" do + let(:log) { create(:lettings_log) } + + it "returns nil" do + expect(question.get_extra_check_answer_value(log)).to be_nil + end + end + + context "when address is present" do + let(:log) do + create( + :lettings_log, + address_line1: "1, Test Street", + town_or_city: "Test Town", + county: "Test County", + postcode_full: "AA1 1AA", + la: "E09000003", + ) + end + + it "returns formatted value" do + expect(question.get_extra_check_answer_value(log)).to eq( + "\n\n1, Test Street\nTest Town\nTest County\nAA1 1AA\nWestminster", + ) + end + end + end + + describe "has the correct hidden_in_check_answers" do + context "when uprn_known == 1" do + let(:log) { create(:lettings_log, uprn_known: 1) } + + it "returns false" do + expect(question.hidden_in_check_answers?(log)).to eq(false) + end + end + + context "when uprn_known != 1" do + let(:log) { create(:lettings_log, uprn_known: 0) } + + it "returns false" do + expect(question.hidden_in_check_answers?(log)).to eq(true) + end + end + end +end diff --git a/spec/models/form/lettings/subsections/property_information_spec.rb b/spec/models/form/lettings/subsections/property_information_spec.rb index 8b30964c3..2e7e58deb 100644 --- a/spec/models/form/lettings/subsections/property_information_spec.rb +++ b/spec/models/form/lettings/subsections/property_information_spec.rb @@ -9,28 +9,67 @@ RSpec.describe Form::Lettings::Subsections::PropertyInformation, type: :model do expect(property_information.section).to eq(section) end - it "has correct pages" do - expect(property_information.pages.map(&:id)).to eq( - %w[ - property_postcode - property_local_authority - first_time_property_let_as_social_housing - property_let_type - property_vacancy_reason_not_first_let - property_vacancy_reason_first_let - property_number_of_times_relet_not_social_let - property_number_of_times_relet_social_let - property_unit_type - property_building_type - property_wheelchair_accessible - property_number_of_bedrooms - void_or_renewal_date - void_date_value_check - new_build_handover_date - property_major_repairs - property_major_repairs_value_check - ], - ) + describe "pages" do + let(:section) { instance_double(Form::Sales::Sections::Household, form: instance_double(Form, start_date:)) } + + context "when 2022" do + let(:start_date) { Time.utc(2022, 2, 8) } + + it "has correct pages" do + expect(property_information.pages.compact.map(&:id)).to eq( + %w[ + property_postcode + property_local_authority + first_time_property_let_as_social_housing + property_let_type + property_vacancy_reason_not_first_let + property_vacancy_reason_first_let + property_number_of_times_relet_not_social_let + property_number_of_times_relet_social_let + property_unit_type + property_building_type + property_wheelchair_accessible + property_number_of_bedrooms + void_or_renewal_date + void_date_value_check + new_build_handover_date + property_major_repairs + property_major_repairs_value_check + ], + ) + end + end + + context "when 2023" do + let(:start_date) { Time.utc(2023, 2, 8) } + + it "has correct pages" do + expect(property_information.pages.map(&:id)).to eq( + %w[ + uprn_known + uprn + uprn_confirmation + address + property_local_authority + first_time_property_let_as_social_housing + property_let_type + property_vacancy_reason_not_first_let + property_vacancy_reason_first_let + property_number_of_times_relet_not_social_let + property_number_of_times_relet_social_let + property_unit_type + property_building_type + property_wheelchair_accessible + property_number_of_bedrooms + void_or_renewal_date + void_date_value_check + new_build_handover_date + property_major_repairs + property_major_repairs_value_check + ], + ) + end + end end it "has the correct id" do diff --git a/spec/models/form/sales/questions/address_line1_spec.rb b/spec/models/form/sales/questions/address_line1_spec.rb index bc65c0646..27c0179e2 100644 --- a/spec/models/form/sales/questions/address_line1_spec.rb +++ b/spec/models/form/sales/questions/address_line1_spec.rb @@ -11,6 +11,10 @@ RSpec.describe Form::Sales::Questions::AddressLine1, type: :model do expect(question.page).to eq(page) end + it "has the correct question_number" do + expect(question.question_number).to eq(15) + end + it "has the correct id" do expect(question.id).to eq("address_line1") end diff --git a/spec/models/form/sales/questions/uprn_spec.rb b/spec/models/form/sales/questions/uprn_spec.rb index 2f42c1cdd..50e575445 100644 --- a/spec/models/form/sales/questions/uprn_spec.rb +++ b/spec/models/form/sales/questions/uprn_spec.rb @@ -31,6 +31,10 @@ RSpec.describe Form::Sales::Questions::Uprn, type: :model do expect(question.derived?).to be false end + it "has the correct question_number" do + expect(question.question_number).to eq(14) + end + it "has the correct hint" do expect(question.hint_text).to eq("The Unique Property Reference Number (UPRN) is a unique number system created by Ordnance Survey and used by housing providers and sectors UK-wide. For example 10010457355.") end diff --git a/spec/models/lettings_log_spec.rb b/spec/models/lettings_log_spec.rb index 43cbc69ce..9a8666eea 100644 --- a/spec/models/lettings_log_spec.rb +++ b/spec/models/lettings_log_spec.rb @@ -1,6 +1,7 @@ require "rails_helper" require "shared/shared_examples_for_derived_fields" +# rubocop:disable RSpec/AnyInstance RSpec.describe LettingsLog do let(:different_managing_organisation) { create(:organisation) } let(:created_by_user) { create(:user) } @@ -3010,4 +3011,60 @@ RSpec.describe LettingsLog do end end end + + describe "#process_uprn_change!" do + context "when UPRN set to a value" do + let(:lettings_log) do + create( + :lettings_log, + uprn: "123456789", + uprn_confirmed: 1, + county: "county", + ) + end + + it "updates sales log fields" do + lettings_log.uprn = "1111111" + + allow_any_instance_of(UprnClient).to receive(:call) + allow_any_instance_of(UprnClient).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", + }) + + expect { lettings_log.process_uprn_change! }.to change(lettings_log, :address_line1).from(nil).to("0, Building Name, Thoroughfare") + .and change(lettings_log, :town_or_city).from(nil).to("Posttown") + .and change(lettings_log, :postcode_full).from(nil).to("POSTCODE") + .and change(lettings_log, :uprn_confirmed).from(1).to(nil) + .and change(lettings_log, :county).from("county").to(nil) + end + end + + context "when UPRN nil" do + let(:lettings_log) { create(:lettings_log, uprn: nil) } + + it "does not update sales log" do + expect { lettings_log.process_uprn_change! }.not_to change(lettings_log, :attributes) + end + end + + context "when service errors" do + let(:lettings_log) { create(:lettings_log, uprn: "123456789", uprn_confirmed: 1) } + let(:error_message) { "error" } + + it "adds error to sales log" do + allow_any_instance_of(UprnClient).to receive(:call) + allow_any_instance_of(UprnClient).to receive(:error).and_return(error_message) + + expect { lettings_log.process_uprn_change! }.to change { lettings_log.errors[:uprn] }.from([]).to([error_message]) + end + end + end end +# rubocop:enable RSpec/AnyInstance diff --git a/spec/models/sales_log_spec.rb b/spec/models/sales_log_spec.rb index 231dc68c4..4bc90da37 100644 --- a/spec/models/sales_log_spec.rb +++ b/spec/models/sales_log_spec.rb @@ -517,7 +517,14 @@ RSpec.describe SalesLog, type: :model do describe "#process_uprn_change!" do context "when UPRN set to a value" do - let(:sales_log) { create(:sales_log, uprn: "123456789", uprn_confirmed: 1) } + let(:sales_log) do + create( + :sales_log, + uprn: "123456789", + uprn_confirmed: 1, + county: "county", + ) + end it "updates sales log fields" do sales_log.uprn = "1111111" @@ -538,6 +545,7 @@ RSpec.describe SalesLog, type: :model do .and change(sales_log, :town_or_city).from(nil).to("Posttown") .and change(sales_log, :postcode_full).from(nil).to("POSTCODE") .and change(sales_log, :uprn_confirmed).from(1).to(nil) + .and change(sales_log, :county).from("county").to(nil) end end