Browse Source

CLDC-4402: simplify p4

CLDC-4402-audit-start-year-2024-or-later-usage-2
Rebecca Jesson 3 weeks ago
parent
commit
37769cf330
  1. 23
      app/models/form/sales/questions/buyer1_ethnic_background_white.rb
  2. 23
      app/models/form/sales/questions/buyer2_ethnic_background_white.rb
  3. 21
      app/models/form/sales/questions/buyer2_relationship_to_buyer1.rb
  4. 2
      app/models/form/sales/questions/discount.rb
  5. 7
      app/models/form/sales/questions/mortgage_lender.rb
  6. 8
      app/models/form/sales/questions/ownership_scheme.rb
  7. 21
      app/models/form/sales/questions/person_relationship_to_buyer_1.rb
  8. 12
      app/models/form/sales/questions/privacy_notice.rb
  9. 15
      app/models/form/sales/questions/uprn_confirmation.rb
  10. 2
      config/locales/en.yml
  11. 38
      spec/models/form/sales/questions/buyer1_ethnic_background_white_spec.rb
  12. 38
      spec/models/form/sales/questions/buyer2_ethnic_background_white_spec.rb
  13. 6
      spec/models/form/sales/questions/buyer2_relationship_to_buyer1_spec.rb
  14. 16
      spec/models/form/sales/questions/discount_spec.rb
  15. 292
      spec/models/form/sales/questions/mortgage_lender_spec.rb
  16. 19
      spec/models/form/sales/questions/ownership_scheme_spec.rb
  17. 6
      spec/models/form/sales/questions/person_relationship_to_buyer1_spec.rb
  18. 113
      spec/models/form/sales/questions/privacy_notice_spec.rb

23
app/models/form/sales/questions/buyer1_ethnic_background_white.rb

@ -9,22 +9,13 @@ class Form::Sales::Questions::Buyer1EthnicBackgroundWhite < ::Form::Question
end end
def answer_options def answer_options
if form.start_year_2024_or_later? {
{ "1" => { "value" => "English, Welsh, Northern Irish, Scottish or British" },
"1" => { "value" => "English, Welsh, Northern Irish, Scottish or British" }, "2" => { "value" => "Irish" },
"2" => { "value" => "Irish" }, "18" => { "value" => "Gypsy or Irish Traveller" },
"18" => { "value" => "Gypsy or Irish Traveller" }, "20" => { "value" => "Roma" },
"20" => { "value" => "Roma" }, "3" => { "value" => "Any other White background" },
"3" => { "value" => "Any other White background" }, }.freeze
}.freeze
else
{
"1" => { "value" => "English, Welsh, Northern Irish, Scottish or British" },
"2" => { "value" => "Irish" },
"18" => { "value" => "Gypsy or Irish Traveller" },
"3" => { "value" => "Any other White background" },
}.freeze
end
end end
QUESTION_NUMBER_FROM_YEAR = { 2023 => 23, 2024 => 25, 2025 => 23, 2026 => 25 }.freeze QUESTION_NUMBER_FROM_YEAR = { 2023 => 23, 2024 => 25, 2025 => 23, 2026 => 25 }.freeze

23
app/models/form/sales/questions/buyer2_ethnic_background_white.rb

@ -9,22 +9,13 @@ class Form::Sales::Questions::Buyer2EthnicBackgroundWhite < ::Form::Question
end end
def answer_options def answer_options
if form.start_year_2024_or_later? {
{ "1" => { "value" => "English, Welsh, Northern Irish, Scottish or British" },
"1" => { "value" => "English, Welsh, Northern Irish, Scottish or British" }, "2" => { "value" => "Irish" },
"2" => { "value" => "Irish" }, "18" => { "value" => "Gypsy or Irish Traveller" },
"18" => { "value" => "Gypsy or Irish Traveller" }, "20" => { "value" => "Roma" },
"20" => { "value" => "Roma" }, "3" => { "value" => "Any other White background" },
"3" => { "value" => "Any other White background" }, }.freeze
}.freeze
else
{
"1" => { "value" => "English, Welsh, Northern Irish, Scottish or British" },
"2" => { "value" => "Irish" },
"18" => { "value" => "Gypsy or Irish Traveller" },
"3" => { "value" => "Any other White background" },
}.freeze
end
end end
QUESTION_NUMBER_FROM_YEAR = { 2023 => 31, 2024 => 33, 2025 => 31, 2026 => 34 }.freeze QUESTION_NUMBER_FROM_YEAR = { 2023 => 31, 2024 => 33, 2025 => 31, 2026 => 34 }.freeze

21
app/models/form/sales/questions/buyer2_relationship_to_buyer1.rb

