Browse Source

Fix/add tests

CLDC-4139-tenancy-type-other-free-text-validation
oscar-richardson-softwire 6 days ago
parent
commit
5da8e34fc0
  1. 2
      app/models/form/lettings/subsections/tenancy_information.rb
  2. 6
      spec/fixtures/files/lettings_log_csv_export_codes_26.csv
  3. 6
      spec/fixtures/files/lettings_log_csv_export_labels_26.csv
  4. 20
      spec/models/form/lettings/subsections/tenancy_information_spec.rb
  5. 38
      spec/models/validations/soft_validations_spec.rb

2
app/models/form/lettings/subsections/tenancy_information.rb

@ -12,8 +12,8 @@ class Form::Lettings::Subsections::TenancyInformation < ::Form::Subsection
Form::Lettings::Pages::StarterTenancy.new("starter_tenancy", nil, self), Form::Lettings::Pages::StarterTenancy.new("starter_tenancy", nil, self),
Form::Lettings::Pages::TenancyType.new(nil, nil, self), Form::Lettings::Pages::TenancyType.new(nil, nil, self),
Form::Lettings::Pages::StarterTenancyType.new(nil, nil, self), Form::Lettings::Pages::StarterTenancyType.new(nil, nil, self),
Form::Lettings::Pages::TenancyLength.new(nil, nil, self),
(Form::Lettings::Pages::TenancyotherValueCheck.new(nil, nil, self) if form.start_year_2026_or_later?), (Form::Lettings::Pages::TenancyotherValueCheck.new(nil, nil, self) if form.start_year_2026_or_later?),
Form::Lettings::Pages::TenancyLength.new(nil, nil, self),
Form::Lettings::Pages::TenancyLengthAffordableRent.new(nil, nil, self), Form::Lettings::Pages::TenancyLengthAffordableRent.new(nil, nil, self),
Form::Lettings::Pages::TenancyLengthIntermediateRent.new(nil, nil, self), Form::Lettings::Pages::TenancyLengthIntermediateRent.new(nil, nil, self),
(Form::Lettings::Pages::TenancyLengthPeriodic.new(nil, nil, self) if form.start_year_2024_or_later?), (Form::Lettings::Pages::TenancyLengthPeriodic.new(nil, nil, self) if form.start_year_2024_or_later?),

6
spec/fixtures/files/lettings_log_csv_export_codes_26.csv vendored

File diff suppressed because one or more lines are too long

6
spec/fixtures/files/lettings_log_csv_export_labels_26.csv vendored

File diff suppressed because one or more lines are too long

20
spec/models/form/lettings/subsections/tenancy_information_spec.rb

@ -18,6 +18,7 @@ RSpec.describe Form::Lettings::Subsections::TenancyInformation, type: :model do
before do before do
allow(form).to receive(:start_year_2024_or_later?).and_return(true) allow(form).to receive(:start_year_2024_or_later?).and_return(true)
allow(form).to receive(:start_year_2025_or_later?).and_return(false) allow(form).to receive(:start_year_2025_or_later?).and_return(false)
allow(form).to receive(:start_year_2026_or_later?).and_return(false)
end end
context "when 2023" do context "when 2023" do
@ -26,6 +27,7 @@ RSpec.describe Form::Lettings::Subsections::TenancyInformation, type: :model do
before do before do
allow(form).to receive(:start_year_2024_or_later?).and_return(false) allow(form).to receive(:start_year_2024_or_later?).and_return(false)
allow(form).to receive(:start_year_2025_or_later?).and_return(false) allow(form).to receive(:start_year_2025_or_later?).and_return(false)
allow(form).to receive(:start_year_2026_or_later?).and_return(false)
end end
it "has correct pages" do it "has correct pages" do
@ -41,6 +43,7 @@ RSpec.describe Form::Lettings::Subsections::TenancyInformation, type: :model do
before do before do
allow(form).to receive(:start_year_2024_or_later?).and_return(true) allow(form).to receive(:start_year_2024_or_later?).and_return(true)
allow(form).to receive(:start_year_2025_or_later?).and_return(false) allow(form).to receive(:start_year_2025_or_later?).and_return(false)
allow(form).to receive(:start_year_2026_or_later?).and_return(false)
end end
it "has correct pages" do it "has correct pages" do
@ -56,6 +59,7 @@ RSpec.describe Form::Lettings::Subsections::TenancyInformation, type: :model do
before do before do
allow(form).to receive(:start_year_2024_or_later?).and_return(true) allow(form).to receive(:start_year_2024_or_later?).and_return(true)
allow(form).to receive(:start_year_2025_or_later?).and_return(true) allow(form).to receive(:start_year_2025_or_later?).and_return(true)
allow(form).to receive(:start_year_2026_or_later?).and_return(false)
end end
it "has correct pages" do it "has correct pages" do
@ -64,6 +68,22 @@ RSpec.describe Form::Lettings::Subsections::TenancyInformation, type: :model do
) )
end end
end end
context "when 2026" do
let(:start_date) { Time.utc(2026, 2, 8) }
before do
allow(form).to receive(:start_year_2024_or_later?).and_return(true)
allow(form).to receive(:start_year_2025_or_later?).and_return(true)
allow(form).to receive(:start_year_2026_or_later?).and_return(true)
end
it "has correct pages" do
expect(tenancy_information.pages.map(&:id)).to eq(
%w[joint starter_tenancy tenancy_type starter_tenancy_type tenancyother_value_check tenancy_length tenancy_length_affordable_rent tenancy_length_intermediate_rent tenancy_length_periodic],
)
end
end
end end
it "has the correct id" do it "has the correct id" do

38
spec/models/validations/soft_validations_spec.rb

@ -1355,6 +1355,44 @@ RSpec.describe Validations::SoftValidations do
end end
end end
describe "tenancyother_might_be_introductory_or_starter_period?" do
it "returns true if tenancyother is exactly in the 'likely introductory/starter period' list" do
record.tenancyother = "introductory"
expect(record).to be_tenancyother_might_be_introductory_or_starter_period
end
it "returns true if any word of tenancyother is exactly in the 'likely introductory/starter period' list" do
record.tenancyother = "a starter tenancy"
expect(record).to be_tenancyother_might_be_introductory_or_starter_period
end
it "is not case sensitive when matching" do
record.tenancyother = "Intro"
expect(record).to be_tenancyother_might_be_introductory_or_starter_period
end
it "returns false if no part of tenancyother is in the 'likely introductory/starter period' list" do
record.tenancyother = "other"
expect(record).not_to be_tenancyother_might_be_introductory_or_starter_period
end
it "returns false if match to the 'likely introductory/starter period' list is only part of a word" do
record.tenancyother = "wasintroductory"
expect(record).not_to be_tenancyother_might_be_introductory_or_starter_period
end
it "ignores neighbouring non-alphabet for matching" do
record.tenancyother = "1starter."
expect(record).to be_tenancyother_might_be_introductory_or_starter_period
end
end
describe "at_least_one_working_situation_is_sickness_and_household_sickness_is_no" do describe "at_least_one_working_situation_is_sickness_and_household_sickness_is_no" do
it "returns true if one person has working situation as illness and household sickness is no" do it "returns true if one person has working situation as illness and household sickness is no" do
record.illness = 2 record.illness = 2

Loading…
Cancel
Save