Browse Source

CLDC-3676: sales discounted sale soft validation

CLDC-3676-remove-all-pre-2025-validations
samyou-softwire 1 week ago
parent
commit
4454a815de
  1. 43
      app/models/form/sales/pages/discounted_sale_value_check.rb
  2. 22
      app/models/form/sales/questions/discounted_sale_value_check.rb
  3. 5
      app/models/form/sales/subsections/discounted_ownership_scheme.rb
  4. 9
      app/models/validations/sales/soft_validations.rb
  5. 53
      spec/models/form/sales/pages/discounted_sale_value_check_spec.rb
  6. 45
      spec/models/form/sales/questions/discounted_sale_value_check_spec.rb
  7. 55
      spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb
  8. 123
      spec/models/validations/sales/soft_validations_spec.rb

43
app/models/form/sales/pages/discounted_sale_value_check.rb

@ -1,43 +0,0 @@
class Form::Sales::Pages::DiscountedSaleValueCheck < ::Form::Page
def initialize(id, hsh, subsection, person_index = nil)
super(id, hsh, subsection)
@depends_on = depends_on
@copy_key = "sales.soft_validations.discounted_sale_value_check"
@title_text = {
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text",
"arguments" => [
{
"key" => "field_formatted_as_currency",
"arguments_for_key" => "value_with_discount",
"i18n_template" => "value_with_discount",
},
],
}
@informative_text = {
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.informative_text",
"arguments" => [
{
"key" => "field_formatted_as_currency",
"arguments_for_key" => "mortgage_deposit_and_grant_total",
"i18n_template" => "mortgage_deposit_and_grant_total",
},
],
}
@person_index = person_index
@depends_on = [
{
"discounted_ownership_value_invalid?" => true,
},
]
end
def questions
@questions ||= [
Form::Sales::Questions::DiscountedSaleValueCheck.new(nil, nil, self),
]
end
def interruption_screen_question_ids
%w[value deposit ownershipsch mortgage mortgageused discount grant type]
end
end

22
app/models/form/sales/questions/discounted_sale_value_check.rb

@ -1,22 +0,0 @@
class Form::Sales::Questions::DiscountedSaleValueCheck < ::Form::Question
def initialize(id, hsh, page)
super
@id = "discounted_sale_value_check"
@copy_key = "sales.soft_validations.discounted_sale_value_check"
@type = "interruption_screen"
@answer_options = {
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
}
@hidden_in_check_answers = {
"depends_on" => [
{
"discounted_sale_value_check" => 0,
},
{
"discounted_sale_value_check" => 1,
},
],
}
end
end

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

@ -18,16 +18,12 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection
Form::Sales::Pages::Grant.new(nil, nil, self),
Form::Sales::Pages::GrantValueCheck.new(nil, nil, self),
Form::Sales::Pages::PurchasePriceOutrightOwnership.new("purchase_price_discounted_ownership", nil, self, ownershipsch: 2),
Form::Sales::Pages::DiscountedSaleValueCheck.new("discounted_sale_grant_value_check", nil, self),
Form::Sales::Pages::AboutPriceValueCheck.new("about_price_discounted_ownership_value_check", nil, self),
Form::Sales::Pages::DepositAndMortgageValueCheck.new("discounted_ownership_deposit_and_mortgage_value_check_after_value_and_discount", nil, self),
Form::Sales::Pages::Mortgageused.new("mortgage_used_discounted_ownership", nil, self, ownershipsch: 2),
Form::Sales::Pages::MortgageValueCheck.new("discounted_ownership_mortgage_used_mortgage_value_check", nil, self),
Form::Sales::Pages::DiscountedSaleValueCheck.new("discounted_sale_mortgage_used_value_check", nil, self),
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_discounted_ownership", nil, self, ownershipsch: 2),
Form::Sales::Pages::MortgageValueCheck.new("discounted_ownership_mortgage_amount_mortgage_value_check", nil, self),
Form::Sales::Pages::DiscountedSaleValueCheck.new("discounted_sale_mortgage_value_check", nil, self),
Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_mortgage_value_check", nil, self),
Form::Sales::Pages::DepositAndMortgageValueCheck.new("discounted_ownership_deposit_and_mortgage_value_check_after_mortgage", nil, self),
mortgage_lender_questions,
(Form::Sales::Pages::MortgageLength.new("mortgage_length_discounted_ownership", nil, self, ownershipsch: 2) unless form.start_year_2026_or_later?),
@ -40,7 +36,6 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection
Form::Sales::Pages::DepositValueCheck.new("discounted_ownership_deposit_joint_purchase_value_check", nil, self, joint_purchase: true),
Form::Sales::Pages::DepositValueCheck.new("discounted_ownership_deposit_value_check", nil, self, joint_purchase: false),
Form::Sales::Pages::DepositAndMortgageValueCheck.new("discounted_ownership_deposit_and_mortgage_value_check_after_deposit", nil, self),
Form::Sales::Pages::DiscountedSaleValueCheck.new("discounted_sale_deposit_value_check", nil, self),
Form::Sales::Pages::LeaseholdCharges.new("leasehold_charges_discounted_ownership", nil, self, ownershipsch: 2),
Form::Sales::Pages::MonthlyChargesValueCheck.new("monthly_charges_discounted_ownership_value_check", nil, self),
].flatten.compact

