Browse Source

Use subsection copy key (#2792)

* CLDC-3766: Ensure copy for Q78 is found correctly

* Fix tests

* Use subsection copy key in defaults and remove explit keys that are now defaults

* Replace other uses of subsection.id interpolation in copy keys

* Test copy key when specified on subsection

* Update tests

* Update privacy notice page tests

* More test fixes
pull/2805/head
Rachael Booth 2 months ago committed by GitHub
parent
commit
542565ed85
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      app/models/form/page.rb
  2. 2
      app/models/form/question.rb
  3. 2
      app/models/form/sales/pages/buyer_interview.rb
  4. 1
      app/models/form/sales/pages/deposit.rb
  5. 1
      app/models/form/sales/pages/deposit_discount.rb
  6. 1
      app/models/form/sales/pages/discount.rb
  7. 1
      app/models/form/sales/pages/equity.rb
  8. 1
      app/models/form/sales/pages/extra_borrowing.rb
  9. 1
      app/models/form/sales/pages/grant.rb
  10. 1
      app/models/form/sales/pages/monthly_rent.rb
  11. 1
      app/models/form/sales/pages/mortgage_amount.rb
  12. 1
      app/models/form/sales/pages/mortgage_lender.rb
  13. 1
      app/models/form/sales/pages/mortgage_lender_other.rb
  14. 1
      app/models/form/sales/pages/mortgage_length.rb
  15. 1
      app/models/form/sales/pages/mortgageused.rb
  16. 1
      app/models/form/sales/pages/previous_bedrooms.rb
  17. 1
      app/models/form/sales/pages/previous_property_type.rb
  18. 1
      app/models/form/sales/pages/previous_tenure.rb
  19. 2
      app/models/form/sales/pages/privacy_notice.rb
  20. 1
      app/models/form/sales/pages/resale.rb
  21. 2
      app/models/form/sales/pages/staircase.rb
  22. 1
      app/models/form/sales/pages/value_shared_ownership.rb
  23. 2
      app/models/form/sales/questions/buyer_interview.rb
  24. 1
      app/models/form/sales/questions/deposit_amount.rb
  25. 1
      app/models/form/sales/questions/deposit_discount.rb
  26. 1
      app/models/form/sales/questions/discount.rb
  27. 1
      app/models/form/sales/questions/equity.rb
  28. 1
      app/models/form/sales/questions/extra_borrowing.rb
  29. 1
      app/models/form/sales/questions/fromprop.rb
  30. 1
      app/models/form/sales/questions/grant.rb
  31. 1
      app/models/form/sales/questions/monthly_rent.rb
  32. 1
      app/models/form/sales/questions/mortgage_amount.rb
  33. 1
      app/models/form/sales/questions/mortgage_lender.rb
  34. 1
      app/models/form/sales/questions/mortgage_lender_other.rb
  35. 1
      app/models/form/sales/questions/mortgage_length.rb
  36. 1
      app/models/form/sales/questions/mortgageused.rb
  37. 1
      app/models/form/sales/questions/previous_bedrooms.rb
  38. 1
      app/models/form/sales/questions/previous_tenure.rb
  39. 2
      app/models/form/sales/questions/privacy_notice.rb
  40. 1
      app/models/form/sales/questions/resale.rb
  41. 1
      app/models/form/sales/questions/value.rb
  42. 1
      app/models/form/sales/subsections/discounted_ownership_scheme.rb
  43. 1
      app/models/form/sales/subsections/outright_sale.rb
  44. 4
      spec/models/form/lettings/questions/homeless_spec.rb
  45. 4
      spec/models/form/page_spec.rb
  46. 4
      spec/models/form/question_spec.rb
  47. 42
      spec/models/form/sales/pages/buyer_interview_spec.rb
  48. 34
      spec/models/form/sales/pages/privacy_notice_spec.rb
  49. 37
      spec/models/form/sales/questions/buyer_interview_spec.rb
  50. 4
      spec/models/form/sales/questions/privacy_notice_spec.rb
  51. 4
      spec/models/form/sales/questions/uprn_confirmation_spec.rb
  52. 4
      spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb
  53. 4
      spec/models/form/sales/subsections/outright_sale_spec.rb
  54. 4
      spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb
  55. 4
      spec/models/form/subsection_spec.rb

2
app/models/form/page.rb

@ -25,7 +25,7 @@ class Form::Page
delegate :form, to: :subsection
def copy_key
@copy_key ||= "#{form.type}.#{subsection.id}.#{questions[0].id}"
@copy_key ||= "#{form.type}.#{subsection.copy_key}.#{questions[0].id}"
end
def header

2
app/models/form/question.rb

@ -51,7 +51,7 @@ class Form::Question
delegate :form, to: :subsection
def copy_key
@copy_key ||= "#{form.type}.#{subsection.id}.#{id}"
@copy_key ||= "#{form.type}.#{subsection.copy_key}.#{id}"
end
def check_answer_label

2
app/models/form/sales/pages/buyer_interview.rb

@ -2,7 +2,7 @@ class Form::Sales::Pages::BuyerInterview < ::Form::Page
def initialize(id, hsh, subsection, joint_purchase:)
super(id, hsh, subsection)
@joint_purchase = joint_purchase
@copy_key = "sales.#{subsection.id}.noint.#{joint_purchase ? 'joint_purchase' : 'not_joint_purchase'}"
@copy_key = "sales.#{subsection.copy_key}.noint.#{joint_purchase ? 'joint_purchase' : 'not_joint_purchase'}"
end
def questions

1
app/models/form/sales/pages/deposit.rb

@ -3,7 +3,6 @@ class Form::Sales::Pages::Deposit < ::Form::Page
super(id, hsh, subsection)
@ownershipsch = ownershipsch
@optional = optional
@copy_key = "sales.sale_information.deposit"
end
def questions

1
app/models/form/sales/pages/deposit_discount.rb

@ -2,7 +2,6 @@ class Form::Sales::Pages::DepositDiscount < ::Form::Page
def initialize(id, hsh, subsection, optional:)
super(id, hsh, subsection)
@optional = optional
@copy_key = "sales.sale_information.cashdis"
end
def questions

1
app/models/form/sales/pages/discount.rb

@ -2,7 +2,6 @@ class Form::Sales::Pages::Discount < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "discount"
@copy_key = "sales.sale_information.discount"
@depends_on = [{
"right_to_buy?" => true,
}]

1
app/models/form/sales/pages/equity.rb

@ -2,7 +2,6 @@ class Form::Sales::Pages::Equity < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "equity"
@copy_key = "sales.sale_information.equity"
end
def questions

1
app/models/form/sales/pages/extra_borrowing.rb

@ -2,7 +2,6 @@ class Form::Sales::Pages::ExtraBorrowing < ::Form::Page
def initialize(id, hsh, subsection, ownershipsch:)
super(id, hsh, subsection)
@ownershipsch = ownershipsch
@copy_key = "sales.sale_information.extrabor"
@description = ""
@subsection = subsection
@depends_on = [{

1
app/models/form/sales/pages/grant.rb

@ -2,7 +2,6 @@ class Form::Sales::Pages::Grant < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "grant"
@copy_key = "sales.sale_information.grant"
@depends_on = [{
"right_to_buy?" => false,
"rent_to_buy_full_ownership?" => false,

1
app/models/form/sales/pages/monthly_rent.rb

@ -2,7 +2,6 @@ class Form::Sales::Pages::MonthlyRent < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "monthly_rent"
@copy_key = "sales.sale_information.mrent"
end
def questions

1
app/models/form/sales/pages/mortgage_amount.rb

@ -2,7 +2,6 @@ class Form::Sales::Pages::MortgageAmount < ::Form::Page
def initialize(id, hsh, subsection, ownershipsch:)
super(id, hsh, subsection)
@ownershipsch = ownershipsch
@copy_key = "sales.sale_information.mortgage"
@depends_on = [{ "mortgage_used?" => true }]
end

1
app/models/form/sales/pages/mortgage_lender.rb

@ -2,7 +2,6 @@ class Form::Sales::Pages::MortgageLender < ::Form::Page
def initialize(id, hsh, subsection, ownershipsch:)
super(id, hsh, subsection)
@ownershipsch = ownershipsch
@copy_key = "sales.sale_information.mortgagelender"
@description = ""
@subsection = subsection
@depends_on = [{

1
app/models/form/sales/pages/mortgage_lender_other.rb

@ -2,7 +2,6 @@ class Form::Sales::Pages::MortgageLenderOther < ::Form::Page
def initialize(id, hsh, subsection, ownershipsch:)
super(id, hsh, subsection)
@ownershipsch = ownershipsch
@copy_key = "sales.sale_information.mortgagelenderother"
@description = ""
@subsection = subsection
@depends_on = [{

1
app/models/form/sales/pages/mortgage_length.rb

@ -2,7 +2,6 @@ class Form::Sales::Pages::MortgageLength < ::Form::Page
def initialize(id, hsh, subsection, ownershipsch:)
super(id, hsh, subsection)
@ownershipsch = ownershipsch
@copy_key = "sales.sale_information.mortlen"
@depends_on = [{
"mortgageused" => 1,
}]

1
app/models/form/sales/pages/mortgageused.rb

@ -1,7 +1,6 @@
class Form::Sales::Pages::Mortgageused < ::Form::Page
def initialize(id, hsh, subsection, ownershipsch:)
super(id, hsh, subsection)
@copy_key = "sales.sale_information.mortgageused"
@ownershipsch = ownershipsch
end

1
app/models/form/sales/pages/previous_bedrooms.rb

@ -2,7 +2,6 @@ class Form::Sales::Pages::PreviousBedrooms < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "previous_bedrooms"
@copy_key = "sales.sale_information.frombeds"
@depends_on = [
{
"soctenant" => 1,

1
app/models/form/sales/pages/previous_property_type.rb

@ -2,7 +2,6 @@ class Form::Sales::Pages::PreviousPropertyType < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "previous_property_type"
@copy_key = "sales.sale_information.fromprop"
@description = ""
@subsection = subsection
@depends_on = [

1
app/models/form/sales/pages/previous_tenure.rb

@ -2,7 +2,6 @@ class Form::Sales::Pages::PreviousTenure < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "shared_ownership_previous_tenure"
@copy_key = "sales.sale_information.socprevten"
@header = ""
@description = ""
@subsection = subsection

2
app/models/form/sales/pages/privacy_notice.rb

@ -1,7 +1,7 @@
class Form::Sales::Pages::PrivacyNotice < ::Form::Page
def initialize(id, hsh, subsection, joint_purchase:)
super(id, hsh, subsection)
@copy_key = "sales.#{subsection.id}.privacynotice.#{joint_purchase ? 'joint_purchase' : 'not_joint_purchase'}"
@copy_key = "sales.#{subsection.copy_key}.privacynotice.#{joint_purchase ? 'joint_purchase' : 'not_joint_purchase'}"
@joint_purchase = joint_purchase
end

1
app/models/form/sales/pages/resale.rb

@ -2,7 +2,6 @@ class Form::Sales::Pages::Resale < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "resale"
@copy_key = "sales.sale_information.resale"
@depends_on = [
{
"staircase" => 2,

2
app/models/form/sales/pages/staircase.rb

@ -3,7 +3,7 @@ class Form::Sales::Pages::Staircase < ::Form::Page
super
@id = "staircasing"
@depends_on = [{ "ownershipsch" => 1 }]
@copy_key = "sales.#{subsection.id}.staircasing"
@copy_key = "sales.#{subsection.copy_key}.staircasing"
end
def questions

1
app/models/form/sales/pages/value_shared_ownership.rb

@ -2,7 +2,6 @@ class Form::Sales::Pages::ValueSharedOwnership < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "value_shared_ownership"
@copy_key = "sales.sale_information.value"
end
def questions

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

@ -2,7 +2,7 @@ class Form::Sales::Questions::BuyerInterview < ::Form::Question
def initialize(id, hsh, page, joint_purchase:)
super(id, hsh, page)
@id = "noint"
@copy_key = "sales.#{subsection.id}.noint.#{joint_purchase ? 'joint_purchase' : 'not_joint_purchase'}"
@copy_key = "sales.#{subsection.copy_key}.noint.#{joint_purchase ? 'joint_purchase' : 'not_joint_purchase'}"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max]

1
app/models/form/sales/questions/deposit_amount.rb

@ -2,7 +2,6 @@ class Form::Sales::Questions::DepositAmount < ::Form::Question
def initialize(id, hsh, subsection, ownershipsch:, optional:)
super(id, hsh, subsection)
@id = "deposit"
@copy_key = "sales.sale_information.deposit"
@type = "numeric"
@min = 0
@max = 999_999

1
app/models/form/sales/questions/deposit_discount.rb

@ -2,7 +2,6 @@ class Form::Sales::Questions::DepositDiscount < ::Form::Question
def initialize(id, hsh, page)
super
@id = "cashdis"
@copy_key = "sales.sale_information.cashdis"
@type = "numeric"
@min = 0
@max = 999_999

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

@ -3,7 +3,6 @@ class Form::Sales::Questions::Discount < ::Form::Question
super
@id = "discount"
@type = "numeric"
@copy_key = "sales.sale_information.discount"
@min = 0
@max = form.start_year_2024_or_later? ? 70 : 100
@step = 0.1

1
app/models/form/sales/questions/equity.rb

@ -2,7 +2,6 @@ class Form::Sales::Questions::Equity < ::Form::Question
def initialize(id, hsh, page)
super
@id = "equity"
@copy_key = "sales.sale_information.equity"
@type = "numeric"
@min = 0
@max = 100

1
app/models/form/sales/questions/extra_borrowing.rb

@ -2,7 +2,6 @@ class Form::Sales::Questions::ExtraBorrowing < ::Form::Question
def initialize(id, hsh, subsection, ownershipsch:)
super(id, hsh, subsection)
@id = "extrabor"
@copy_key = "sales.sale_information.extrabor"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page

1
app/models/form/sales/questions/fromprop.rb

@ -2,7 +2,6 @@ class Form::Sales::Questions::Fromprop < ::Form::Question
def initialize(id, hsh, page)
super
@id = "fromprop"
@copy_key = "sales.sale_information.fromprop"
@type = "radio"
@page = page
@answer_options = ANSWER_OPTIONS

1
app/models/form/sales/questions/grant.rb

@ -2,7 +2,6 @@ class Form::Sales::Questions::Grant < ::Form::Question
def initialize(id, hsh, page)
super
@id = "grant"
@copy_key = "sales.sale_information.grant"
@type = "numeric"
@min = 0
@max = 999_999

1
app/models/form/sales/questions/monthly_rent.rb

@ -2,7 +2,6 @@ class Form::Sales::Questions::MonthlyRent < ::Form::Question
def initialize(id, hsh, page)
super
@id = "mrent"
@copy_key = "sales.sale_information.mrent"
@type = "numeric"
@min = 0
@step = 0.01

1
app/models/form/sales/questions/mortgage_amount.rb

@ -2,7 +2,6 @@ class Form::Sales::Questions::MortgageAmount < ::Form::Question
def initialize(id, hsh, subsection, ownershipsch:)
super(id, hsh, subsection)
@id = "mortgage"
@copy_key = "sales.sale_information.mortgage"
@type = "numeric"
@min = 1
@step = 1

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

@ -2,7 +2,6 @@ class Form::Sales::Questions::MortgageLender < ::Form::Question
def initialize(id, hsh, subsection, ownershipsch:)
super(id, hsh, subsection)
@id = "mortgagelender"
@copy_key = "sales.sale_information.mortgagelender"
@type = "select"
@page = page
@bottom_guidance_partial = "mortgage_lender"

1
app/models/form/sales/questions/mortgage_lender_other.rb

@ -2,7 +2,6 @@ class Form::Sales::Questions::MortgageLenderOther < ::Form::Question
def initialize(id, hsh, subsection, ownershipsch:)
super(id, hsh, subsection)
@id = "mortgagelenderother"
@copy_key = "sales.sale_information.mortgagelenderother"
@type = "text"
@page = page
@ownershipsch = ownershipsch

1
app/models/form/sales/questions/mortgage_length.rb

@ -2,7 +2,6 @@ class Form::Sales::Questions::MortgageLength < ::Form::Question
def initialize(id, hsh, subsection, ownershipsch:)
super(id, hsh, subsection)
@id = "mortlen"
@copy_key = "sales.sale_information.mortlen"
@type = "numeric"
@min = 0
@max = 60

1
app/models/form/sales/questions/mortgageused.rb

@ -2,7 +2,6 @@ class Form::Sales::Questions::Mortgageused < ::Form::Question
def initialize(id, hsh, subsection, ownershipsch:)
super(id, hsh, subsection)
@id = "mortgageused"
@copy_key = "sales.sale_information.mortgageused"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@ownershipsch = ownershipsch

1
app/models/form/sales/questions/previous_bedrooms.rb

@ -2,7 +2,6 @@ class Form::Sales::Questions::PreviousBedrooms < ::Form::Question
def initialize(id, hsh, page)
super
@id = "frombeds"
@copy_key = "sales.sale_information.frombeds"
@type = "numeric"
@width = 5
@min = 1

1
app/models/form/sales/questions/previous_tenure.rb

@ -2,7 +2,6 @@ class Form::Sales::Questions::PreviousTenure < ::Form::Question
def initialize(id, hsh, page)
super
@id = "socprevten"
@copy_key = "sales.sale_information.socprevten"
@type = "radio"
@page = page
@answer_options = ANSWER_OPTIONS

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

@ -2,7 +2,7 @@ class Form::Sales::Questions::PrivacyNotice < ::Form::Question
def initialize(id, hsh, page, joint_purchase:)
super(id, hsh, page)
@id = "privacynotice"
@copy_key = "sales.#{subsection.id}.privacynotice.#{joint_purchase ? 'joint_purchase' : 'not_joint_purchase'}"
@copy_key = "sales.#{subsection.copy_key}.privacynotice.#{joint_purchase ? 'joint_purchase' : 'not_joint_purchase'}"
@type = "checkbox"
@question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max]
@joint_purchase = joint_purchase

1
app/models/form/sales/questions/resale.rb

@ -2,7 +2,6 @@ class Form::Sales::Questions::Resale < ::Form::Question
def initialize(id, hsh, page)
super
@id = "resale"
@copy_key = "sales.sale_information.resale"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max]

1
app/models/form/sales/questions/value.rb

@ -2,7 +2,6 @@ class Form::Sales::Questions::Value < ::Form::Question
def initialize(id, hsh, page)
super
@id = "value"
@copy_key = "sales.sale_information.value"
@type = "numeric"
@min = 0
@step = 1

1
app/models/form/sales/subsections/discounted_ownership_scheme.rb

@ -4,6 +4,7 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection
@id = "discounted_ownership_scheme"
@label = "Discounted ownership scheme"
@depends_on = [{ "ownershipsch" => 2, "setup_completed?" => true }]
@copy_key = "sale_information"
end
def pages

1
app/models/form/sales/subsections/outright_sale.rb

@ -4,6 +4,7 @@ class Form::Sales::Subsections::OutrightSale < ::Form::Subsection
@id = "outright_sale"
@label = "Outright sale"
@depends_on = [{ "ownershipsch" => 3, "setup_completed?" => true }]
@copy_key = "sale_information"
end
def pages

4
spec/models/form/lettings/questions/homeless_spec.rb

@ -28,10 +28,6 @@ RSpec.describe Form::Lettings::Questions::Homeless, type: :model do
})
end
it "has no hint text" do
expect(question.hint_text).to be_empty
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(0)
end

4
spec/models/form/page_spec.rb

@ -9,7 +9,7 @@ RSpec.describe Form::Page, type: :model do
let(:enabled) { true }
let(:depends_on_met) { true }
let(:form) { instance_double(Form, depends_on_met:, type: "form-type", start_date: Time.utc(2024, 12, 25)) }
let(:subsection) { instance_double(Form::Subsection, depends_on:, enabled?: enabled, form:, id: "subsection-id") }
let(:subsection) { instance_double(Form::Subsection, depends_on:, enabled?: enabled, form:, id: "subsection-id", copy_key: "subsection-copy-key") }
let(:page_id) { "net_income" }
let(:questions) { [["earnings", { "conditional_for" => { "age1": nil }, "type" => "radio" }], %w[incfreq]] }
let(:page_definition) do
@ -25,7 +25,7 @@ RSpec.describe Form::Page, type: :model do
end
it "sets copy_key in the default style" do
expect(page.copy_key).to eq("#{form.type}.#{subsection.id}.#{questions[0][0]}")
expect(page.copy_key).to eq("#{form.type}.#{subsection.copy_key}.#{questions[0][0]}")
end
context "when header is not provided" do

4
spec/models/form/question_spec.rb

@ -15,7 +15,7 @@ RSpec.describe Form::Question, type: :model do
let(:inferred_check_answers_value) { [{ "condition" => { "postcode_known" => 0 }, "value" => "Weekly" }] }
let(:form) { instance_double(Form, depends_on_met:, conditional_question_conditions:, type: "form-type", start_date: Time.utc(2024, 12, 25)) }
let(:subsection) { instance_double(Form::Subsection, form:, id: "subsection-id") }
let(:subsection) { instance_double(Form::Subsection, form:, id: "subsection-id", copy_key: "subsection-copy-key") }
let(:page) { instance_double(Form::Page, subsection:, routed_to?: true, questions: form_questions) }
let(:question_id) { "earnings" }
let(:question_definition) do
@ -39,7 +39,7 @@ RSpec.describe Form::Question, type: :model do
end
it "sets copy_key in the default style" do
expect(question.copy_key).to eq("#{form.type}.#{subsection.id}.#{question_id}")
expect(question.copy_key).to eq("#{form.type}.#{subsection.copy_key}.#{question_id}")
end
context "when copy is not provided" do

42
spec/models/form/sales/pages/buyer_interview_spec.rb

@ -6,7 +6,7 @@ RSpec.describe Form::Sales::Pages::BuyerInterview, type: :model do
let(:page_id) { "buyer_interview" }
let(:page_definition) { nil }
let(:form) { instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2024_or_later?: false) }
let(:subsection) { instance_double(Form::Subsection, form:, id: "setup") }
let(:subsection) { instance_double(Form::Subsection, form:, id: "setup", copy_key: "subsection_copy_key") }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
@ -24,43 +24,23 @@ RSpec.describe Form::Sales::Pages::BuyerInterview, type: :model do
expect(page.description).to be_nil
end
context "when form is before 2024" do
let(:subsection) { instance_double(Form::Subsection, form:, id: "household_characteristics") }
context "when there are joint buyers" do
subject(:page) { described_class.new(page_id, page_definition, subsection, joint_purchase: true) }
context "when there are joint buyers" do
subject(:page) { described_class.new(page_id, page_definition, subsection, joint_purchase: true) }
let(:subsection) { instance_double(Form::Subsection, form:, copy_key: "subsection_copy_key") }
it "has the expected copy_key" do
expect(page.copy_key).to eq("sales.household_characteristics.noint.joint_purchase")
end
end
context "when there is a single buyer" do
subject(:page) { described_class.new(page_id, page_definition, subsection, joint_purchase: false) }
it "has the expected copy_key" do
expect(page.copy_key).to eq("sales.household_characteristics.noint.not_joint_purchase")
end
it "has the expected copy_key" do
expect(page.copy_key).to eq("sales.subsection_copy_key.noint.joint_purchase")
end
end
context "when form is after 2024" do
let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1), start_year_2024_or_later?: true) }
context "when there are joint buyers" do
subject(:page) { described_class.new(page_id, page_definition, subsection, joint_purchase: true) }
it "has the expected copy_key" do
expect(page.copy_key).to eq("sales.setup.noint.joint_purchase")
end
end
context "when there is a single buyer" do
subject(:page) { described_class.new(page_id, page_definition, subsection, joint_purchase: false) }
context "when there is a single buyer" do
subject(:page) { described_class.new(page_id, page_definition, subsection, joint_purchase: false) }
let(:subsection) { instance_double(Form::Subsection, form:, copy_key: "subsection_copy_key") }
it "has the expected copy_key" do
expect(page.copy_key).to eq("sales.setup.noint.not_joint_purchase")
end
it "has the expected copy_key" do
expect(page.copy_key).to eq("sales.subsection_copy_key.noint.not_joint_purchase")
end
end
end

34
spec/models/form/sales/pages/privacy_notice_spec.rb

@ -5,7 +5,7 @@ RSpec.describe Form::Sales::Pages::PrivacyNotice, type: :model do
let(:page_id) { "privacy_notice" }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection, id: "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), start_year_2024_or_later?: false) }
before do
@ -31,20 +31,10 @@ RSpec.describe Form::Sales::Pages::PrivacyNotice, type: :model do
context "when there are joint buyers" do
subject(:page) { described_class.new(page_id, page_definition, subsection, joint_purchase: true) }
context "when the form start year is before 2024" do
let(:subsection) { instance_double(Form::Subsection, id: "household_characteristics") }
let(:subsection) { instance_double(Form::Subsection, id: "subsection_id", copy_key: "subsection_copy_key") }
it "has the expected copy_key" do
expect(page.copy_key).to eq("sales.household_characteristics.privacynotice.joint_purchase")
end
end
context "when the form start year is after 2024" do
let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1), start_year_2024_or_later?: true) }
it "has the expected copy_key" do
expect(page.copy_key).to eq("sales.setup.privacynotice.joint_purchase")
end
it "has the expected copy_key" do
expect(page.copy_key).to eq("sales.subsection_copy_key.privacynotice.joint_purchase")
end
it "has correct depends_on" do
@ -55,20 +45,10 @@ RSpec.describe Form::Sales::Pages::PrivacyNotice, type: :model do
context "when there is a single buyer" do
subject(:page) { described_class.new(page_id, page_definition, subsection, joint_purchase: false) }
context "when the form start year is before 2024" do
let(:subsection) { instance_double(Form::Subsection, id: "household_characteristics") }
it "has the expected copy_key" do
expect(page.copy_key).to eq("sales.household_characteristics.privacynotice.not_joint_purchase")
end
end
context "when the form start year is after 2024" do
let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1), start_year_2024_or_later?: true) }
let(:subsection) { instance_double(Form::Subsection, id: "subsection_id", copy_key: "subsection_copy_key") }
it "has the expected copy_key" do
expect(page.copy_key).to eq("sales.setup.privacynotice.not_joint_purchase")
end
it "has the expected copy_key" do
expect(page.copy_key).to eq("sales.subsection_copy_key.privacynotice.not_joint_purchase")
end
it "has correct depends_on" do

