Browse Source

CLDC-868 Add purchase price validations (#1225)

* feat: wip behaviour

* feat: hide in cya

* feat: show in cya

* feat: purchase price range service and rake task

* feat: fix hodate validation and use purchase price ranges

* db:update

* feat: more saledate -> exdate fixing

* feat: add min and max conditional text

* refactor: linting

* refactor: remove duplicated behaviour

* refactor: linting

* feat: update tests

* test: add validation tests

* test: add purchase price rangeimport service tests

* refactor: linting

* feat: allow translation text and title text to display currency formatting even when not a log field

* feat: use i18n

* feat: update i18n

* refactor: pratical -> practical

* refactor: linting

* refactor: revert unnecessary change

* feat: respond to PR comments

* tests: update after merge

* feat: improve currency interruption screen display

* feat: update docs

* feat: fix typo

* feat: missing end after merge

* feat: respond to PR comments

* feat: add soft validation to beds and la pages

* db:update

* feat: revert saledate/exdate work

* feat: revert saledate/exdate work

* feat: revert saledate/exdate work

* feat: revert saledate/exdate work

* feat: revert saledate/exdate work

* feat: PO comment responses

* tests: update

* refactor: linting

* refactor: simplification

* refactor: railsification

* test: fix

* refactor: use number_to_currency units

* refactor: remove duplicated copy

* db:update
pull/1272/head
natdeanlewissoftwire 2 years ago committed by GitHub
parent
commit
d254ef8c62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/helpers/interruption_screen_helper.rb
  2. 42
      app/models/form/sales/pages/about_price_shared_ownership_value_check.rb
  3. 23
      app/models/form/sales/questions/about_price_shared_ownership_value_check.rb
  4. 2
      app/models/form/sales/subsections/property_information.rb
  5. 1
      app/models/form/sales/subsections/shared_ownership_scheme.rb
  6. 2
      app/models/la_sale_range.rb
  7. 1
      app/models/log.rb
  8. 10
      app/models/sales_log.rb
  9. 4
      app/models/validations/sales/sale_information_validations.rb
  10. 20
      app/models/validations/sales/soft_validations.rb
  11. 6
      app/services/imports/rent_ranges_service.rb
  12. 27
      app/services/imports/sale_ranges_service.rb
  13. 7
      config/locales/en.yml
  14. 1329
      config/sale_range_data/2022.csv
  15. 5
      db/migrate/20230123171907_add_about_price_shared_ownership_value_check_to_sales_log.rb
  16. 14
      db/migrate/20230124111328_create_la_sale_ranges.rb
  17. 12
      db/schema.rb
  18. 9
      db/seeds.rb
  19. 21
      docs/form/page.md
  20. 14
      lib/tasks/sale_ranges.rake
  21. 5
      spec/fixtures/files/sale_ranges.csv
  22. 47
      spec/lib/tasks/sale_range_import_spec.rb
  23. 2
      spec/models/form/sales/subsections/property_information_spec.rb
  24. 1
      spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb
  25. 4
      spec/models/form_handler_spec.rb
  26. 4
      spec/models/validations/sales/sale_information_validations_spec.rb
  27. 63
      spec/models/validations/sales/soft_validations_spec.rb

4
app/helpers/interruption_screen_helper.rb

@ -7,6 +7,8 @@ module InterruptionScreenHelper
value = if argument["label"] value = if argument["label"]
pre_casing_value = lettings_log.form.get_question(argument["key"], lettings_log).answer_label(lettings_log) pre_casing_value = lettings_log.form.get_question(argument["key"], lettings_log).answer_label(lettings_log)
pre_casing_value.downcase pre_casing_value.downcase
elsif argument["currency"]
number_to_currency(lettings_log.public_send(argument["key"]), delimiter: ",", format: "%n", unit: "£")
else else
lettings_log.public_send(argument["key"]) lettings_log.public_send(argument["key"])
end end
@ -30,6 +32,8 @@ module InterruptionScreenHelper
arguments.each do |argument| arguments.each do |argument|
value = if argument["label"] value = if argument["label"]
lettings_log.form.get_question(argument["key"], lettings_log).answer_label(lettings_log).downcase lettings_log.form.get_question(argument["key"], lettings_log).answer_label(lettings_log).downcase
elsif argument["currency"]
number_to_currency(lettings_log.public_send(argument["key"]), delimiter: ",", format: "%n", unit: "£")
else else
lettings_log.public_send(argument["key"]) lettings_log.public_send(argument["key"])
end end

42
app/models/form/sales/pages/about_price_shared_ownership_value_check.rb

@ -0,0 +1,42 @@
class Form::Sales::Pages::AboutPriceSharedOwnershipValueCheck < ::Form::Page
def initialize(id, hsh, subsection)
super
@depends_on = [
{
"purchase_price_out_of_soft_range?" => true,
},
]
@title_text = {
"translation" => "soft_validations.purchase_price.title_text",
"arguments" => [
{
"key" => "value",
"label" => true,
"i18n_template" => "value",
},
],
}
@informative_text = {
"translation" => "soft_validations.purchase_price.hint_text",
"arguments" => [
{
"key" => "purchase_price_soft_min_or_soft_max",
"label" => false,
"i18n_template" => "soft_min_or_soft_max",
"currency" => true,
},
{
"key" => "purchase_price_min_or_max_text",
"label" => false,
"i18n_template" => "min_or_max",
},
],
}
end
def questions
@questions ||= [
Form::Sales::Questions::AboutPriceSharedOwnershipValueCheck.new(nil, nil, self),
]
end
end

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

@ -0,0 +1,23 @@
class Form::Sales::Questions::AboutPriceSharedOwnershipValueCheck < ::Form::Question
def initialize(id, hsh, page)
super
@id = "value_value_check"
@check_answer_label = "Purchase price confirmation"
@header = "Are you sure?"
@type = "interruption_screen"
@answer_options = {
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
}
@hidden_in_check_answers = {
"depends_on" => [
{
"value_value_check" => 0,
},
{
"value_value_check" => 1,
},
],
}
end
end

2
app/models/form/sales/subsections/property_information.rb

@ -9,11 +9,13 @@ class Form::Sales::Subsections::PropertyInformation < ::Form::Subsection
def pages def pages
@pages ||= [ @pages ||= [
Form::Sales::Pages::PropertyNumberOfBedrooms.new(nil, nil, self), Form::Sales::Pages::PropertyNumberOfBedrooms.new(nil, nil, self),
Form::Sales::Pages::AboutPriceSharedOwnershipValueCheck.new("about_price_shared_ownership_bedrooms_value_check", nil, self),
Form::Sales::Pages::PropertyUnitType.new(nil, nil, self), Form::Sales::Pages::PropertyUnitType.new(nil, nil, self),
Form::Sales::Pages::MonthlyChargesValueCheck.new("monthly_charges_property_type_value_check", nil, self), Form::Sales::Pages::MonthlyChargesValueCheck.new("monthly_charges_property_type_value_check", nil, self),
Form::Sales::Pages::PropertyBuildingType.new(nil, nil, self), Form::Sales::Pages::PropertyBuildingType.new(nil, nil, self),
Form::Sales::Pages::Postcode.new(nil, nil, self), Form::Sales::Pages::Postcode.new(nil, nil, self),
Form::Sales::Pages::PropertyLocalAuthority.new(nil, nil, self), Form::Sales::Pages::PropertyLocalAuthority.new(nil, nil, self),
Form::Sales::Pages::AboutPriceSharedOwnershipValueCheck.new("about_price_shared_ownership_la_value_check", nil, self),
Form::Sales::Pages::PropertyWheelchairAccessible.new(nil, nil, self), Form::Sales::Pages::PropertyWheelchairAccessible.new(nil, nil, self),
] ]
end end

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

@ -22,6 +22,7 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection
Form::Sales::Pages::PreviousPropertyType.new(nil, nil, self), Form::Sales::Pages::PreviousPropertyType.new(nil, nil, self),
Form::Sales::Pages::PreviousTenure.new(nil, nil, self), Form::Sales::Pages::PreviousTenure.new(nil, nil, self),
Form::Sales::Pages::AboutPriceSharedOwnership.new(nil, nil, self), Form::Sales::Pages::AboutPriceSharedOwnership.new(nil, nil, self),
Form::Sales::Pages::AboutPriceSharedOwnershipValueCheck.new("about_price_shared_ownership_value_check", nil, self),
Form::Sales::Pages::SharedOwnershipDepositValueCheck.new("shared_ownership_equity_value_check", nil, self), Form::Sales::Pages::SharedOwnershipDepositValueCheck.new("shared_ownership_equity_value_check", nil, self),
Form::Sales::Pages::Mortgageused.new("mortgage_used_shared_ownership", nil, self), Form::Sales::Pages::Mortgageused.new("mortgage_used_shared_ownership", nil, self),
Form::Sales::Pages::MortgageValueCheck.new("mortgage_used_mortgage_value_check", nil, self), Form::Sales::Pages::MortgageValueCheck.new("mortgage_used_mortgage_value_check", nil, self),

2
app/models/la_sale_range.rb

@ -0,0 +1,2 @@
class LaSaleRange < ApplicationRecord
end

1
app/models/log.rb

@ -32,6 +32,7 @@ class Log < ApplicationRecord
def collection_start_year def collection_start_year
return @start_year if @start_year return @start_year if @start_year
return unless startdate return unless startdate
window_end_date = Time.zone.local(startdate.year, 4, 1) window_end_date = Time.zone.local(startdate.year, 4, 1)

10
app/models/sales_log.rb

@ -223,7 +223,7 @@ class SalesLog < Log
type == 24 type == 24
end end
def shared_owhership_scheme? def shared_ownership_scheme?
ownershipsch == 1 ownershipsch == 1
end end
@ -236,4 +236,12 @@ class SalesLog < Log
def ages_unknown_or_under_64?(person_indexes) def ages_unknown_or_under_64?(person_indexes)
person_indexes.all? { |person_num| self["age#{person_num}"].present? && self["age#{person_num}"] < 64 || self["age#{person_num}_known"] == 1 } person_indexes.all? { |person_num| self["age#{person_num}"].present? && self["age#{person_num}"] < 64 || self["age#{person_num}_known"] == 1 }
end end
def purchase_price_soft_min
LaSaleRange.find_by(start_year: collection_start_year, la:, bedrooms: beds).soft_min
end
def purchase_price_soft_max
LaSaleRange.find_by(start_year: collection_start_year, la:, bedrooms: beds).soft_max
end
end end

4
app/models/validations/sales/sale_information_validations.rb

@ -39,7 +39,7 @@ module Validations::Sales::SaleInformationValidations
return unless record.fromprop && record.frombeds return unless record.fromprop && record.frombeds
if record.frombeds != 1 && record.fromprop == 2 if record.frombeds != 1 && record.fromprop == 2
record.errors.add :frombeds, I18n.t("validations.sale_information.previous_property_beds.property_type_bedsit") record.errors.add :frombeds, I18n.t("validations.sale_information.previous_property_type.property_type_bedsit")
record.errors.add :fromprop, I18n.t("validations.sale_information.previous_property_type.property_type_bedsit") record.errors.add :fromprop, I18n.t("validations.sale_information.previous_property_type.property_type_bedsit")
end end
end end
@ -63,7 +63,7 @@ module Validations::Sales::SaleInformationValidations
def validate_basic_monthly_rent(record) def validate_basic_monthly_rent(record)
return unless record.mrent && record.ownershipsch && record.type return unless record.mrent && record.ownershipsch && record.type
if record.shared_owhership_scheme? && !record.old_persons_shared_ownership? && record.mrent > 9999 if record.shared_ownership_scheme? && !record.old_persons_shared_ownership? && record.mrent > 9999
record.errors.add :mrent, I18n.t("validations.sale_information.monthly_rent.higher_than_expected") record.errors.add :mrent, I18n.t("validations.sale_information.monthly_rent.higher_than_expected")
record.errors.add :type, I18n.t("validations.sale_information.monthly_rent.higher_than_expected") record.errors.add :type, I18n.t("validations.sale_information.monthly_rent.higher_than_expected")
end end

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

@ -47,6 +47,12 @@ module Validations::Sales::SoftValidations
extrabor != 1 && mortgage + deposit > value - value * discount / 100 extrabor != 1 && mortgage + deposit > value - value * discount / 100
end end
def purchase_price_out_of_soft_range?
return unless value && beds && la && sale_range
!value.between?(sale_range.soft_min, sale_range.soft_max)
end
def shared_ownership_deposit_invalid? def shared_ownership_deposit_invalid?
return unless mortgage || mortgageused == 2 return unless mortgage || mortgageused == 2
return unless cashdis || !is_type_discount? return unless cashdis || !is_type_discount?
@ -70,6 +76,14 @@ module Validations::Sales::SoftValidations
saledate - hodate >= 3.years saledate - hodate >= 3.years
end end
def purchase_price_min_or_max_text
value < sale_range.soft_min ? "minimum" : "maximum"
end
def purchase_price_soft_min_or_soft_max
value < sale_range.soft_min ? sale_range.soft_min : sale_range.soft_max
end
def grant_outside_common_range? def grant_outside_common_range?
return unless grant return unless grant
@ -82,4 +96,10 @@ module Validations::Sales::SoftValidations
soft_max = old_persons_shared_ownership? ? 550 : 300 soft_max = old_persons_shared_ownership? ? 550 : 300
mscharge > soft_max mscharge > soft_max
end end
private
def sale_range
LaSaleRange.find_by(start_year: collection_start_year, la:, bedrooms: beds)
end
end end

6
app/services/imports/rent_ranges_service.rb

@ -24,12 +24,8 @@ module Imports
hard_max: row["hard_max"] }, hard_max: row["hard_max"] },
unique_by: %i[start_year lettype beds la], unique_by: %i[start_year lettype beds la],
) )
self.count = count + 1 @count += 1
end end
end end
private
attr_writer :count
end end
end end

