Browse Source

Merge branch 'main' into CLDC-3919-Sales-BU-mortage-percentage-rounding-error

pull/2987/head
Manny Dinssa 2 months ago
parent
commit
e79e4fefff
  1. 4
      app/models/form/lettings/questions/reason.rb
  2. 4
      app/models/validations/sales/property_validations.rb
  3. 9
      app/services/bulk_upload/sales/year2025/row_parser.rb
  4. 7
      app/services/csv/lettings_log_csv_service.rb
  5. 7
      app/services/csv/sales_log_csv_service.rb
  6. 11
      app/services/uprn_client.rb
  7. 3
      app/views/form/_date_question.html.erb
  8. 28
      spec/services/uprn_client_spec.rb

4
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" }, "18" => { "value" => "To move to accommodation with support" },
"19" => { "value" => "To move to independent accommodation" }, "19" => { "value" => "To move to independent accommodation" },
"20" => { "value" => "Other" }, "20" => { "value" => "Other" },
"28" => { "value" => "Don’t know" },
"divider" => { "value" => true },
"47" => { "value" => "Tenant prefers not to say" }, "47" => { "value" => "Tenant prefers not to say" },
"divider" => { "value" => true },
"28" => { "value" => "Don’t know" },
}.freeze }.freeze
end end

4
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_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") record.errors.add :uprn_selection, I18n.t("validations.sales.property_information.uprn_selection.not_in_england")
if record.uprn.present? 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 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 end
end end

9
app/services/bulk_upload/sales/year2025/row_parser.rb

@ -393,6 +393,15 @@ class BulkUpload::Sales::Year2025::RowParser
}, },
on: :after_log 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_buyer1_economic_status, on: :before_log
validate :validate_buyer2_economic_status, on: :before_log validate :validate_buyer2_economic_status, on: :before_log
validate :validate_valid_radio_option, on: :before_log validate :validate_valid_radio_option, on: :before_log

7
app/services/csv/lettings_log_csv_service.rb

@ -284,13 +284,12 @@ module Csv
end end
def lettings_log_definitions def lettings_log_definitions
CsvVariableDefinition.lettings.group_by { |record| [record.variable, record.definition] } CsvVariableDefinition.lettings.group_by(&:variable).map { |_, options|
.map do |_, options|
exact_match = options.find { |definition| definition.year == @year } exact_match = options.find { |definition| definition.year == @year }
next exact_match if exact_match next exact_match if exact_match
options.max_by(&:year) options.select { |opt| opt.year < @year }.max_by(&:year)
end }.compact
end end
def insert_derived_and_related_attributes(ordered_questions) def insert_derived_and_related_attributes(ordered_questions)

7
app/services/csv/sales_log_csv_service.rb

@ -179,13 +179,12 @@ module Csv
end end
def sales_log_definitions def sales_log_definitions
CsvVariableDefinition.sales.group_by { |record| [record.variable, record.definition] } CsvVariableDefinition.sales.group_by(&:variable).map { |_, options|
.map do |_, options|
exact_match = options.find { |definition| definition.year == @year } exact_match = options.find { |definition| definition.year == @year }
next exact_match if exact_match next exact_match if exact_match
options.max_by(&:year) options.select { |opt| opt.year < @year }.max_by(&:year)
end }.compact
end end
def insert_derived_and_related_attributes(ordered_questions) def insert_derived_and_related_attributes(ordered_questions)

11
app/services/uprn_client.rb

@ -20,7 +20,16 @@ class UprnClient
end end
def result 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 end
private private

3
app/views/form/_date_question.html.erb

@ -1,9 +1,10 @@
<%= render partial: "form/guidance/#{question.top_guidance_partial}" if question.top_guidance? %> <%= render partial: "form/guidance/#{question.top_guidance_partial}" if question.top_guidance? %>
<% legend = legend(question, page_header, conditional) %>
<%= render partial: "components/date_picker", locals: <%= render partial: "components/date_picker", locals:
{ {
resource: @log, resource: @log,
question_id: question.id, 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, resource_type: @log.log_type,
hint: (question.hint_text.blank? ? "" : (question.hint_text.html_safe + "</br></br>".html_safe)) + "For example, #{date_mid_collection_year_formatted(@log.startdate).tr(' ', '/')}", hint: (question.hint_text.blank? ? "" : (question.hint_text.html_safe + "</br></br>".html_safe)) + "For example, #{date_mid_collection_year_formatted(@log.startdate).tr(' ', '/')}",
f:, f:,

28
spec/services/uprn_client_spec.rb

@ -86,5 +86,33 @@ describe UprnClient do
expect(client.error).to be_nil expect(client.error).to be_nil
end end
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
end end

Loading…
Cancel
Save