Browse Source

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

# Conflicts:
#	db/schema.rb
pull/1285/head
natdeanlewissoftwire 3 years ago
parent
commit
01325b19af
  1. 4
      app/models/bulk_upload.rb
  2. 15
      app/models/form/sales/pages/previous_shared.rb
  3. 17
      app/models/form/sales/questions/prevshared.rb
  4. 11
      app/models/form/sales/subsections/income_benefits_and_savings.rb
  5. 14
      app/services/bulk_upload/lettings/row_parser.rb
  6. 2
      config/locales/en.yml
  7. 7
      db/migrate/20230203153051_add_prev_shared_to_sales.rb
  8. 1
      db/schema.rb
  9. 1
      spec/factories/sales_log.rb
  10. 29
      spec/models/form/sales/pages/previous_shared_spec.rb
  11. 49
      spec/models/form/sales/questions/prevshared_spec.rb
  12. 1
      spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb
  13. 34
      spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb
  14. 2
      spec/models/form_handler_spec.rb
  15. 47
      spec/services/bulk_upload/lettings/row_parser_spec.rb

4
app/models/bulk_upload.rb

@ -30,6 +30,10 @@ class BulkUpload < ApplicationRecord
end
end
def general_needs?
needstype == 1
end
private
def generate_identifier

15
app/models/form/sales/pages/previous_shared.rb

@ -0,0 +1,15 @@
class Form::Sales::Pages::PreviousShared < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "previous_shared"
@depends_on = [
{ "prevown" => 1 },
]
end
def questions
@questions ||= [
Form::Sales::Questions::Prevshared.new(nil, nil, self),
]
end
end

17
app/models/form/sales/questions/prevshared.rb

@ -0,0 +1,17 @@
class Form::Sales::Questions::Prevshared < ::Form::Question
def initialize(id, hsh, page)
super
@id = "prevshared"
@check_answer_label = "Previous property shared ownership?"
@header = "Was the previous property a shared ownership property?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@hint = "For any buyer"
end
ANSWER_OPTIONS = {
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
"3" => { "value" => "Don’t know" },
}.freeze
end

11
app/models/form/sales/subsections/income_benefits_and_savings.rb

@ -22,6 +22,15 @@ class Form::Sales::Subsections::IncomeBenefitsAndSavings < ::Form::Subsection
Form::Sales::Pages::SavingsValueCheck.new("savings_value_check", nil, self),
Form::Sales::Pages::DepositValueCheck.new("savings_deposit_value_check", nil, self),
Form::Sales::Pages::PreviousOwnership.new(nil, nil, self),
]
previous_shared_page,
].compact
end
private
def previous_shared_page
if form.start_date.year >= 2023
Form::Sales::Pages::PreviousShared.new(nil, nil, self)
end
end
end

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

@ -147,6 +147,8 @@ class BulkUpload::Lettings::RowParser
validate :validate_nulls
validate :validate_relevant_collection_window
validate :validate_la_with_local_housing_referral
validate :validate_cannot_be_la_referral_if_general_needs
validate :leaving_reason_for_renewal
def valid?
errors.clear
@ -169,12 +171,24 @@ class BulkUpload::Lettings::RowParser
private
def validate_cannot_be_la_referral_if_general_needs
if field_78 == 4 && bulk_upload.general_needs?
errors.add :field_78, I18n.t("validations.household.referral.la_general_needs.prp_referred_by_la")
end
end
def validate_la_with_local_housing_referral
if field_78 == 3 && owning_organisation && owning_organisation.la?
errors.add(:field_78, I18n.t("validations.household.referral.nominated_by_local_ha_but_la"))
end
end
def leaving_reason_for_renewal
if field_134 == 1 && ![40, 42].include?(field_52)
errors.add(:field_52, I18n.t("validations.household.reason.renewal_reason_needed"))
end
end
def validate_relevant_collection_window
return unless start_date && bulk_upload.form

2
config/locales/en.yml

@ -359,6 +359,7 @@ en:
nominated_by_local_ha_but_la: The source of the referral cannot be Nominated by local housing authority as your organisation is a local authority
la_general_needs:
internal_transfer: "Answer cannot be internal transfer as it’s the same landlord on the tenancy agreement and the household had either a fixed-term or lifetime local authority general needs tenancy immediately before this letting"
prp_referred_by_la: "The source of the referral cannot be referred by local authority housing department for a general needs log"
prp:
local_housing_referral: "Answer cannot be ‘nominated by a local housing authority’ as a local authority is on the tenancy agreement"
homeless:
@ -375,6 +376,7 @@ en:
male_refuge: "Answer cannot be ‘male’ as you told us their housing situation immediately before this letting was a refuge"
reason:
not_internal_transfer: "Answer cannot be ‘permanently decanted from another property owned by this landlord’ as you told us the source of referral for this tenancy was not an internal transfer"
renewal_reason_needed: 'The reason for leaving must be "End of assured shorthold tenancy - no fault" or "End of fixed term tenancy - no fault" if the letting is a renewal'
condition_effects:
no_choices: "You cannot answer this question as you told us nobody in the household has a physical or mental health condition (or other illness) expected to last 12 months or more"
postcode:

