Browse Source

Improve tests

pull/3373/head
oscric 4 weeks ago
parent
commit
d1fa7464d1
  1. 73
      spec/models/form/lettings/pages/address_fallback_spec.rb
  2. 73
      spec/models/form/lettings/pages/address_search_spec.rb
  3. 13
      spec/services/bulk_upload/lettings/year2026/row_parser_spec.rb

73
spec/models/form/lettings/pages/address_fallback_spec.rb

@ -26,4 +26,77 @@ RSpec.describe Form::Lettings::Pages::AddressFallback, type: :model do
it "has correct depends_on" do it "has correct depends_on" do
expect(page.depends_on).to eq([{ "manual_address_entry_selected" => true, "is_address_asked?" => true }]) expect(page.depends_on).to eq([{ "manual_address_entry_selected" => true, "is_address_asked?" => true }])
end end
context "when routing to the page" do
let(:form) { FormHandler.instance.forms["current_lettings"] }
let(:subsection) { instance_double(Form::Subsection, form:, enabled?: true) }
context "when the log is general needs" do
let(:log) { build(:lettings_log, needstype: 1) }
it "is routed to when the address is being entered manually" do
log.manual_address_entry_selected = true
expect(page).to be_routed_to(log, nil)
end
it "is not routed to when the address is not being entered manually" do
log.manual_address_entry_selected = false
expect(page).not_to be_routed_to(log, nil)
end
it "is not routed to when `manual_address_entry_selected` is nil" do
log.manual_address_entry_selected = nil
expect(page).not_to be_routed_to(log, nil)
end
end
context "when the log is supported housing" do
let(:log) { build(:lettings_log, needstype: 2) }
context "and the collection year is 2026 or later" do
before do
allow(form).to receive(:start_year_2026_or_later?).and_return(true)
end
it "is routed to when the address is being entered manually" do
log.manual_address_entry_selected = true
expect(page).to be_routed_to(log, nil)
end
it "is not routed to when the address is not being entered manually" do
log.manual_address_entry_selected = false
expect(page).not_to be_routed_to(log, nil)
end
it "is not routed to when `manual_address_entry_selected` is nil" do
log.manual_address_entry_selected = nil
expect(page).not_to be_routed_to(log, nil)
end
end
context "and the collection year is before 2026" do
before do
allow(form).to receive(:start_year_2026_or_later?).and_return(false)
end
it "is not routed to, even when the address is being entered manually" do
log.manual_address_entry_selected = true
expect(page).not_to be_routed_to(log, nil)
end
end
context "when the scheme has confidential information" do
let(:log) { build(:lettings_log, needstype: 2, scheme: build(:scheme, sensitive: 1)) }
before do
allow(form).to receive(:start_year_2026_or_later?).and_return(true)
end
it "is not routed to, even when the address is being entered manually" do
log.manual_address_entry_selected = true
expect(page).not_to be_routed_to(log, nil)
end
end
end
end
end end

73
spec/models/form/lettings/pages/address_search_spec.rb

@ -39,4 +39,77 @@ RSpec.describe Form::Lettings::Pages::AddressSearch, type: :model do
expect(page.question_number).to eq(16) expect(page.question_number).to eq(16)
end end
end end
context "when routing to the page" do
let(:form) { FormHandler.instance.forms["current_lettings"] }
let(:subsection) { instance_double(Form::Subsection, form:, enabled?: true) }
context "when the log is general needs" do
let(:log) { build(:lettings_log, needstype: 1) }
it "is routed to when the address is not being entered manually" do
log.manual_address_entry_selected = false
expect(page).to be_routed_to(log, nil)
end
it "is not routed to when the address is being entered manually" do
log.manual_address_entry_selected = true
expect(page).not_to be_routed_to(log, nil)
end
it "is not routed to when `manual_address_entry_selected` is nil" do
log.manual_address_entry_selected = nil
expect(page).not_to be_routed_to(log, nil)
end
end
context "when the log is supported housing" do
let(:log) { build(:lettings_log, needstype: 2) }
context "and the collection year is 2026 or later" do
before do
allow(form).to receive(:start_year_2026_or_later?).and_return(true)
end
it "is routed to when the address is not being entered manually" do
log.manual_address_entry_selected = false
expect(page).to be_routed_to(log, nil)
end
it "is not routed to when the address is being entered manually" do
log.manual_address_entry_selected = true
expect(page).not_to be_routed_to(log, nil)
end
it "is not routed to when `manual_address_entry_selected` is nil" do
log.manual_address_entry_selected = nil
expect(page).not_to be_routed_to(log, nil)
end
end
context "and the collection year is before 2026" do
before do
allow(form).to receive(:start_year_2026_or_later?).and_return(false)
end
it "is not routed to, even when the address is not being entered manually" do
log.manual_address_entry_selected = false
expect(page).not_to be_routed_to(log, nil)
end
end
context "when the scheme has confidential information" do
let(:log) { build(:lettings_log, needstype: 2, scheme: build(:scheme, sensitive: 1)) }
before do
allow(form).to receive(:start_year_2026_or_later?).and_return(true)
end
it "is not routed to, even when the address is not being entered manually" do
log.manual_address_entry_selected = false
expect(page).not_to be_routed_to(log, nil)
end
end
end
end
end end