9
app/models/validations/sales/soft_validations.rb

@ -159,15 +159,6 @@ module Validations::Sales::SoftValidations
end
end
def discounted_ownership_value_invalid?
return unless saledate && collection_start_year <= 2023
return unless value && deposit && ownershipsch
return unless mortgage || mortgageused == 2 || mortgageused == 3
return unless discount || grant || type == 29
mortgage_deposit_and_grant_total != value_with_discount && discounted_ownership_sale?
end
def buyer1_livein_wrong_for_ownership_type?
return unless ownershipsch && buy1livein

53
spec/models/form/sales/pages/discounted_sale_value_check_spec.rb

@ -1,53 +0,0 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::DiscountedSaleValueCheck, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection, index) }
let(:page_id) { "discounted_sale_value_check" }
let(:page_definition) { nil }
let(:index) { 1 }
let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) }
let(:subsection) { instance_double(Form::Subsection, form:) }
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[discounted_sale_value_check])
end
it "has the correct id" do
expect(page.id).to eq("discounted_sale_value_check")
end
it "has the correct title_text" do
expect(page.title_text).to eq({
"translation" => "forms.2024.sales.soft_validations.discounted_sale_value_check.title_text",
"arguments" => [{ "arguments_for_key" => "value_with_discount", "i18n_template" => "value_with_discount", "key" => "field_formatted_as_currency" }],
})
end
it "has the correct informative_text" do
expect(page.informative_text).to eq({
"translation" => "forms.2024.sales.soft_validations.discounted_sale_value_check.informative_text",
"arguments" => [{ "arguments_for_key" => "mortgage_deposit_and_grant_total", "i18n_template" => "mortgage_deposit_and_grant_total", "key" => "field_formatted_as_currency" }],
})
end
it "is interruption screen page" do
expect(page.interruption_screen?).to be(true)
end
it "has correct depends_on" do
expect(page.depends_on).to eq([
{
"discounted_ownership_value_invalid?" => true,
},
])
end
it "has correct interruption_screen_question_ids" do
expect(page.interruption_screen_question_ids).to eq(%w[value deposit ownershipsch mortgage mortgageused discount grant type])
end
end

45
spec/models/form/sales/questions/discounted_sale_value_check_spec.rb

@ -1,45 +0,0 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::DiscountedSaleValueCheck, 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("discounted_sale_value_check")
end
it "has the correct type" do
expect(question.type).to eq("interruption_screen")
end
it "is not marked as derived" do
expect(question.derived?(nil)).to be false
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
})
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq({
"depends_on" => [
{
"discounted_sale_value_check" => 0,
},
{
"discounted_sale_value_check" => 1,
},
],
})
end
end

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

