Browse Source

test: attempt to stub setup question to have nil check_answer_label

pull/1524/head
Sam Seed 2 years ago
parent
commit
f5b3f6179b
  1. 1
      app/services/bulk_upload/lettings/year2023/row_parser.rb
  2. 39
      spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb

1
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

39
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

Loading…
Cancel
Save