From e5e6e1e21a02076092f0eaf6c91460ead2bdb57e Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Thu, 7 Sep 2023 16:09:46 +0100 Subject: [PATCH] Enforce offered as integer (#1897) * feat: ensure offered is an integer (decimal 0 was triggering validation errors) * feat: allow decimals but clear when not integer equivalent as per new requirements --- app/models/validations/shared_validations.rb | 2 +- .../imports/lettings_logs_import_service.rb | 1 + .../lettings_logs_import_service_spec.rb | 21 +++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/models/validations/shared_validations.rb b/app/models/validations/shared_validations.rb index 8cf2e53fe..81bda79de 100644 --- a/app/models/validations/shared_validations.rb +++ b/app/models/validations/shared_validations.rb @@ -49,7 +49,7 @@ module Validations::SharedValidations elsif incorrect_accuracy || value.to_d != value.to_i # if the user enters a value in exponent notation (eg '4e1') the to_i method does not convert this to the correct value field = question.check_answer_label || question.id case question.step - when 1 then record.errors.add question.id.to_sym, I18n.t("validations.numeric.whole_number", field:) + when 1 then record.errors.add question.id.to_sym, :not_integer, message: I18n.t("validations.numeric.whole_number", field:) when 10 then record.errors.add question.id.to_sym, I18n.t("validations.numeric.nearest_ten", field:) end end diff --git a/app/services/imports/lettings_logs_import_service.rb b/app/services/imports/lettings_logs_import_service.rb index a53048d83..cbaeee01a 100644 --- a/app/services/imports/lettings_logs_import_service.rb +++ b/app/services/imports/lettings_logs_import_service.rb @@ -326,6 +326,7 @@ module Imports %i[prevten non_temp_accommodation] => %w[prevten rsnvac], %i[joint not_joint_tenancy] => %w[joint], %i[offered outside_the_range] => %w[offered], + %i[offered not_integer] => %w[offered], %i[earnings over_hard_max] => %w[ecstat1], %i[tshortfall no_outstanding_charges] => %w[tshortfall hbrentshortfall], %i[beds outside_the_range] => %w[beds], diff --git a/spec/services/imports/lettings_logs_import_service_spec.rb b/spec/services/imports/lettings_logs_import_service_spec.rb index 7dc3d578d..8367c7d71 100644 --- a/spec/services/imports/lettings_logs_import_service_spec.rb +++ b/spec/services/imports/lettings_logs_import_service_spec.rb @@ -545,6 +545,27 @@ RSpec.describe Imports::LettingsLogsImportService do end end + context "and the number of times the property was relet is 0.01" do + before do + lettings_log_xml.at_xpath("//xmlns:Q20").content = "0.01" + end + + it "intercepts the relevant validation error" do + expect { lettings_log_service.send(:create_log, lettings_log_xml) } + .not_to raise_error + end + + it "clears out the number offered answer" do + allow(logger).to receive(:warn) + + lettings_log_service.send(:create_log, lettings_log_xml) + lettings_log = LettingsLog.find_by(old_id: lettings_log_id) + + expect(lettings_log).not_to be_nil + expect(lettings_log.offered).to be_nil + end + end + context "and the gender identity is refused" do before do lettings_log_xml.at_xpath("//xmlns:P1Sex").content = "Person prefers not to say"