diff --git a/app/models/form/lettings/questions/reason.rb b/app/models/form/lettings/questions/reason.rb index 4cf851f4a..d6254f8fa 100644 --- a/app/models/form/lettings/questions/reason.rb +++ b/app/models/form/lettings/questions/reason.rb @@ -46,9 +46,9 @@ class Form::Lettings::Questions::Reason < ::Form::Question "18" => { "value" => "To move to accommodation with support" }, "19" => { "value" => "To move to independent accommodation" }, "20" => { "value" => "Other" }, - "28" => { "value" => "Don’t know" }, - "divider" => { "value" => true }, "47" => { "value" => "Tenant prefers not to say" }, + "divider" => { "value" => true }, + "28" => { "value" => "Don’t know" }, }.freeze end diff --git a/app/models/validations/sales/property_validations.rb b/app/models/validations/sales/property_validations.rb index 7fd4d2440..56a09c36f 100644 --- a/app/models/validations/sales/property_validations.rb +++ b/app/models/validations/sales/property_validations.rb @@ -49,9 +49,9 @@ module Validations::Sales::PropertyValidations record.errors.add :uprn_confirmation, I18n.t("validations.sales.property_information.uprn_confirmation.not_in_england") record.errors.add :uprn_selection, I18n.t("validations.sales.property_information.uprn_selection.not_in_england") if record.uprn.present? - record.errors.add :saledate, I18n.t("validations.sales.property_information.saledate.address_not_in_england") + record.errors.add :saledate, :skip_bu_error, message: I18n.t("validations.sales.property_information.saledate.address_not_in_england") else - record.errors.add :saledate, I18n.t("validations.sales.property_information.saledate.postcode_not_in_england") + record.errors.add :saledate, :skip_bu_error, message: I18n.t("validations.sales.property_information.saledate.postcode_not_in_england") end end end diff --git a/app/services/bulk_upload/sales/year2025/row_parser.rb b/app/services/bulk_upload/sales/year2025/row_parser.rb index ccf4f6531..dc0e31dfa 100644 --- a/app/services/bulk_upload/sales/year2025/row_parser.rb +++ b/app/services/bulk_upload/sales/year2025/row_parser.rb @@ -393,6 +393,15 @@ class BulkUpload::Sales::Year2025::RowParser }, on: :after_log + validates :field_103, + numericality: { + greater_than_or_equal_to: 2, + less_than_or_equal_to: 10, + message: I18n.t("#{ERROR_BASE_KEY}.numeric.within_range", field: "Number of staircasing transactions", min: "2", max: "10"), + allow_blank: true, + }, + on: :before_log + validate :validate_buyer1_economic_status, on: :before_log validate :validate_buyer2_economic_status, on: :before_log validate :validate_valid_radio_option, on: :before_log diff --git a/app/services/csv/lettings_log_csv_service.rb b/app/services/csv/lettings_log_csv_service.rb index 0a187d524..d7ab101ac 100644 --- a/app/services/csv/lettings_log_csv_service.rb +++ b/app/services/csv/lettings_log_csv_service.rb @@ -284,13 +284,12 @@ module Csv end def lettings_log_definitions - CsvVariableDefinition.lettings.group_by { |record| [record.variable, record.definition] } - .map do |_, options| + CsvVariableDefinition.lettings.group_by(&:variable).map { |_, options| exact_match = options.find { |definition| definition.year == @year } next exact_match if exact_match - options.max_by(&:year) - end + options.select { |opt| opt.year < @year }.max_by(&:year) + }.compact end def insert_derived_and_related_attributes(ordered_questions) diff --git a/app/services/csv/sales_log_csv_service.rb b/app/services/csv/sales_log_csv_service.rb index 08ce178e3..35adcf27f 100644 --- a/app/services/csv/sales_log_csv_service.rb +++ b/app/services/csv/sales_log_csv_service.rb @@ -179,13 +179,12 @@ module Csv end def sales_log_definitions - CsvVariableDefinition.sales.group_by { |record| [record.variable, record.definition] } - .map do |_, options| + CsvVariableDefinition.sales.group_by(&:variable).map { |_, options| exact_match = options.find { |definition| definition.year == @year } next exact_match if exact_match - options.max_by(&:year) - end + options.select { |opt| opt.year < @year }.max_by(&:year) + }.compact end def insert_derived_and_related_attributes(ordered_questions) diff --git a/app/services/uprn_client.rb b/app/services/uprn_client.rb index 97dc4753f..f847c7da5 100644 --- a/app/services/uprn_client.rb +++ b/app/services/uprn_client.rb @@ -20,7 +20,16 @@ class UprnClient end def result - @result ||= JSON.parse(response.body).dig("results", 0, "DPA") || JSON.parse(response.body).dig("results", 0, "LPI") + @result ||= if response.is_a?(Net::HTTPSuccess) + parsed_response = JSON.parse(response.body) + parsed_response.dig("results", 0, "DPA") || parsed_response.dig("results", 0, "LPI") + else + @error = "UPRN client failed to return a valid result, try again later." + Sentry.capture_message("UPRN client failed to return a valid result with error code: #{response.code}.") + Rails.logger.error("UPRN client failed to return a valid result with error code: #{response.code}.") + Rails.logger.error("Response body: #{response.body}") + nil + end end private diff --git a/app/views/form/_date_question.html.erb b/app/views/form/_date_question.html.erb index 55193b01a..a1df5f4d5 100644 --- a/app/views/form/_date_question.html.erb +++ b/app/views/form/_date_question.html.erb @@ -1,9 +1,10 @@ <%= render partial: "form/guidance/#{question.top_guidance_partial}" if question.top_guidance? %> +<% legend = legend(question, page_header, conditional) %> <%= render partial: "components/date_picker", locals: { resource: @log, question_id: question.id, - legend: { text: legend(question, page_header, conditional)[:text], size: "l", caption: caption(caption_text, page_header, conditional) }, + legend: { text: legend[:text], size: legend[:size], caption: caption(caption_text, page_header, conditional) }, resource_type: @log.log_type, hint: (question.hint_text.blank? ? "" : (question.hint_text.html_safe + "

".html_safe)) + "For example, #{date_mid_collection_year_formatted(@log.startdate).tr(' ', '/')}", f:, diff --git a/spec/services/uprn_client_spec.rb b/spec/services/uprn_client_spec.rb index b10ab7376..8d5c45ed9 100644 --- a/spec/services/uprn_client_spec.rb +++ b/spec/services/uprn_client_spec.rb @@ -86,5 +86,33 @@ describe UprnClient do expect(client.error).to be_nil end end + + describe "result" do + context "when response is successful" do + before do + stub_api_request(body: valid_response) + + client.call + end + + it "returns parsed result" do + expect(client.result).to eq({ "postcode" => "12345" }) + expect(client.send(:response).code.to_i).to eq(200) + end + end + + context "when response is not successful" do + before do + stub_api_request(body: valid_response, status: 500) + + client.call + end + + it "returns nil" do + expect(client.result).to be_nil + expect(client.error).to eq("UPRN client failed to return a valid result, try again later.") + end + end + end end end