Browse Source

CLDC-3308: Enforce that the declaration has been answered before moving onto other sections in lettings logs (#2314)

pull/2318/head
Rachael Booth 9 months ago committed by GitHub
parent
commit
bb5621ed76
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 9
      app/models/lettings_log.rb
  2. 40
      spec/models/lettings_log_spec.rb

9
app/models/lettings_log.rb

@ -581,7 +581,14 @@ class LettingsLog < Log
end
def non_location_setup_questions_completed?
[needstype, renewal, rent_type, startdate, owning_organisation_id, created_by_id].all?(&:present?)
form.setup_sections.all? do |section|
section.subsections.all? do |subsection|
relevant_qs = subsection.applicable_questions(self).reject { |q| optional_fields.include?(q.id) || %w[scheme_id location].include?(q.id) }
relevant_qs.all? do |question|
question.completed?(self)
end
end
end
end
def resolve!

40
spec/models/lettings_log_spec.rb

@ -3507,5 +3507,45 @@ RSpec.describe LettingsLog do
end
end
end
describe "#non_location_setup_questions_completed" do
before do
Timecop.return
allow(FormHandler.instance).to receive(:current_lettings_form).and_call_original
Singleton.__init__(FormHandler)
end
context "when setup section has been completed" do
let(:lettings_log) { build(:lettings_log, :setup_completed) }
it "returns true" do
expect(lettings_log).to be_non_location_setup_questions_completed
end
end
context "when the declaration has not been completed for a 2024 log" do
let(:lettings_log) { build(:lettings_log, :setup_completed, startdate: Time.utc(2024, 10, 1), declaration: nil) }
it "returns false" do
expect(lettings_log).not_to be_non_location_setup_questions_completed
end
end
context "when an optional question has not been completed" do
let(:lettings_log) { build(:lettings_log, :setup_completed, propcode: nil) }
it "returns true" do
expect(lettings_log).to be_non_location_setup_questions_completed
end
end
context "when scheme and location have not been completed" do
let(:lettings_log) { build(:lettings_log, :setup_completed, :sh, scheme_id: nil, location: nil) }
it "returns true" do
expect(lettings_log).to be_non_location_setup_questions_completed
end
end
end
end
# rubocop:enable RSpec/MessageChain

Loading…
Cancel
Save