Browse Source

CLDC-3127 Amend renewal question wording for 2024 (#2147)

* Amend renewal question wording for 2024

* refactor and fix page tests

* Disable collection year validations on review apps

* Fix flaky test
pull/2148/head
kosiakkatrina 11 months ago committed by GitHub
parent
commit
38ecb50276
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      app/models/form.rb
  2. 23
      app/models/form/lettings/questions/renewal.rb
  3. 2
      app/models/validations/setup_validations.rb
  4. 8
      app/services/feature_toggle.rb
  5. 6
      spec/models/form/lettings/pages/renewal_spec.rb
  6. 22
      spec/models/form/lettings/questions/renewal_spec.rb
  7. 10
      spec/requests/lettings_logs_controller_spec.rb

4
app/models/form.rb

@ -323,4 +323,8 @@ class Form
def sales_or_start_year_after_2022?(type, start_year) def sales_or_start_year_after_2022?(type, start_year)
type == "sales" || (start_year && start_year.to_i > 2022) type == "sales" || (start_year && start_year.to_i > 2022)
end end
def start_year_after_2024?
start_date && start_date.year >= 2024
end
end end

23
app/models/form/lettings/questions/renewal.rb

@ -3,15 +3,32 @@ class Form::Lettings::Questions::Renewal < ::Form::Question
super super
@id = "renewal" @id = "renewal"
@check_answer_label = "Property renewal" @check_answer_label = "Property renewal"
@header = "Is this letting a renewal?" @header = header_text
@type = "radio" @type = "radio"
@answer_options = ANSWER_OPTIONS @answer_options = ANSWER_OPTIONS
@hint_text = "A renewal is a letting to the same tenant in the same property. If the property was previously being used as temporary accommodation, then answer 'no'" @hint_text = hint_text
@question_number = 4 @question_number = 4
end end
ANSWER_OPTIONS = { ANSWER_OPTIONS = {
"1" => { "value" => "Yes" }, "1" => { "value" => "Yes" },
"0" => { "value" => "No" }, "0" => { "value" => "No" },
}.freeze }
.freeze
def header_text
if form.start_year_after_2024?
"Is this letting a renewal of social housing to the same tenant in the same property?"
else
"Is this letting a renewal?"
end
end
def hint_text
if form.start_year_after_2024?
"If the property was previously being used as temporary accommodation, then answer 'no'"
else
"A renewal is a letting to the same tenant in the same property. If the property was previously being used as temporary accommodation, then answer 'no'"
end
end
end end

2
app/models/validations/setup_validations.rb

@ -3,7 +3,7 @@ module Validations::SetupValidations
include CollectionTimeHelper include CollectionTimeHelper
def validate_startdate_setup(record) def validate_startdate_setup(record)
return unless record.startdate && date_valid?("startdate", record) return unless record.startdate && date_valid?("startdate", record) && FeatureToggle.startdate_collection_window_validation_enabled?
first_collection_start_date = if record.startdate_was.present? first_collection_start_date = if record.startdate_was.present?
editable_collection_start_date editable_collection_start_date

8
app/services/feature_toggle.rb

@ -1,7 +1,11 @@
class FeatureToggle class FeatureToggle
# Disable check on preview apps to allow for testing of future forms # Disable check on preview apps to allow for testing of future forms
def self.saledate_collection_window_validation_enabled? def self.saledate_collection_window_validation_enabled?
true Rails.env.production? || Rails.env.test? || Rails.env.staging?
end
def self.startdate_collection_window_validation_enabled?
Rails.env.production? || Rails.env.test? || Rails.env.staging?
end end
def self.startdate_two_week_validation_enabled? def self.startdate_two_week_validation_enabled?
@ -9,7 +13,7 @@ class FeatureToggle
end end
def self.saledate_two_week_validation_enabled? def self.saledate_two_week_validation_enabled?
Rails.env.production? || Rails.env.test? || Rails.env.staging? || Rails.env.review? Rails.env.production? || Rails.env.test? || Rails.env.staging?
end end
def self.bulk_upload_duplicate_log_check_enabled? def self.bulk_upload_duplicate_log_check_enabled?

6
spec/models/form/lettings/pages/renewal_spec.rb

@ -6,6 +6,12 @@ RSpec.describe Form::Lettings::Pages::Renewal, type: :model do
let(:page_id) { nil } let(:page_id) { nil }
let(:page_definition) { nil } let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) } let(:subsection) { instance_double(Form::Subsection) }
let(:form) { instance_double(Form) }
before do
allow(form).to receive(:start_year_after_2024?).and_return(false)
allow(subsection).to receive(:form).and_return(form)
end
it "has correct subsection" do it "has correct subsection" do
expect(page.subsection).to eq(subsection) expect(page.subsection).to eq(subsection)

22
spec/models/form/lettings/questions/renewal_spec.rb

@ -6,6 +6,14 @@ RSpec.describe Form::Lettings::Questions::Renewal, type: :model do
let(:question_id) { nil } let(:question_id) { nil }
let(:question_definition) { nil } let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) } let(:page) { instance_double(Form::Page) }
let(:subsection) { instance_double(Form::Subsection) }
let(:form) { instance_double(Form) }
before do
allow(form).to receive(:start_year_after_2024?).and_return(false)
allow(page).to receive(:subsection).and_return(subsection)
allow(subsection).to receive(:form).and_return(form)
end
it "has correct page" do it "has correct page" do
expect(question.page).to eq(page) expect(question.page).to eq(page)
@ -41,4 +49,18 @@ RSpec.describe Form::Lettings::Questions::Renewal, type: :model do
it "is not marked as derived" do it "is not marked as derived" do
expect(question.derived?).to be false expect(question.derived?).to be false
end end
context "with collection year on or after 2024" do
before do
allow(form).to receive(:start_year_after_2024?).and_return(true)
end
it "has the correct header" do
expect(question.header).to eq("Is this letting a renewal of social housing to the same tenant in the same property?")
end
it "has the correct hint_text" do
expect(question.hint_text).to eq("If the property was previously being used as temporary accommodation, then answer 'no'")
end
end
end end

10
spec/requests/lettings_logs_controller_spec.rb

@ -546,6 +546,16 @@ RSpec.describe LettingsLogsController, type: :request do
end end
context "with bulk_upload_id filter" do context "with bulk_upload_id filter" do
before do
Timecop.freeze(2023, 4, 1)
Singleton.__init__(FormHandler)
end
after do
Timecop.unfreeze
Singleton.__init__(FormHandler)
end
context "with bulk upload that belongs to current user" do context "with bulk upload that belongs to current user" do
let(:organisation) { create(:organisation) } let(:organisation) { create(:organisation) }

Loading…
Cancel
Save