27
app/services/imports/sale_ranges_service.rb

@ -0,0 +1,27 @@
require "csv"
module Imports
class SaleRangesService
attr_reader :start_year, :path, :count
def initialize(start_year:, path:)
@start_year = start_year
@path = path
@count = 0
end
def call
CSV.foreach(path, headers: true) do |row|
LaSaleRange.upsert(
{ start_year:,
la: row["la"],
bedrooms: row["bedrooms"],
soft_min: row["soft_min"],
soft_max: row["soft_max"] },
unique_by: %i[start_year bedrooms la],
)
@count += 1
end
end
end
end

7
config/locales/en.yml

@ -437,8 +437,8 @@ en:
must_be_less_than_1_year_from_exdate: "Completion date must be less than 1 year after contract exchange date" must_be_less_than_1_year_from_exdate: "Completion date must be less than 1 year after contract exchange date"
must_be_less_than_3_years_from_hodate: "You told us completion date is more than 3 years after practical completion or handover date" must_be_less_than_3_years_from_hodate: "You told us completion date is more than 3 years after practical completion or handover date"
must_be_after_hodate: "Completion date must be after practical completion or handover date" must_be_after_hodate: "Completion date must be after practical completion or handover date"
previous_property_beds: previous_property_type:
property_type_bedsit: "Bedsit bedroom maximum 1" property_type_bedsit: "A bedsit cannot have more than 1 bedroom"
discounted_ownership_value: "Mortgage, deposit, and grant total must equal £%{value_with_discount}" discounted_ownership_value: "Mortgage, deposit, and grant total must equal £%{value_with_discount}"
monthly_rent: monthly_rent:
higher_than_expected: "Basic monthly rent must be between £0 and £9,999" higher_than_expected: "Basic monthly rent must be between £0 and £9,999"
@ -455,6 +455,9 @@ en:
outside_range_title: "You told us the rent is %{brent}" outside_range_title: "You told us the rent is %{brent}"
min_hint_text: "The minimum rent expected for this type of property in this local authority is £%{soft_min_for_period}." min_hint_text: "The minimum rent expected for this type of property in this local authority is £%{soft_min_for_period}."
max_hint_text: "The maximum rent expected for this type of property in this local authority is £%{soft_max_for_period}." max_hint_text: "The maximum rent expected for this type of property in this local authority is £%{soft_max_for_period}."
purchase_price:
title_text: "You told us the purchase price is %{value}"
hint_text: "The %{min_or_max} purchase price expected for this type of property in this local authority is %{soft_min_or_soft_max}"
retirement: retirement:
min: min:
title: "You told us this person is under %{age} and retired" title: "You told us this person is under %{age} and retired"