7
db/migrate/20230203153051_add_prev_shared_to_sales.rb

@ -0,0 +1,7 @@
class AddPrevSharedToSales < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :prevshared, :integer
end
end
end

1
db/schema.rb

@ -524,6 +524,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_02_03_174815) do
t.integer "details_known_5"
t.integer "details_known_6"
t.integer "saledate_check"
t.integer "prevshared"
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"

1
spec/factories/sales_log.rb

@ -60,6 +60,7 @@ FactoryBot.define do
la { "E09000003" }
savingsnk { 1 }
prevown { 1 }
prevshared { 2 }
sex3 { "X" }
sex4 { "X" }
sex5 { "X" }

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

@ -0,0 +1,29 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::PreviousShared, 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) }
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[prevshared])
end
it "has the correct id" do
expect(page.id).to eq("previous_shared")
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
end

49
spec/models/form/sales/questions/prevshared_spec.rb

@ -0,0 +1,49 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Prevshared, 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("prevshared")
end
it "has the correct header" do
expect(question.header).to eq("Was the previous property a shared ownership property?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Previous property shared ownership?")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
"3" => { "value" => "Don’t know" },
})
end
it "has correct conditional for" do
expect(question.conditional_for).to eq(nil)
end
it "has the correct hint" do
expect(question.hint_text).to be_nil
end
end

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

@ -12,7 +12,6 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
end
it "has correct pages" do
puts discounted_ownership_scheme.pages.map(&:id)
expect(discounted_ownership_scheme.pages.map(&:id)).to eq(
%w[
living_before_purchase_discounted_ownership

34
spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb

@ -11,6 +11,37 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model
expect(subsection.section).to eq(section)
end
describe "pages" do
let(:section) { instance_double(Form::Sales::Sections::Household, form: instance_double(Form, start_date:)) }
context "when 2022" do
let(:start_date) { Time.utc(2022, 2, 8) }
it "has correct pages" do
expect(subsection.pages.compact.map(&:id)).to eq(
%w[
buyer_1_income
buyer_1_income_value_check
buyer_1_income_mortgage_value_check
buyer_1_mortgage
buyer_1_mortgage_value_check
buyer_2_income
buyer_2_income_mortgage_value_check
buyer_2_mortgage
buyer_2_mortgage_value_check
housing_benefits
savings
savings_value_check
savings_deposit_value_check
previous_ownership
],
)
end
end
context "when 2023" do
let(:start_date) { Time.utc(2023, 2, 8) }
it "has correct pages" do
expect(subsection.pages.map(&:id)).to eq(
%w[
@ -28,9 +59,12 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model
savings_value_check
savings_deposit_value_check
previous_ownership
previous_shared
],
)
end
end
end
it "has the correct id" do
expect(subsection.id).to eq("income_benefits_and_savings")

2
spec/models/form_handler_spec.rb

@ -41,12 +41,14 @@ RSpec.describe FormHandler do
form = form_handler.get_form("current_lettings")
expect(form).to be_a(Form)
expect(form.pages.count).to eq(13)
expect(form.name).to eq("2022_2023_lettings")
end
it "is able to load a previous lettings form" do
form = form_handler.get_form("previous_lettings")
expect(form).to be_a(Form)
expect(form.pages.count).to eq(46)
expect(form.name).to eq("2021_2022_lettings")
end
it "is able to load a current sales form" do

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

@ -250,7 +250,35 @@ RSpec.describe BulkUpload::Lettings::RowParser do
end
end
describe "#field_78" do
describe "#field_52" do # leaving reason
context "when field_134 is 1 meaning it is a renewal" do
context "when field_52 is 40" do
let(:attributes) { { bulk_upload:, field_52: "40", field_134: "1" } }
it "is permitted" do
expect(parser.errors[:field_52]).to be_blank
end
end
context "when field_52 is 42" do
let(:attributes) { { bulk_upload:, field_52: "42", field_134: "1" } }
it "is permitted" do
expect(parser.errors[:field_52]).to be_blank
end
end
context "when field_52 is not 40 or 42" do
let(:attributes) { { bulk_upload:, field_52: "1", field_134: "1" } }
it "is not permitted" do
expect(parser.errors[:field_52]).to be_present
end
end
end
end
describe "#field_78" do # referral
context "when 3 ie PRP nominated by LA and owning org is LA" do
let(:attributes) { { bulk_upload:, field_78: "3", field_111: owning_org.old_visible_id } }
@ -258,6 +286,23 @@ RSpec.describe BulkUpload::Lettings::RowParser do
expect(parser.errors[:field_78]).to be_present
end
end
context "when 4 ie referred by LA and is general needs" do
let(:attributes) { { bulk_upload:, field_78: "4" } }
it "is not permitted" do
expect(parser.errors[:field_78]).to be_present
end
end
context "when 4 ie referred by LA and is not general needs" do
let(:bulk_upload) { create(:bulk_upload, :lettings, user:, needstype: 2) }
let(:attributes) { { bulk_upload:, field_78: "4" } }
it "is permitted" do
expect(parser.errors[:field_78]).to be_blank
end
end
end
describe "fields 96, 97, 98 => startdate" do

Loading…
Cancel
Save