Browse Source

Fix hundredth error on migration of very small scharge values (#1898)

* feat: round all decimal values to 2dp in safe_string_as_decimal

* refactor: lint
pull/1901/head
natdeanlewissoftwire 1 year ago committed by GitHub
parent
commit
41228e2295
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/services/imports/logs_import_service.rb
  2. 23
      spec/services/imports/lettings_logs_import_service_spec.rb

2
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

23
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" }

Loading…
Cancel
Save