Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
4.1 KiB

require "rails_helper"
require_relative "../../request_helper"
RSpec.describe Form::Subsection, type: :model do
subject(:subsection) { described_class.new(subsection_id, subsection_definition, section) }
CLDC-1917 Add Startdate Validation (#1378) * feat: add validation with feature flag, typo fix and update tests * feat: flip feature toggle * feat: update feature toggle name * feat: fix form handler inequality * refactor: linting * refactor: use between in form handler * feat: remove feature toggle * feat: add dynamic date to lettings log factory * feat: fix log_summary_component_spec.rb tests * feat: update lettings_log.rb and start fixing lettings_log_spec.rb * feat: fix more tests * feat: fix more tests * feat: fix lettings log import service * refactor: linting * feat: fix checkboxes_spec.rb * feat: fix interruption_screen_helper_spec.rb * feat: fix check_answers_helper_spec.rb * feat: fix page_routing_spec.rb * feat: fix lettings_logs_field_import_service_spec.rb * feat: fix lettings_log_spec.rb * feat: fix question_spec.rb * feat: fix lettings_logs_controller_spec.rb * feat: fix check_answers_page_lettings_logs_spec.rb * feat: fix tenancy_validations_spec.rb * feat: fix validations_spec.rb * feat: fix accessible_autocomplete_spec.rb * feat: fix form_navigation_spec.rb * feat: fix soft_validations_spec.rb * feat: fix lettings_log_export_service_spec.rb * feat: fix saving_data_spec.rb * feat: fix page_spec.rb * feat: fix form_controller_spec.rb * refactor: linting * feat: fix subsection_spec.rb * feat: fix lettings_log_spec.rb * feat: fix financial_validations_spec.rb * feat: fix tasklist_page_spec.rb * feat: fix conditional_questions_spec.rb * feat: fix form_page_error_helper_spec.rb and log_summary_component_spec.rb * feat: fix lettings_log_csv_service_spec.rb * feat: fix tasklist_helper_spec.rb * refactor: linting * refactor: linting * feat: fix lettings_log_spec.rb * refactor: linting * refactor: replace financial year with collection yaer * feat: respond to PR comments pt. 1 * feat: respond to PR comments pt. 2
2 years ago
around do |example|
Timecop.freeze(Time.zone.local(2022, 1, 1)) do
Singleton.__init__(FormHandler)
example.run
end
Timecop.return
Singleton.__init__(FormHandler)
end
let(:lettings_log) { FactoryBot.build(:lettings_log) }
let(:form) { lettings_log.form }
let(:section_id) { "household" }
let(:section_definition) { form.form_definition["sections"][section_id] }
let(:section) { Form::Section.new(section_id, section_definition, form) }
let(:subsection_id) { "household_characteristics" }
let(:subsection_definition) { section_definition["subsections"][subsection_id] }
let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") }
before do
RequestHelper.stub_http_requests
allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form)
end
it "has an id" do
expect(subsection.id).to eq(subsection_id)
end
it "has a label" do
expect(subsection.label).to eq("Household characteristics")
end
it "has pages" do
expected_pages = %w[tenant_code_test person_1_age person_1_gender person_1_working_situation household_number_of_members retirement_value_check person_2_working_situation propcode]
expect(subsection.pages.map(&:id)).to eq(expected_pages)
end
it "has questions" do
expected_questions = %w[tenancycode age1 sex1 ecstat1 hhmemb relat2 age2 sex2 retirement_value_check ecstat2 propcode]
expect(subsection.questions.map(&:id)).to eq(expected_questions)
end
context "with an in progress lettings log" do
let(:lettings_log) { FactoryBot.build(:lettings_log, :in_progress) }
it "has a status" do
expect(subsection.status(lettings_log)).to eq(:in_progress)
end
it "has a completed status for completed subsection" do
subsection_definition = section_definition["subsections"]["household_needs"]
subsection = described_class.new("household_needs", subsection_definition, section)
lettings_log.armedforces = 3
lettings_log.illness = 1
lettings_log.housingneeds_a = 1
lettings_log.la = "E06000014"
lettings_log.illness_type_1 = 1
expect(subsection.status(lettings_log)).to eq(:completed)
end
it "has status helpers" do
expect(subsection.is_incomplete?(lettings_log)).to be(true)
expect(subsection.is_started?(lettings_log)).to be(true)
end
context "with optional fields" do
subject(:subsection) { described_class.new(subsection_id, subsection_definition, section) }
let(:section_id) { "tenancy_and_property" }
let(:section_definition) { form.form_definition["sections"][section_id] }
let(:section) { Form::Section.new(section_id, section_definition, form) }
let(:subsection_id) { "property_information" }
let(:subsection_definition) { section_definition["subsections"][subsection_id] }
it "has a started status even if only an optional field has been answered" do
lettings_log.postcode_known = 0
expect(subsection.is_started?(lettings_log)).to be(true)
end
end
it "has question helpers for the number of applicable questions" do
expected_questions = %w[tenancycode age1 sex1 ecstat1 hhmemb relat2 age2 sex2 ecstat2 propcode]
expect(subsection.applicable_questions(lettings_log).map(&:id)).to eq(expected_questions)
end
end
context "with a completed lettings log" do
let(:lettings_log) { FactoryBot.build(:lettings_log, :completed) }
it "has a status" do
expect(subsection.status(lettings_log)).to eq(:completed)
end
it "has a status when optional fields are not filled" do
lettings_log.update!({ propcode: nil })
lettings_log.reload
expect(subsection.status(lettings_log)).to eq(:completed)
end
it "has status helpers" do
expect(subsection.is_incomplete?(lettings_log)).to be(false)
expect(subsection.is_started?(lettings_log)).to be(true)
end
end
end