@ -16,21 +16,12 @@ class Form::Sales::Questions::Buyer2RelationshipToBuyer1 < ::Form::Question
end end
def answer_options def answer_options
if form.start_year_2024_or_later? {
{ "P" => { "value" => "Partner" },
"P" => { "value" => "Partner" }, "C" => { "value" => "Child" },
"C" => { "value" => "Child" }, "X" => { "value" => "Other" },
"X" => { "value" => "Other" }, "R" => { "value" => "Buyer prefers not to say" },
"R" => { "value" => "Buyer prefers not to say" }, }
}
else
{
"P" => { "value" => "Partner" },
"C" => { "value" => "Child", "hint" => "Must be eligible for child benefit, aged under 16 or under 20 if still in full-time education." },
"X" => { "value" => "Other" },
"R" => { "value" => "Buyer prefers not to say" },
}
end
end end
QUESTION_NUMBER_FROM_YEAR = { 2023 => 27, 2024 => 29, 2025 => 27, 2026 => 29 }.freeze QUESTION_NUMBER_FROM_YEAR = { 2023 => 27, 2024 => 29, 2025 => 27, 2026 => 29 }.freeze

2
app/models/form/sales/questions/discount.rb

@ -4,7 +4,7 @@ class Form::Sales::Questions::Discount < ::Form::Question
@id = "discount" @id = "discount"
@type = "numeric" @type = "numeric"
@min = 0 @min = 0
@max = form.start_year_2024_or_later? ? 70 : 100 @max = 70
@step = 0.1 @step = 0.1
@width = 5 @width = 5
@suffix = "%" @suffix = "%"

7
app/models/form/sales/questions/mortgage_lender.rb

@ -55,15 +55,10 @@ class Form::Sales::Questions::MortgageLender < ::Form::Question
"0" => "Don’t know", "0" => "Don’t know",
}.freeze }.freeze
OPTIONS_INTRODUCED_2024 = %w[41].freeze
OPTIONS_NOT_DISPLAYED = %w[0].freeze OPTIONS_NOT_DISPLAYED = %w[0].freeze
def answer_options def answer_options
if form.start_year_2024_or_later? ANSWER_OPTIONS
ANSWER_OPTIONS
else
ANSWER_OPTIONS.dup.reject { |k, _v| OPTIONS_INTRODUCED_2024.include?(k) }
end
end end
def displayed_answer_options(_log, _user = nil) def displayed_answer_options(_log, _user = nil)

8
app/models/form/sales/questions/ownership_scheme.rb

@ -12,15 +12,9 @@ class Form::Sales::Questions::OwnershipScheme < ::Form::Question
"1" => { "value" => "Shared Ownership", "hint" => "When the purchaser buys an initial share of up to 75% of the property value and pays rent to the Private Registered Provider (PRP) on the remaining portion, or a subsequent staircasing transaction" }, "1" => { "value" => "Shared Ownership", "hint" => "When the purchaser buys an initial share of up to 75% of the property value and pays rent to the Private Registered Provider (PRP) on the remaining portion, or a subsequent staircasing transaction" },
"2" => { "value" => "Discounted Ownership" }, "2" => { "value" => "Discounted Ownership" },
}.freeze }.freeze
elsif form.start_year_2024_or_later?
{
"1" => { "value" => "Yes - a shared ownership scheme", "hint" => "When the purchaser buys an initial share of up to 75% of the property value and pays rent to the Private Registered Provider (PRP) on the remaining portion, or a subsequent staircasing transaction" },
"2" => { "value" => "Yes - a discounted ownership scheme" },
"3" => { "value" => "No - this is an outright or other sale" },
}.freeze
else else
{ {
"1" => { "value" => "Yes - a shared ownership scheme" }, "1" => { "value" => "Yes - a shared ownership scheme", "hint" => "When the purchaser buys an initial share of up to 75% of the property value and pays rent to the Private Registered Provider (PRP) on the remaining portion, or a subsequent staircasing transaction" },
"2" => { "value" => "Yes - a discounted ownership scheme" }, "2" => { "value" => "Yes - a discounted ownership scheme" },
"3" => { "value" => "No - this is an outright or other sale" }, "3" => { "value" => "No - this is an outright or other sale" },
}.freeze }.freeze

21
app/models/form/sales/questions/person_relationship_to_buyer_1.rb

@ -16,21 +16,12 @@ class Form::Sales::Questions::PersonRelationshipToBuyer1 < ::Form::Question
end end
def answer_options def answer_options
if form.start_year_2024_or_later? {
{ "P" => { "value" => "Partner" },
"P" => { "value" => "Partner" }, "C" => { "value" => "Child" },
"C" => { "value" => "Child" }, "X" => { "value" => "Other" },
"X" => { "value" => "Other" }, "R" => { "value" => "Person prefers not to say" },
"R" => { "value" => "Person prefers not to say" }, }
}
else
{
"P" => { "value" => "Partner" },
"C" => { "value" => "Child", "hint" => "Must be eligible for child benefit, aged under 16 or under 20 if still in full-time education." },
"X" => { "value" => "Other" },
"R" => { "value" => "Person prefers not to say" },
}
end
end end
def question_number def question_number

12
app/models/form/sales/questions/privacy_notice.rb

