Browse Source

CLDC-4174: clone Q88 service charge question for staircasing (#3182)

* add the question

* CLDC-4174: update question number for 2026

* CLDc-4174: update question number for 2026

* CLDc-4174: update subsection

* CLDc-4174: update question specs

* CLDC-4174: add subsection spec

* CLDc-4174: lint

* CLDc-4174: add new page test

* CLDC-4241: lint

* CLDC-4241: lint

* CLDC-4174: copy sales log csv updates from CLDC-4176

---------

Co-authored-by: Samuel Young <samuel.young@softwire.com>
pull/3186/head^2
Nat Dean-Lewis 2 weeks ago committed by GitHub
parent
commit
6f0bef3432
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      app/models/form/sales/pages/service_charge.rb
  2. 13
      app/models/form/sales/pages/service_charge_staircasing.rb
  3. 15
      app/models/form/sales/questions/has_service_charge.rb
  4. 16
      app/models/form/sales/questions/service_charge.rb
  5. 1
      app/models/form/sales/subsections/shared_ownership_staircasing_transaction.rb
  6. 11
      app/services/csv/sales_log_csv_service.rb
  7. 29
      spec/models/form/sales/pages/service_charge_staircasing_spec.rb
  8. 48
      spec/models/form/sales/questions/has_service_charge_spec.rb
  9. 47
      spec/models/form/sales/questions/service_charge_spec.rb
  10. 85
      spec/models/form/sales/subsections/shared_ownership_staircasing_transaction_spec.rb

4
app/models/form/sales/pages/service_charge.rb

@ -6,8 +6,8 @@ class Form::Sales::Pages::ServiceCharge < ::Form::Page
def questions
@questions ||= [
Form::Sales::Questions::HasServiceCharge.new(nil, nil, self),
Form::Sales::Questions::ServiceCharge.new(nil, nil, self),
Form::Sales::Questions::HasServiceCharge.new(nil, nil, self, staircasing: false),
Form::Sales::Questions::ServiceCharge.new(nil, nil, self, staircasing: false),
]
end
end

13
app/models/form/sales/pages/service_charge_staircasing.rb

@ -0,0 +1,13 @@
class Form::Sales::Pages::ServiceChargeStaircasing < ::Form::Page
def initialize(id, hsh, subsection)
super
@copy_key = "sales.sale_information.servicecharges"
end
def questions
@questions ||= [
Form::Sales::Questions::HasServiceCharge.new(nil, nil, self, staircasing: true),
Form::Sales::Questions::ServiceCharge.new(nil, nil, self, staircasing: true),
]
end
end

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

@ -1,6 +1,6 @@
class Form::Sales::Questions::HasServiceCharge < ::Form::Question
def initialize(id, hsh, subsection)
super
def initialize(id, hsh, subsection, staircasing:)
super(id, hsh, subsection)
@id = "has_mscharge"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@ -15,7 +15,8 @@ class Form::Sales::Questions::HasServiceCharge < ::Form::Question
],
}
@copy_key = "sales.sale_information.servicecharges.has_servicecharge"
@question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max]
@staircasing = staircasing
@question_number = question_number_from_year[form.start_date.year] || question_number_from_year[question_number_from_year.keys.max]
end
ANSWER_OPTIONS = {
@ -23,5 +24,11 @@ class Form::Sales::Questions::HasServiceCharge < ::Form::Question
"0" => { "value" => "No" },
}.freeze
QUESTION_NUMBER_FROM_YEAR = { 2025 => 88 }.freeze
def question_number_from_year
if @staircasing
{ 2026 => 0 }.freeze
else
{ 2025 => 88, 2026 => 0 }.freeze
end
end
end

16
app/models/form/sales/questions/service_charge.rb

@ -1,16 +1,24 @@
class Form::Sales::Questions::ServiceCharge < ::Form::Question
def initialize(id, hsh, subsection)
super
def initialize(id, hsh, subsection, staircasing:)
super(id, hsh, subsection)
@id = "mscharge"
@type = "numeric"
@min = 1
@max = 9999.99
@step = 0.01
@width = 5
@prefix = "£"
@copy_key = "sales.sale_information.servicecharges.servicecharge"
@question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max]
@staircasing = staircasing
@question_number = question_number_from_year[form.start_date.year] || question_number_from_year[question_number_from_year.keys.max]
@strip_commas = true
end
QUESTION_NUMBER_FROM_YEAR = { 2025 => 88 }.freeze
def question_number_from_year
if @staircasing
{ 2026 => 0 }.freeze
else
{ 2025 => 88, 2026 => 0 }.freeze
end
end
end

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

