Browse Source

Merge branch 'main' into CLDC-868-purchase-price-validations

# Conflicts:
#	spec/models/form_handler_spec.rb
pull/1285/head
natdeanlewissoftwire 3 years ago
parent
commit
666c056136
  1. 11
      app/models/form/sales/pages/living_before_purchase.rb
  2. 14
      app/models/form/sales/pages/purchase_price.rb
  3. 31
      app/models/form/sales/questions/living_before_purchase.rb
  4. 31
      app/models/form/sales/questions/living_before_purchase_years.rb
  5. 1
      app/models/form/sales/subsections/discounted_ownership_scheme.rb
  6. 2
      app/services/bulk_upload/lettings/row_parser.rb
  7. 5
      db/migrate/20230213140932_add_proplen_asked_to_sales_log.rb
  8. 3
      db/schema.rb
  9. 16
      spec/models/form/sales/pages/living_before_purchase_spec.rb
  10. 35
      spec/models/form/sales/pages/purchase_price_spec.rb
  11. 31
      spec/models/form/sales/questions/living_before_purchase_spec.rb
  12. 114
      spec/models/form/sales/questions/living_before_purchase_years_spec.rb
  13. 1
      spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb
  14. 4
      spec/models/form_handler_spec.rb
  15. 14
      spec/services/bulk_upload/lettings/row_parser_spec.rb

11
app/models/form/sales/pages/living_before_purchase.rb

@ -1,7 +1,14 @@
class Form::Sales::Pages::LivingBeforePurchase < ::Form::Page
def questions
@questions ||= [
Form::Sales::Questions::LivingBeforePurchase.new(nil, nil, self),
]
living_before_purchase,
Form::Sales::Questions::LivingBeforePurchaseYears.new(nil, nil, self),
].compact
end
def living_before_purchase
if form.start_date.year >= 2023
Form::Sales::Questions::LivingBeforePurchase.new(nil, nil, self)
end
end
end

14
app/models/form/sales/pages/purchase_price.rb

@ -1,14 +0,0 @@
class Form::Sales::Pages::PurchasePrice < ::Form::Page
def initialize(id, hsh, subsection)
super
@depends_on = [
{ "ownershipsch" => 2, "rent_to_buy_full_ownership?" => false },
]
end
def questions
@questions ||= [
Form::Sales::Questions::PurchasePrice.new(nil, nil, self),
]
end
end

31
app/models/form/sales/questions/living_before_purchase.rb

@ -1,15 +1,26 @@
class Form::Sales::Questions::LivingBeforePurchase < ::Form::Question
def initialize(id, hsh, page)
super
@id = "proplen"
@check_answer_label = "Number of years living in the property before purchase"
@header = "How long did the buyer(s) live in the property before purchase?"
@hint_text = "You should round this up to the nearest year. If the buyers haven't been living in the property, enter '0'"
@type = "numeric"
@min = 0
@max = 80
@step = 1
@width = 5
@suffix = " years"
@id = "proplen_asked"
@check_answer_label = "Buyer lived in the property before purchasing"
@header = "Did the buyer live in the property before purchasing it?"
@hint_text = nil
@type = "radio"
@answer_options = ANSWER_OPTIONS
@conditional_for = {
"proplen" => [0],
}
@hidden_in_check_answers = {
"depends_on" => [
{
"proplen_asked" => 0,
},
],
}
end
ANSWER_OPTIONS = {
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
}.freeze
end

31
app/models/form/sales/questions/living_before_purchase_years.rb

@ -0,0 +1,31 @@
class Form::Sales::Questions::LivingBeforePurchaseYears < ::Form::Question
def initialize(id, hsh, page)
super
@id = "proplen"
@check_answer_label = "Number of years living in the property before purchase"
@header = header_text
@hint_text = hint_text
@type = "numeric"
@min = 0
@max = 80
@step = 1
@width = 5
@suffix = " years"
end
def header_text
if form.start_date.year >= 2023
"How long did they live there?"
else
"How long did the buyer(s) live in the property before purchase?"
end
end
def hint_text
if form.start_date.year >= 2023
"You should round up to the nearest year"
else
"You should round this up to the nearest year. If the buyers haven't been living in the property, enter '0'"
end
end
end

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

@ -13,7 +13,6 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection
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::PurchasePriceOutrightOwnership.new("purchase_price_outright_ownership", 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),

2
app/services/bulk_upload/lettings/row_parser.rb

@ -776,6 +776,8 @@ private
case rsnvac
when 15, 16, 17
1
else
0
end
end

5
db/migrate/20230213140932_add_proplen_asked_to_sales_log.rb

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

3
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_02_10_143120) do
ActiveRecord::Schema[7.0].define(version: 2023_02_13_140932) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -529,6 +529,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_02_10_143120) do
t.integer "staircasesale"
t.integer "ethnic_group2"
t.integer "ethnicbuy2"
t.integer "proplen_asked"
t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id"
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id"
t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id"

16
spec/models/form/sales/pages/living_before_purchase_spec.rb