13
spec/services/bulk_upload/lettings/year2026/row_parser_spec.rb

@ -12,7 +12,7 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
let(:owning_org) { create(:organisation, :with_old_visible_id) } let(:owning_org) { create(:organisation, :with_old_visible_id) }
let(:managing_org) { create(:organisation, :with_old_visible_id, rent_periods: [4, 1]) } let(:managing_org) { create(:organisation, :with_old_visible_id, rent_periods: [4, 1]) }
# Pinned non-confidential so the address/UPRN validations run as these tests expect; # Pinned non-confidential so the address/UPRN validations run as these tests expect;
# the confidential-scheme behaviour is covered by its own describe below (sensitive: 1). # the confidential scheme behaviour is covered by its own describe below (sensitive: 1).
let(:scheme) { create(:scheme, :with_old_visible_id, owning_organisation: owning_org, sensitive: 0) } let(:scheme) { create(:scheme, :with_old_visible_id, owning_organisation: owning_org, sensitive: 0) }
let(:postcode_first_part) { "AA1".freeze } let(:postcode_first_part) { "AA1".freeze }
let(:postcode_second_part) { "1AA".freeze } let(:postcode_second_part) { "1AA".freeze }
@ -1887,11 +1887,11 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
end end
context "when no UPRN or address fields are provided" do context "when no UPRN or address fields are provided" do
let(:attributes) { base_attributes.merge({ field_18: nil, field_19: nil, field_21: nil, field_23: nil, field_24: nil }) } let(:attributes) { base_attributes.merge({ field_18: nil, field_19: nil, field_20: nil, field_21: nil, field_22: nil, field_23: nil, field_24: nil }) }
it "does not require the address or UPRN (no not answered errors)" do it "does not require the address or UPRN (no not answered errors)" do
parser.valid? parser.valid?
%i[field_18 field_19 field_21 field_23 field_24].each do |field| %i[field_18 field_19 field_20 field_21 field_22 field_23 field_24].each do |field|
expect(parser.errors[field]).to be_empty expect(parser.errors[field]).to be_empty
end end
end end
@ -1901,7 +1901,9 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
log.valid? log.valid?
expect(log.read_attribute(:uprn)).to be_nil expect(log.read_attribute(:uprn)).to be_nil
expect(log.read_attribute(:address_line1)).to be_nil expect(log.read_attribute(:address_line1)).to be_nil
expect(log.read_attribute(:address_line2)).to be_nil
expect(log.read_attribute(:town_or_city)).to be_nil expect(log.read_attribute(:town_or_city)).to be_nil
expect(log.read_attribute(:county)).to be_nil
expect(log.read_attribute(:postcode_full)).to be_nil expect(log.read_attribute(:postcode_full)).to be_nil
end end
@ -1917,7 +1919,9 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
base_attributes.merge({ base_attributes.merge({
field_18: "123456789012", field_18: "123456789012",
field_19: "1 Test Street", field_19: "1 Test Street",
field_20: "Test District",
field_21: "Testville", field_21: "Testville",
field_22: "Testshire",
field_23: postcode_first_part, field_23: postcode_first_part,
field_24: postcode_second_part, field_24: postcode_second_part,
field_25: "E09000008", field_25: "E09000008",
@ -1929,6 +1933,9 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
log.valid? log.valid?
expect(log.read_attribute(:uprn)).to be_nil expect(log.read_attribute(:uprn)).to be_nil
expect(log.read_attribute(:address_line1)).to be_nil expect(log.read_attribute(:address_line1)).to be_nil
expect(log.read_attribute(:address_line2)).to be_nil
expect(log.read_attribute(:town_or_city)).to be_nil
expect(log.read_attribute(:county)).to be_nil
expect(log.read_attribute(:postcode_full)).to be_nil expect(log.read_attribute(:postcode_full)).to be_nil
end end

Loading…
Cancel
Save