@ -25,6 +25,7 @@ class Form::Sales::Subsections::SharedOwnershipStaircasingTransaction < ::Form::
Form::Sales::Pages::Mortgageused.new("staircase_mortgage_used_shared_ownership", nil, self, ownershipsch: 1),
Form::Sales::Pages::MonthlyRentStaircasingOwned.new(nil, nil, self),
Form::Sales::Pages::MonthlyRentStaircasing.new(nil, nil, self),
(Form::Sales::Pages::ServiceChargeStaircasing.new("service_charge_staircasing", nil, self) if form.start_year_2026_or_later?),
Form::Sales::Pages::MonthlyChargesValueCheck.new("monthly_charges_shared_ownership_value_check", nil, self),
].compact
end

11
app/services/csv/sales_log_csv_service.rb

@ -249,7 +249,7 @@ module Csv
return @attributes unless @user.support?
mappings = SUPPORT_ATTRIBUTE_NAME_MAPPINGS
mappings = mappings.merge(SUPPORT_ATTRIBUTE_NAME_MAPPINGS_2025) if @year == 2025
mappings = mappings.merge(SUPPORT_ATTRIBUTE_NAME_MAPPINGS_2025) if @year >= 2025
@attributes.map do |attribute|
mappings[attribute] || attribute.upcase
@ -297,11 +297,10 @@ module Csv
end
def attribute_mappings
mappings = case @year
when 2024
ATTRIBUTE_MAPPINGS.merge(ATTRIBUTE_MAPPINGS_2024)
when 2025
mappings = if @year >= 2025
ATTRIBUTE_MAPPINGS.merge(ATTRIBUTE_MAPPINGS_2024).merge(ATTRIBUTE_MAPPINGS_2025)
elsif @year == 2024
ATTRIBUTE_MAPPINGS.merge(ATTRIBUTE_MAPPINGS_2024)
else
ATTRIBUTE_MAPPINGS
end
@ -348,6 +347,8 @@ module Csv
%w[id status duplicate_set_id created_at updated_at collection_start_year creation_method bulk_upload_id is_dpo]
when 2025
%w[id status duplicate_set_id created_at created_by_id updated_at updated_by_id creation_method bulk_upload_id]
when 2026
%w[id status duplicate_set_id created_at created_by_id updated_at updated_by_id creation_method bulk_upload_id]
else
%w[id status duplicate_set_id created_at updated_at collection_start_year creation_method bulk_upload_id is_dpo]
end

29
spec/models/form/sales/pages/service_charge_staircasing_spec.rb

@ -0,0 +1,29 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::ServiceChargeStaircasing, 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, form: instance_double(Form, start_date: Time.zone.local(2026, 4, 1))) }
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[has_mscharge mscharge])
end
it "has the correct id" do
expect(page.id).to be_nil
end
it "has the correct description" do
expect(page.description).to be_nil
end
it "has correct depends_on" do
expect(page.depends_on).to be_nil
end
end

48
spec/models/form/sales/questions/has_service_charge_spec.rb

@ -1,12 +1,14 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::HasServiceCharge, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
subject(:question) { described_class.new(question_id, question_definition, page, staircasing:) }
let(:form) { instance_double(Form, start_date: Time.zone.local(2025, 4, 4)) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, id: "shared_ownership", form:)) }
let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date:)) }
let(:page) { instance_double(Form::Page, subsection:) }
let(:start_date) { Time.utc(2025, 5, 1) }
let(:staircasing) { false }
it "has correct page" do
expect(question.page).to eq(page)
@ -46,4 +48,44 @@ RSpec.describe Form::Sales::Questions::HasServiceCharge, type: :model do
],
})
end
context "with 2025/26 form" do
let(:start_date) { Time.utc(2025, 4, 1) }
before do
allow(subsection.form).to receive(:start_year_2025_or_later?).and_return(true)
end
context "when not staircasing" do
let(:staircasing) { false }
it "has the correct question number" do
expect(question.question_number).to eq(88)
end
end
end
context "with 2026/27 form" do
let(:start_date) { Time.utc(2026, 4, 1) }
before do
allow(subsection.form).to receive(:start_year_2026_or_later?).and_return(true)
end
context "when staircasing" do
let(:staircasing) { true }
it "has the correct question number" do
expect(question.question_number).to eq(0)
end
end
context "when not staircasing" do
let(:staircasing) { false }
it "has the correct question number" do
expect(question.question_number).to eq(0)
end
end
end
end