1329
config/sale_range_data/2022.csv

File diff suppressed because it is too large Load Diff

5
db/migrate/20230123171907_add_about_price_shared_ownership_value_check_to_sales_log.rb

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

14
db/migrate/20230124111328_create_la_sale_ranges.rb

@ -0,0 +1,14 @@
class CreateLaSaleRanges < ActiveRecord::Migration[7.0]
def change
create_table :la_sale_ranges do |t|
t.string :la
t.integer :bedrooms
t.decimal :soft_min, precision: 10, scale: 2
t.decimal :soft_max, precision: 10, scale: 2
t.integer :start_year
t.index %i[start_year bedrooms la], unique: true, name: "index_la_sale_ranges_on_start_year_bedrooms_la"
t.timestamps
end
end
end

12
db/schema.rb

@ -70,6 +70,17 @@ ActiveRecord::Schema[7.0].define(version: 2023_02_03_104238) do
t.index ["start_year", "lettype", "beds", "la"], name: "index_la_rent_ranges_on_start_year_and_lettype_and_beds_and_la", unique: true t.index ["start_year", "lettype", "beds", "la"], name: "index_la_rent_ranges_on_start_year_and_lettype_and_beds_and_la", unique: true
end end
create_table "la_sale_ranges", force: :cascade do |t|
t.string "la"
t.integer "bedrooms"
t.decimal "soft_min", precision: 10, scale: 2
t.decimal "soft_max", precision: 10, scale: 2
t.integer "start_year"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["start_year", "bedrooms", "la"], name: "index_la_sale_ranges_on_start_year_bedrooms_la", unique: true
end
create_table "legacy_users", force: :cascade do |t| create_table "legacy_users", force: :cascade do |t|
t.string "old_user_id" t.string "old_user_id"
t.integer "user_id" t.integer "user_id"
@ -507,6 +518,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_02_03_104238) do
t.integer "deposit_and_mortgage_value_check" t.integer "deposit_and_mortgage_value_check"
t.integer "shared_ownership_deposit_value_check" t.integer "shared_ownership_deposit_value_check"
t.integer "grant_value_check" t.integer "grant_value_check"
t.integer "value_value_check"
t.integer "old_persons_shared_ownership_value_check" t.integer "old_persons_shared_ownership_value_check"
t.integer "staircase_bought_value_check" t.integer "staircase_bought_value_check"
t.integer "monthly_charges_value_check" t.integer "monthly_charges_value_check"