@ -10,22 +10,14 @@ class Form::Sales::Questions::PrivacyNotice < ::Form::Question
end end
def answer_options def answer_options
declaration_text = if form.start_year_2024_or_later? declaration_text = "The #{@joint_purchase ? 'buyers have' : 'buyer has'} seen or been given access to the MHCLG privacy notice"
"The #{@joint_purchase ? 'buyers have' : 'buyer has'} seen or been given access to the MHCLG privacy notice"
else
"The #{@joint_purchase ? 'buyers have' : 'buyer has'} seen the MHCLG privacy notice"
end
{ "privacynotice" => { "value" => declaration_text } }.freeze { "privacynotice" => { "value" => declaration_text } }.freeze
end end
def unanswered_error_message(_log = nil) def unanswered_error_message(_log = nil)
buyer_or_buyers = @joint_purchase ? "buyers" : "buyer" buyer_or_buyers = @joint_purchase ? "buyers" : "buyer"
if form.start_year_2024_or_later? I18n.t("validations.privacynotice.missing.post_2024", buyer_or_buyers:)
I18n.t("validations.privacynotice.missing.post_2024", buyer_or_buyers:)
else
I18n.t("validations.privacynotice.missing.pre_2024", buyer_or_buyers:)
end
end end
def guidance def guidance

15
app/models/form/sales/questions/uprn_confirmation.rb

@ -6,17 +6,10 @@ class Form::Sales::Questions::UprnConfirmation < ::Form::Question
end end
def answer_options def answer_options
if form.start_year_2024_or_later? {
{ "1" => { "value" => "Yes" },
"1" => { "value" => "Yes" }, "0" => { "value" => "No, I want to search for the address instead" },
"0" => { "value" => "No, I want to search for the address instead" }, }.freeze
}.freeze
else
{
"1" => { "value" => "Yes" },
"0" => { "value" => "No, I want to enter the address manually" },
}.freeze
end
end end
def notification_banner(log = nil) def notification_banner(log = nil)

2
config/locales/en.yml

@ -341,12 +341,10 @@ en:
declaration: declaration:
missing: missing:
pre_2024: "You must show the MHCLG privacy notice to the tenant before you can submit this log."
post_2024: "You must show or give the tenant access to the MHCLG privacy notice before you can submit this log." post_2024: "You must show or give the tenant access to the MHCLG privacy notice before you can submit this log."
privacynotice: privacynotice:
missing: missing:
pre_2024: "You must show the MHCLG privacy notice to the %{buyer_or_buyers} before you can submit this log."
post_2024: "You must show or give the %{buyer_or_buyers} access to the MHCLG privacy notice before you can submit this log." post_2024: "You must show or give the %{buyer_or_buyers} access to the MHCLG privacy notice before you can submit this log."
scheme: scheme:

38
spec/models/form/sales/questions/buyer1_ethnic_background_white_spec.rb

@ -1,16 +1,17 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Questions::Buyer1EthnicBackgroundWhite, type: :model do RSpec.describe Form::Sales::Questions::Buyer1EthnicBackgroundWhite, type: :model do
include CollectionTimeHelper
subject(:question) { described_class.new(question_id, question_definition, page) } subject(:question) { described_class.new(question_id, question_definition, page) }
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(:subsection) { instance_double(Form::Subsection) }
let(:form) { instance_double(Form, start_date: Time.zone.local(2023, 4, 1)) } let(:form) { instance_double(Form, start_date: current_collection_start_date) }
before do before do
allow(form).to receive(:start_year_2024_or_later?).and_return(false)
allow(page).to receive(:subsection).and_return(subsection) allow(page).to receive(:subsection).and_return(subsection)
allow(subsection).to receive(:form).and_return(form) allow(subsection).to receive(:form).and_return(form)
end end
@ -31,31 +32,14 @@ RSpec.describe Form::Sales::Questions::Buyer1EthnicBackgroundWhite, type: :model
expect(question.derived?(nil)).to be false expect(question.derived?(nil)).to be false
end end
context "with 2023/24 form" do it "has the correct answer_options" do
it "has the correct answer_options" do expect(question.answer_options).to eq({
expect(question.answer_options).to eq({ "1" => { "value" => "English, Welsh, Northern Irish, Scottish or British" },
"1" => { "value" => "English, Welsh, Northern Irish, Scottish or British" }, "2" => { "value" => "Irish" },
"2" => { "value" => "Irish" }, "18" => { "value" => "Gypsy or Irish Traveller" },
"18" => { "value" => "Gypsy or Irish Traveller" }, "20" => { "value" => "Roma" },
"3" => { "value" => "Any other White background" }, "3" => { "value" => "Any other White background" },
}) })
end
end
context "with 2024/25 form" do
before do
allow(form).to receive(:start_year_2024_or_later?).and_return(true)
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"1" => { "value" => "English, Welsh, Northern Irish, Scottish or British" },
"2" => { "value" => "Irish" },
"18" => { "value" => "Gypsy or Irish Traveller" },
"20" => { "value" => "Roma" },
"3" => { "value" => "Any other White background" },
})
end
end end
it "has the correct check_answers_card_number" do it "has the correct check_answers_card_number" do

38
spec/models/form/sales/questions/buyer2_ethnic_background_white_spec.rb

