<% if applicable_questions.first.check_answers_card_number != 0 && applicable_questions.first.check_answers_card_number.present? %>
<% end %>
diff --git a/app/components/check_answers_summary_list_card_component.rb b/app/components/check_answers_summary_list_card_component.rb
index de7fe9685..246173f48 100644
--- a/app/components/check_answers_summary_list_card_component.rb
+++ b/app/components/check_answers_summary_list_card_component.rb
@@ -15,4 +15,28 @@ class CheckAnswersSummaryListCardComponent < ViewComponent::Base
def get_answer_label(question)
question.answer_label(log).presence || "You didn’t answer this question".html_safe
end
+
+ def check_answers_card_title(question)
+ if question.form.type == "lettings"
+ case question.check_answers_card_number
+ when 1
+ "Lead tenant"
+ when 2..8
+ "Person #{question.check_answers_card_number}"
+ end
+ else
+ case question.check_answers_card_number
+ when 1..number_of_buyers
+ "Buyer #{question.check_answers_card_number}"
+ when (number_of_buyers + 1)..(number_of_buyers + 4)
+ "Person #{question.check_answers_card_number - number_of_buyers}"
+ end
+ end
+ end
+
+private
+
+ def number_of_buyers
+ log[:jointpur] == 1 ? 2 : 1
+ end
end
diff --git a/app/models/form/sales/pages/buyer1_working_situation.rb b/app/models/form/sales/pages/buyer1_working_situation.rb
index caaa0e60f..bde1dba09 100644
--- a/app/models/form/sales/pages/buyer1_working_situation.rb
+++ b/app/models/form/sales/pages/buyer1_working_situation.rb
@@ -2,7 +2,7 @@ class Form::Sales::Pages::Buyer1WorkingSituation < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "buyer_1_working_situation"
- @header = "Which of these best describes buyer 1's working situation?"
+ @header = ""
@description = ""
@subsection = subsection
end
diff --git a/app/models/form/sales/pages/person.rb b/app/models/form/sales/pages/person.rb
index 66e797cfa..3cf347353 100644
--- a/app/models/form/sales/pages/person.rb
+++ b/app/models/form/sales/pages/person.rb
@@ -17,6 +17,8 @@ class Form::Sales::Pages::Person < ::Form::Page
end
def field_for_person(field, suffix = "")
+ return [field, person_display_number, suffix].join if field == "details_known_"
+
[field, @person_index, suffix].join
end
end
diff --git a/app/models/form/sales/pages/person_age.rb b/app/models/form/sales/pages/person_age.rb
index 1eea81818..f0f86a251 100644
--- a/app/models/form/sales/pages/person_age.rb
+++ b/app/models/form/sales/pages/person_age.rb
@@ -4,7 +4,7 @@ class Form::Sales::Pages::PersonAge < Form::Sales::Pages::Person
@header = ""
@description = ""
@subsection = subsection
- @depends_on = page_depends_on
+ @depends_on = [{ details_known_question_id => 1, "jointpur" => joint_purchase? ? 1 : 2 }]
end
def questions
@@ -13,10 +13,4 @@ class Form::Sales::Pages::PersonAge < Form::Sales::Pages::Person
Form::Sales::Questions::PersonAge.new(field_for_person("age"), nil, self, person_index: @person_index),
]
end
-
- def page_depends_on
- return (person_display_number..4).map { |index| { "hholdcount" => index, "jointpur" => joint_purchase? ? 1 : 2 } } if person_display_number == 1
-
- [{ details_known_question_id => 1, "jointpur" => joint_purchase? ? 1 : 2 }]
- end
end
diff --git a/app/models/form/sales/pages/person_known.rb b/app/models/form/sales/pages/person_known.rb
index 8a2d29bba..df82ff41d 100644
--- a/app/models/form/sales/pages/person_known.rb
+++ b/app/models/form/sales/pages/person_known.rb
@@ -1,11 +1,11 @@
class Form::Sales::Pages::PersonKnown < Form::Sales::Pages::Person
def initialize(id, hsh, subsection, person_index:)
super
- @header_partial = "#{id}_page"
+ @header_partial = "person_#{person_display_number}_known_page"
@header = ""
@description = ""
@subsection = subsection
- @depends_on = page_depends_on
+ @depends_on = (person_display_number..4).map { |index| { "hholdcount" => index, "jointpur" => joint_purchase? ? 1 : 2 } }
end
def questions
@@ -13,8 +13,4 @@ class Form::Sales::Pages::PersonKnown < Form::Sales::Pages::Person
Form::Sales::Questions::PersonKnown.new(field_for_person("details_known_"), nil, self, person_index: @person_index),
]
end
-
- def page_depends_on
- (@person_index..4).map { |index| { "hholdcount" => index } }
- end
end
diff --git a/app/models/form/sales/pages/person_working_situation.rb b/app/models/form/sales/pages/person_working_situation.rb
index f232f6a84..a78e90be3 100644
--- a/app/models/form/sales/pages/person_working_situation.rb
+++ b/app/models/form/sales/pages/person_working_situation.rb
@@ -4,7 +4,7 @@ class Form::Sales::Pages::PersonWorkingSituation < Form::Sales::Pages::Person
@header = ""
@description = ""
@subsection = subsection
- @depends_on = page_depends_on
+ @depends_on = [{ details_known_question_id => 1, "jointpur" => joint_purchase? ? 1 : 2 }]
end
def questions
@@ -12,10 +12,4 @@ class Form::Sales::Pages::PersonWorkingSituation < Form::Sales::Pages::Person
Form::Sales::Questions::PersonWorkingSituation.new(field_for_person("ecstat"), nil, self, person_index: @person_index),
]
end
-
- def page_depends_on
- return (person_display_number..4).map { |index| { "hholdcount" => index, "jointpur" => joint_purchase? ? 1 : 2 } } if person_display_number == 1
-
- [{ details_known_question_id => 1, "jointpur" => joint_purchase? ? 1 : 2 }]
- end
end
diff --git a/app/models/form/sales/questions/person.rb b/app/models/form/sales/questions/person.rb
index ebc280860..3c7f78214 100644
--- a/app/models/form/sales/questions/person.rb
+++ b/app/models/form/sales/questions/person.rb
@@ -13,6 +13,8 @@ class Form::Sales::Questions::Person < ::Form::Question
end
def field_for_person(field, suffix = "")
+ return [field, person_display_number, suffix].join if field == "details_known_"
+
[field, @person_index, suffix].join
end
end
diff --git a/app/models/form/sales/questions/person_known.rb b/app/models/form/sales/questions/person_known.rb
index 0c1ef09c2..487b3f6d9 100644
--- a/app/models/form/sales/questions/person_known.rb
+++ b/app/models/form/sales/questions/person_known.rb
@@ -1,8 +1,8 @@
class Form::Sales::Questions::PersonKnown < Form::Sales::Questions::Person
def initialize(id, hsh, page, person_index:)
super
- @check_answer_label = "Details known for person #{person_index}?"
- @header = "Do you know the details for person #{person_index}?"
+ @check_answer_label = "Details known for person #{person_display_number}?"
+ @header = "Do you know the details for person #{person_display_number}?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
@@ -14,7 +14,7 @@ class Form::Sales::Questions::PersonKnown < Form::Sales::Questions::Person
},
],
}
- @check_answers_card_number = person_index + 2
+ @check_answers_card_number = person_index
end
ANSWER_OPTIONS = {
diff --git a/app/models/form/sales/subsections/household_characteristics.rb b/app/models/form/sales/subsections/household_characteristics.rb
index 4eb252c52..763577ffe 100644
--- a/app/models/form/sales/subsections/household_characteristics.rb
+++ b/app/models/form/sales/subsections/household_characteristics.rb
@@ -29,7 +29,8 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Sales::Pages::Buyer2WorkingSituation.new(nil, nil, self),
Form::Sales::Pages::Buyer2LiveInProperty.new(nil, nil, self),
Form::Sales::Pages::NumberOfOthersInProperty.new(nil, nil, self),
- Form::Sales::Pages::PersonKnown.new("person_1_known", nil, self, person_index: 1),
+ Form::Sales::Pages::PersonKnown.new("person_1_known", nil, self, person_index: 2),
+ Form::Sales::Pages::PersonKnown.new("person_1_known_joint_purchase", nil, self, person_index: 3),
Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_1_relationship_to_buyer_1", nil, self, person_index: 2),
Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_1_relationship_to_buyer_1_joint_purchase", nil, self, person_index: 3),
Form::Sales::Pages::PersonAge.new("person_1_age", nil, self, person_index: 2),
@@ -38,21 +39,24 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Sales::Pages::Person1GenderIdentityJointPurchase.new(nil, nil, self),
Form::Sales::Pages::PersonWorkingSituation.new("person_1_working_situation", nil, self, person_index: 2),
Form::Sales::Pages::PersonWorkingSituation.new("person_1_working_situation_joint_purchase", nil, self, person_index: 3),
- Form::Sales::Pages::PersonKnown.new("person_2_known", nil, self, person_index: 2),
+ Form::Sales::Pages::PersonKnown.new("person_2_known", nil, self, person_index: 3),
+ Form::Sales::Pages::PersonKnown.new("person_2_known_joint_purchase", nil, self, person_index: 4),
Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_2_relationship_to_buyer_1", nil, self, person_index: 3),
Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_2_relationship_to_buyer_1_joint_purchase", nil, self, person_index: 4),
Form::Sales::Pages::PersonAge.new("person_2_age", nil, self, person_index: 3),
Form::Sales::Pages::PersonAge.new("person_2_age_joint_purchase", nil, self, person_index: 4),
Form::Sales::Pages::PersonWorkingSituation.new("person_2_working_situation", nil, self, person_index: 3),
Form::Sales::Pages::PersonWorkingSituation.new("person_2_working_situation_joint_purchase", nil, self, person_index: 4),
- Form::Sales::Pages::PersonKnown.new("person_3_known", nil, self, person_index: 3),
+ Form::Sales::Pages::PersonKnown.new("person_3_known", nil, self, person_index: 4),
+ Form::Sales::Pages::PersonKnown.new("person_3_known_joint_purchase", nil, self, person_index: 5),
Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_3_relationship_to_buyer_1", nil, self, person_index: 4),
Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_3_relationship_to_buyer_1_joint_purchase", nil, self, person_index: 5),
Form::Sales::Pages::PersonAge.new("person_3_age", nil, self, person_index: 4),
Form::Sales::Pages::PersonAge.new("person_3_age_joint_purchase", nil, self, person_index: 5),
Form::Sales::Pages::PersonWorkingSituation.new("person_3_working_situation", nil, self, person_index: 4),
Form::Sales::Pages::PersonWorkingSituation.new("person_3_working_situation_joint_purchase", nil, self, person_index: 5),
- Form::Sales::Pages::PersonKnown.new("person_4_known", nil, self, person_index: 4),
+ Form::Sales::Pages::PersonKnown.new("person_4_known", nil, self, person_index: 5),
+ Form::Sales::Pages::PersonKnown.new("person_4_known_joint_purchase", nil, self, person_index: 6),
Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_4_relationship_to_buyer_1", nil, self, person_index: 5),
Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_4_relationship_to_buyer_1_joint_purchase", nil, self, person_index: 6),
Form::Sales::Pages::PersonAge.new("person_4_age", nil, self, person_index: 5),
diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json
index ca2fa6e2e..92d495f24 100644
--- a/config/forms/2021_2022.json
+++ b/config/forms/2021_2022.json
@@ -4624,7 +4624,7 @@
}
},
"person_7_known": {
- "header": "You’ve given us the details for 7 people in the household",
+ "header": "You’ve given us the details for 6 people in the household",
"description": "",
"questions": {
"details_known_7": {
diff --git a/config/forms/2022_2023.json b/config/forms/2022_2023.json
index dd6d933a3..f49070bbf 100644
--- a/config/forms/2022_2023.json
+++ b/config/forms/2022_2023.json
@@ -4623,7 +4623,7 @@
}
},
"person_7_known": {
- "header": "You’ve given us the details for 7 people in the household",
+ "header": "You’ve given us the details for 6 people in the household",
"description": "",
"questions": {
"details_known_7": {
diff --git a/db/schema.rb b/db/schema.rb
index 30a510ab1..49f59a503 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -420,6 +420,9 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_05_103733) do
t.string "relat4"
t.string "relat5"
t.string "relat6"
+ t.integer "hb"
+ t.integer "savings_value_check"
+ t.integer "deposit_value_check"
t.integer "frombeds"
t.integer "staircase"
t.integer "stairbought"
@@ -455,9 +458,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_05_103733) do
t.integer "hhregresstill"
t.integer "proplen"
t.integer "prevten"
- t.integer "savings_value_check"
- t.integer "deposit_value_check"
- t.integer "hb"
t.integer "mortgageused"
t.integer "wchair"
t.integer "armedforcesspouse"
diff --git a/spec/features/form/check_answers_page_spec.rb b/spec/features/form/check_answers_page_lettings_logs_spec.rb
similarity index 99%
rename from spec/features/form/check_answers_page_spec.rb
rename to spec/features/form/check_answers_page_lettings_logs_spec.rb
index 7834e0dad..f8f0b8064 100644
--- a/spec/features/form/check_answers_page_spec.rb
+++ b/spec/features/form/check_answers_page_lettings_logs_spec.rb
@@ -1,7 +1,7 @@
require "rails_helper"
require_relative "helpers"
-RSpec.describe "Form Check Answers Page" do
+RSpec.describe "Lettings Log Check Answers Page" do
include Helpers
let(:user) { FactoryBot.create(:user) }
let(:subsection) { "household-characteristics" }
diff --git a/spec/features/form/check_answers_page_sales_logs_spec.rb b/spec/features/form/check_answers_page_sales_logs_spec.rb
new file mode 100644
index 000000000..9d1f33d64
--- /dev/null
+++ b/spec/features/form/check_answers_page_sales_logs_spec.rb
@@ -0,0 +1,62 @@
+require "rails_helper"
+require_relative "helpers"
+
+RSpec.describe "Sales Log Check Answers Page" do
+ include Helpers
+ let(:user) { FactoryBot.create(:user) }
+ let(:subsection) { "household-characteristics" }
+ let(:conditional_subsection) { "conditional-question" }
+
+ let(:completed_sales_log_joint_purchase) do
+ FactoryBot.create(
+ :sales_log,
+ :completed,
+ created_by: user,
+ jointpur: 1,
+ )
+ end
+
+ let(:completed_sales_log_non_joint_purchase) do
+ FactoryBot.create(
+ :sales_log,
+ :completed,
+ created_by: user,
+ jointpur: 2,
+ )
+ end
+
+ before do
+ sign_in user
+ end
+
+ context "when the user needs to check their answers for a subsection" do
+ let(:last_question_for_subsection) { "propcode" }
+
+ it "does not group questions into summary cards if the questions in the subsection don't have a check_answers_card_number attribute" do
+ visit("/sales-logs/#{completed_sales_log_joint_purchase.id}/household-needs/check-answers")
+ assert_selector ".x-govuk-summary-card__title", count: 0
+ end
+
+ context "when the user is checking their answers for the household characteristics subsection" do
+ context "and the log is for a joint purchase" do
+ it "they see a seperate summary card for each member of the household" do
+ visit("/sales-logs/#{completed_sales_log_joint_purchase.id}/#{subsection}/check-answers")
+ assert_selector ".x-govuk-summary-card__title", text: "Buyer 1", count: 1
+ assert_selector ".x-govuk-summary-card__title", text: "Buyer 2", count: 1
+ assert_selector ".x-govuk-summary-card__title", text: "Person 1", count: 1
+ assert_selector ".x-govuk-summary-card__title", text: "Person 2", count: 0
+ end
+ end
+
+ context "and the log is for a non-joint purchase" do
+ it "they see a seperate summary card for each member of the household" do
+ visit("/sales-logs/#{completed_sales_log_non_joint_purchase.id}/#{subsection}/check-answers")
+ assert_selector ".x-govuk-summary-card__title", text: "Buyer 1", count: 1
+ assert_selector ".x-govuk-summary-card__title", text: "Buyer 2", count: 0
+ assert_selector ".x-govuk-summary-card__title", text: "Person 1", count: 1
+ assert_selector ".x-govuk-summary-card__title", text: "Person 2", count: 0
+ end
+ end
+ end
+ end
+end
diff --git a/spec/models/form/sales/pages/buyer1_working_situation_spec.rb b/spec/models/form/sales/pages/buyer1_working_situation_spec.rb
index 2a48f0b0f..4b432ed03 100644
--- a/spec/models/form/sales/pages/buyer1_working_situation_spec.rb
+++ b/spec/models/form/sales/pages/buyer1_working_situation_spec.rb
@@ -20,6 +20,6 @@ RSpec.describe Form::Sales::Pages::Buyer1WorkingSituation, type: :model do
end
it "has the correct header" do
- expect(page.header).to eq("Which of these best describes buyer 1's working situation?")
+ expect(page.header).to eq("")
end
end
diff --git a/spec/models/form/sales/pages/person_age_spec.rb b/spec/models/form/sales/pages/person_age_spec.rb
index 4c4159896..f8bc96692 100644
--- a/spec/models/form/sales/pages/person_age_spec.rb
+++ b/spec/models/form/sales/pages/person_age_spec.rb
@@ -35,7 +35,7 @@ RSpec.describe Form::Sales::Pages::PersonAge, type: :model do
it "has correct depends_on" do
expect(page.depends_on).to eq(
- [{ "hholdcount" => 1, "jointpur" => 2 }, { "hholdcount" => 2, "jointpur" => 2 }, { "hholdcount" => 3, "jointpur" => 2 }, { "hholdcount" => 4, "jointpur" => 2 }],
+ [{ "details_known_1" => 1, "jointpur" => 2 }],
)
end
end
@@ -119,7 +119,7 @@ RSpec.describe Form::Sales::Pages::PersonAge, type: :model do
it "has correct depends_on" do
expect(page.depends_on).to eq(
- [{ "hholdcount" => 1, "jointpur" => 1 }, { "hholdcount" => 2, "jointpur" => 1 }, { "hholdcount" => 3, "jointpur" => 1 }, { "hholdcount" => 4, "jointpur" => 1 }],
+ [{ "details_known_1" => 1, "jointpur" => 1 }],
)
end
end
diff --git a/spec/models/form/sales/pages/person_known_spec.rb b/spec/models/form/sales/pages/person_known_spec.rb
index 0dc454143..bb73d6b63 100644
--- a/spec/models/form/sales/pages/person_known_spec.rb
+++ b/spec/models/form/sales/pages/person_known_spec.rb
@@ -3,117 +3,229 @@ require "rails_helper"
RSpec.describe Form::Sales::Pages::PersonKnown, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection, person_index:) }
- let(:page_id) { "person_2_known" }
- let(:page_definition) { nil }
- let(:subsection) { instance_double(Form::Subsection) }
- let(:person_index) { 1 }
+ context "without joint purchase" do
+ let(:page_id) { "person_2_known" }
+ let(:page_definition) { nil }
+ let(:subsection) { instance_double(Form::Subsection) }
+ let(:person_index) { 3 }
- it "has correct subsection" do
- expect(page.subsection).to eq(subsection)
- end
+ it "has correct subsection" do
+ expect(page.subsection).to eq(subsection)
+ end
- it "has the correct header" do
- expect(page.header).to eq("")
- end
+ it "has the correct header" do
+ expect(page.header).to eq("")
+ end
- it "has the correct description" do
- expect(page.description).to eq("")
- end
+ it "has the correct description" do
+ expect(page.description).to eq("")
+ end
+
+ context "with person 1" do
+ let(:page_id) { "person_1_known" }
+ let(:person_index) { 2 }
+
+ it "has correct questions" do
+ expect(page.questions.map(&:id)).to eq(%w[details_known_1])
+ end
+
+ it "has the correct id" do
+ expect(page.id).to eq("person_1_known")
+ end
- context "with person 1" do
- let(:page_id) { "person_1_known" }
- let(:person_index) { 1 }
+ it "has the correct header_partial" do
+ expect(page.header_partial).to eq("person_1_known_page")
+ end
- it "has correct questions" do
- expect(page.questions.map(&:id)).to eq(%w[details_known_1])
+ it "has correct depends_on" do
+ expect(page.depends_on).to eq(
+ [
+ { "hholdcount" => 1, "jointpur" => 2 }, { "hholdcount" => 2, "jointpur" => 2 }, { "hholdcount" => 3, "jointpur" => 2 }, { "hholdcount" => 4, "jointpur" => 2 }
+ ],
+ )
+ end
end
- it "has the correct id" do
- expect(page.id).to eq("person_1_known")
+ context "with person 2" do
+ let(:page_id) { "person_2_known" }
+ let(:person_index) { 3 }
+
+ it "has correct questions" do
+ expect(page.questions.map(&:id)).to eq(%w[details_known_2])
+ end
+
+ it "has the correct id" do
+ expect(page.id).to eq("person_2_known")
+ end
+
+ it "has the correct header_partial" do
+ expect(page.header_partial).to eq("person_2_known_page")
+ end
+
+ it "has correct depends_on" do
+ expect(page.depends_on).to eq(
+ [{ "hholdcount" => 2, "jointpur" => 2 }, { "hholdcount" => 3, "jointpur" => 2 }, { "hholdcount" => 4, "jointpur" => 2 }],
+ )
+ end
end
- it "has the correct header_partial" do
- expect(page.header_partial).to eq("person_1_known_page")
+ context "with person 3" do
+ let(:page_id) { "person_3_known" }
+ let(:person_index) { 4 }
+
+ it "has correct questions" do
+ expect(page.questions.map(&:id)).to eq(%w[details_known_3])
+ end
+
+ it "has the correct id" do
+ expect(page.id).to eq("person_3_known")
+ end
+
+ it "has the correct header_partial" do
+ expect(page.header_partial).to eq("person_3_known_page")
+ end
+
+ it "has correct depends_on" do
+ expect(page.depends_on).to eq(
+ [{ "hholdcount" => 3, "jointpur" => 2 }, { "hholdcount" => 4, "jointpur" => 2 }],
+ )
+ end
end
- it "has correct depends_on" do
- expect(page.depends_on).to eq(
- [
- { "hholdcount" => 1 },
- { "hholdcount" => 2 },
- { "hholdcount" => 3 },
- { "hholdcount" => 4 },
- ],
- )
+ context "with person 4" do
+ let(:page_id) { "person_4_known" }
+ let(:person_index) { 5 }
+
+ it "has correct questions" do
+ expect(page.questions.map(&:id)).to eq(%w[details_known_4])
+ end
+
+ it "has the correct id" do
+ expect(page.id).to eq("person_4_known")
+ end
+
+ it "has the correct header_partial" do
+ expect(page.header_partial).to eq("person_4_known_page")
+ end
+
+ it "has correct depends_on" do
+ expect(page.depends_on).to eq(
+ [{ "hholdcount" => 4, "jointpur" => 2 }],
+ )
+ end
end
end
- context "with person 2" do
+ context "with joint purchase" do
let(:page_id) { "person_2_known" }
- let(:person_index) { 2 }
+ let(:page_definition) { nil }
+ let(:subsection) { instance_double(Form::Subsection) }
+ let(:person_index) { 4 }
- it "has correct questions" do
- expect(page.questions.map(&:id)).to eq(%w[details_known_2])
+ it "has correct subsection" do
+ expect(page.subsection).to eq(subsection)
end
- it "has the correct id" do
- expect(page.id).to eq("person_2_known")
+ it "has the correct header" do
+ expect(page.header).to eq("")
end
- it "has the correct header_partial" do
- expect(page.header_partial).to eq("person_2_known_page")
+ it "has the correct description" do
+ expect(page.description).to eq("")
end
- it "has correct depends_on" do
- expect(page.depends_on).to eq(
- [{ "hholdcount" => 2 }, { "hholdcount" => 3 }, { "hholdcount" => 4 }],
- )
- end
- end
+ context "with person 1" do
+ let(:page_id) { "person_1_known_joint_purchase" }
+ let(:person_index) { 3 }
- context "with person 3" do
- let(:page_id) { "person_3_known" }
- let(:person_index) { 3 }
+ it "has correct questions" do
+ expect(page.questions.map(&:id)).to eq(%w[details_known_1])
+ end
- it "has correct questions" do
- expect(page.questions.map(&:id)).to eq(%w[details_known_3])
- end
+ it "has the correct id" do
+ expect(page.id).to eq("person_1_known_joint_purchase")
+ end
- it "has the correct id" do
- expect(page.id).to eq("person_3_known")
- end
+ it "has the correct header_partial" do
+ expect(page.header_partial).to eq("person_1_known_page")
+ end
- it "has the correct header_partial" do
- expect(page.header_partial).to eq("person_3_known_page")
+ it "has correct depends_on" do
+ expect(page.depends_on).to eq(
+ [
+ { "hholdcount" => 1, "jointpur" => 1 }, { "hholdcount" => 2, "jointpur" => 1 }, { "hholdcount" => 3, "jointpur" => 1 }, { "hholdcount" => 4, "jointpur" => 1 }
+ ],
+ )
+ end
end
- it "has correct depends_on" do
- expect(page.depends_on).to eq(
- [{ "hholdcount" => 3 }, { "hholdcount" => 4 }],
- )
- end
- end
+ context "with person 2" do
+ let(:page_id) { "person_2_known_joint_purchase" }
+ let(:person_index) { 4 }
- context "with person 4" do
- let(:page_id) { "person_4_known" }
- let(:person_index) { 4 }
+ it "has correct questions" do
+ expect(page.questions.map(&:id)).to eq(%w[details_known_2])
+ end
- it "has correct questions" do
- expect(page.questions.map(&:id)).to eq(%w[details_known_4])
- end
+ it "has the correct id" do
+ expect(page.id).to eq("person_2_known_joint_purchase")
+ end
+
+ it "has the correct header_partial" do
+ expect(page.header_partial).to eq("person_2_known_page")
+ end
- it "has the correct id" do
- expect(page.id).to eq("person_4_known")
+ it "has correct depends_on" do
+ expect(page.depends_on).to eq(
+ [{ "hholdcount" => 2, "jointpur" => 1 }, { "hholdcount" => 3, "jointpur" => 1 }, { "hholdcount" => 4, "jointpur" => 1 }],
+ )
+ end
end
- it "has the correct header_partial" do
- expect(page.header_partial).to eq("person_4_known_page")
+ context "with person 3" do
+ let(:page_id) { "person_3_known_joint_purchase" }
+ let(:person_index) { 5 }
+
+ it "has correct questions" do
+ expect(page.questions.map(&:id)).to eq(%w[details_known_3])
+ end
+
+ it "has the correct id" do
+ expect(page.id).to eq("person_3_known_joint_purchase")
+ end
+
+ it "has the correct header_partial" do
+ expect(page.header_partial).to eq("person_3_known_page")
+ end
+
+ it "has correct depends_on" do
+ expect(page.depends_on).to eq(
+ [{ "hholdcount" => 3, "jointpur" => 1 }, { "hholdcount" => 4, "jointpur" => 1 }],
+ )
+ end
end
- it "has correct depends_on" do
- expect(page.depends_on).to eq(
- [{ "hholdcount" => 4 }],
- )
+ context "with person 4" do
+ let(:page_id) { "person_4_known_joint_purchase" }
+ let(:person_index) { 6 }
+
+ it "has correct questions" do
+ expect(page.questions.map(&:id)).to eq(%w[details_known_4])
+ end
+
+ it "has the correct id" do
+ expect(page.id).to eq("person_4_known_joint_purchase")
+ end
+
+ it "has the correct header_partial" do
+ expect(page.header_partial).to eq("person_4_known_page")
+ end
+
+ it "has correct depends_on" do
+ expect(page.depends_on).to eq(
+ [{ "hholdcount" => 4, "jointpur" => 1 }],
+ )
+ end
end
end
end
diff --git a/spec/models/form/sales/pages/person_working_situation_spec.rb b/spec/models/form/sales/pages/person_working_situation_spec.rb
index e38d5ff47..65bdb42d0 100644
--- a/spec/models/form/sales/pages/person_working_situation_spec.rb
+++ b/spec/models/form/sales/pages/person_working_situation_spec.rb
@@ -35,7 +35,7 @@ RSpec.describe Form::Sales::Pages::PersonWorkingSituation, type: :model do
end
it "has correct depends_on" do
- expect(page.depends_on).to eq([{ "hholdcount" => 1, "jointpur" => 2 }, { "hholdcount" => 2, "jointpur" => 2 }, { "hholdcount" => 3, "jointpur" => 2 }, { "hholdcount" => 4, "jointpur" => 2 }])
+ expect(page.depends_on).to eq([{ "details_known_1" => 1, "jointpur" => 2 }])
end
end
@@ -119,7 +119,7 @@ RSpec.describe Form::Sales::Pages::PersonWorkingSituation, type: :model do
end
it "has correct depends_on" do
- expect(page.depends_on).to eq([{ "hholdcount" => 1, "jointpur" => 1 }, { "hholdcount" => 2, "jointpur" => 1 }, { "hholdcount" => 3, "jointpur" => 1 }, { "hholdcount" => 4, "jointpur" => 1 }])
+ expect(page.depends_on).to eq([{ "details_known_1" => 1, "jointpur" => 1 }])
end
end
diff --git a/spec/models/form/sales/questions/person_known_spec.rb b/spec/models/form/sales/questions/person_known_spec.rb
index 2c33346f0..551ac096e 100644
--- a/spec/models/form/sales/questions/person_known_spec.rb
+++ b/spec/models/form/sales/questions/person_known_spec.rb
@@ -6,7 +6,11 @@ RSpec.describe Form::Sales::Questions::PersonKnown, type: :model do
let(:question_id) { "details_known_1" }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
- let(:person_index) { 1 }
+ let(:person_index) { 2 }
+
+ before do
+ allow(page).to receive(:id).and_return("person_1_known")
+ end
it "has correct page" do
expect(question.page).to eq(page)
@@ -27,44 +31,291 @@ RSpec.describe Form::Sales::Questions::PersonKnown, type: :model do
})
end
- it "has correct conditional for" do
- expect(question.conditional_for).to eq(nil)
- end
-
it "has the correct hint" do
expect(question.hint_text).to eq("")
end
- context "with person 1" do
- let(:question_id) { "details_known_1" }
- let(:person_index) { 1 }
+ context "with a non joint purchase" do
+ context "and person 1" do
+ let(:question_id) { "details_known_1" }
+ let(:person_index) { 2 }
+
+ before do
+ allow(page).to receive(:id).and_return("person_1_known")
+ end
+
+ it "has the correct id" do
+ expect(question.id).to eq("details_known_1")
+ end
+
+ it "has the correct header" do
+ expect(question.header).to eq("Do you know the details for person 1?")
+ end
+
+ it "has the correct check_answer_label" do
+ expect(question.check_answer_label).to eq("Details known for person 1?")
+ end
+
+ it "has correct conditional for" do
+ expect(question.conditional_for).to be_nil
+ end
+
+ it "has the correct hidden_in_check_answers" do
+ expect(question.hidden_in_check_answers).to eq(
+ "depends_on" => [{ "details_known_1" => 1 }],
+ )
+ end
+
+ it "has the correct check_answers_card_number" do
+ expect(question.check_answers_card_number).to eq(2)
+ end
+ end
+
+ context "and person 2" do
+ let(:question_id) { "details_known_2" }
+ let(:person_index) { 3 }
+
+ before do
+ allow(page).to receive(:id).and_return("person_2_known")
+ end
+
+ it "has the correct id" do
+ expect(question.id).to eq("details_known_2")
+ end
+
+ it "has the correct header" do
+ expect(question.header).to eq("Do you know the details for person 2?")
+ end
+
+ it "has the correct check_answer_label" do
+ expect(question.check_answer_label).to eq("Details known for person 2?")
+ end
+
+ it "has correct conditional for" do
+ expect(question.conditional_for).to be_nil
+ end
+
+ it "has the correct hidden_in_check_answers" do
+ expect(question.hidden_in_check_answers).to eq(
+ "depends_on" => [{ "details_known_2" => 1 }],
+ )
+ end
+
+ it "has the correct check_answers_card_number" do
+ expect(question.check_answers_card_number).to eq(3)
+ end
+ end
+
+ context "and person 3" do
+ let(:question_id) { "details_known_3" }
+ let(:person_index) { 4 }
+
+ before do
+ allow(page).to receive(:id).and_return("person_3_known")
+ end
+
+ it "has the correct id" do
+ expect(question.id).to eq("details_known_3")
+ end
+
+ it "has the correct header" do
+ expect(question.header).to eq("Do you know the details for person 3?")
+ end
+
+ it "has the correct check_answer_label" do
+ expect(question.check_answer_label).to eq("Details known for person 3?")
+ end
+
+ it "has correct conditional for" do
+ expect(question.conditional_for).to be_nil
+ end
+
+ it "has the correct hidden_in_check_answers" do
+ expect(question.hidden_in_check_answers).to eq(
+ "depends_on" => [{ "details_known_3" => 1 }],
+ )
+ end
+
+ it "has the correct check_answers_card_number" do
+ expect(question.check_answers_card_number).to eq(4)
+ end
+ end
+
+ context "and person 4" do
+ let(:question_id) { "details_known_4" }
+ let(:person_index) { 5 }
+
+ before do
+ allow(page).to receive(:id).and_return("person_4_known")
+ end
+
+ it "has the correct id" do
+ expect(question.id).to eq("details_known_4")
+ end
- it "has the correct id" do
- expect(question.id).to eq("details_known_1")
+ it "has the correct header" do
+ expect(question.header).to eq("Do you know the details for person 4?")
+ end
+
+ it "has the correct check_answer_label" do
+ expect(question.check_answer_label).to eq("Details known for person 4?")
+ end
+
+ it "has correct conditional for" do
+ expect(question.conditional_for).to be_nil
+ end
+
+ it "has the correct hidden_in_check_answers" do
+ expect(question.hidden_in_check_answers).to eq(
+ "depends_on" => [{ "details_known_4" => 1 }],
+ )
+ end
+
+ it "has the correct check_answers_card_number" do
+ expect(question.check_answers_card_number).to eq(5)
+ end
end
+ end
+
+ context "with a joint purchase" do
+ context "and person 1" do
+ let(:question_id) { "details_known_1" }
+ let(:person_index) { 3 }
+
+ before do
+ allow(page).to receive(:id).and_return("person_1_known_joint_purchase")
+ end
+
+ it "has the correct id" do
+ expect(question.id).to eq("details_known_1")
+ end
+
+ it "has the correct header" do
+ expect(question.header).to eq("Do you know the details for person 1?")
+ end
- it "has the correct header" do
- expect(question.header).to eq("Do you know the details for person 1?")
+ it "has the correct check_answer_label" do
+ expect(question.check_answer_label).to eq("Details known for person 1?")
+ end
+
+ it "has correct conditional for" do
+ expect(question.conditional_for).to be_nil
+ end
+
+ it "has the correct hidden_in_check_answers" do
+ expect(question.hidden_in_check_answers).to eq(
+ "depends_on" => [{ "details_known_1" => 1 }],
+ )
+ end
+
+ it "has the correct check_answers_card_number" do
+ expect(question.check_answers_card_number).to eq(3)
+ end
end
- it "has the correct check_answer_label" do
- expect(question.check_answer_label).to eq("Details known for person 1?")
+ context "and person 2" do
+ let(:question_id) { "details_known_2" }
+ let(:person_index) { 4 }
+
+ before do
+ allow(page).to receive(:id).and_return("person_2_known_joint_purchase")
+ end
+
+ it "has the correct id" do
+ expect(question.id).to eq("details_known_2")
+ end
+
+ it "has the correct header" do
+ expect(question.header).to eq("Do you know the details for person 2?")
+ end
+
+ it "has the correct check_answer_label" do
+ expect(question.check_answer_label).to eq("Details known for person 2?")
+ end
+
+ it "has correct conditional for" do
+ expect(question.conditional_for).to be_nil
+ end
+
+ it "has the correct hidden_in_check_answers" do
+ expect(question.hidden_in_check_answers).to eq(
+ "depends_on" => [{ "details_known_2" => 1 }],
+ )
+ end
+
+ it "has the correct check_answers_card_number" do
+ expect(question.check_answers_card_number).to eq(4)
+ end
end
- it "has the correct hidden_in_check_answers" do
- expect(question.hidden_in_check_answers).to eq(
- {
- "depends_on" => [
- {
- "details_known_1" => 1,
- },
- ],
- },
- )
+ context "and person 3" do
+ let(:question_id) { "details_known_3" }
+ let(:person_index) { 5 }
+
+ before do
+ allow(page).to receive(:id).and_return("person_3_known_joint_purchase")
+ end
+
+ it "has the correct id" do
+ expect(question.id).to eq("details_known_3")
+ end
+
+ it "has the correct header" do
+ expect(question.header).to eq("Do you know the details for person 3?")
+ end
+
+ it "has the correct check_answer_label" do
+ expect(question.check_answer_label).to eq("Details known for person 3?")
+ end
+
+ it "has correct conditional for" do
+ expect(question.conditional_for).to be_nil
+ end
+
+ it "has the correct hidden_in_check_answers" do
+ expect(question.hidden_in_check_answers).to eq(
+ "depends_on" => [{ "details_known_3" => 1 }],
+ )
+ end
+
+ it "has the correct check_answers_card_number" do
+ expect(question.check_answers_card_number).to eq(5)
+ end
end
- it "has the correct check_answers_card_number" do
- expect(question.check_answers_card_number).to eq(3)
+ context "and person 4" do
+ let(:question_id) { "details_known_4" }
+ let(:person_index) { 6 }
+
+ before do
+ allow(page).to receive(:id).and_return("person_4_known_joint_purchase")
+ end
+
+ it "has the correct id" do
+ expect(question.id).to eq("details_known_4")
+ end
+
+ it "has the correct header" do
+ expect(question.header).to eq("Do you know the details for person 4?")
+ end
+
+ it "has the correct check_answer_label" do
+ expect(question.check_answer_label).to eq("Details known for person 4?")
+ end
+
+ it "has correct conditional for" do
+ expect(question.conditional_for).to be_nil
+ end
+
+ it "has the correct hidden_in_check_answers" do
+ expect(question.hidden_in_check_answers).to eq(
+ "depends_on" => [{ "details_known_4" => 1 }],
+ )
+ end
+
+ it "has the correct check_answers_card_number" do
+ expect(question.check_answers_card_number).to eq(6)
+ end
end
end
end
diff --git a/spec/models/form/sales/subsections/household_characteristics_spec.rb b/spec/models/form/sales/subsections/household_characteristics_spec.rb
index 9c96ecb3a..ecdeca2dd 100644
--- a/spec/models/form/sales/subsections/household_characteristics_spec.rb
+++ b/spec/models/form/sales/subsections/household_characteristics_spec.rb
@@ -35,6 +35,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
buyer_2_live_in_property
number_of_others_in_property
person_1_known
+ person_1_known_joint_purchase
person_1_relationship_to_buyer_1
person_1_relationship_to_buyer_1_joint_purchase
person_1_age
@@ -44,6 +45,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
person_1_working_situation
person_1_working_situation_joint_purchase
person_2_known
+ person_2_known_joint_purchase
person_2_relationship_to_buyer_1
person_2_relationship_to_buyer_1_joint_purchase
person_2_age
@@ -51,6 +53,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
person_2_working_situation
person_2_working_situation_joint_purchase
person_3_known
+ person_3_known_joint_purchase
person_3_relationship_to_buyer_1
person_3_relationship_to_buyer_1_joint_purchase
person_3_age
@@ -58,6 +61,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
person_3_working_situation
person_3_working_situation_joint_purchase
person_4_known
+ person_4_known_joint_purchase
person_4_relationship_to_buyer_1
person_4_relationship_to_buyer_1_joint_purchase
person_4_age
diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb
index 355f8cf2c..7d5339806 100644
--- a/spec/models/form_handler_spec.rb
+++ b/spec/models/form_handler_spec.rb
@@ -52,14 +52,14 @@ RSpec.describe FormHandler do
it "is able to load a current sales form" do
form = form_handler.get_form("current_sales")
expect(form).to be_a(Form)
- expect(form.pages.count).to eq(118)
+ expect(form.pages.count).to eq(122)
expect(form.name).to eq("2022_2023_sales")
end
it "is able to load a previous sales form" do
form = form_handler.get_form("previous_sales")
expect(form).to be_a(Form)
- expect(form.pages.count).to eq(118)
+ expect(form.pages.count).to eq(122)
expect(form.name).to eq("2021_2022_sales")
end
end
From b9f775fba1d18277350d6349bd0ecb8883cb499f Mon Sep 17 00:00:00 2001
From: natdeanlewissoftwire
<94526761+natdeanlewissoftwire@users.noreply.github.com>
Date: Mon, 9 Jan 2023 14:49:01 +0000
Subject: [PATCH 6/6] Cldc 1547 leasehold charges (#1134)
* Mark subsection as completed if it is not displayed in the tasklist and hide it from the UI
* Add sale_information section
* add sales information subsections
* Cldc 1531 staircasing (#1109)
* Add staircase field to sales_logs table
* Add staircase question and page
* add staircase page to the shared ownership scheme subsection fix file name
* Cldc 1539 previous bedrooms (#1108)
* add frombeds field
* Add previous_bedrooms page and question
* add Previous Bedrooms page to the shared ownership subsection
* Cldc 1532 about staircasing (#1110)
* Add stairboughts and stairowned fields to the database
* Add about staircasing page and questions
* Add about staircasing page to the shared wnership scheme subsection
* Add a space before percent
* Cldc 1546 monthly rent (#1111)
* Add monthly rent column to sales logs table
* Add monthly rent question and page
* Add monthly rent page to the shared ownership scheme subsection
* Cldc 1535 exchange contracts (#1112)
* Add exdate to sales logs table
* Add exchange date page and question
* Add exchange contracts page to the shared ownership subsection
* derive exday, exmonth and exyear, tests and lint
* rebase tests
* Cldc 1538 la nominations (#1115)
* Add la nominations column to sales logs table
* Add La nominations page and questions
* Add la nominations to the shared ownership subsection
* Add accidentally removed files
* Cldc 1545 about the deposit (#1113)
* feat: add question(s) without depends_on behaviour
* feat: separate ids for diff sections
* test: update tests
* test: add tests
* tests: test tweaks
* refactor: linting
* Cldc 1538 la nominations (#1115)
* Add la nominations column to sales logs table
* Add La nominations page and questions
* Add la nominations to the shared ownership subsection
* Add accidentally removed files
* feat: add question(s) without depends_on behaviour
Co-authored-by: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>
* Cldc 1533 is resale (#1118)
* feat: add resale question and page
* tests: add new tests
* test: update previous tests
* refactor: linting
* refactor: linting
* Cldc 1576 buyer prp (#1117)
* Add soctenant field to sales logs
* Add buyer previous page and question
* Add buyer previous page to shared ownership scheme subsection
* rebase migrate
* rebase too
* Cldc 1540 about price (#1121)
* add price fields to the sales logs table
* Add about proce questions
* add about proce pages
* Add about price pages to sale information sections
* rebase changes
* happy new year
* Switch the order of sales log sections
* Cldc 1540 fixes (#1130)
* Update order of pages and remove wrong id's
* Add spacing to the hint text
* feat: add page, question, and update db
* Cldc 1521 living before purchase (#1129)
* feat: add new page and question and update db
* test: add and update tests
* feat: reset db
* feat: infer mscharge if mscharge_known == No
* test: add and update tests
* feat: add page, question, and update db
* feat: infer mscharge if mscharge_known == No
* test: add and update tests
* feat: update to main
* test: update tests
* tests: update tests
* faet: move mscharge derivation
Co-authored-by: Kat
Co-authored-by: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>
---
.../derived_variables/sales_log_variables.rb | 3 +
.../form/sales/pages/leasehold_charges.rb | 15 +++++
.../form/sales/questions/leasehold_charges.rb | 13 ++++
.../questions/leasehold_charges_known.rb | 27 +++++++++
.../discounted_ownership_scheme.rb | 1 +
.../form/sales/subsections/outright_sale.rb | 1 +
.../subsections/shared_ownership_scheme.rb | 1 +
...30103112225_add_mscharge_known_to_sales.rb | 8 +++
db/schema.rb | 2 +
spec/factories/sales_log.rb | 2 +
.../sales/pages/leasehold_charges_spec.rb | 33 ++++++++++
.../questions/leasehold_charges_known_spec.rb | 60 +++++++++++++++++++
.../sales/questions/leasehold_charges_spec.rb | 49 +++++++++++++++
.../discounted_ownership_scheme_spec.rb | 1 +
.../sales/subsections/outright_sale_spec.rb | 13 ++--
.../shared_ownership_scheme_spec.rb | 1 +
spec/models/form_handler_spec.rb | 4 +-
17 files changed, 227 insertions(+), 7 deletions(-)
create mode 100644 app/models/form/sales/pages/leasehold_charges.rb
create mode 100644 app/models/form/sales/questions/leasehold_charges.rb
create mode 100644 app/models/form/sales/questions/leasehold_charges_known.rb
create mode 100644 db/migrate/20230103112225_add_mscharge_known_to_sales.rb
create mode 100644 spec/models/form/sales/pages/leasehold_charges_spec.rb
create mode 100644 spec/models/form/sales/questions/leasehold_charges_known_spec.rb
create mode 100644 spec/models/form/sales/questions/leasehold_charges_spec.rb
diff --git a/app/models/derived_variables/sales_log_variables.rb b/app/models/derived_variables/sales_log_variables.rb
index 5fff0900d..c9675d84a 100644
--- a/app/models/derived_variables/sales_log_variables.rb
+++ b/app/models/derived_variables/sales_log_variables.rb
@@ -7,5 +7,8 @@ module DerivedVariables::SalesLogVariables
self.exyear = exdate.year
end
self.deposit = value if outright_sale? && mortgage_not_used?
+ if mscharge_known.present? && mscharge_known.zero?
+ self.mscharge = 0
+ end
end
end
diff --git a/app/models/form/sales/pages/leasehold_charges.rb b/app/models/form/sales/pages/leasehold_charges.rb
new file mode 100644
index 000000000..7aed92db9
--- /dev/null
+++ b/app/models/form/sales/pages/leasehold_charges.rb
@@ -0,0 +1,15 @@
+class Form::Sales::Pages::LeaseholdCharges < ::Form::Page
+ def initialize(id, hsh, subsection)
+ super
+ @header = ""
+ @description = ""
+ @subsection = subsection
+ end
+
+ def questions
+ @questions ||= [
+ Form::Sales::Questions::LeaseholdChargesKnown.new(nil, nil, self),
+ Form::Sales::Questions::LeaseholdCharges.new(nil, nil, self),
+ ]
+ end
+end
diff --git a/app/models/form/sales/questions/leasehold_charges.rb b/app/models/form/sales/questions/leasehold_charges.rb
new file mode 100644
index 000000000..eb19a7377
--- /dev/null
+++ b/app/models/form/sales/questions/leasehold_charges.rb
@@ -0,0 +1,13 @@
+class Form::Sales::Questions::LeaseholdCharges < ::Form::Question
+ def initialize(id, hsh, page)
+ super
+ @id = "mscharge"
+ @check_answer_label = "Monthly leasehold charges"
+ @header = "Enter the total monthly charge"
+ @type = "numeric"
+ @page = page
+ @min = 0
+ @width = 5
+ @prefix = "£"
+ end
+end
diff --git a/app/models/form/sales/questions/leasehold_charges_known.rb b/app/models/form/sales/questions/leasehold_charges_known.rb
new file mode 100644
index 000000000..a94e7f63e
--- /dev/null
+++ b/app/models/form/sales/questions/leasehold_charges_known.rb
@@ -0,0 +1,27 @@
+class Form::Sales::Questions::LeaseholdChargesKnown < ::Form::Question
+ def initialize(id, hsh, page)
+ super
+ @id = "mscharge_known"
+ @check_answer_label = "Monthly leasehold charges known?"
+ @header = "Does the property have any monthly leasehold charges?"
+ @hint_text = "For example, service and management charges"
+ @type = "radio"
+ @answer_options = ANSWER_OPTIONS
+ @page = page
+ @conditional_for = {
+ "mscharge" => [1],
+ }
+ @hidden_in_check_answers = {
+ "depends_on" => [
+ {
+ "mscharge_known" => 1,
+ },
+ ],
+ }
+ end
+
+ ANSWER_OPTIONS = {
+ "1" => { "value" => "Yes" },
+ "0" => { "value" => "No" },
+ }.freeze
+end
diff --git a/app/models/form/sales/subsections/discounted_ownership_scheme.rb b/app/models/form/sales/subsections/discounted_ownership_scheme.rb
index 9181e9c41..827ecf1de 100644
--- a/app/models/form/sales/subsections/discounted_ownership_scheme.rb
+++ b/app/models/form/sales/subsections/discounted_ownership_scheme.rb
@@ -16,6 +16,7 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_discounted_ownership", nil, self),
Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_discounted_ownership", nil, self),
Form::Sales::Pages::DepositValueCheck.new("discounted_ownership_deposit_value_check", nil, self),
+ Form::Sales::Pages::LeaseholdCharges.new("leasehold_charges_discounted_ownership", nil, self),
]
end
diff --git a/app/models/form/sales/subsections/outright_sale.rb b/app/models/form/sales/subsections/outright_sale.rb
index 2b38841ba..a751c6734 100644
--- a/app/models/form/sales/subsections/outright_sale.rb
+++ b/app/models/form/sales/subsections/outright_sale.rb
@@ -14,6 +14,7 @@ class Form::Sales::Subsections::OutrightSale < ::Form::Subsection
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_outright_sale", nil, self),
Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_outright_sale", nil, self),
Form::Sales::Pages::DepositValueCheck.new("outright_sale_deposit_value_check", nil, self),
+ Form::Sales::Pages::LeaseholdCharges.new("leasehold_charges_outright_sale", nil, self),
]
end
diff --git a/app/models/form/sales/subsections/shared_ownership_scheme.rb b/app/models/form/sales/subsections/shared_ownership_scheme.rb
index c40fa9441..043459adb 100644
--- a/app/models/form/sales/subsections/shared_ownership_scheme.rb
+++ b/app/models/form/sales/subsections/shared_ownership_scheme.rb
@@ -24,6 +24,7 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection
Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_shared_ownership", nil, self),
Form::Sales::Pages::DepositValueCheck.new("shared_ownership_deposit_value_check", nil, self),
Form::Sales::Pages::MonthlyRent.new(nil, nil, self),
+ Form::Sales::Pages::LeaseholdCharges.new("leasehold_charges_shared_ownership", nil, self),
]
end
diff --git a/db/migrate/20230103112225_add_mscharge_known_to_sales.rb b/db/migrate/20230103112225_add_mscharge_known_to_sales.rb
new file mode 100644
index 000000000..cf09e8a52
--- /dev/null
+++ b/db/migrate/20230103112225_add_mscharge_known_to_sales.rb
@@ -0,0 +1,8 @@
+class AddMschargeKnownToSales < ActiveRecord::Migration[7.0]
+ def change
+ change_table :sales_logs, bulk: true do |t|
+ t.column :mscharge_known, :integer
+ t.column :mscharge, :decimal, precision: 10, scale: 2
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 49f59a503..8812128eb 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -461,6 +461,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_05_103733) do
t.integer "mortgageused"
t.integer "wchair"
t.integer "armedforcesspouse"
+ t.integer "mscharge_known"
+ t.decimal "mscharge", precision: 10, scale: 2
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id"
t.index ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id"
diff --git a/spec/factories/sales_log.rb b/spec/factories/sales_log.rb
index 22d7320f4..08f37b3bf 100644
--- a/spec/factories/sales_log.rb
+++ b/spec/factories/sales_log.rb
@@ -90,6 +90,8 @@ FactoryBot.define do
mortgageused { 1 }
wchair { 1 }
armedforcesspouse { 5 }
+ mscharge_known { 1 }
+ mscharge { 100 }
end
end
end
diff --git a/spec/models/form/sales/pages/leasehold_charges_spec.rb b/spec/models/form/sales/pages/leasehold_charges_spec.rb
new file mode 100644
index 000000000..d35d1076b
--- /dev/null
+++ b/spec/models/form/sales/pages/leasehold_charges_spec.rb
@@ -0,0 +1,33 @@
+require "rails_helper"
+
+RSpec.describe Form::Sales::Pages::LeaseholdCharges, type: :model do
+ subject(:page) { described_class.new(page_id, page_definition, subsection) }
+
+ let(:page_id) { nil }
+ let(:page_definition) { nil }
+ let(:subsection) { instance_double(Form::Subsection) }
+
+ it "has correct subsection" do
+ expect(page.subsection).to eq(subsection)
+ end
+
+ it "has correct questions" do
+ expect(page.questions.map(&:id)).to eq(%w[mscharge_known mscharge])
+ end
+
+ it "has the correct id" do
+ expect(page.id).to eq(nil)
+ end
+
+ it "has the correct header" do
+ expect(page.header).to eq("")
+ end
+
+ it "has the correct description" do
+ expect(page.description).to eq("")
+ end
+
+ it "has correct depends_on" do
+ expect(page.depends_on).to be_nil
+ end
+end
diff --git a/spec/models/form/sales/questions/leasehold_charges_known_spec.rb b/spec/models/form/sales/questions/leasehold_charges_known_spec.rb
new file mode 100644
index 000000000..d47b535eb
--- /dev/null
+++ b/spec/models/form/sales/questions/leasehold_charges_known_spec.rb
@@ -0,0 +1,60 @@
+require "rails_helper"
+
+RSpec.describe Form::Sales::Questions::LeaseholdChargesKnown, type: :model do
+ subject(:question) { described_class.new(question_id, question_definition, page) }
+
+ let(:question_id) { nil }
+ let(:question_definition) { nil }
+ let(:page) { instance_double(Form::Page) }
+
+ it "has correct page" do
+ expect(question.page).to eq(page)
+ end
+
+ it "has the correct id" do
+ expect(question.id).to eq("mscharge_known")
+ end
+
+ it "has the correct header" do
+ expect(question.header).to eq("Does the property have any monthly leasehold charges?")
+ end
+
+ it "has the correct check_answer_label" do
+ expect(question.check_answer_label).to eq("Monthly leasehold charges known?")
+ end
+
+ it "has the correct type" do
+ expect(question.type).to eq("radio")
+ end
+
+ it "is not marked as derived" do
+ expect(question.derived?).to be false
+ end
+
+ it "has the correct answer_options" do
+ expect(question.answer_options).to eq({
+ "0" => { "value" => "No" },
+ "1" => { "value" => "Yes" },
+ })
+ end
+
+ it "has correct conditional for" do
+ expect(question.conditional_for).to eq({
+ "mscharge" => [1],
+ })
+ end
+
+ it "has the correct hint" do
+ expect(question.hint_text).to eq("For example, service and management charges")
+ end
+
+ it "has correct hidden_in_check_answers for" do
+ expect(question.hidden_in_check_answers).to eq({
+ "depends_on" => [
+ {
+ "mscharge_known" => 1,
+ },
+ ],
+ })
+ end
+end
diff --git a/spec/models/form/sales/questions/leasehold_charges_spec.rb b/spec/models/form/sales/questions/leasehold_charges_spec.rb
new file mode 100644
index 000000000..a06fc9975
--- /dev/null
+++ b/spec/models/form/sales/questions/leasehold_charges_spec.rb
@@ -0,0 +1,49 @@
+require "rails_helper"
+
+RSpec.describe Form::Sales::Questions::LeaseholdCharges, type: :model do
+ subject(:question) { described_class.new(question_id, question_definition, page) }
+
+ let(:question_id) { nil }
+ let(:question_definition) { nil }
+ let(:page) { instance_double(Form::Page) }
+
+ it "has correct page" do
+ expect(question.page).to eq(page)
+ end
+
+ it "has the correct id" do
+ expect(question.id).to eq("mscharge")
+ end
+
+ it "has the correct header" do
+ expect(question.header).to eq("Enter the total monthly charge")
+ end
+
+ it "has the correct check_answer_label" do
+ expect(question.check_answer_label).to eq("Monthly leasehold charges")
+ end
+
+ it "has the correct type" do
+ expect(question.type).to eq("numeric")
+ end
+
+ it "is not marked as derived" do
+ expect(question.derived?).to be false
+ end
+
+ it "has the correct hint" do
+ expect(question.hint_text).to be_nil
+ end
+
+ it "has the correct width" do
+ expect(question.width).to eq(5)
+ end
+
+ it "has the correct min" do
+ expect(question.min).to eq(0)
+ end
+
+ it "has the correct prefix" do
+ expect(question.prefix).to eq("£")
+ end
+end
diff --git a/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb b/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb
index f6c05aeb6..e30e5bfde 100644
--- a/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb
+++ b/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb
@@ -21,6 +21,7 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
mortgage_amount_discounted_ownership
about_deposit_discounted_ownership
discounted_ownership_deposit_value_check
+ leasehold_charges_discounted_ownership
],
)
end
diff --git a/spec/models/form/sales/subsections/outright_sale_spec.rb b/spec/models/form/sales/subsections/outright_sale_spec.rb
index d39dee44c..06b394f27 100644
--- a/spec/models/form/sales/subsections/outright_sale_spec.rb
+++ b/spec/models/form/sales/subsections/outright_sale_spec.rb
@@ -13,11 +13,14 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do
it "has correct pages" do
expect(outright_sale.pages.map(&:id)).to eq(
- %w[purchase_price
- mortgage_used_outright_sale
- mortgage_amount_outright_sale
- about_deposit_outright_sale
- outright_sale_deposit_value_check],
+ %w[
+ purchase_price
+ mortgage_used_outright_sale
+ mortgage_amount_outright_sale
+ about_deposit_outright_sale
+ outright_sale_deposit_value_check
+ leasehold_charges_outright_sale
+ ],
)
end
diff --git a/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb b/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb
index e95579df3..06f98ba09 100644
--- a/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb
+++ b/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb
@@ -29,6 +29,7 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do
about_deposit_shared_ownership
shared_ownership_deposit_value_check
monthly_rent
+ leasehold_charges_shared_ownership
],
)
end
diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb
index 7d5339806..4fef52c66 100644
--- a/spec/models/form_handler_spec.rb
+++ b/spec/models/form_handler_spec.rb
@@ -52,14 +52,14 @@ RSpec.describe FormHandler do
it "is able to load a current sales form" do
form = form_handler.get_form("current_sales")
expect(form).to be_a(Form)
- expect(form.pages.count).to eq(122)
+ expect(form.pages.count).to eq(125)
expect(form.name).to eq("2022_2023_sales")
end
it "is able to load a previous sales form" do
form = form_handler.get_form("previous_sales")
expect(form).to be_a(Form)
- expect(form.pages.count).to eq(122)
+ expect(form.pages.count).to eq(125)
expect(form.name).to eq("2021_2022_sales")
end
end