diff --git a/app/services/imports/logs_import_service.rb b/app/services/imports/logs_import_service.rb index 930956f16..a82208bbe 100644 --- a/app/services/imports/logs_import_service.rb +++ b/app/services/imports/logs_import_service.rb @@ -72,7 +72,7 @@ module Imports if str.nil? nil else - BigDecimal(str, exception: false) + BigDecimal(str, exception: false).round(2) end end diff --git a/spec/services/imports/lettings_logs_import_service_spec.rb b/spec/services/imports/lettings_logs_import_service_spec.rb index 8367c7d71..6bfe53571 100644 --- a/spec/services/imports/lettings_logs_import_service_spec.rb +++ b/spec/services/imports/lettings_logs_import_service_spec.rb @@ -796,6 +796,29 @@ RSpec.describe Imports::LettingsLogsImportService do end end + context "and scharge is ever so slightly positive" do + let(:lettings_log_id) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" } + + before do + lettings_log_xml.at_xpath("//xmlns:Q18aii").content = "1.66533E-16" + end + + it "does not raise an error" do + expect { lettings_log_service.send(:create_log, lettings_log_xml) } + .not_to raise_error + end + + it "sets scharge to 0" 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.scharge).to eq(0) + end + end + context "and tshortfall is not positive" do let(:lettings_log_id) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" }