Browse Source

feat: update duplicate log behaviour and tests

pull/1971/head
natdeanlewissoftwire 3 years ago
parent
commit
0be9b211a7
  1. 3
      app/services/bulk_upload/lettings/year2023/row_parser.rb
  2. 78
      spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb

3
app/services/bulk_upload/lettings/year2023/row_parser.rb

@ -868,7 +868,8 @@ private
errors.add(:field_8, error_message) # startdate errors.add(:field_8, error_message) # startdate
errors.add(:field_9, error_message) # startdate errors.add(:field_9, error_message) # startdate
errors.add(:field_13, error_message) # tenancycode errors.add(:field_13, error_message) # tenancycode
errors.add(location_field, error_message) if field_4 != 1 && location_field.present?# location errors.add(location_field, error_message) if field_4 != 1 && location_field.present? # location
errors.add(:field_16, error_message) if field_4 != 1 && !location_field.present? # add to Scheme field as unclear whether log uses New or Old CORE ids
errors.add(:field_23, error_message) if field_4 != 2 # postcode_full errors.add(:field_23, error_message) if field_4 != 2 # postcode_full
errors.add(:field_24, error_message) if field_4 != 2 # postcode_full errors.add(:field_24, error_message) if field_4 != 2 # postcode_full
errors.add(:field_25, error_message) if field_4 != 2 # la errors.add(:field_25, error_message) if field_4 != 2 # la

78
spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb

@ -327,7 +327,7 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
:field_8, # startdate :field_8, # startdate
:field_9, # startdate :field_9, # startdate
:field_13, # tenancycode :field_13, # tenancycode
:field_17, # location :field_16, # location
:field_46, # age1 :field_46, # age1
:field_47, # sex1 :field_47, # sex1
:field_50, # ecstat1 :field_50, # ecstat1
@ -343,6 +343,44 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
end end
context "with old core scheme and location ids" do context "with old core scheme and location ids" do
context "when a supported housing log already exists in the db" do
let(:attributes) { { bulk_upload:, field_4: "2", field_16: "123" } }
before do
parser.log.save!
parser.instance_variable_set(:@valid, nil)
end
it "is not a valid row" do
expect(parser).not_to be_valid
end
it "adds an error to all the fields used to determine duplicates" do
parser.valid?
error_message = "This is a duplicate log"
[
:field_1, # owning_organisation
:field_7, # startdate
:field_8, # startdate
:field_9, # startdate
:field_13, # tenancycode
:field_16, # location
:field_46, # age1
:field_47, # sex1
:field_50, # ecstat1
:field_132, # tcharge
].each do |field|
expect(parser.errors[field]).to include(error_message)
end
expect(parser.errors[:field_23]).not_to include(error_message)
expect(parser.errors[:field_24]).not_to include(error_message)
expect(parser.errors[:field_25]).not_to include(error_message)
end
end
context "when a supported housing log with chcharges already exists in the db" do context "when a supported housing log with chcharges already exists in the db" do
let(:bulk_upload) { create(:bulk_upload, :lettings, user:, needstype: 2) } let(:bulk_upload) { create(:bulk_upload, :lettings, user:, needstype: 2) }
let(:attributes) do let(:attributes) do
@ -449,6 +487,44 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
end end
context "with new core scheme and location ids" do context "with new core scheme and location ids" do
context "when a supported housing log already exists in the db" do
let(:attributes) { { bulk_upload:, field_4: "2", field_16: "S123" } }
before do
parser.log.save!
parser.instance_variable_set(:@valid, nil)
end
it "is not a valid row" do
expect(parser).not_to be_valid
end
it "adds an error to all the fields used to determine duplicates" do
parser.valid?
error_message = "This is a duplicate log"
[
:field_1, # owning_organisation
:field_7, # startdate
:field_8, # startdate
:field_9, # startdate
:field_13, # tenancycode
:field_17, # location
:field_46, # age1
:field_47, # sex1
:field_50, # ecstat1
:field_132, # tcharge
].each do |field|
expect(parser.errors[field]).to include(error_message)
end
expect(parser.errors[:field_23]).not_to include(error_message)
expect(parser.errors[:field_24]).not_to include(error_message)
expect(parser.errors[:field_25]).not_to include(error_message)
end
end
context "when a supported housing log with chcharges already exists in the db" do context "when a supported housing log with chcharges already exists in the db" do
let(:bulk_upload) { create(:bulk_upload, :lettings, user:, needstype: 2) } let(:bulk_upload) { create(:bulk_upload, :lettings, user:, needstype: 2) }
let(:attributes) do let(:attributes) do

Loading…
Cancel
Save