@ -1,16 +1,17 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Questions::Buyer2EthnicBackgroundWhite, type: :model do RSpec.describe Form::Sales::Questions::Buyer2EthnicBackgroundWhite, type: :model do
include CollectionTimeHelper
subject(:question) { described_class.new(question_id, question_definition, page) } subject(:question) { described_class.new(question_id, question_definition, page) }
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(:subsection) { instance_double(Form::Subsection) }
let(:form) { instance_double(Form, start_date: Time.zone.local(2023, 4, 1)) } let(:form) { instance_double(Form, start_date: current_collection_start_date) }
before do before do
allow(form).to receive(:start_year_2024_or_later?).and_return(false)
allow(page).to receive(:subsection).and_return(subsection) allow(page).to receive(:subsection).and_return(subsection)
allow(subsection).to receive(:form).and_return(form) allow(subsection).to receive(:form).and_return(form)
end end
@ -31,30 +32,13 @@ RSpec.describe Form::Sales::Questions::Buyer2EthnicBackgroundWhite, type: :model
expect(question.derived?(nil)).to be false expect(question.derived?(nil)).to be false
end end
context "with 2023/24 form" do it "has the correct answer_options" do
it "has the correct answer_options" do expect(question.answer_options).to eq({
expect(question.answer_options).to eq({ "1" => { "value" => "English, Welsh, Northern Irish, Scottish or British" },
"1" => { "value" => "English, Welsh, Northern Irish, Scottish or British" }, "2" => { "value" => "Irish" },
"2" => { "value" => "Irish" }, "18" => { "value" => "Gypsy or Irish Traveller" },
"18" => { "value" => "Gypsy or Irish Traveller" }, "20" => { "value" => "Roma" },
"3" => { "value" => "Any other White background" }, "3" => { "value" => "Any other White background" },
}) })
end
end
context "with 2024/25 form" do
before do
allow(form).to receive(:start_year_2024_or_later?).and_return(true)
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"1" => { "value" => "English, Welsh, Northern Irish, Scottish or British" },
"2" => { "value" => "Irish" },
"18" => { "value" => "Gypsy or Irish Traveller" },
"20" => { "value" => "Roma" },
"3" => { "value" => "Any other White background" },
})
end
end end
end end

6
spec/models/form/sales/questions/buyer2_relationship_to_buyer1_spec.rb

@ -1,11 +1,13 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Questions::Buyer2RelationshipToBuyer1, type: :model do RSpec.describe Form::Sales::Questions::Buyer2RelationshipToBuyer1, type: :model do
include CollectionTimeHelper
subject(:question) { described_class.new(question_id, question_definition, page) } subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil } let(:question_id) { nil }
let(:question_definition) { nil } let(:question_definition) { nil }
let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2024_or_later?: false))) } let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: current_collection_start_date))) }
it "has correct page" do it "has correct page" do
expect(question.page).to eq(page) expect(question.page).to eq(page)
@ -26,7 +28,7 @@ RSpec.describe Form::Sales::Questions::Buyer2RelationshipToBuyer1, type: :model
it "has the correct answer_options" do it "has the correct answer_options" do
expect(question.answer_options).to eq({ expect(question.answer_options).to eq({
"P" => { "value" => "Partner" }, "P" => { "value" => "Partner" },
"C" => { "value" => "Child", "hint" => "Must be eligible for child benefit, aged under 16 or under 20 if still in full-time education." }, "C" => { "value" => "Child" },
"X" => { "value" => "Other" }, "X" => { "value" => "Other" },
"R" => { "value" => "Buyer prefers not to say" }, "R" => { "value" => "Buyer prefers not to say" },
}) })

16
spec/models/form/sales/questions/discount_spec.rb

@ -1,6 +1,8 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Questions::Discount, type: :model do RSpec.describe Form::Sales::Questions::Discount, type: :model do
include CollectionTimeHelper
subject(:question) { described_class.new(question_id, question_definition, page) } subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil } let(:question_id) { nil }
@ -10,7 +12,7 @@ RSpec.describe Form::Sales::Questions::Discount, type: :model do
before do before do
allow(page).to receive(:subsection).and_return(subsection) allow(page).to receive(:subsection).and_return(subsection)
allow(subsection).to receive(:form).and_return(instance_double(Form, start_year_2024_or_later?: false, start_date: Time.zone.local(2023, 4, 1))) allow(subsection).to receive(:form).and_return(instance_double(Form, start_date: current_collection_start_date))
end end
it "has correct page" do it "has correct page" do
@ -42,16 +44,6 @@ RSpec.describe Form::Sales::Questions::Discount, type: :model do
end end
it "has correct max" do it "has correct max" do
expect(question.max).to eq(100) expect(question.max).to eq(70)
end
context "with form start year after 2024" do
before do
allow(subsection).to receive(:form).and_return(instance_double(Form, start_year_2024_or_later?: true, start_date: Time.zone.local(2024, 4, 1)))
end
it "has correct max" do
expect(question.max).to eq(70)
end
end end
end end

292
spec/models/form/sales/questions/mortgage_lender_spec.rb