9
db/seeds.rb

@ -310,5 +310,14 @@ unless Rails.env.test?
service.call service.call
end end
end end
if LaSaleRange.count.zero?
Dir.glob("config/sale_range_data/*.csv").each do |path|
start_year = File.basename(path, ".csv")
service = Imports::SaleRangesService.new(start_year:, path:)
service.call
end
end
puts LaSaleRange.count
end end
# rubocop:enable Rails/Output # rubocop:enable Rails/Output

21
docs/form/page.md

@ -21,7 +21,28 @@ An example page might look something like this:
{ {
"needstype": 1 "needstype": 1
} }
],
"title_text": {
"translation": "translation1",
"arguments": [
{
"key": "some_general_field",
"label": true,
"i18n_template": "template1"
}
] ]
},
"informative_text": {
"translation": "translation2",
"arguments": [
{
"key": "some_currency_method",
"label": false,
"i18n_template": "template2",
"currency": true,
}
]
},
} }
``` ```

14
lib/tasks/sale_ranges.rake

@ -0,0 +1,14 @@
namespace :data_import do
desc "Import annual sale range data"
task :sale_ranges, %i[start_year path] => :environment do |_task, args|
start_year = args[:start_year]
path = args[:path]
raise "Usage: rake data_import:sale_ranges[start_year,'path/to/csv_file']" if path.blank? || start_year.blank?
service = Imports::SaleRangesService.new(start_year:, path:)
service.call
pp "Created/updated #{service.count} LA Sale Range records for #{start_year}" unless Rails.env.test?
end
end

