Browse Source

CLDC-3210: Handle "R" properly for income/savings in sales bulk upload (#2152)

* Blank commit for replication

* CLDC-3210: Check for R properly for sales BU savings field

* Sort refused check for income fields

* Add tests

* Allow any number of digits
pull/2171/head
Rachael Booth 11 months ago committed by GitHub
parent
commit
663ac60590
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 18
      app/services/bulk_upload/sales/year2023/row_parser.rb
  2. 48
      spec/services/bulk_upload/sales/year2023/row_parser_spec.rb

18
app/services/bulk_upload/sales/year2023/row_parser.rb

@ -243,13 +243,13 @@ class BulkUpload::Sales::Year2023::RowParser
attribute :field_75, :integer
attribute :field_76, :integer
attribute :field_77, :integer
attribute :field_78, :integer
attribute :field_78, :string
attribute :field_79, :integer
attribute :field_80, :integer
attribute :field_80, :string
attribute :field_81, :integer
attribute :field_82, :integer
attribute :field_83, :integer
attribute :field_83, :string
attribute :field_84, :integer
attribute :field_85, :integer
attribute :field_86, :integer
@ -841,17 +841,17 @@ private
attributes["ethnic"] = field_32
attributes["national"] = field_33
attributes["income1nk"] = field_78.present? ? 0 : 1
attributes["income1"] = field_78
attributes["income1nk"] = field_78 == "R" ? 1 : 0
attributes["income1"] = field_78.to_i if attributes["income1nk"]&.zero? && field_78&.match(/\A\d+\z/)
attributes["income2nk"] = field_80.present? ? 0 : 1
attributes["income2"] = field_80
attributes["income2nk"] = field_80 == "R" ? 1 : 0
attributes["income2"] = field_80.to_i if attributes["income2nk"]&.zero? && field_80&.match(/\A\d+\z/)
attributes["inc1mort"] = field_79
attributes["inc2mort"] = field_81
attributes["savingsnk"] = field_83.present? ? 0 : 1
attributes["savings"] = field_83
attributes["savingsnk"] = field_83 == "R" ? 1 : 0
attributes["savings"] = field_83.to_i if attributes["savingsnk"]&.zero? && field_83&.match(/\A\d+\z/)
attributes["prevown"] = field_84
attributes["prevten"] = field_62

48
spec/services/bulk_upload/sales/year2023/row_parser_spec.rb

@ -182,6 +182,54 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
end
end
describe "income and savings fields" do
context "when set to R" do
let(:attributes) do
{
bulk_upload:,
field_78: "R", # income 1
field_80: "R", # income 2
field_83: "R", # savings
}
end
it "sets the not known field as not known" do
expect(parser.log.income1nk).to be(1)
expect(parser.log.income2nk).to be(1)
expect(parser.log.savingsnk).to be(1)
end
it "leaves the value field nil" do
expect(parser.log.income1).to be_nil
expect(parser.log.income2).to be_nil
expect(parser.log.savings).to be_nil
end
end
context "when set to a number" do
let(:attributes) do
{
bulk_upload:,
field_78: "30000", # income 1
field_80: "0", # income 2
field_83: "12420", # savings
}
end
it "sets the not known field as known" do
expect(parser.log.income1nk).to be(0)
expect(parser.log.income2nk).to be(0)
expect(parser.log.savingsnk).to be(0)
end
it "sets the values" do
expect(parser.log.income1).to be(30_000)
expect(parser.log.income2).to be(0)
expect(parser.log.savings).to be(12_420)
end
end
end
describe "validations" do
before do
stub_request(:get, /api.postcodes.io/)

Loading…
Cancel
Save