@ -1,16 +1,17 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Questions::MortgageLender, type: :model do RSpec.describe Form::Sales::Questions::MortgageLender, type: :model do
include CollectionTimeHelper
subject(:question) { described_class.new(question_id, question_definition, page, ownershipsch: 1) } subject(:question) { described_class.new(question_id, question_definition, page, ownershipsch: 1) }
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(:subsection) { instance_double(Form::Subsection) }
let(:form) { instance_double(Form, start_date: Time.zone.local(2023, 4, 1)) } let(:form) { instance_double(Form, start_date: current_collection_start_date) }
before do before do
allow(form).to receive(:start_year_2024_or_later?)
allow(page).to receive(:subsection).and_return(subsection) allow(page).to receive(:subsection).and_return(subsection)
allow(subsection).to receive(:form).and_return(form) allow(subsection).to receive(:form).and_return(form)
end end
@ -44,203 +45,98 @@ RSpec.describe Form::Sales::Questions::MortgageLender, type: :model do
expect(question.top_guidance_partial).to be_nil expect(question.top_guidance_partial).to be_nil
end end
context "when form year is before 2024" do it "has the correct answer_options" do
before do expect(question.answer_options).to eq({
allow(form).to receive(:start_year_2024_or_later?).and_return(false) "" => "Select an option",
end "0" => "Don’t know",
"1" => "Atom Bank",
it "has the correct answer_options" do "2" => "Barclays Bank PLC",
expect(question.answer_options).to eq({ "3" => "Bath Building Society",
"" => "Select an option", "4" => "Buckinghamshire Building Society",
"0" => "Don’t know", "5" => "Cambridge Building Society",
"1" => "Atom Bank", "6" => "Coventry Building Society",
"2" => "Barclays Bank PLC", "7" => "Cumberland Building Society",
"3" => "Bath Building Society", "8" => "Darlington Building Society",
"4" => "Buckinghamshire Building Society", "9" => "Dudley Building Society",
"5" => "Cambridge Building Society", "10" => "Ecology Building Society",
"6" => "Coventry Building Society", "11" => "Halifax",
"7" => "Cumberland Building Society", "12" => "Hanley Economic Building Society",
"8" => "Darlington Building Society", "13" => "Hinckley and Rugby Building Society",
"9" => "Dudley Building Society", "14" => "Holmesdale Building Society",
"10" => "Ecology Building Society", "15" => "Ipswich Building Society",
"11" => "Halifax", "16" => "Leeds Building Society",
"12" => "Hanley Economic Building Society", "17" => "Lloyds Bank",
"13" => "Hinckley and Rugby Building Society", "18" => "Mansfield Building Society",
"14" => "Holmesdale Building Society", "19" => "Market Harborough Building Society",
"15" => "Ipswich Building Society", "20" => "Melton Mowbray Building Society",
"16" => "Leeds Building Society", "21" => "Nationwide Building Society",
"17" => "Lloyds Bank", "22" => "Natwest",
"18" => "Mansfield Building Society", "23" => "Nedbank Private Wealth",
"19" => "Market Harborough Building Society", "24" => "Newbury Building Society",
"20" => "Melton Mowbray Building Society", "25" => "OneSavings Bank",
"21" => "Nationwide Building Society", "26" => "Parity Trust",
"22" => "Natwest", "27" => "Penrith Building Society",
"23" => "Nedbank Private Wealth", "28" => "Pepper Homeloans",
"24" => "Newbury Building Society", "29" => "Royal Bank of Scotland",
"25" => "OneSavings Bank", "30" => "Santander",
"26" => "Parity Trust", "31" => "Skipton Building Society",
"27" => "Penrith Building Society", "32" => "Teachers Building Society",
"28" => "Pepper Homeloans", "33" => "The Co-operative Bank",
"29" => "Royal Bank of Scotland", "34" => "Tipton & Coseley Building Society",
"30" => "Santander", "35" => "TSB",
"31" => "Skipton Building Society", "36" => "Ulster Bank",
"32" => "Teachers Building Society", "37" => "Virgin Money",
"33" => "The Co-operative Bank", "38" => "West Bromwich Building Society",
"34" => "Tipton & Coseley Building Society", "39" => "Yorkshire Building Society",
"35" => "TSB", "41" => "Kent Reliance",
"36" => "Ulster Bank", "40" => "Other",
"37" => "Virgin Money", })
"38" => "West Bromwich Building Society",
"39" => "Yorkshire Building Society",
"40" => "Other",
})
end
it "has the correct displayed_answer_options" do
expect(question.displayed_answer_options(nil, nil)).to eq({
"" => "Select an option",
"1" => "Atom Bank",
"2" => "Barclays Bank PLC",
"3" => "Bath Building Society",
"4" => "Buckinghamshire Building Society",
"5" => "Cambridge Building Society",
"6" => "Coventry Building Society",
"7" => "Cumberland Building Society",
"8" => "Darlington Building Society",
"9" => "Dudley Building Society",
"10" => "Ecology Building Society",
"11" => "Halifax",
"12" => "Hanley Economic Building Society",
"13" => "Hinckley and Rugby Building Society",
"14" => "Holmesdale Building Society",
"15" => "Ipswich Building Society",
"16" => "Leeds Building Society",
"17" => "Lloyds Bank",
"18" => "Mansfield Building Society",
"19" => "Market Harborough Building Society",
"20" => "Melton Mowbray Building Society",
"21" => "Nationwide Building Society",
"22" => "Natwest",
"23" => "Nedbank Private Wealth",
"24" => "Newbury Building Society",
"25" => "OneSavings Bank",
"26" => "Parity Trust",
"27" => "Penrith Building Society",
"28" => "Pepper Homeloans",
"29" => "Royal Bank of Scotland",
"30" => "Santander",
"31" => "Skipton Building Society",
"32" => "Teachers Building Society",
"33" => "The Co-operative Bank",
"34" => "Tipton & Coseley Building Society",
"35" => "TSB",
"36" => "Ulster Bank",
"37" => "Virgin Money",
"38" => "West Bromwich Building Society",
"39" => "Yorkshire Building Society",
"40" => "Other",
})
end
end end
context "when form year is >= 2024" do it "has the correct displayed_answer_options" do
before do expect(question.displayed_answer_options(nil, nil)).to eq({
allow(form).to receive(:start_year_2024_or_later?).and_return(true) "" => "Select an option",
end "1" => "Atom Bank",
"2" => "Barclays Bank PLC",
it "has the correct answer_options" do "3" => "Bath Building Society",
expect(question.answer_options).to eq({ "4" => "Buckinghamshire Building Society",
"" => "Select an option", "5" => "Cambridge Building Society",
"0" => "Don’t know", "6" => "Coventry Building Society",
"1" => "Atom Bank", "7" => "Cumberland Building Society",
"2" => "Barclays Bank PLC", "8" => "Darlington Building Society",
"3" => "Bath Building Society", "9" => "Dudley Building Society",
"4" => "Buckinghamshire Building Society", "10" => "Ecology Building Society",
"5" => "Cambridge Building Society", "11" => "Halifax",
"6" => "Coventry Building Society", "12" => "Hanley Economic Building Society",
"7" => "Cumberland Building Society", "13" => "Hinckley and Rugby Building Society",
"8" => "Darlington Building Society", "14" => "Holmesdale Building Society",
"9" => "Dudley Building Society", "15" => "Ipswich Building Society",
"10" => "Ecology Building Society", "16" => "Leeds Building Society",
"11" => "Halifax", "17" => "Lloyds Bank",
"12" => "Hanley Economic Building Society", "18" => "Mansfield Building Society",
"13" => "Hinckley and Rugby Building Society", "19" => "Market Harborough Building Society",
"14" => "Holmesdale Building Society", "20" => "Melton Mowbray Building Society",
"15" => "Ipswich Building Society", "21" => "Nationwide Building Society",
"16" => "Leeds Building Society", "22" => "Natwest",
"17" => "Lloyds Bank", "23" => "Nedbank Private Wealth",
"18" => "Mansfield Building Society", "24" => "Newbury Building Society",
"19" => "Market Harborough Building Society", "25" => "OneSavings Bank",
"20" => "Melton Mowbray Building Society", "26" => "Parity Trust",
"21" => "Nationwide Building Society", "27" => "Penrith Building Society",
"22" => "Natwest", "28" => "Pepper Homeloans",
"23" => "Nedbank Private Wealth", "29" => "Royal Bank of Scotland",
"24" => "Newbury Building Society", "30" => "Santander",
"25" => "OneSavings Bank", "31" => "Skipton Building Society",
"26" => "Parity Trust", "32" => "Teachers Building Society",
"27" => "Penrith Building Society", "33" => "The Co-operative Bank",
"28" => "Pepper Homeloans", "34" => "Tipton & Coseley Building Society",
"29" => "Royal Bank of Scotland", "35" => "TSB",
"30" => "Santander", "36" => "Ulster Bank",
"31" => "Skipton Building Society", "37" => "Virgin Money",
"32" => "Teachers Building Society", "38" => "West Bromwich Building Society",
"33" => "The Co-operative Bank", "39" => "Yorkshire Building Society",
"34" => "Tipton & Coseley Building Society", "41" => "Kent Reliance",
"35" => "TSB", "40" => "Other",
"36" => "Ulster Bank", })
"37" => "Virgin Money",
"38" => "West Bromwich Building Society",
"39" => "Yorkshire Building Society",
"41" => "Kent Reliance",
"40" => "Other",
})
end
it "has the correct displayed_answer_options" do
expect(question.displayed_answer_options(nil, nil)).to eq({
"" => "Select an option",
"1" => "Atom Bank",
"2" => "Barclays Bank PLC",
"3" => "Bath Building Society",
"4" => "Buckinghamshire Building Society",
"5" => "Cambridge Building Society",
"6" => "Coventry Building Society",
"7" => "Cumberland Building Society",
"8" => "Darlington Building Society",
"9" => "Dudley Building Society",
"10" => "Ecology Building Society",
"11" => "Halifax",
"12" => "Hanley Economic Building Society",
"13" => "Hinckley and Rugby Building Society",
"14" => "Holmesdale Building Society",
"15" => "Ipswich Building Society",
"16" => "Leeds Building Society",
"17" => "Lloyds Bank",
"18" => "Mansfield Building Society",
"19" => "Market Harborough Building Society",
"20" => "Melton Mowbray Building Society",
"21" => "Nationwide Building Society",
"22" => "Natwest",
"23" => "Nedbank Private Wealth",
"24" => "Newbury Building Society",
"25" => "OneSavings Bank",
"26" => "Parity Trust",
"27" => "Penrith Building Society",
"28" => "Pepper Homeloans",
"29" => "Royal Bank of Scotland",
"30" => "Santander",
"31" => "Skipton Building Society",
"32" => "Teachers Building Society",
"33" => "The Co-operative Bank",
"34" => "Tipton & Coseley Building Society",
"35" => "TSB",
"36" => "Ulster Bank",
"37" => "Virgin Money",
"38" => "West Bromwich Building Society",
"39" => "Yorkshire Building Society",
"41" => "Kent Reliance",
"40" => "Other",
})
end
end end
end end