37
spec/models/form/sales/questions/buyer_interview_spec.rb

@ -6,7 +6,8 @@ RSpec.describe Form::Sales::Questions::BuyerInterview, type: :model do
let(:question_id) { nil }
let(:question_definition) { nil }
let(:form) { instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2024_or_later?: true) }
let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form:, id: "setup")) }
let(:subsection) { instance_double(Form::Subsection, form:, copy_key: "setup") }
let(:page) { instance_double(Form::Page, subsection:) }
it "has correct page" do
expect(question.page).to eq(page)
@ -34,42 +35,20 @@ RSpec.describe Form::Sales::Questions::BuyerInterview, type: :model do
context "when there are joint buyers" do
subject(:question) { described_class.new(question_id, question_definition, page, joint_purchase: true) }
context "when the form start year is before 2024" do
let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form:, id: "household_characteristics")) }
let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 3, 1), start_year_2024_or_later?: false) }
let(:subsection) { instance_double(Form::Subsection, form:, copy_key: "subsection_copy_key") }
it "has the expected copy_key" do
expect(question.copy_key).to eq("sales.household_characteristics.noint.joint_purchase")
end
end
context "when the form start year is after 2024" do
let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1), start_year_2024_or_later?: true) }
it "has the expected copy_key" do
expect(question.copy_key).to eq("sales.setup.noint.joint_purchase")
end
it "has the expected copy_key" do
expect(question.copy_key).to eq("sales.subsection_copy_key.noint.joint_purchase")
end
end
context "when there is a single buyer" do
subject(:question) { described_class.new(question_id, question_definition, page, joint_purchase: false) }
context "when the form start year is before 2024" do
let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form:, id: "household_characteristics")) }
let(:form) { instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2024_or_later?: false) }
it "has the expected copy_key" do
expect(question.copy_key).to eq("sales.household_characteristics.noint.not_joint_purchase")
end
end
context "when the form start year is after 2024" do
let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1), start_year_2024_or_later?: true) }
let(:subsection) { instance_double(Form::Subsection, form:, copy_key: "subsection_copy_key") }
it "has the expected copy_key" do
expect(question.copy_key).to eq("sales.setup.noint.not_joint_purchase")
end
it "has the expected copy_key" do
expect(question.copy_key).to eq("sales.subsection_copy_key.noint.not_joint_purchase")
end
end
end

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