@ -52,51 +52,6 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
end
end
context "when 2024", metadata: { year: 24 } do
let(:start_year_2025_or_later?) { false }
let(:start_year_2026_or_later?) { false }
it "has correct pages" do
expect(discounted_ownership_scheme.pages.map(&:id)).to eq(
%w[
living_before_purchase_discounted_ownership_joint_purchase
living_before_purchase_discounted_ownership
purchase_price
discount
extra_borrowing_price_value_check
percentage_discount_value_check
grant
grant_value_check
purchase_price_discounted_ownership
discounted_sale_grant_value_check
about_price_discounted_ownership_value_check
discounted_ownership_deposit_and_mortgage_value_check_after_value_and_discount
mortgage_used_discounted_ownership
discounted_ownership_mortgage_used_mortgage_value_check
discounted_sale_mortgage_used_value_check
mortgage_amount_discounted_ownership
discounted_ownership_mortgage_amount_mortgage_value_check
discounted_sale_mortgage_value_check
extra_borrowing_mortgage_value_check
discounted_ownership_deposit_and_mortgage_value_check_after_mortgage
mortgage_lender_discounted_ownership
mortgage_lender_other_discounted_ownership
mortgage_length_discounted_ownership
extra_borrowing_discounted_ownership
extra_borrowing_value_check
deposit_discounted_ownership
extra_borrowing_deposit_value_check
discounted_ownership_deposit_joint_purchase_value_check
discounted_ownership_deposit_value_check
discounted_ownership_deposit_and_mortgage_value_check_after_deposit
discounted_sale_deposit_value_check
leasehold_charges_discounted_ownership
monthly_charges_discounted_ownership_value_check
],
)
end
end
context "when 2025", metadata: { year: 25 } do
let(:start_year_2026_or_later?) { false }
@ -112,16 +67,12 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
grant
grant_value_check
purchase_price_discounted_ownership
discounted_sale_grant_value_check
about_price_discounted_ownership_value_check
discounted_ownership_deposit_and_mortgage_value_check_after_value_and_discount
mortgage_used_discounted_ownership
discounted_ownership_mortgage_used_mortgage_value_check
discounted_sale_mortgage_used_value_check
mortgage_amount_discounted_ownership
discounted_ownership_mortgage_amount_mortgage_value_check
discounted_sale_mortgage_value_check
extra_borrowing_mortgage_value_check
discounted_ownership_deposit_and_mortgage_value_check_after_mortgage
mortgage_length_discounted_ownership
extra_borrowing_discounted_ownership
@ -131,7 +82,6 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
discounted_ownership_deposit_joint_purchase_value_check
discounted_ownership_deposit_value_check
discounted_ownership_deposit_and_mortgage_value_check_after_deposit
discounted_sale_deposit_value_check
leasehold_charges_discounted_ownership
monthly_charges_discounted_ownership_value_check
],
@ -152,16 +102,12 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
grant
grant_value_check
purchase_price_discounted_ownership
discounted_sale_grant_value_check
about_price_discounted_ownership_value_check
discounted_ownership_deposit_and_mortgage_value_check_after_value_and_discount
mortgage_used_discounted_ownership
discounted_ownership_mortgage_used_mortgage_value_check
discounted_sale_mortgage_used_value_check
mortgage_amount_discounted_ownership
discounted_ownership_mortgage_amount_mortgage_value_check
discounted_sale_mortgage_value_check
extra_borrowing_mortgage_value_check
discounted_ownership_deposit_and_mortgage_value_check_after_mortgage
mortgage_length_discounted_ownership_not_interviewed
mortgage_length_discounted_ownership_interviewed
@ -172,7 +118,6 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
discounted_ownership_deposit_joint_purchase_value_check
discounted_ownership_deposit_value_check
discounted_ownership_deposit_and_mortgage_value_check_after_deposit
discounted_sale_deposit_value_check
leasehold_charges_discounted_ownership
monthly_charges_discounted_ownership_value_check
],

123
spec/models/validations/sales/soft_validations_spec.rb

