Browse Source

add allocations system to bulk upload

remotes/origin/bulk-upload-errors-integration
Phil Lee 3 years ago
parent
commit
21d1531aa1
  1. 33
      app/services/bulk_upload/lettings/row_parser.rb
  2. 81
      spec/services/bulk_upload/lettings/row_parser_spec.rb

33
app/services/bulk_upload/lettings/row_parser.rb

@ -173,6 +173,10 @@ class BulkUpload::Lettings::RowParser
errors.blank? errors.blank?
end end
def log
@log ||= LettingsLog.new(attributes_for_log)
end
private private
def postcode_full def postcode_full
@ -191,10 +195,6 @@ private
log.form.subsections.flat_map { |ss| ss.applicable_questions(log) } log.form.subsections.flat_map { |ss| ss.applicable_questions(log) }
end end
def log
@log ||= LettingsLog.new(attributes_for_log)
end
def validate_nulls def validate_nulls
field_mapping_for_errors.each do |error_key, fields| field_mapping_for_errors.each do |error_key, fields|
question_id = error_key.to_s question_id = error_key.to_s
@ -281,6 +281,10 @@ private
rp_medwel: %i[field_72], rp_medwel: %i[field_72],
rp_hardship: %i[field_73], rp_hardship: %i[field_73],
rp_dontknow: %i[field_74], rp_dontknow: %i[field_74],
cbl: %i[field_75],
chr: %i[field_76],
cap: %i[field_77],
} }
end end
@ -404,9 +408,30 @@ private
attributes["rp_hardship"] = field_73 attributes["rp_hardship"] = field_73
attributes["rp_dontknow"] = field_74 attributes["rp_dontknow"] = field_74
attributes["cbl"] = cbl
attributes["chr"] = chr
attributes["cap"] = cap
attributes["letting_allocation_unknown"] = letting_allocation_unknown
attributes attributes
end end
def letting_allocation_unknown
[cbl, chr, cap].all?(0) ? 1 : 0
end
def cbl
field_75 == 2 ? 0 : field_75
end
def chr
field_76 == 2 ? 0 : field_76
end
def cap
field_77 == 2 ? 0 : field_77
end
def ppostcode_full def ppostcode_full
"#{field_63} #{field_64}".strip.gsub(/\s+/, " ") "#{field_63} #{field_64}".strip.gsub(/\s+/, " ")
end end

81
spec/services/bulk_upload/lettings/row_parser_spec.rb

@ -110,6 +110,10 @@ RSpec.describe BulkUpload::Lettings::RowParser do
field_72: "1", field_72: "1",
field_73: "", field_73: "",
field_74: "", field_74: "",
field_75: "1",
field_76: "2",
field_77: "2",
} }
end end
@ -117,11 +121,12 @@ RSpec.describe BulkUpload::Lettings::RowParser do
expect(parser).to be_valid expect(parser).to be_valid
end end
it "instantiates a log with everything completed" do it "instantiates a log with everything completed", aggregate_failures: true do
questions = parser.send(:questions).reject do |q| questions = parser.send(:questions).reject do |q|
parser.send(:log).optional_fields.include?(q.id) || q.completed?(parser.send(:log)) parser.send(:log).optional_fields.include?(q.id) || q.completed?(parser.send(:log))
end end
expect(questions.map(&:id).size).to be(0)
expect(questions.map(&:id)).to eql([]) expect(questions.map(&:id)).to eql([])
end end
end end
@ -237,4 +242,78 @@ RSpec.describe BulkUpload::Lettings::RowParser do
end end
end end
end end
describe "#log" do
describe "#cbl" do
context "when field_75 is yes ie 1" do
let(:attributes) { { bulk_upload:, field_75: 1 } }
it "sets value to 1" do
expect(parser.log.cbl).to be(1)
end
end
context "when field_75 is no ie 2" do
let(:attributes) { { bulk_upload:, field_75: 2 } }
it "sets value to 0" do
expect(parser.log.cbl).to be(0)
end
end
end
describe "#chr" do
context "when field_76 is yes ie 1" do
let(:attributes) { { bulk_upload:, field_76: 1 } }
it "sets value to 1" do
expect(parser.log.chr).to be(1)
end
end
context "when field_76 is no ie 2" do
let(:attributes) { { bulk_upload:, field_76: 2 } }
it "sets value to 0" do
expect(parser.log.chr).to be(0)
end
end
end
describe "#cap" do
context "when field_77 is yes ie 1" do
let(:attributes) { { bulk_upload:, field_77: 1 } }
it "sets value to 1" do
expect(parser.log.cap).to be(1)
end
end
context "when field_77 is no ie 2" do
let(:attributes) { { bulk_upload:, field_77: 2 } }
it "sets value to 0" do
expect(parser.log.cap).to be(0)
end
end
end
describe "#letting_allocation_unknown" do
context "when field_75, 76, 77 are no ie 2" do
let(:attributes) { { bulk_upload:, field_75: 2, field_76: 2, field_77: 2 } }
it "sets value to 1" do
expect(parser.log.letting_allocation_unknown).to be(1)
end
end
context "when any one of field_75, 76, 77 is yes ie 1" do
let(:attributes) { { bulk_upload:, field_75: 1 } }
it "sets value to 0" do
expect(parser.log.letting_allocation_unknown).to be(0)
end
end
end
end
end end

Loading…
Cancel
Save