@ -6,7 +6,7 @@ RSpec.describe Form::Sales::Questions::PrivacyNotice, type: :model do
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
let(:subsection) { instance_double(Form::Subsection, id: "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)) }
before do
@ -32,7 +32,7 @@ RSpec.describe Form::Sales::Questions::PrivacyNotice, type: :model do
end
context "when the form year is before 2024" do
let(:subsection) { instance_double(Form::Subsection, id: "household_characteristics") }
let(:subsection) { instance_double(Form::Subsection, id: "household_characteristics", copy_key: "household_characteristics") }
before do
allow(form).to receive(:start_year_2024_or_later?).and_return(false)

4
spec/models/form/sales/questions/uprn_confirmation_spec.rb

@ -25,10 +25,6 @@ RSpec.describe Form::Sales::Questions::UprnConfirmation, type: :model do
expect(question.derived?(nil)).to be false
end
it "has the correct unanswered_error_message" do
expect(question.unanswered_error_message).to eq("You must answer #{format_ending(I18n.t('forms.2023.sales.property_information.uprn_confirmed.check_answer_label'))}")
end
describe "notification_banner" do
context "when address is not present" do
it "returns nil" do

4
spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb

@ -56,6 +56,10 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
expect(discounted_ownership_scheme.id).to eq("discounted_ownership_scheme")
end
it "has the correct copy key" do
expect(discounted_ownership_scheme.copy_key).to eq("sale_information")
end
it "has the correct label" do
expect(discounted_ownership_scheme.label).to eq("Discounted ownership scheme")
end

4
spec/models/form/sales/subsections/outright_sale_spec.rb

@ -109,6 +109,10 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do
expect(outright_sale.id).to eq("outright_sale")
end
it "has the correct copy key" do
expect(outright_sale.copy_key).to eq("sale_information")
end
it "has the correct label" do
expect(outright_sale.label).to eq("Outright sale")
end

4
spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb

@ -65,6 +65,10 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do
expect(shared_ownership_scheme.id).to eq("shared_ownership_scheme")
end
it "has the correct copy key" do
expect(shared_ownership_scheme.copy_key).to eq("sale_information")
end
it "has the correct label" do
expect(shared_ownership_scheme.label).to eq("Shared ownership scheme")
end

4
spec/models/form/subsection_spec.rb

@ -19,6 +19,10 @@ RSpec.describe Form::Subsection, type: :model do
expect(subsection.id).to eq(subsection_id)
end
it "has a copy_key defaulting to the id" do
expect(subsection.copy_key).to eq(subsection_id)
end
it "has a label" do
expect(subsection.label).to eq("Household characteristics")
end

Loading…
Cancel
Save