Browse Source

initialise missing forms using the new format, disable 14 days validation on non production

pull/1263/head
Kat 3 years ago
parent
commit
b104ef9ef5
  1. 7
      app/models/form.rb
  2. 23
      app/models/form_handler.rb
  3. 2
      config/initializers/feature_toggle.rb
  4. 39
      spec/models/form_handler_spec.rb

7
app/models/form.rb

@ -4,10 +4,10 @@ class Form
:setup_sections, :form_sections, :unresolved_log_redirect_page_id
def initialize(form_path, start_year = "", sections_in_form = [], type = "lettings")
if type == "sales"
@setup_sections = [Form::Sales::Sections::Setup.new(nil, nil, self)]
if type == "sales" || (start_year && start_year.to_i > 2022)
@setup_sections = type == "sales" ? [Form::Sales::Sections::Setup.new(nil, nil, self)] : [Form::Lettings::Sections::Setup.new(nil, nil, self)]
@form_sections = sections_in_form.map { |sec| sec.new(nil, nil, self) }
@type = "sales"
@type = type == "sales" ? "sales" : "lettings"
@sections = setup_sections + form_sections
@subsections = sections.flat_map(&:subsections)
@pages = subsections.flat_map(&:pages)
@ -20,6 +20,7 @@ class Form
"end_date" => end_date,
"sections" => sections,
}
@unresolved_log_redirect_page_id = "tenancy_start_date"
else
raise "No form definition file exists for given year".freeze unless File.exist?(form_path)

23
app/models/form_handler.rb

@ -28,8 +28,10 @@ class FormHandler
]
current_form = Form.new(nil, current_collection_start_year, sales_sections, "sales")
previous_form = Form.new(nil, current_collection_start_year - 1, sales_sections, "sales")
{ "current_sales" => current_form,
"previous_sales" => previous_form }
{
"current_sales" => current_form,
"previous_sales" => previous_form,
}
end
def lettings_forms
@ -42,6 +44,23 @@ class FormHandler
forms[form_to_set] = form if forms[form_to_set].blank?
end
end
lettings_sections = [
Form::Lettings::Sections::TenancyAndProperty,
Form::Lettings::Sections::Household,
Form::Lettings::Sections::RentAndCharges,
]
if forms["previous_lettings"].blank? && current_collection_start_year >= 2022
forms["previous_lettings"] = Form.new(nil, current_collection_start_year - 1, lettings_sections, "lettings")
end
if forms["current_lettings"].blank? && current_collection_start_year >= 2022
forms["current_lettings"] = Form.new(nil, current_collection_start_year, lettings_sections, "lettings")
end
if forms["next_lettings"].blank? && current_collection_start_year >= 2022
forms["next_lettings"] = Form.new(nil, current_collection_start_year + 1, lettings_sections, "lettings")
end
forms
end

2
config/initializers/feature_toggle.rb

@ -1,6 +1,6 @@
class FeatureToggle
def self.startdate_two_week_validation_enabled?
true
Rails.env.production?
end
def self.sales_log_enabled?

39
spec/models/form_handler_spec.rb

@ -168,5 +168,44 @@ RSpec.describe FormHandler do
end
end
end
describe "lettings_forms" do
context "when current and previous forms are defined in JSON (current collection start year before 2023)" do
it "creates a next_lettings form from ruby form objects" do
expect(form_handler.lettings_forms["previous_lettings"]).to be_present
expect(form_handler.lettings_forms["previous_lettings"].start_date.year).to eq(2021)
expect(form_handler.lettings_forms["current_lettings"]).to be_present
expect(form_handler.lettings_forms["current_lettings"].start_date.year).to eq(2022)
expect(form_handler.lettings_forms["next_lettings"]).to be_present
expect(form_handler.lettings_forms["next_lettings"].start_date.year).to eq(2023)
end
end
context "when only previous form is defined in JSON (current collection start year 2023)" do
let(:now) { Time.utc(2023, 9, 20) }
it "creates current_lettings and next_lettings forms from ruby form objects" do
expect(form_handler.lettings_forms["previous_lettings"]).to be_present
expect(form_handler.lettings_forms["previous_lettings"].start_date.year).to eq(2022)
expect(form_handler.lettings_forms["current_lettings"]).to be_present
expect(form_handler.lettings_forms["current_lettings"].start_date.year).to eq(2023)
expect(form_handler.lettings_forms["next_lettings"]).to be_present
expect(form_handler.lettings_forms["next_lettings"].start_date.year).to eq(2024)
end
end
context "when no form is defined in JSON (current collection start year 2024 onwards)" do
let(:now) { Time.utc(2024, 9, 20) }
it "creates previous_lettings, current_lettings and next_lettings forms from ruby form objects" do
expect(form_handler.lettings_forms["previous_lettings"]).to be_present
expect(form_handler.lettings_forms["previous_lettings"].start_date.year).to eq(2023)
expect(form_handler.lettings_forms["current_lettings"]).to be_present
expect(form_handler.lettings_forms["current_lettings"].start_date.year).to eq(2024)
expect(form_handler.lettings_forms["next_lettings"]).to be_present
expect(form_handler.lettings_forms["next_lettings"].start_date.year).to eq(2025)
end
end
end
# rubocop:enable RSpec/PredicateMatcher
end

Loading…
Cancel
Save