5
spec/fixtures/files/sale_ranges.csv vendored

@ -0,0 +1,5 @@
la_name,la,bedrooms,soft_min,soft_max
Adur,E07000223,1,105000,369000
Adur,E07000223,2,177000,384000
Adur,E07000223,3,246000,539000
Adur,E07000223,4,310000,860000
1 la_name la bedrooms soft_min soft_max
2 Adur E07000223 1 105000 369000
3 Adur E07000223 2 177000 384000
4 Adur E07000223 3 246000 539000
5 Adur E07000223 4 310000 860000

47
spec/lib/tasks/sale_range_import_spec.rb

@ -0,0 +1,47 @@
require "rails_helper"
require "rake"
RSpec.describe "data_import" do
describe ":sale_ranges", type: :task do
subject(:task) { Rake::Task["data_import:sale_ranges"] }
before do
Rake.application.rake_require("tasks/sale_ranges")
Rake::Task.define_task(:environment)
task.reenable
end
context "when the rake task is run" do
let(:start_year) { 2022 }
let(:sale_ranges_file_path) { "./spec/fixtures/files/sale_ranges.csv" }
let(:wrong_file_path) { "/test/no_csv_here.csv" }
it "creates new rent range records" do
expect { task.invoke(start_year, sale_ranges_file_path) }.to change(LaSaleRange, :count).by(4)
expect(LaSaleRange.where(bedrooms: 1).exists?).to be true
end
it "raises an error when no path is given" do
expect { task.invoke(start_year, nil) }.to raise_error(RuntimeError, "Usage: rake data_import:sale_ranges[start_year,'path/to/csv_file']")
end
it "raises an error when no file exists at the given path" do
expect { task.invoke(start_year, wrong_file_path) }.to raise_error(Errno::ENOENT)
end
it "asks for a start year if it is not given" do
expect { task.invoke(nil, sale_ranges_file_path) }.to raise_error(RuntimeError, "Usage: rake data_import:sale_ranges[start_year,'path/to/csv_file']")
end
context "when a record already exists with a matching index of la, bedrooms and start year" do
let!(:sale_range) { LaSaleRange.create(la: "E07000223", bedrooms: 2, soft_min: 177_000, soft_max: 384_000, start_year: 2022) }
it "updates rent ranges if the record is matched on la, bedrooms and start year" do
task.invoke(start_year, sale_ranges_file_path)
sale_range.reload
expect(sale_range.soft_max).to eq(384_000)
end
end
end
end
end

