diff --git a/app/services/bulk_upload/lettings/year2023/row_parser.rb b/app/services/bulk_upload/lettings/year2023/row_parser.rb index 284163ede..1653a4d17 100644 --- a/app/services/bulk_upload/lettings/year2023/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2023/row_parser.rb @@ -835,6 +835,7 @@ private end def questions + # binding.pry if log.form.subsections.count == 1 @questions ||= log.form.subsections.flat_map { |ss| ss.applicable_questions(log) } end 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 045c127fa..047118014 100644 --- a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb @@ -30,6 +30,11 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do before do create(:organisation_relationship, parent_organisation: owning_org, child_organisation: managing_org) + allow(form).to receive(:subsections).and_return([setup_subsection]) + allow(FormHandler.instance).to receive(:current_lettings_form).and_return(form) + allow(setup_subsection).to receive(:pages).and_return([setup_page]) + allow(setup_page).to receive(:questions).and_return([setup_question]) + allow(setup_question).to receive(:check_answer_label).and_return(nil) end around do |example| @@ -238,12 +243,36 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do end describe "#validate_nulls" do - let(:attributes) { { bulk_upload:, field_18: "", field_19: "", field_21: "" } } + context "for setup questions" do + let(:attributes) { { bulk_upload:, field_1: "a", field_4: nil, field_6: nil } } + let(:form) { Form.new(nil, 2023, [], "lettings") } + let(:setup_subsection) { Form::Lettings::Subsections::Setup.new(nil, nil, form.setup_sections.first) } + let(:setup_page) { Form::Lettings::Pages::NeedsType.new(nil, nil, setup_subsection) } + let(:setup_question) { Form::Lettings::Questions::NeedsType.new(nil, nil, setup_page) } + + # before do + # allow(form).to receive(:subsections).and_return([setup_subsection]) + # allow(FormHandler.instance).to receive(:current_lettings_form).and_return(form) + # allow(setup_subsection).to receive(:pages).and_return([setup_page]) + # allow(setup_page).to receive(:questions).and_return([setup_question]) + # end + + it "fetches the question's check_answer_label if it exists, otherwise it gets the question's header" do + binding.pry + parser.valid? + expect(parser.errors[:field_4]).to eql(["You must answer what is the needs type?"]) + expect(parser.errors[:field_6]).to eql(["You must answer property renewal"]) + end + end - it "fetches the question's check_answer_label if it exists, otherwise it get's the question's header" do - parser.valid? - expect(parser.errors[:field_19]).to eql(["You must answer q12 - address"]) - expect(parser.errors[:field_21]).to eql(["You must answer town or city"]) + context "for non-setup questions" do + let(:attributes) { { bulk_upload:, field_1: "a", field_18: "", field_19: "", field_21: "" } } + + it "fetches the question's check_answer_label if it exists, otherwise it gets the question's header" do + parser.valid? + expect(parser.errors[:field_19]).to eql(["You must answer q12 - address"]) + expect(parser.errors[:field_21]).to eql(["You must answer town or city"]) + end end end end