Browse Source

CLDC-3067 Surface organisation and date errors in summary (#2104)

* Surface organisation and date errors in summary

* Refactor

* Refactor sales row parser

* Check that question is present
pull/2128/head
kosiakkatrina 12 months ago committed by GitHub
parent
commit
991d3a5ffa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      app/services/bulk_upload/lettings/year2023/row_parser.rb
  2. 8
      app/services/bulk_upload/sales/year2023/row_parser.rb
  3. 23
      spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb
  4. 23
      spec/services/bulk_upload/sales/year2023/row_parser_spec.rb

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

@ -415,7 +415,13 @@ class BulkUpload::Lettings::Year2023::RowParser
fields = field_mapping_for_errors[error.attribute] || []
fields.each do |field|
unless errors.include?(field)
next if errors.include?(field)
question = log.form.get_question(error.attribute, log)
if question.present? && setup_question?(question)
errors.add(field, error.message, category: :setup)
else
errors.add(field, error.message)
end
end

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

@ -509,7 +509,13 @@ class BulkUpload::Sales::Year2023::RowParser
fields = field_mapping_for_errors[error.attribute] || []
fields.each do |field|
unless errors.include?(field)
next if errors.include?(field)
question = log.form.get_question(error.attribute, log)
if question.present? && setup_question?(question)
errors.add(field, error.message, category: :setup)
else
errors.add(field, error.message)
end
end

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

@ -1465,6 +1465,29 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
expect(parser.errors.where(:field_3)).not_to be_present
end
end
context "when user's org has absorbed owning organisation before the startdate" do
let(:merged_org) { create(:organisation, :with_old_visible_id, holds_own_stock: true) }
let(:attributes) { setup_section_params.merge({ field_1: merged_org.old_visible_id, field_2: merged_org.old_visible_id, field_3: user.email }) }
before do
merged_org.update!(absorbing_organisation: user.organisation, merge_date: Time.zone.today - 5.years)
merged_org.reload
user.organisation.reload
end
it "is not permitted" do
parser = described_class.new(attributes)
parser.valid?
expect(parser.errors[:field_1]).to include(/The owning organisation must be active on the tenancy start date/)
expect(parser.errors[:field_2]).to include(/The managing organisation must be active on the tenancy start date/)
expect(parser.errors[:field_7]).to include(/Enter a date when the owning and managing organisation was active/)
expect(parser.errors[:field_8]).to include(/Enter a date when the owning and managing organisation was active/)
expect(parser.errors[:field_9]).to include(/Enter a date when the owning and managing organisation was active/)
end
end
end
describe "#field_2" do # managing org

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

@ -420,6 +420,29 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
expect(parser.errors.where(:field_2)).not_to be_present
end
end
context "when user's org has absorbed owning organisation before the startdate" do
let(:merged_org) { create(:organisation, :with_old_visible_id, holds_own_stock: true) }
let(:attributes) { setup_section_params.merge({ field_1: merged_org.old_visible_id, field_2: user.email }) }
before do
merged_org.update!(absorbing_organisation: user.organisation, merge_date: Time.zone.today - 3.years)
merged_org.reload
user.organisation.reload
user.reload
end
it "is not permitted" do
parser = described_class.new(attributes)
parser.valid?
expect(parser.errors[:field_1]).to include(/The owning organisation must be active on the sale completion date/)
expect(parser.errors[:field_3]).to include(/Enter a date when the owning organisation was active/)
expect(parser.errors[:field_4]).to include(/Enter a date when the owning organisation was active/)
expect(parser.errors[:field_5]).to include(/Enter a date when the owning organisation was active/)
end
end
end
describe "#field_2" do # username for created_by

Loading…
Cancel
Save