@ -961,129 +961,6 @@ RSpec.describe Validations::Sales::SoftValidations do
end
end
describe "#discounted_ownership_value_invalid?" do
context "when grant is routed to" do
let(:record) { FactoryBot.build(:sales_log, mortgage: 10_000, deposit: 5_000, value: 30_000, ownershipsch: 2, type: 8, saledate: Time.zone.local(2023, 4, 3)) }
context "and not provided" do
before do
record.grant = nil
end
it "returns false" do
expect(record).not_to be_discounted_ownership_value_invalid
end
end
context "and is provided" do
it "returns true if mortgage, deposit and grant total does not equal market value" do
record.grant = 3_000
expect(record).to be_discounted_ownership_value_invalid
end
it "returns false if mortgage, deposit and grant total equals market value" do
record.grant = 15_000
expect(record).not_to be_discounted_ownership_value_invalid
end
end
end
context "when discount is routed to" do
let(:record) { FactoryBot.build(:sales_log, mortgage: 10_000, deposit: 5_000, value: 30_000, ownershipsch: 2, type: 9, saledate: Time.zone.local(2023, 4, 3)) }
context "and not provided" do
before do
record.discount = nil
end
it "returns false" do
expect(record).not_to be_discounted_ownership_value_invalid
end
end
context "and is provided" do
it "returns true if mortgage and deposit total does not equal market value - discount" do
record.discount = 10
expect(record).to be_discounted_ownership_value_invalid
end
it "returns false if mortgage and deposit total equals market value - discount" do
record.discount = 50
expect(record).not_to be_discounted_ownership_value_invalid
end
end
end
context "when neither discount nor grant is routed to" do
let(:record) { FactoryBot.build(:sales_log, mortgage: 10_000, value: 30_000, ownershipsch: 2, type: 29, saledate: Time.zone.local(2023, 4, 3)) }
it "returns true if mortgage and deposit total does not equal market value" do
record.deposit = 2_000
expect(record).to be_discounted_ownership_value_invalid
end
it "returns false if mortgage and deposit total equals market value" do
record.deposit = 20_000
expect(record).not_to be_discounted_ownership_value_invalid
end
end
context "when mortgage is routed to" do
let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, deposit: 5_000, grant: 3_000, value: 20_000, discount: 10, ownershipsch: 2, saledate: Time.zone.local(2023, 4, 3)) }
context "and not provided" do
before do
record.mortgage = nil
end
it "returns false" do
expect(record).not_to be_discounted_ownership_value_invalid
end
end
context "and is provided" do
it "returns true if mortgage, grant and deposit total does not equal market value - discount" do
record.mortgage = 10
expect(record).to be_discounted_ownership_value_invalid
end
it "returns false if mortgage, grant and deposit total equals market value - discount" do
record.mortgage = 10_000
expect(record).not_to be_discounted_ownership_value_invalid
end
end
end
context "when mortgage is not routed to" do
let(:record) { FactoryBot.build(:sales_log, mortgageused: 2, deposit: 5_000, grant: 3_000, value: 20_000, discount: 10, ownershipsch: 2, saledate: Time.zone.local(2023, 4, 3)) }
it "returns true if grant and deposit total does not equal market value - discount" do
expect(record).to be_discounted_ownership_value_invalid
end
it "returns false if mortgage, grant and deposit total equals market value - discount" do
record.grant = 13_000
expect(record).not_to be_discounted_ownership_value_invalid
end
end
context "when ownership is not discounted" do
let(:record) { FactoryBot.build(:sales_log, mortgage: 10_000, deposit: 5_000, grant: 3_000, value: 20_000, discount: 10, ownershipsch: 1, saledate: Time.zone.local(2023, 4, 3)) }
it "returns false" do
expect(record).not_to be_discounted_ownership_value_invalid
end
end
context "when it is a 2024 log" do
let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, deposit: 5_000, grant: 3_000, value: 20_000, discount: 10, ownershipsch: 2, saledate: Time.zone.local(2024, 4, 3)) }
it "returns true if mortgage, grant and deposit total does not equal market value - discount" do
record.mortgage = 10
expect(record).not_to be_discounted_ownership_value_invalid
end
end
end
describe "#buyer1_livein_wrong_for_ownership_type?" do
context "when it's a shared ownership" do

Loading…
Cancel
Save