19
spec/models/form/sales/questions/ownership_scheme_spec.rb

@ -1,16 +1,17 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Questions::OwnershipScheme, type: :model do RSpec.describe Form::Sales::Questions::OwnershipScheme, type: :model do
include CollectionTimeHelper
subject(:question) { described_class.new(question_id, question_definition, page) } subject(:question) { described_class.new(question_id, question_definition, page) }
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(:subsection) { instance_double(Form::Subsection) }
let(:form) { instance_double(Form, start_date: Time.zone.local(2023, 4, 1)) } let(:form) { instance_double(Form, start_date: current_collection_start_date) }
before do before do
allow(form).to receive_messages(start_year_2024_or_later?: false, start_year_2025_or_later?: false)
allow(page).to receive(:subsection).and_return(subsection) allow(page).to receive(:subsection).and_return(subsection)
allow(subsection).to receive(:form).and_return(form) allow(subsection).to receive(:form).and_return(form)
end end
@ -31,17 +32,9 @@ RSpec.describe Form::Sales::Questions::OwnershipScheme, type: :model do
expect(question.derived?(nil)).to be false expect(question.derived?(nil)).to be false
end end
it "has the correct answer_options" do context "with collection year before 2025" do
expect(question.answer_options).to eq({
"1" => { "value" => "Yes - a shared ownership scheme" },
"2" => { "value" => "Yes - a discounted ownership scheme" },
"3" => { "value" => "No - this is an outright or other sale" },
})
end
context "with collection year in 2024" do
before do before do
allow(form).to receive(:start_year_2024_or_later?).and_return(true) allow(form).to receive_messages(start_year_2025_or_later?: false)
end end
it "has the correct answer_options" do it "has the correct answer_options" do
@ -55,7 +48,7 @@ RSpec.describe Form::Sales::Questions::OwnershipScheme, type: :model do
context "with collection year on or after 2025" do context "with collection year on or after 2025" do
before do before do
allow(form).to receive_messages(start_year_2024_or_later?: true, start_year_2025_or_later?: true) allow(form).to receive_messages(start_year_2025_or_later?: true)
end end
it "has the correct answer_options" do it "has the correct answer_options" do