@ -11,9 +11,25 @@ RSpec.describe Form::Sales::Pages::LivingBeforePurchase, type: :model do
expect(page.subsection).to eq(subsection)
end
describe "questions" do
let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date:)) }
context "when 2022" do
let(:start_date) { Time.utc(2022, 2, 8) }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[proplen])
end
end
context "when 2023" do
let(:start_date) { Time.utc(2023, 2, 8) }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[proplen_asked proplen])
end
end
end
it "has the correct id" do
expect(page.id).to eq(nil)

35
spec/models/form/sales/pages/purchase_price_spec.rb

@ -1,35 +0,0 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::PurchasePrice, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { "purchase_price" }
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[value])
end
it "has the correct id" do
expect(page.id).to eq("purchase_price")
end
it "has the correct header" do
expect(page.header).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 eq([
{ "ownershipsch" => 2, "rent_to_buy_full_ownership?" => false },
])
end
end

31
spec/models/form/sales/questions/living_before_purchase_spec.rb

@ -12,19 +12,19 @@ RSpec.describe Form::Sales::Questions::LivingBeforePurchase, type: :model do
end
it "has the correct id" do
expect(question.id).to eq("proplen")
expect(question.id).to eq("proplen_asked")
end
it "has the correct header" do
expect(question.header).to eq("How long did the buyer(s) live in the property before purchase?")
expect(question.header).to eq("Did the buyer live in the property before purchasing it?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Number of years living in the property before purchase")
expect(question.check_answer_label).to eq("Buyer lived in the property before purchasing")
end
it "has the correct type" do
expect(question.type).to eq("numeric")
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
@ -32,26 +32,11 @@ RSpec.describe Form::Sales::Questions::LivingBeforePurchase, type: :model do
end
it "has the correct hint" do
expect(question.hint_text).to eq("You should round this up to the nearest year. If the buyers haven't been living in the property, enter '0'")
expect(question.hint_text).to be_nil
end
it "has correct width" do
expect(question.width).to eq(5)
end
it "has correct step" do
expect(question.step).to eq(1)
end
it "has correct suffix" do
expect(question.suffix).to eq(" years")
end
it "has correct min" do
expect(question.min).to eq(0)
end
it "has correct max" do
expect(question.max).to eq(80)
it "has the correct answer_options" do
expect(question.answer_options).to eq("0" => { "value" => "Yes" },
"1" => { "value" => "No" })
end
end

114
spec/models/form/sales/questions/living_before_purchase_years_spec.rb

@ -0,0 +1,114 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::LivingBeforePurchaseYears, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date:)) }
let(:page) { instance_double(Form::Page, subsection:) }
context "when 2022" do
let(:start_date) { Time.utc(2022, 2, 8) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("proplen")
end
it "has the correct header" do
expect(question.header).to eq("How long did the buyer(s) live in the property before purchase?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Number of years living in the property before purchase")
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 eq("You should round this up to the nearest year. If the buyers haven't been living in the property, enter '0'")
end
it "has correct width" do
expect(question.width).to eq(5)
end
it "has correct step" do
expect(question.step).to eq(1)
end
it "has correct suffix" do
expect(question.suffix).to eq(" years")
end
it "has correct min" do
expect(question.min).to eq(0)
end
it "has correct max" do
expect(question.max).to eq(80)
end
end
context "when 2023" do
let(:start_date) { Time.utc(2023, 2, 8) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("proplen")
end
it "has the correct header" do
expect(question.header).to eq("How long did they live there?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Number of years living in the property before purchase")
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 eq("You should round up to the nearest year")
end
it "has correct width" do
expect(question.width).to eq(5)
end
it "has correct step" do
expect(question.step).to eq(1)
end
it "has correct suffix" do
expect(question.suffix).to eq(" years")
end
it "has correct min" do
expect(question.min).to eq(0)
end
it "has correct max" do
expect(question.max).to eq(80)
end
end
end

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

@ -19,7 +19,6 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
extra_borrowing_price_value_check
about_price_not_rtb
grant_value_check
purchase_price_discounted_ownership
purchase_price_outright_ownership
about_price_discounted_ownership_value_check
discounted_ownership_deposit_and_mortgage_value_check_after_value_and_discount

4
spec/models/form_handler_spec.rb

@ -54,14 +54,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(183)
expect(form.pages.count).to eq(182)
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(183)
expect(form.pages.count).to eq(182)
expect(form.name).to eq("2021_2022_sales")
end
end

14
spec/services/bulk_upload/lettings/row_parser_spec.rb

@ -186,6 +186,12 @@ RSpec.describe BulkUpload::Lettings::RowParser do
field_80: "1234.56",
field_87: "1",
field_88: "234.56",
field_106: "15",
field_99: "0",
field_89: now.day.to_s,
field_90: now.month.to_s,
field_91: now.strftime("%g"),
}
end
@ -1154,6 +1160,14 @@ RSpec.describe BulkUpload::Lettings::RowParser do
expect(parser.log.first_time_property_let_as_social_housing).to eq(1)
end
end
context "when field_106 is not 15, 16, or 17" do
let(:attributes) { { bulk_upload:, field_106: "1" } }
it "sets to 0" do
expect(parser.log.first_time_property_let_as_social_housing).to eq(0)
end
end
end
describe "#housingneeds" do

Loading…
Cancel
Save