Browse Source

CLDC 882 add validation against grant (#1220)

* fix rebase conflicts

* fix rebase conflicts

* fix rebase conflicts

* implement soft validation of grant value

* fix rebase conflicts

* fix rebase conflicts

* fix rebase conflicts

* fix rebase conflicts

* fix final test from added page

* update test after rebase
pull/1245/head
Arthur Campbell 2 years ago committed by GitHub
parent
commit
0f17eab3fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      app/models/form/sales/pages/grant_value_check.rb
  2. 1
      app/models/form/sales/questions/grant.rb
  3. 23
      app/models/form/sales/questions/grant_value_check.rb
  4. 1
      app/models/form/sales/subsections/discounted_ownership_scheme.rb
  5. 6
      app/models/validations/sales/soft_validations.rb
  6. 5
      db/migrate/20230123160741_add_grant_value_check_to_sales_log.rb
  7. 6
      db/schema.rb
  8. 1
      spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb
  9. 4
      spec/models/form_handler_spec.rb
  10. 20
      spec/models/validations/sales/soft_validations_spec.rb

18
app/models/form/sales/pages/grant_value_check.rb

@ -0,0 +1,18 @@
class Form::Sales::Pages::GrantValueCheck < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "grant_value_check"
@depends_on = [
{
"grant_outside_common_range?" => true,
},
]
@informative_text = {}
end
def questions
@questions ||= [
Form::Sales::Questions::GrantValueCheck.new(nil, nil, self),
]
end
end

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

@ -6,6 +6,7 @@ class Form::Sales::Questions::Grant < ::Form::Question
@header = "What was the amount of any loan, grant, discount or subsidy given?"
@type = "numeric"
@min = 0
@max = 999_999
@width = 5
@prefix = "£"
@hint_text = "For all schemes except Right to Buy (RTB), Preserved Right to Buy (PRTB), Voluntary Right to Buy (VRTB)"

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

@ -0,0 +1,23 @@
class Form::Sales::Questions::GrantValueCheck < ::Form::Question
def initialize(id, hsh, page)
super
@id = "grant_value_check"
@check_answer_label = "Grant value confirmation"
@header = "Are you sure? Grants are usually £9,000 - £16,000"
@type = "interruption_screen"
@answer_options = {
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
}
@hidden_in_check_answers = {
"depends_on" => [
{
"grant_value_check" => 0,
},
{
"grant_value_check" => 1,
},
],
}
end
end

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

@ -12,6 +12,7 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection
Form::Sales::Pages::AboutPriceRtb.new(nil, nil, self),
Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_price_value_check", nil, self),
Form::Sales::Pages::AboutPriceNotRtb.new(nil, nil, self),
Form::Sales::Pages::GrantValueCheck.new(nil, nil, self),
Form::Sales::Pages::PurchasePrice.new("purchase_price_discounted_ownership", nil, self),
Form::Sales::Pages::Mortgageused.new("mortgage_used_discounted_ownership", nil, self),
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_discounted_ownership", nil, self),

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

@ -48,4 +48,10 @@ module Validations::Sales::SoftValidations
((saledate.to_date - hodate.to_date).to_i / 365) >= 3
end
def grant_outside_common_range?
return unless grant
!grant.between?(9_000, 16_000)
end
end

5
db/migrate/20230123160741_add_grant_value_check_to_sales_log.rb

@ -0,0 +1,5 @@
class AddGrantValueCheckToSalesLog < ActiveRecord::Migration[7.0]
def change
add_column :sales_logs, :grant_value_check, :integer
end
end

6
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_01_18_170602) do
ActiveRecord::Schema[7.0].define(version: 2023_01_23_160741) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -486,9 +486,9 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_18_170602) do
t.integer "hoyear"
t.integer "fromprop"
t.integer "socprevten"
t.integer "mortlen"
t.integer "mortgagelender"
t.string "mortgagelenderother"
t.integer "mortlen"
t.integer "extrabor"
t.integer "hhmemb"
t.integer "totadult"
@ -501,6 +501,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_18_170602) do
t.boolean "is_la_inferred"
t.bigint "bulk_upload_id"
t.integer "retirement_value_check"
t.integer "deposit_and_mortgage_value_check"
t.integer "grant_value_check"
t.integer "hodate_check"
t.integer "extrabor_value_check"
t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id"

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

@ -18,6 +18,7 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
about_price_rtb
extra_borrowing_price_value_check
about_price_not_rtb
grant_value_check
purchase_price_discounted_ownership
mortgage_used_discounted_ownership
mortgage_amount_discounted_ownership

4
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(187)
expect(form.pages.count).to eq(188)
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(187)
expect(form.pages.count).to eq(188)
expect(form.name).to eq("2021_2022_sales")
end
end

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

@ -396,4 +396,24 @@ RSpec.describe Validations::Sales::SoftValidations do
expect(record).not_to be_wheelchair_when_not_disabled
end
end
describe "#grant_outside_common_range?" do
it "returns true if grant is below 9000" do
record.grant = 1_000
expect(record).to be_grant_outside_common_range
end
it "returns true if grant is above 16000" do
record.grant = 100_000
expect(record).to be_grant_outside_common_range
end
it "returns false if grant is within expected range" do
record.grant = 10_000
expect(record).not_to be_grant_outside_common_range
end
end
end

Loading…
Cancel
Save