47
spec/models/form/sales/questions/service_charge_spec.rb

@ -1,11 +1,14 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::ServiceCharge, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
subject(:question) { described_class.new(question_id, question_definition, page, staircasing:) }
let(:question_id) { 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)))) }
let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date:)) }
let(:page) { instance_double(Form::Page, subsection:) }
let(:start_date) { Time.utc(2023, 4, 1) }
let(:staircasing) { false }
it "has correct page" do
expect(question.page).to eq(page)
@ -34,4 +37,44 @@ RSpec.describe Form::Sales::Questions::ServiceCharge, type: :model do
it "has the correct prefix" do
expect(question.prefix).to eq("£")
end
context "with 2025/26 form" do
let(:start_date) { Time.utc(2025, 4, 1) }
before do
allow(subsection.form).to receive(:start_year_2025_or_later?).and_return(true)
end
context "when not staircasing" do
let(:staircasing) { false }
it "has the correct question number" do
expect(question.question_number).to eq(88)
end
end
end
context "with 2026/27 form" do
let(:start_date) { Time.utc(2026, 4, 1) }
before do
allow(subsection.form).to receive(:start_year_2026_or_later?).and_return(true)
end
context "when staircasing" do
let(:staircasing) { true }
it "has the correct question number" do
expect(question.question_number).to eq(0)
end
end
context "when not staircasing" do
let(:staircasing) { false }
it "has the correct question number" do
expect(question.question_number).to eq(0)
end
end
end
end

85
spec/models/form/sales/subsections/shared_ownership_staircasing_transaction_spec.rb

@ -0,0 +1,85 @@
require "rails_helper"
RSpec.describe Form::Sales::Subsections::SharedOwnershipStaircasingTransaction, type: :model do
subject(:shared_ownership_staircasing_transaction) { described_class.new(nil, nil, section) }
let(:form) { instance_double(Form, start_year_2026_or_later?: false) }
let(:section) { instance_double(Form::Sales::Sections::SaleInformation, form:) }
it "has correct section" do
expect(shared_ownership_staircasing_transaction.section).to eq(section)
end
it "has the correct depends_on" do
expect(shared_ownership_staircasing_transaction.depends_on).to eq([{ "ownershipsch" => 1, "setup_completed?" => true, "staircase" => 1 }])
end
it "has the correct id" do
expect(shared_ownership_staircasing_transaction.id).to eq("shared_ownership_staircasing_transaction")
end
it "has the correct label" do
expect(shared_ownership_staircasing_transaction.label).to eq("Shared ownership - staircasing transaction")
end
it "has the correct copy key" do
expect(shared_ownership_staircasing_transaction.copy_key).to eq("sale_information")
end
context "when the start year is 2025" do
let(:form) { instance_double(Form, start_year_2025_or_later?: true, start_year_2026_or_later?: false, start_date: Time.utc(2025, 4, 1)) }
it "has correct pages" do
expect(shared_ownership_staircasing_transaction.pages.map(&:id)).to eq(
%w[
about_staircasing_joint_purchase
about_staircasing_not_joint_purchase
staircase_sale
staircase_bought_value_check
staircase_owned_value_check_joint_purchase
staircase_owned_value_check_not_joint_purchase
staircase_first_time
staircase_previous
staircase_initial_date
value_shared_ownership_staircase
about_price_shared_ownership_value_check_staircasing
staircase_equity
shared_ownership_equity_value_check_staircasing
staircase_mortgage_used_shared_ownership
monthly_rent_staircasing_owned
monthly_rent_staircasing
monthly_charges_shared_ownership_value_check
],
)
end
end
context "when the start year is 2026" do
let(:form) { instance_double(Form, start_year_2025_or_later?: true, start_year_2026_or_later?: true, start_date: Time.utc(2026, 4, 1)) }
it "has correct pages" do
expect(shared_ownership_staircasing_transaction.pages.map(&:id)).to eq(
%w[
about_staircasing_joint_purchase
about_staircasing_not_joint_purchase
staircase_sale
staircase_bought_value_check
staircase_owned_value_check_joint_purchase
staircase_owned_value_check_not_joint_purchase
staircase_first_time
staircase_previous
staircase_initial_date
value_shared_ownership_staircase
about_price_shared_ownership_value_check_staircasing
staircase_equity
shared_ownership_equity_value_check_staircasing
staircase_mortgage_used_shared_ownership
monthly_rent_staircasing_owned
monthly_rent_staircasing
service_charge_staircasing
monthly_charges_shared_ownership_value_check
],
)
end
end
end
Loading…
Cancel
Save