2
spec/models/form/sales/subsections/property_information_spec.rb

@ -15,11 +15,13 @@ RSpec.describe Form::Sales::Subsections::PropertyInformation, type: :model do
expect(property_information.pages.map(&:id)).to eq( expect(property_information.pages.map(&:id)).to eq(
%w[ %w[
property_number_of_bedrooms property_number_of_bedrooms
about_price_shared_ownership_bedrooms_value_check
property_unit_type property_unit_type
monthly_charges_property_type_value_check monthly_charges_property_type_value_check
property_building_type property_building_type
property_postcode property_postcode
property_local_authority property_local_authority
about_price_shared_ownership_la_value_check
property_wheelchair_accessible property_wheelchair_accessible
], ],
) )

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

@ -28,6 +28,7 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do
previous_property_type previous_property_type
shared_ownership_previous_tenure shared_ownership_previous_tenure
about_price_shared_ownership about_price_shared_ownership
about_price_shared_ownership_value_check
shared_ownership_equity_value_check shared_ownership_equity_value_check
mortgage_used_shared_ownership mortgage_used_shared_ownership
mortgage_used_mortgage_value_check mortgage_used_mortgage_value_check

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 it "is able to load a current sales form" do
form = form_handler.get_form("current_sales") form = form_handler.get_form("current_sales")
expect(form).to be_a(Form) expect(form).to be_a(Form)
expect(form.pages.count).to eq(211) expect(form.pages.count).to eq(214)
expect(form.name).to eq("2022_2023_sales") expect(form.name).to eq("2022_2023_sales")
end end
it "is able to load a previous sales form" do it "is able to load a previous sales form" do
form = form_handler.get_form("previous_sales") form = form_handler.get_form("previous_sales")
expect(form).to be_a(Form) expect(form).to be_a(Form)
expect(form.pages.count).to eq(211) expect(form.pages.count).to eq(214)
expect(form.name).to eq("2021_2022_sales") expect(form.name).to eq("2021_2022_sales")
end end
end end

