diff --git a/app/services/bulk_upload/lettings/year2023/row_parser.rb b/app/services/bulk_upload/lettings/year2023/row_parser.rb index 5c726b8fa..2ee81b2bc 100644 --- a/app/services/bulk_upload/lettings/year2023/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2023/row_parser.rb @@ -747,7 +747,7 @@ private fields.each do |field| if errors.select { |e| fields.include?(e.attribute) }.none? question_text = question.error_display_label.presence || "this question" - errors.add(field, I18n.t("validations.not_answered", question: question_text.downcase), category: :setup) + errors.add(field, I18n.t("validations.not_answered", question: question_text.downcase), category: :setup) if field.present? end end else @@ -892,7 +892,9 @@ private owning_organisation_id: [:field_1], managing_organisation_id: [:field_2], renewal: [:field_6], + scheme_id: [scheme_field], scheme: [scheme_field], + location_id: [location_field], location: [location_field], created_by: [:field_3], needstype: [:field_4], diff --git a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb index 90bdbed71..45ff3e6d1 100644 --- a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb @@ -888,7 +888,11 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do context "when using New CORE ids" do let(:scheme) { create(:scheme, :with_old_visible_id, owning_organisation: owning_org) } - let(:location) { create(:location, :with_old_visible_id, scheme:) } + let!(:location) { create(:location, :with_old_visible_id, scheme:) } + + before do + parser.valid? + end context "when matching scheme cannot be found" do let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_5: "2", field_16: "S123", field_17: location.id } } @@ -969,17 +973,32 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do let(:managing_org_location) { create(:location, :with_old_visible_id, scheme: managing_org_scheme) } let(:attributes) { { bulk_upload:, field_4: "2", field_5: "2", field_16: "S#{managing_org_scheme.id}", field_17: managing_org_location.id, field_2: managing_org.old_visible_id } } - it "does not return an error" do + it "clears the scheme answer" do expect(parser.errors[:field_15]).to be_blank - expect(parser.errors[:field_16]).to be_blank + expect(parser.errors[:field_16]).to include("You must answer scheme name") expect(parser.errors[:field_17]).to be_blank end end + + context "when matching location exists but is incomplete" do + let(:incomplete_location) { create(:location, :with_old_visible_id, :incomplete, scheme:) } + let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_5: "2", field_16: "S#{scheme.id}", field_17: incomplete_location.id } } + + it "returns a setup error for scheme" do + expect(parser.errors[:field_15]).to be_blank + expect(parser.errors.where(:field_16).map(&:message)).to eq(["This location is incomplete. Select another location or update this one"]) + expect(parser.errors.where(:field_17).map(&:message)).to eq(["This location is incomplete. Select another location or update this one"]) + end + end end context "when using Old CORE ids" do let(:scheme) { create(:scheme, :with_old_visible_id, owning_organisation: owning_org) } - let(:location) { create(:location, :with_old_visible_id, scheme:) } + let!(:location) { create(:location, :with_old_visible_id, scheme:) } + + before do + parser.valid? + end context "when matching scheme cannot be found" do let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_5: "2", field_15: "123", field_16: location.old_visible_id } } @@ -1060,8 +1079,8 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do let(:managing_org_location) { create(:location, :with_old_visible_id, scheme: managing_org_scheme) } let(:attributes) { { bulk_upload:, field_4: "2", field_5: "2", field_15: managing_org_scheme.old_visible_id, field_16: managing_org_location.old_visible_id, field_2: managing_org.old_visible_id } } - it "does not return an error" do - expect(parser.errors[:field_15]).to be_blank + it "clears the scheme answer" do + expect(parser.errors[:field_15]).to include("You must answer scheme name") expect(parser.errors[:field_16]).to be_blank expect(parser.errors[:field_17]).to be_blank end