6
spec/models/form/sales/questions/person_relationship_to_buyer1_spec.rb

@ -1,11 +1,13 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Questions::PersonRelationshipToBuyer1, type: :model do RSpec.describe Form::Sales::Questions::PersonRelationshipToBuyer1, type: :model do
include CollectionTimeHelper
subject(:question) { described_class.new(question_id, question_definition, page, person_index:) } subject(:question) { described_class.new(question_id, question_definition, page, person_index:) }
let(:question_id) { "relat2" } let(:question_id) { "relat2" }
let(:question_definition) { nil } let(:question_definition) { nil }
let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2024_or_later?: false, person_question_count: 4))) } let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: current_collection_start_date, person_question_count: 4))) }
let(:person_index) { 2 } let(:person_index) { 2 }
it "has correct page" do it "has correct page" do
@ -27,7 +29,7 @@ RSpec.describe Form::Sales::Questions::PersonRelationshipToBuyer1, type: :model
it "has the correct answer_options" do it "has the correct answer_options" do
expect(question.answer_options).to eq({ expect(question.answer_options).to eq({
"P" => { "value" => "Partner" }, "P" => { "value" => "Partner" },
"C" => { "value" => "Child", "hint" => "Must be eligible for child benefit, aged under 16 or under 20 if still in full-time education." }, "C" => { "value" => "Child" },
"X" => { "value" => "Other" }, "X" => { "value" => "Other" },
"R" => { "value" => "Person prefers not to say" }, "R" => { "value" => "Person prefers not to say" },
}) })

113
spec/models/form/sales/questions/privacy_notice_spec.rb