4
spec/models/validations/sales/sale_information_validations_spec.rb

@ -166,7 +166,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
it "does add an error if it's a bedsit" do it "does add an error if it's a bedsit" do
sale_information_validator.validate_previous_property_unit_type(record) sale_information_validator.validate_previous_property_unit_type(record)
expect(record.errors["fromprop"]).to include(I18n.t("validations.sale_information.previous_property_type.property_type_bedsit")) expect(record.errors["fromprop"]).to include(I18n.t("validations.sale_information.previous_property_type.property_type_bedsit"))
expect(record.errors["frombeds"]).to include(I18n.t("validations.sale_information.previous_property_beds.property_type_bedsit")) expect(record.errors["frombeds"]).to include(I18n.t("validations.sale_information.previous_property_type.property_type_bedsit"))
end end
end end
end end
@ -367,7 +367,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end end
end end
context "when owhership is not discounted" do 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) } let(:record) { FactoryBot.build(:sales_log, mortgage: 10_000, deposit: 5_000, grant: 3_000, value: 20_000, discount: 10, ownershipsch: 1) }
it "does not add an error" do it "does not add an error" do

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

@ -566,6 +566,69 @@ RSpec.describe Validations::Sales::SoftValidations do
end end
end end
describe "purchase_price_out_of_soft_range" do
before do
LaSaleRange.create!(
la: "E07000223",
bedrooms: 2,
soft_min: 177_000,
soft_max: 384_000,
start_year: 2022,
)
end
it "when value not set" do
record.value = nil
expect(record).not_to be_purchase_price_out_of_soft_range
end
it "when beds not set" do
record.beds = nil
expect(record).not_to be_purchase_price_out_of_soft_range
end
it "when la not set" do
record.la = nil
expect(record).not_to be_purchase_price_out_of_soft_range
end
it "when saledate not set" do
record.saledate = nil
expect(record).not_to be_purchase_price_out_of_soft_range
end
it "when below soft min" do
record.value = 176_999
record.beds = 2
record.la = "E07000223"
record.saledate = Time.zone.local(2023, 1, 1)
expect(record).to be_purchase_price_out_of_soft_range
end
it "when above soft max" do
record.value = 384_001
record.beds = 2
record.la = "E07000223"
record.saledate = Time.zone.local(2023, 1, 1)
expect(record).to be_purchase_price_out_of_soft_range
end
it "when in soft range" do
record.value = 200_000
record.beds = 2
record.la = "E07000223"
record.saledate = Time.zone.local(2023, 1, 1)
expect(record).not_to be_purchase_price_out_of_soft_range
end
end
describe "#grant_outside_common_range?" do describe "#grant_outside_common_range?" do
it "returns true if grant is below 9000" do it "returns true if grant is below 9000" do
record.grant = 1_000 record.grant = 1_000

Loading…
Cancel
Save