Browse Source

Update enabled method (#990)

* Change enabled? subsection method to check depends on using log questions and methods instead of a subsection status

* Update sales subsections

* Update rent validation tests to check all the affected fields

* Update setup_completed? to check all the setup sections
pull/997/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
ecf1fa1a28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/models/form/sales/subsections/household_characteristics.rb
  2. 2
      app/models/form/sales/subsections/household_needs.rb
  3. 2
      app/models/form/sales/subsections/income_benefits_and_outgoings.rb
  4. 2
      app/models/form/sales/subsections/property_information.rb
  5. 6
      app/models/form/subsection.rb
  6. 4
      app/models/lettings_log.rb
  7. 4
      app/models/log.rb
  8. 4
      app/models/sales_log.rb
  9. 12
      config/forms/2021_2022.json
  10. 20
      config/forms/2022_2023.json
  11. 7
      spec/fixtures/forms/2021_2022.json
  12. 2
      spec/fixtures/forms/2022_2023.json
  13. 2
      spec/models/form/sales/subsections/household_characteristics_spec.rb
  14. 2
      spec/models/form/sales/subsections/income_benefits_and_outgoings_spec.rb
  15. 60
      spec/models/validations/financial_validations_spec.rb

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

@ -4,7 +4,7 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection
@id = "household_characteristics" @id = "household_characteristics"
@label = "Household characteristics" @label = "Household characteristics"
@section = section @section = section
@depends_on = [{ "setup" => "completed" }] @depends_on = [{ "setup_completed?" => true }]
end end
def pages def pages

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

@ -4,7 +4,7 @@ class Form::Sales::Subsections::HouseholdNeeds < ::Form::Subsection
@id = "household_needs" @id = "household_needs"
@label = "Household needs" @label = "Household needs"
@section = section @section = section
@depends_on = [{ "setup" => "completed" }] @depends_on = [{ "setup_completed?" => true }]
end end
def pages def pages

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

@ -4,7 +4,7 @@ class Form::Sales::Subsections::IncomeBenefitsAndOutgoings < ::Form::Subsection
@id = "income_benefits_and_outgoings" @id = "income_benefits_and_outgoings"
@label = "Income, benefits and outgoings" @label = "Income, benefits and outgoings"
@section = section @section = section
@depends_on = [{ "setup" => "completed" }] @depends_on = [{ "setup_completed?" => true }]
end end
def pages def pages

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

@ -4,7 +4,7 @@ class Form::Sales::Subsections::PropertyInformation < ::Form::Subsection
@id = "property_information" @id = "property_information"
@label = "Property information" @label = "Property information"
@section = section @section = section
@depends_on = [{ "setup" => "completed" }] @depends_on = [{ "setup_completed?" => true }]
end end
def pages def pages

6
app/models/form/subsection.rb

@ -20,11 +20,7 @@ class Form::Subsection
def enabled?(log) def enabled?(log)
return true unless depends_on return true unless depends_on
depends_on.any? do |conditions_set| form.depends_on_met(depends_on, log)
conditions_set.all? do |subsection_id, dependent_status|
form.get_subsection(subsection_id).status(log) == dependent_status.to_sym
end
end
end end
def status(log) def status(log)

4
app/models/lettings_log.rb

@ -507,6 +507,10 @@ class LettingsLog < Log
form.get_question("rent_type", self)&.label_from_value(rent_type) form.get_question("rent_type", self)&.label_from_value(rent_type)
end end
def non_location_setup_questions_completed?
[needstype, renewal, rent_type, startdate, owning_organisation_id, created_by_id].all?(&:present?)
end
private private
PIO = PostcodeService.new PIO = PostcodeService.new

4
app/models/log.rb

@ -40,6 +40,10 @@ class Log < ApplicationRecord
ethnic_group == 17 ethnic_group == 17
end end
def managing_organisation_provider_type
managing_organisation&.provider_type
end
private private
def update_status! def update_status!

4
app/models/sales_log.rb

@ -47,4 +47,8 @@ class SalesLog < Log
def completed? def completed?
status == "completed" status == "completed"
end end
def setup_completed?
form.setup_sections.all? { |sections| sections.subsections.all? { |subsection| subsection.status(self) == :completed } }
end
end end

12
config/forms/2021_2022.json

@ -10,7 +10,7 @@
"label": "Property information", "label": "Property information",
"depends_on": [ "depends_on": [
{ {
"setup": "completed" "non_location_setup_questions_completed?": true
} }
], ],
"pages": { "pages": {
@ -952,7 +952,7 @@
"label": "Tenancy information", "label": "Tenancy information",
"depends_on": [ "depends_on": [
{ {
"setup": "completed" "non_location_setup_questions_completed?": true
} }
], ],
"pages": { "pages": {
@ -1133,7 +1133,7 @@
"label": "Household characteristics", "label": "Household characteristics",
"depends_on": [ "depends_on": [
{ {
"setup": "completed" "non_location_setup_questions_completed?": true
} }
], ],
"pages": { "pages": {
@ -5671,7 +5671,7 @@
"label": "Household needs", "label": "Household needs",
"depends_on": [ "depends_on": [
{ {
"setup": "completed" "non_location_setup_questions_completed?": true
} }
], ],
"pages": { "pages": {
@ -6060,7 +6060,7 @@
"label": "Household situation", "label": "Household situation",
"depends_on": [ "depends_on": [
{ {
"setup": "completed" "non_location_setup_questions_completed?": true
} }
], ],
"pages": { "pages": {
@ -7302,7 +7302,7 @@
"label": "Income, benefits and outgoings", "label": "Income, benefits and outgoings",
"depends_on": [ "depends_on": [
{ {
"setup": "completed" "non_location_setup_questions_completed?": true
} }
], ],
"pages": { "pages": {

20
config/forms/2022_2023.json

@ -10,7 +10,7 @@
"label": "Property information", "label": "Property information",
"depends_on": [ "depends_on": [
{ {
"setup": "completed" "non_location_setup_questions_completed?": true
} }
], ],
"pages": { "pages": {
@ -952,7 +952,7 @@
"label": "Tenancy information", "label": "Tenancy information",
"depends_on": [ "depends_on": [
{ {
"setup": "completed" "non_location_setup_questions_completed?": true
} }
], ],
"pages": { "pages": {
@ -1168,7 +1168,7 @@
"label": "Household characteristics", "label": "Household characteristics",
"depends_on": [ "depends_on": [
{ {
"setup": "completed" "non_location_setup_questions_completed?": true
} }
], ],
"pages": { "pages": {
@ -5670,7 +5670,7 @@
"label": "Household needs", "label": "Household needs",
"depends_on": [ "depends_on": [
{ {
"setup": "completed" "non_location_setup_questions_completed?": true
} }
], ],
"pages": { "pages": {
@ -6062,7 +6062,7 @@
"label": "Household situation", "label": "Household situation",
"depends_on": [ "depends_on": [
{ {
"setup": "completed" "non_location_setup_questions_completed?": true
} }
], ],
"pages": { "pages": {
@ -7070,7 +7070,7 @@
}, },
"depends_on": [ "depends_on": [
{ {
"managing_organisation.provider_type": "LA", "managing_organisation_provider_type": "LA",
"needstype": 1, "needstype": 1,
"renewal": 0 "renewal": 0
} }
@ -7127,7 +7127,7 @@
}, },
"depends_on": [ "depends_on": [
{ {
"managing_organisation.provider_type": "PRP", "managing_organisation_provider_type": "PRP",
"needstype": 1, "needstype": 1,
"renewal": 0 "renewal": 0
} }
@ -7184,7 +7184,7 @@
}, },
"depends_on": [ "depends_on": [
{ {
"managing_organisation.provider_type": "LA", "managing_organisation_provider_type": "LA",
"needstype": 2, "needstype": 2,
"renewal": 0 "renewal": 0
} }
@ -7244,7 +7244,7 @@
}, },
"depends_on": [ "depends_on": [
{ {
"managing_organisation.provider_type": "PRP", "managing_organisation_provider_type": "PRP",
"needstype": 2, "needstype": 2,
"renewal": 0 "renewal": 0
} }
@ -7261,7 +7261,7 @@
"label": "Income, benefits and outgoings", "label": "Income, benefits and outgoings",
"depends_on": [ "depends_on": [
{ {
"setup": "completed" "non_location_setup_questions_completed?": true
} }
], ],
"pages": { "pages": {

7
spec/fixtures/forms/2021_2022.json vendored

@ -1099,9 +1099,10 @@
"label": "Declaration", "label": "Declaration",
"depends_on": [ "depends_on": [
{ {
"household_characteristics": "completed", "armedforces": 1
"household_needs": "completed", },
"property_information": "completed" {
"armedforces": 3
} }
], ],
"pages": { "pages": {

2
spec/fixtures/forms/2022_2023.json vendored

@ -47,7 +47,7 @@
}, },
"depends_on": [ "depends_on": [
{ {
"setup": "completed" "non_location_setup_questions_completed?": true
} }
] ]
} }

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

@ -53,6 +53,6 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
end end
it "has correct depends on" do it "has correct depends on" do
expect(household_characteristics.depends_on).to eq([{ "setup" => "completed" }]) expect(household_characteristics.depends_on).to eq([{ "setup_completed?" => true }])
end end
end end

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

@ -28,6 +28,6 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndOutgoings, type: :mode
end end
it "has correct depends on" do it "has correct depends on" do
expect(subsection.depends_on).to eq([{ "setup" => "completed" }]) expect(subsection.depends_on).to eq([{ "setup_completed?" => true }])
end end
end end

60
spec/models/validations/financial_validations_spec.rb

@ -832,6 +832,11 @@ RSpec.describe Validations::FinancialValidations do
financial_validator.validate_rent_amount(record) financial_validator.validate_rent_amount(record)
expect(record.errors["brent"]) expect(record.errors["brent"])
.to include(match I18n.t("validations.financial.brent.below_hard_min")) .to include(match I18n.t("validations.financial.brent.below_hard_min"))
%w[beds la postcode_known scheme_id location_id rent_type needstype period].each do |field|
expect(record.errors[field])
.to include(match I18n.t("validations.financial.brent.#{field}.below_hard_min"))
end
end end
it "validates hard max for general needs" do it "validates hard max for general needs" do
@ -846,22 +851,11 @@ RSpec.describe Validations::FinancialValidations do
financial_validator.validate_rent_amount(record) financial_validator.validate_rent_amount(record)
expect(record.errors["brent"]) expect(record.errors["brent"])
.to include(match I18n.t("validations.financial.brent.above_hard_max")) .to include(match I18n.t("validations.financial.brent.above_hard_max"))
expect(record.errors["beds"])
.to include(match I18n.t("validations.financial.brent.beds.above_hard_max")) %w[beds la postcode_known scheme_id location_id rent_type needstype period].each do |field|
expect(record.errors["la"]) expect(record.errors[field])
.to include(match I18n.t("validations.financial.brent.la.above_hard_max")) .to include(match I18n.t("validations.financial.brent.#{field}.above_hard_max"))
expect(record.errors["postcode_known"]) end
.to include(match I18n.t("validations.financial.brent.postcode_known.above_hard_max"))
expect(record.errors["scheme_id"])
.to include(match I18n.t("validations.financial.brent.scheme_id.above_hard_max"))
expect(record.errors["location_id"])
.to include(match I18n.t("validations.financial.brent.location_id.above_hard_max"))
expect(record.errors["rent_type"])
.to include(match I18n.t("validations.financial.brent.rent_type.above_hard_max"))
expect(record.errors["needstype"])
.to include(match I18n.t("validations.financial.brent.needstype.above_hard_max"))
expect(record.errors["period"])
.to include(match I18n.t("validations.financial.brent.period.above_hard_max"))
end end
it "validates hard max for supported housing" do it "validates hard max for supported housing" do
@ -875,22 +869,11 @@ RSpec.describe Validations::FinancialValidations do
financial_validator.validate_rent_amount(record) financial_validator.validate_rent_amount(record)
expect(record.errors["brent"]) expect(record.errors["brent"])
.to include(match I18n.t("validations.financial.brent.above_hard_max")) .to include(match I18n.t("validations.financial.brent.above_hard_max"))
expect(record.errors["beds"])
.to include(match I18n.t("validations.financial.brent.beds.above_hard_max")) %w[beds la postcode_known scheme_id location_id rent_type needstype period].each do |field|
expect(record.errors["la"]) expect(record.errors[field])
.to include(match I18n.t("validations.financial.brent.la.above_hard_max")) .to include(match I18n.t("validations.financial.brent.#{field}.above_hard_max"))
expect(record.errors["postcode_known"]) end
.to include(match I18n.t("validations.financial.brent.postcode_known.above_hard_max"))
expect(record.errors["scheme_id"])
.to include(match I18n.t("validations.financial.brent.scheme_id.above_hard_max"))
expect(record.errors["location_id"])
.to include(match I18n.t("validations.financial.brent.location_id.above_hard_max"))
expect(record.errors["rent_type"])
.to include(match I18n.t("validations.financial.brent.rent_type.above_hard_max"))
expect(record.errors["needstype"])
.to include(match I18n.t("validations.financial.brent.needstype.above_hard_max"))
expect(record.errors["period"])
.to include(match I18n.t("validations.financial.brent.period.above_hard_max"))
end end
it "validates hard max for correct collection year" do it "validates hard max for correct collection year" do
@ -904,14 +887,11 @@ RSpec.describe Validations::FinancialValidations do
financial_validator.validate_rent_amount(record) financial_validator.validate_rent_amount(record)
expect(record.errors["brent"]) expect(record.errors["brent"])
.to include(match I18n.t("validations.financial.brent.above_hard_max")) .to include(match I18n.t("validations.financial.brent.above_hard_max"))
expect(record.errors["beds"])
.to include(match I18n.t("validations.financial.brent.beds.above_hard_max")) %w[beds la postcode_known scheme_id location_id rent_type needstype period].each do |field|
expect(record.errors["la"]) expect(record.errors[field])
.to include(match I18n.t("validations.financial.brent.la.above_hard_max")) .to include(match I18n.t("validations.financial.brent.#{field}.above_hard_max"))
expect(record.errors["rent_type"]) end
.to include(match I18n.t("validations.financial.brent.rent_type.above_hard_max"))
expect(record.errors["needstype"])
.to include(match I18n.t("validations.financial.brent.needstype.above_hard_max"))
end end
it "does not error if some of the fields are missing" do it "does not error if some of the fields are missing" do

Loading…
Cancel
Save