@ -1,16 +1,17 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Questions::PrivacyNotice, type: :model do RSpec.describe Form::Sales::Questions::PrivacyNotice, type: :model do
include CollectionTimeHelper
subject(:question) { described_class.new(question_id, question_definition, page, joint_purchase: false) } subject(:question) { described_class.new(question_id, question_definition, page, joint_purchase: false) }
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, id: "setup", copy_key: "setup") } let(:subsection) { instance_double(Form::Subsection, id: "setup", copy_key: "setup") }
let(:form) { instance_double(Form, start_date: Time.zone.local(2023, 4, 1)) } let(:form) { instance_double(Form, start_date: current_collection_start_date) }
before do before do
allow(form).to receive(:start_year_2024_or_later?)
allow(page).to receive(:subsection).and_return(subsection) allow(page).to receive(:subsection).and_return(subsection)
allow(subsection).to receive(:form).and_return(form) allow(subsection).to receive(:form).and_return(form)
end end
@ -31,101 +32,45 @@ RSpec.describe Form::Sales::Questions::PrivacyNotice, type: :model do
expect(question.derived?(nil)).to be false expect(question.derived?(nil)).to be false
end end
context "when the form year is before 2024" do context "and there is a single buyer" do
let(:subsection) { instance_double(Form::Subsection, id: "household_characteristics", copy_key: "household_characteristics") } it "has the correct answer_options" do
expect(question.answer_options).to eq({
before do "privacynotice" => { "value" => "The buyer has seen or been given access to the MHCLG privacy notice" },
allow(form).to receive(:start_year_2024_or_later?).and_return(false) })
end end
context "and there is a single buyer" do it "uses the expected top guidance partial" do
it "has the correct answer_options" do expect(question.top_guidance_partial).to eq("privacy_notice_buyer")
expect(question.answer_options).to eq({
"privacynotice" => { "value" => "The buyer has seen the MHCLG privacy notice" },
})
end
it "uses the expected top guidance partial" do
expect(question.top_guidance_partial).to eq("privacy_notice_buyer")
end
it "returns correct unanswered_error_message" do
expect(question.unanswered_error_message).to eq("You must show the MHCLG privacy notice to the buyer before you can submit this log.")
end
it "has the expected copy_key" do
expect(question.copy_key).to eq("sales.household_characteristics.privacynotice.not_joint_purchase")
end
end end
context "and there are joint buyers" do it "returns correct unanswered_error_message" do
subject(:question) { described_class.new(question_id, question_definition, page, joint_purchase: true) } expect(question.unanswered_error_message).to eq("You must show or give the buyer access to the MHCLG privacy notice before you can submit this log.")
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"privacynotice" => { "value" => "The buyers have seen the MHCLG privacy notice" },
})
end
it "uses the expected top guidance partial" do
expect(question.top_guidance_partial).to eq("privacy_notice_buyer_joint_purchase")
end
it "returns correct unanswered_error_message" do
expect(question.unanswered_error_message).to eq("You must show the MHCLG privacy notice to the buyers before you can submit this log.")
end
it "has the expected copy_key" do
expect(question.copy_key).to eq("sales.household_characteristics.privacynotice.joint_purchase")
end
end end
end
context "when the form year is >= 2024" do it "has the expected copy_key" do
before do expect(question.copy_key).to eq("sales.setup.privacynotice.not_joint_purchase")
allow(form).to receive(:start_year_2024_or_later?).and_return(true)
end end
end
context "and there is a single buyer" do context "and there are joint buyers" do
it "has the correct answer_options" do subject(:question) { described_class.new(question_id, question_definition, page, joint_purchase: true) }
expect(question.answer_options).to eq({
"privacynotice" => { "value" => "The buyer has seen or been given access to the MHCLG privacy notice" },
})
end
it "uses the expected top guidance partial" do
expect(question.top_guidance_partial).to eq("privacy_notice_buyer")
end
it "returns correct unanswered_error_message" do
expect(question.unanswered_error_message).to eq("You must show or give the buyer access to the MHCLG privacy notice before you can submit this log.")
end
it "has the expected copy_key" do it "has the correct answer_options" do
expect(question.copy_key).to eq("sales.setup.privacynotice.not_joint_purchase") expect(question.answer_options).to eq({
end "privacynotice" => { "value" => "The buyers have seen or been given access to the MHCLG privacy notice" },
})
end end
context "and there are joint buyers" do it "uses the expected top guidance partial" do
subject(:question) { described_class.new(question_id, question_definition, page, joint_purchase: true) } expect(question.top_guidance_partial).to eq("privacy_notice_buyer_joint_purchase")
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"privacynotice" => { "value" => "The buyers have seen or been given access to the MHCLG privacy notice" },
})
end
it "uses the expected top guidance partial" do
expect(question.top_guidance_partial).to eq("privacy_notice_buyer_joint_purchase")
end
it "returns correct unanswered_error_message" do it "returns correct unanswered_error_message" do
expect(question.unanswered_error_message).to eq("You must show or give the buyers access to the MHCLG privacy notice before you can submit this log.") expect(question.unanswered_error_message).to eq("You must show or give the buyers access to the MHCLG privacy notice before you can submit this log.")
end end
it "has the expected copy_key" do it "has the expected copy_key" do
expect(question.copy_key).to eq("sales.setup.privacynotice.joint_purchase") expect(question.copy_key).to eq("sales.setup.privacynotice.joint_purchase")
end
end end
end end
end end

Loading…
Cancel
Save