Browse Source

Changes from #462 (JSON vs data dictionary)

pull/470/head
Stéphane Meny 3 years ago
parent
commit
f09c054b5b
No known key found for this signature in database
GPG Key ID: 9D0AFEA988527923
  1. 90
      app/models/case_log.rb
  2. 6
      app/models/form/question.rb
  3. 2
      app/models/validations/tenancy_validations.rb
  4. 6
      app/services/imports/case_logs_import_service.rb
  5. 2
      config/forms/2021_2022.json
  6. 14
      spec/factories/case_log.rb
  7. 2
      spec/features/form/check_answers_page_spec.rb
  8. 6
      spec/features/form/conditional_questions_spec.rb
  9. 2
      spec/features/form/form_navigation_spec.rb
  10. 6
      spec/features/form/page_routing_spec.rb
  11. 4
      spec/features/form/validations_spec.rb
  12. 12
      spec/fixtures/complete_case_log.json
  13. 12
      spec/fixtures/exports/case_logs.xml
  14. 36
      spec/fixtures/forms/2021_2022.json
  15. 2
      spec/helpers/conditional_questions_helper_spec.rb
  16. 2
      spec/helpers/interuption_screen_helper_spec.rb
  17. 12
      spec/models/case_log_spec.rb
  18. 2
      spec/models/form/page_spec.rb
  19. 14
      spec/models/form/question_spec.rb
  20. 8
      spec/models/form_spec.rb
  21. 8
      spec/models/validations/financial_validations_spec.rb
  22. 18
      spec/models/validations/household_validations_spec.rb
  23. 18
      spec/models/validations/property_validations_spec.rb
  24. 20
      spec/models/validations/tenancy_validations_spec.rb
  25. 4
      spec/requests/form_controller_spec.rb
  26. 1
      spec/services/imports/case_logs_import_service_spec.rb

90
app/models/case_log.rb

@ -122,19 +122,23 @@ class CaseLog < ApplicationRecord
end end
def net_income_refused? def net_income_refused?
# 2: Tenant prefers not to say
net_income_known == 2 net_income_known == 2
end end
def net_income_is_weekly? def net_income_is_weekly?
!!(incfreq && incfreq.zero?) # 1: Weekly
!!(incfreq && incfreq == 1)
end end
def net_income_is_monthly? def net_income_is_monthly?
incfreq == 1 # 2: Monthly
incfreq == 2
end end
def net_income_is_yearly? def net_income_is_yearly?
incfreq == 2 # 3: Yearly
incfreq == 3
end end
def net_income_soft_validation_triggered? def net_income_soft_validation_triggered?
@ -142,138 +146,181 @@ class CaseLog < ApplicationRecord
end end
def given_reasonable_preference? def given_reasonable_preference?
# 1: Yes
reasonpref == 1 reasonpref == 1
end end
def is_renewal? def is_renewal?
# 1: Yes
renewal == 1 renewal == 1
end end
def is_general_needs? def is_general_needs?
# 1: General Needs
needstype == 1 needstype == 1
end end
def is_supported_housing? def is_supported_housing?
!!(needstype && needstype.zero?) # 0: Supported Housing
!!(needstype&.zero?)
end end
def has_hbrentshortfall? def has_hbrentshortfall?
!!(hbrentshortfall && hbrentshortfall.zero?) # 0: Yes
!!(hbrentshortfall&.zero?)
end end
def postcode_known? def postcode_known?
# 1: Yes
postcode_known == 1 postcode_known == 1
end end
def previous_postcode_known? def previous_postcode_known?
# 1: Yes
previous_postcode_known == 1 previous_postcode_known == 1
end end
def la_known? def la_known?
# 1: Yes
la_known == 1 la_known == 1
end end
def previous_la_known? def previous_la_known?
# 1: Yes
previous_la_known == 1 previous_la_known == 1
end end
def is_secure_tenancy? def is_secure_tenancy?
tenancy == 3 # 1: Secure (including flexible)
tenancy == 1
end end
def is_assured_shorthold_tenancy? def is_assured_shorthold_tenancy?
tenancy == 1 # 4: Assured Shorthold
tenancy == 4
end end
def is_internal_transfer? def is_internal_transfer?
# 1: Internal Transfer
referral == 1 referral == 1
end end
def is_relet_to_temp_tenant? def is_relet_to_temp_tenant?
rsnvac == 2 # 9: Re-let to tenant who occupied same property as temporary accommodation
rsnvac == 9
end end
def is_bedsit? def is_bedsit?
unittype_gn == 1 # 2: Bedsit
unittype_gn == 2
end end
def is_shared_housing? def is_shared_housing?
[4, 5, 6].include?(unittype_gn) # 4: Shared flat or maisonette
# 9: Shared house
# 10: Shared bungalow
[4, 9, 10].include?(unittype_gn)
end end
def has_first_let_vacancy_reason? def has_first_let_vacancy_reason?
# 15: First let of new-build property
# 16: First let of conversion, rehabilitation or acquired property
# 17: First let of leased property
[15, 16, 17].include?(rsnvac) [15, 16, 17].include?(rsnvac)
end end
def previous_tenancy_was_temporary? def previous_tenancy_was_temporary?
![4, 5, 16, 21, 22].include?(prevten) # 4: Tied housing or renting with job
# 6: Supported housing
# 8: Sheltered accomodation
# 24: Housed by National Asylum Support Service (prev Home Office)
# 25: Other
![4, 6, 8, 24, 25].include?(prevten)
end end
def armed_forces_regular? def armed_forces_regular?
!!(armedforces && armedforces.zero?) # 1: Yes – the person is a current or former regular
!!(armedforces && armedforces == 1)
end end
def armed_forces_no? def armed_forces_no?
armedforces == 3 # 2: No
armedforces == 2
end end
def armed_forces_refused? def armed_forces_refused?
armedforces == 4 # 3: Person prefers not to say / Refused
armedforces == 3
end end
def has_pregnancy? def has_pregnancy?
!!(preg_occ && preg_occ.zero?) # 1: Yes
!!(preg_occ && preg_occ == 1)
end end
def pregnancy_refused? def pregnancy_refused?
preg_occ == 2 # 3: Tenant prefers not to say / Refused
preg_occ == 3
end end
def is_assessed_homeless? def is_assessed_homeless?
# 11: Assessed as homeless (or threatened with homelessness within 56 days) by a local authority and owed a homelessness duty
homeless == 11 homeless == 11
end end
def is_other_homeless? def is_other_homeless?
# 7: Other homeless – not found statutorily homeless but considered homeless by landlord
homeless == 7 homeless == 7
end end
def is_not_homeless? def is_not_homeless?
# 1: No
homeless == 1 homeless == 1
end end
def is_london_rent? def is_london_rent?
# 2: London Affordable Rent
# 4: London Living Rent
rent_type == 2 || rent_type == 4 rent_type == 2 || rent_type == 4
end end
def previous_tenancy_was_foster_care? def previous_tenancy_was_foster_care?
# 13: Children's home or foster care
prevten == 13 prevten == 13
end end
def previous_tenancy_was_refuge? def previous_tenancy_was_refuge?
# 21: Refuge
prevten == 21 prevten == 21
end end
def is_reason_permanently_decanted? def is_reason_permanently_decanted?
# 1: Permanently decanted from another property owned by this landlord
reason == 1 reason == 1
end end
def receives_housing_benefit_only? def receives_housing_benefit_only?
# 1: Housing benefit
hb == 1 hb == 1
end end
def receives_housing_benefit_and_universal_credit? def receives_housing_benefit_and_universal_credit?
# 8: Housing benefit and Universal Credit (without housing element)
hb == 8 hb == 8
end end
def receives_uc_with_housing_element_excl_housing_benefit? def receives_uc_with_housing_element_excl_housing_benefit?
# 6: Universal Credit with housing element (excluding housing benefit)
hb == 6 hb == 6
end end
def receives_no_benefits? def receives_no_benefits?
# 9: None
hb == 9 hb == 9
end end
def receives_universal_credit_but_no_housing_benefit? def receives_universal_credit_but_no_housing_benefit?
# 7: Universal Credit (without housing element)
hb == 7 hb == 7
end end
@ -283,23 +330,31 @@ class CaseLog < ApplicationRecord
end end
def benefits_unknown? def benefits_unknown?
# 3: Don’t know
hb == 3 hb == 3
end end
def this_landlord? def this_landlord?
# 1: This landlord
landlord == 1 landlord == 1
end end
def other_landlord? def other_landlord?
# 2: Another RP (HA/LA)
landlord == 2 landlord == 2
end end
def local_housing_referral? def local_housing_referral?
# 3: PRP lettings only - Nominated by local housing authority
referral == 3 referral == 3
end end
def is_prevten_la_general_needs? def is_prevten_la_general_needs?
[30, 31].any?(prevten) # 30: Fixed term Local Authority General Needs tenancy
# 31: Lifetime Local Authority General Needs tenancy
# 32: Fixed term Private Registered Provider General Needs tenancy
# 33: Lifetime Private Registered Provider General Needs tenancy
[30, 31, 32, 33].any?(prevten)
end end
def self.to_csv def self.to_csv
@ -418,6 +473,7 @@ private
self.referral = 0 self.referral = 0
self.layear = 1 self.layear = 1
if is_general_needs? if is_general_needs?
# TODO: Check value since 30/31 are LA and 32/33 are PRP (fixed term VS lifetime)
self.prevten = 32 if managing_organisation.provider_type == "PRP" self.prevten = 32 if managing_organisation.provider_type == "PRP"
self.prevten = 30 if managing_organisation.provider_type == "LA" self.prevten = 30 if managing_organisation.provider_type == "LA"
end end

6
app/models/form/question.rb

@ -218,9 +218,9 @@ private
end end
ANSWER_SUFFIX_LABELS = { ANSWER_SUFFIX_LABELS = {
0 => " every week", 1 => " every week",
1 => " every month", 2 => " every month",
2 => " every year", 3 => " every year",
}.freeze }.freeze
RADIO_YES_VALUE = { RADIO_YES_VALUE = {

2
app/models/validations/tenancy_validations.rb

@ -30,6 +30,6 @@ module Validations::TenancyValidations
end end
def validate_other_tenancy_type(record) def validate_other_tenancy_type(record)
validate_other_field(record, 4, :tenancy, :tenancyother) validate_other_field(record, 3, :tenancy, :tenancyother)
end end
end end

6
app/services/imports/case_logs_import_service.rb

@ -148,11 +148,9 @@ module Imports
attributes["la_known"] = 1 # Defaulting to Yes (Required) attributes["la_known"] = 1 # Defaulting to Yes (Required)
attributes["created_at"] = Date.parse(field_value(xml_doc, "meta", "created-date")) attributes["created_at"] = Date.parse(field_value(xml_doc, "meta", "created-date"))
attributes["updated_at"] = Date.parse(field_value(xml_doc, "meta", "modified-date")) attributes["updated_at"] = Date.parse(field_value(xml_doc, "meta", "modified-date"))
attributes
# Pending validation with new form case_log = CaseLog.new(attributes)
# case_log = CaseLog.new(attributes) case_log.save!
# case_log.save!
end end
# Safe: A string that represents only an integer (or empty/nil) # Safe: A string that represents only an integer (or empty/nil)

2
config/forms/2021_2022.json

@ -976,7 +976,7 @@
}, },
"conditional_for": { "conditional_for": {
"tenancyother": [ "tenancyother": [
4 3
] ]
} }
}, },

14
spec/factories/case_log.rb

@ -20,7 +20,7 @@ FactoryBot.define do
status { 1 } status { 1 }
ecstat1 { 1 } ecstat1 { 1 }
earnings { 750 } earnings { 750 }
incfreq { 0 } incfreq { 1 }
end end
trait :conditional_section_complete do trait :conditional_section_complete do
tenant_code { "TH356" } tenant_code { "TH356" }
@ -50,21 +50,21 @@ FactoryBot.define do
leftreg { 1 } leftreg { 1 }
reservist { 0 } reservist { 0 }
illness { 0 } illness { 0 }
preg_occ { 1 } preg_occ { 2 }
tenancy_code { "BZ757" } tenancy_code { "BZ757" }
startertenancy { 0 } startertenancy { 0 }
tenancylength { 5 } tenancylength { 5 }
tenancy { 3 } tenancy { 1 }
landlord { 1 } landlord { 1 }
ppostcode_full { "SE2 6RT" } ppostcode_full { "SE2 6RT" }
rsnvac { 7 } rsnvac { 6 }
unittype_gn { 2 } unittype_gn { 7 }
beds { 3 } beds { 3 }
voiddate { "03/11/2019" } voiddate { "03/11/2019" }
offered { 2 } offered { 2 }
wchair { 1 } wchair { 1 }
earnings { 68 } earnings { 68 }
incfreq { 0 } incfreq { 1 }
benefits { 1 } benefits { 1 }
period { 2 } period { 2 }
brent { 200 } brent { 200 }
@ -123,7 +123,7 @@ FactoryBot.define do
incref { 0 } incref { 0 }
sale_completion_date { nil } sale_completion_date { nil }
startdate { Time.utc(2022, 2, 2, 10, 36, 49) } startdate { Time.utc(2022, 2, 2, 10, 36, 49) }
armedforces { 0 } armedforces { 1 }
builtype { 1 } builtype { 1 }
unitletas { 2 } unitletas { 2 }
has_benefits { 1 } has_benefits { 1 }

2
spec/features/form/check_answers_page_spec.rb

@ -113,7 +113,7 @@ RSpec.describe "Form Check Answers Page" do
it "displays conditional question that were visited" do it "displays conditional question that were visited" do
visit("/logs/#{id}/conditional-question") visit("/logs/#{id}/conditional-question")
choose("case-log-preg-occ-1-field", allow_label_click: true) choose("case-log-preg-occ-2-field", allow_label_click: true)
click_button("Save and continue") click_button("Save and continue")
visit("/logs/#{id}/#{conditional_subsection}/check-answers") visit("/logs/#{id}/#{conditional_subsection}/check-answers")
question_labels = ["Has the condition been met?", "Has the condition not been met?"] question_labels = ["Has the condition been met?", "Has the condition not been met?"]

6
spec/features/form/conditional_questions_spec.rb

@ -27,11 +27,11 @@ RSpec.describe "Form Conditional Questions" do
it "shows conditional questions if the required answer is selected and hides it again when a different answer option is selected", js: true do it "shows conditional questions if the required answer is selected and hides it again when a different answer option is selected", js: true do
visit("/logs/#{id}/armed-forces") visit("/logs/#{id}/armed-forces")
# Something about our styling makes the selenium webdriver think the actual radio buttons are not visible so we allow label click here # Something about our styling makes the selenium webdriver think the actual radio buttons are not visible so we allow label click here
choose("case-log-armedforces-0-field", allow_label_click: true)
fill_in("case-log-leftreg-field", with: "text")
choose("case-log-armedforces-1-field", allow_label_click: true) choose("case-log-armedforces-1-field", allow_label_click: true)
fill_in("case-log-leftreg-field", with: "text")
choose("case-log-armedforces-4-field", allow_label_click: true)
expect(page).not_to have_field("case-log-leftreg-field") expect(page).not_to have_field("case-log-leftreg-field")
choose("case-log-armedforces-0-field", allow_label_click: true) choose("case-log-armedforces-1-field", allow_label_click: true)
expect(page).to have_field("case-log-leftreg-field", with: "") expect(page).to have_field("case-log-leftreg-field", with: "")
end end
end end

2
spec/features/form/form_navigation_spec.rb

@ -71,7 +71,7 @@ RSpec.describe "Form Navigation" do
visit("/logs") visit("/logs")
visit("/logs/#{id}/net-income") visit("/logs/#{id}/net-income")
fill_in("case-log-earnings-field", with: 740) fill_in("case-log-earnings-field", with: 740)
choose("case-log-incfreq-0-field", allow_label_click: true) choose("case-log-incfreq-1-field", allow_label_click: true)
click_button("Save and continue") click_button("Save and continue")
click_link(text: "Back") click_link(text: "Back")
click_link(text: "Back") click_link(text: "Back")

6
spec/features/form/page_routing_spec.rb

@ -24,12 +24,12 @@ RSpec.describe "Form Page Routing" do
visit("/logs/#{id}/conditional-question") visit("/logs/#{id}/conditional-question")
# using a question name that is already in the db to avoid # using a question name that is already in the db to avoid
# having to add a new column to the db for this test # having to add a new column to the db for this test
choose("case-log-preg-occ-0-field", allow_label_click: true) choose("case-log-preg-occ-1-field", allow_label_click: true)
click_button("Save and continue") click_button("Save and continue")
expect(page).to have_current_path("/logs/#{id}/conditional-question-yes-page") expect(page).to have_current_path("/logs/#{id}/conditional-question-yes-page")
click_link(text: "Back") click_link(text: "Back")
expect(page).to have_current_path("/logs/#{id}/conditional-question") expect(page).to have_current_path("/logs/#{id}/conditional-question")
choose("case-log-preg-occ-1-field", allow_label_click: true) choose("case-log-preg-occ-2-field", allow_label_click: true)
click_button("Save and continue") click_button("Save and continue")
expect(page).to have_current_path("/logs/#{id}/conditional-question-no-page") expect(page).to have_current_path("/logs/#{id}/conditional-question-no-page")
end end
@ -40,7 +40,7 @@ RSpec.describe "Form Page Routing" do
click_button("Save and continue") click_button("Save and continue")
expect(page).to have_current_path("/logs/#{id}/person-1-working-situation") expect(page).to have_current_path("/logs/#{id}/person-1-working-situation")
visit("/logs/#{id}/conditional-question") visit("/logs/#{id}/conditional-question")
choose("case-log-preg-occ-1-field", allow_label_click: true) choose("case-log-preg-occ-2-field", allow_label_click: true)
click_button("Save and continue") click_button("Save and continue")
expect(page).to have_current_path("/logs/#{id}/conditional-question-no-page") expect(page).to have_current_path("/logs/#{id}/conditional-question-no-page")
click_button("Save and continue") click_button("Save and continue")

4
spec/features/form/validations_spec.rb

@ -127,7 +127,7 @@ RSpec.describe "validations" do
it "prompts the user to confirm the value is correct with an interruption screen" do it "prompts the user to confirm the value is correct with an interruption screen" do
visit("/logs/#{case_log.id}/net-income") visit("/logs/#{case_log.id}/net-income")
fill_in("case-log-earnings-field", with: income_over_soft_limit) fill_in("case-log-earnings-field", with: income_over_soft_limit)
choose("case-log-incfreq-0-field", allow_label_click: true) choose("case-log-incfreq-1-field", allow_label_click: true)
click_button("Save and continue") click_button("Save and continue")
expect(page).to have_current_path("/logs/#{case_log.id}/net-income-value-check") expect(page).to have_current_path("/logs/#{case_log.id}/net-income-value-check")
expect(page).to have_content("Net income is outside the expected range based on the lead tenant’s working situation") expect(page).to have_content("Net income is outside the expected range based on the lead tenant’s working situation")
@ -141,7 +141,7 @@ RSpec.describe "validations" do
it "returns the user to the previous question if they do not confirm the value as correct on the interruption screen" do it "returns the user to the previous question if they do not confirm the value as correct on the interruption screen" do
visit("/logs/#{case_log.id}/net-income") visit("/logs/#{case_log.id}/net-income")
fill_in("case-log-earnings-field", with: income_over_soft_limit) fill_in("case-log-earnings-field", with: income_over_soft_limit)
choose("case-log-incfreq-0-field", allow_label_click: true) choose("case-log-incfreq-1-field", allow_label_click: true)
click_button("Save and continue") click_button("Save and continue")
choose("case-log-net-income-value-check-1-field", allow_label_click: true) choose("case-log-net-income-value-check-1-field", allow_label_click: true)
click_button("Save and continue") click_button("Save and continue")

12
spec/fixtures/complete_case_log.json vendored

@ -6,7 +6,7 @@
"ethnic": 0, "ethnic": 0,
"national": 0, "national": 0,
"prevten": 6, "prevten": 6,
"armedforces": 0, "armedforces": 1,
"armed_forces_partner": "", "armed_forces_partner": "",
"ecstat1": 1, "ecstat1": 1,
"hhmemb": 8, "hhmemb": 8,
@ -43,19 +43,19 @@
"leftreg": 1, "leftreg": 1,
"reservist": 0, "reservist": 0,
"illness": 0, "illness": 0,
"preg_occ": 0, "preg_occ": 1,
"tenancy_code": "BZ757", "tenancy_code": "BZ757",
"startdate": "12/12/2021", "startdate": "12/12/2021",
"startertenancy": 0, "startertenancy": 0,
"tenancylength": 5, "tenancylength": 5,
"tenancy": 3, "tenancy": 1,
"landlord": 1, "landlord": 1,
"la": "Barnet", "la": "Barnet",
"postcode_full": "NW1 5TY", "postcode_full": "NW1 5TY",
"property_relet": 0, "property_relet": 0,
"rsnvac": 0, "rsnvac": 14,
"property_reference": "P9876", "property_reference": "P9876",
"unittype_gn": 2, "unittype_gn": 7,
"property_building_type": "dummy", "property_building_type": "dummy",
"beds": 3, "beds": 3,
"voiddate": "10/10/2020", "voiddate": "10/10/2020",
@ -65,7 +65,7 @@
"wchair": 1, "wchair": 1,
"net_income_known": 1, "net_income_known": 1,
"earnings": 150, "earnings": 150,
"incfreq": 0, "incfreq": 1,
"benefits": 1, "benefits": 1,
"hb": 1, "hb": 1,
"period": 2, "period": 2,

12
spec/fixtures/exports/case_logs.xml vendored

@ -39,20 +39,20 @@
<leftreg>1</leftreg> <leftreg>1</leftreg>
<reservist>0</reservist> <reservist>0</reservist>
<illness>0</illness> <illness>0</illness>
<preg_occ>1</preg_occ> <preg_occ>2</preg_occ>
<tenancy_code>BZ757</tenancy_code> <tenancy_code>BZ757</tenancy_code>
<startertenancy>0</startertenancy> <startertenancy>0</startertenancy>
<tenancylength>5</tenancylength> <tenancylength>5</tenancylength>
<tenancy>3</tenancy> <tenancy>1</tenancy>
<landlord>1</landlord> <landlord>1</landlord>
<ppostcode_full>SE26RT</ppostcode_full> <ppostcode_full>SE26RT</ppostcode_full>
<rsnvac>7</rsnvac> <rsnvac>6</rsnvac>
<unittype_gn>2</unittype_gn> <unittype_gn>7</unittype_gn>
<beds>3</beds> <beds>3</beds>
<offered>2</offered> <offered>2</offered>
<wchair>1</wchair> <wchair>1</wchair>
<earnings>68</earnings> <earnings>68</earnings>
<incfreq>0</incfreq> <incfreq>1</incfreq>
<benefits>1</benefits> <benefits>1</benefits>
<period>2</period> <period>2</period>
<layear>2</layear> <layear>2</layear>
@ -103,7 +103,7 @@
<incref>0</incref> <incref>0</incref>
<sale_completion_date/> <sale_completion_date/>
<startdate>2022-02-02 10:36:49 UTC</startdate> <startdate>2022-02-02 10:36:49 UTC</startdate>
<armedforces>0</armedforces> <armedforces>1</armedforces>
<first_time_property_let_as_social_housing/> <first_time_property_let_as_social_housing/>
<unitletas>2</unitletas> <unitletas>2</unitletas>
<builtype>1</builtype> <builtype>1</builtype>

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

@ -225,24 +225,24 @@
"type": "radio", "type": "radio",
"check_answer_label": "Household links to UK armed forces", "check_answer_label": "Household links to UK armed forces",
"answer_options": { "answer_options": {
"0": { "1": {
"value": "Yes, the person is a current or former regular" "value": "Yes, the person is a current or former regular"
}, },
"1": { "4": {
"value": "Yes, the person is a current or former reserve" "value": "Yes, the person is a current or former reserve"
}, },
"2": { "5": {
"value": "Yes, the tenant is a spouse or civil partner of a UK armed forces member and has been bereaved or separated from them within the last 2 years" "value": "Yes, the tenant is a spouse or civil partner of a UK armed forces member and has been bereaved or separated from them within the last 2 years"
}, },
"3": { "2": {
"value": "No" "value": "No"
}, },
"4": { "3": {
"value": "Person prefers not to say" "value": "Person prefers not to say"
} }
}, },
"conditional_for": { "conditional_for": {
"leftreg": [0] "leftreg": [1]
} }
}, },
"leftreg": { "leftreg": {
@ -463,10 +463,10 @@
"header": "Has the condition been met?", "header": "Has the condition been met?",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": { "1": {
"value": "Yes" "value": "Yes"
}, },
"1": { "2": {
"value": "No" "value": "No"
} }
} }
@ -486,7 +486,7 @@
} }
} }
}, },
"depends_on": [{ "preg_occ": 0 }, { "wchair" : 1 }] "depends_on": [{ "preg_occ": 1 }, { "wchair" : 1 }]
}, },
"conditional_question_no_page": { "conditional_question_no_page": {
"questions": { "questions": {
@ -504,7 +504,7 @@
} }
} }
}, },
"depends_on": [{ "preg_occ": 1 }] "depends_on": [{ "preg_occ": 2 }]
}, },
"conditional_question_no_second_page": { "conditional_question_no_second_page": {
"questions": { "questions": {
@ -522,7 +522,7 @@
} }
} }
}, },
"depends_on": [{ "preg_occ": 1, "sex1": "M" }] "depends_on": [{ "preg_occ": 2, "sex1": "M" }]
} }
} }
} }
@ -548,9 +548,9 @@
"width": 5, "width": 5,
"prefix": "£", "prefix": "£",
"suffix": [ "suffix": [
{ "label": "every week", "depends_on" : { "incfreq": 0 } }, { "label": "every week", "depends_on" : { "incfreq": 1 } },
{ "label": "every month", "depends_on" : { "incfreq": 1 } }, { "label": "every month", "depends_on" : { "incfreq": 2 } },
{ "label": "every month", "depends_on" : { "incfreq": 2 } } { "label": "every month", "depends_on" : { "incfreq": 3 } }
] ]
}, },
"incfreq": { "incfreq": {
@ -558,13 +558,13 @@
"header": "How often do they receive this income?", "header": "How often do they receive this income?",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": { "1": {
"value": "Weekly" "value": "Weekly"
}, },
"1": { "2": {
"value": "Monthly" "value": "Monthly"
}, },
"2": { "3": {
"value": "Yearly" "value": "Yearly"
} }
} }
@ -646,7 +646,7 @@
} }
}, },
"dependent_page": { "dependent_page": {
"depends_on": [{ "incfreq": 0 }], "depends_on": [{ "incfreq": 1 }],
"questions": { "questions": {
"dependent_question": { "dependent_question": {
"check_answer_label": "Dependent Question", "check_answer_label": "Dependent Question",

2
spec/helpers/conditional_questions_helper_spec.rb

@ -14,7 +14,7 @@ RSpec.describe ConditionalQuestionsHelper do
describe "find conditional question" do describe "find conditional question" do
let(:question) { page.questions.find { |q| q.id == "armedforces" } } let(:question) { page.questions.find { |q| q.id == "armedforces" } }
let(:answer_value) { 0 } let(:answer_value) { 1 }
it "returns the conditional question for a given answer option" do it "returns the conditional question for a given answer option" do
expect(find_conditional_question(page, question, answer_value).id).to eq("leftreg") expect(find_conditional_question(page, question, answer_value).id).to eq("leftreg")

2
spec/helpers/interuption_screen_helper_spec.rb

@ -11,7 +11,7 @@ RSpec.describe InteruptionScreenHelper do
:in_progress, :in_progress,
ecstat1: 1, ecstat1: 1,
earnings: 750, earnings: 750,
incfreq: 0, incfreq: 1,
owning_organisation: user.organisation, owning_organisation: user.organisation,
managing_organisation: user.organisation, managing_organisation: user.organisation,
) )

12
spec/models/case_log_spec.rb

@ -175,17 +175,17 @@ RSpec.describe CaseLog do
let(:case_log) { FactoryBot.build(:case_log, earnings: net_income) } let(:case_log) { FactoryBot.build(:case_log, earnings: net_income) }
it "returns input income if frequency is already weekly" do it "returns input income if frequency is already weekly" do
case_log.incfreq = 0 case_log.incfreq = 1
expect(case_log.weekly_net_income).to eq(net_income) expect(case_log.weekly_net_income).to eq(net_income)
end end
it "calculates the correct weekly income from monthly income" do it "calculates the correct weekly income from monthly income" do
case_log.incfreq = 1 case_log.incfreq = 2
expect(case_log.weekly_net_income).to eq(1154) expect(case_log.weekly_net_income).to eq(1154)
end end
it "calculates the correct weekly income from yearly income" do it "calculates the correct weekly income from yearly income" do
case_log.incfreq = 2 case_log.incfreq = 3
expect(case_log.weekly_net_income).to eq(417) expect(case_log.weekly_net_income).to eq(417)
end end
end end
@ -1663,7 +1663,7 @@ RSpec.describe CaseLog do
describe "resetting invalidated fields" do describe "resetting invalidated fields" do
context "when a question that has already been answered, no longer has met dependencies" do context "when a question that has already been answered, no longer has met dependencies" do
let(:case_log) { FactoryBot.create(:case_log, :in_progress, cbl: 1, preg_occ: 1, wchair: 1) } let(:case_log) { FactoryBot.create(:case_log, :in_progress, cbl: 1, preg_occ: 2, wchair: 1) }
it "clears the answer" do it "clears the answer" do
expect { case_log.update!(preg_occ: nil) }.to change(case_log, :cbl).from(1).to(nil) expect { case_log.update!(preg_occ: nil) }.to change(case_log, :cbl).from(1).to(nil)
@ -1679,7 +1679,7 @@ RSpec.describe CaseLog do
end end
context "with two pages having the same question key, only one's dependency is met" do context "with two pages having the same question key, only one's dependency is met" do
let(:case_log) { FactoryBot.create(:case_log, :in_progress, cbl: 0, preg_occ: 1, wchair: 1) } let(:case_log) { FactoryBot.create(:case_log, :in_progress, cbl: 0, preg_occ: 2, wchair: 1) }
it "does not clear the value for answers that apply to both pages" do it "does not clear the value for answers that apply to both pages" do
expect(case_log.cbl).to eq(0) expect(case_log.cbl).to eq(0)
@ -1688,7 +1688,7 @@ RSpec.describe CaseLog do
it "does clear the value for answers that do not apply for invalidated page" do it "does clear the value for answers that do not apply for invalidated page" do
case_log.update!({ wchair: 1, sex2: "F", age2: 33 }) case_log.update!({ wchair: 1, sex2: "F", age2: 33 })
case_log.update!({ cbl: 1 }) case_log.update!({ cbl: 1 })
case_log.update!({ preg_occ: 0 }) case_log.update!({ preg_occ: 1 })
expect(case_log.cbl).to eq(nil) expect(case_log.cbl).to eq(nil)
end end

2
spec/models/form/page_spec.rb

@ -56,7 +56,7 @@ RSpec.describe Form::Page, type: :model do
end end
it "evaluates met conditions correctly" do it "evaluates met conditions correctly" do
case_log.incfreq = "Weekly" case_log.incfreq = 1
expect(page.routed_to?(case_log)).to be true expect(page.routed_to?(case_log)).to be true
end end
end end

14
spec/models/form/question_spec.rb

@ -75,16 +75,16 @@ RSpec.describe Form::Question, type: :model do
let(:question_id) { "incfreq" } let(:question_id) { "incfreq" }
it "has answer options" do it "has answer options" do
expected_answer_options = { "0" => { "value" => "Weekly" }, "1" => { "value" => "Monthly" }, "2" => { "value" => "Yearly" } } expected_answer_options = { "1" => { "value" => "Weekly" }, "2" => { "value" => "Monthly" }, "3" => { "value" => "Yearly" } }
expect(question.answer_options).to eq(expected_answer_options) expect(question.answer_options).to eq(expected_answer_options)
end end
it "can map value from label" do it "can map value from label" do
expect(question.value_from_label("Monthly")).to eq("1") expect(question.value_from_label("Monthly")).to eq("2")
end end
it "can map label from value" do it "can map label from value" do
expect(question.label_from_value(2)).to eq("Yearly") expect(question.label_from_value(3)).to eq("Yearly")
end end
context "when answer options include yes, no, prefer not to say" do context "when answer options include yes, no, prefer not to say" do
@ -221,7 +221,7 @@ RSpec.describe Form::Question, type: :model do
let(:question_id) { "incfreq" } let(:question_id) { "incfreq" }
it "has an answer label" do it "has an answer label" do
case_log.incfreq = 0 case_log.incfreq = 1
expect(question.answer_label(case_log)).to eq("Weekly") expect(question.answer_label(case_log)).to eq("Weekly")
end end
@ -321,12 +321,12 @@ RSpec.describe Form::Question, type: :model do
let(:question_id) { "earnings" } let(:question_id) { "earnings" }
it "displays the correct label for given suffix and answer the suffix depends on" do it "displays the correct label for given suffix and answer the suffix depends on" do
case_log.incfreq = 0 case_log.incfreq = 1
case_log.earnings = 500 case_log.earnings = 500
expect(question.answer_label(case_log)).to eq("£500.00 every week") expect(question.answer_label(case_log)).to eq("£500.00 every week")
case_log.incfreq = 1
expect(question.answer_label(case_log)).to eq("£500.00 every month")
case_log.incfreq = 2 case_log.incfreq = 2
expect(question.answer_label(case_log)).to eq("£500.00 every month")
case_log.incfreq = 3
expect(question.answer_label(case_log)).to eq("£500.00 every year") expect(question.answer_label(case_log)).to eq("£500.00 every year")
end end
end end

8
spec/models/form_spec.rb

@ -16,7 +16,7 @@ RSpec.describe Form, type: :model do
context "when the current page is a value check page" do context "when the current page is a value check page" do
before do before do
case_log.incfreq = 0 case_log.incfreq = 1
case_log.earnings = 140 case_log.earnings = 140
case_log.ecstat1 = 1 case_log.ecstat1 = 1
end end
@ -39,7 +39,7 @@ RSpec.describe Form, type: :model do
let!(:page_ids) { subsection.pages.map(&:id) } let!(:page_ids) { subsection.pages.map(&:id) }
before do before do
case_log.preg_occ = 1 case_log.preg_occ = 2
end end
it "returns the previous page if the page is routed to" do it "returns the previous page if the page is routed to" do
@ -68,7 +68,7 @@ RSpec.describe Form, type: :model do
end end
it "returns a correct page path if there is conditional routing" do it "returns a correct page path if there is conditional routing" do
case_log["preg_occ"] = 1 case_log["preg_occ"] = 2
expect(form.next_page_redirect_path(previous_conditional_page, case_log)).to eq("case_log_conditional_question_no_page_path") expect(form.next_page_redirect_path(previous_conditional_page, case_log)).to eq("case_log_conditional_question_no_page_path")
end end
end end
@ -102,7 +102,7 @@ RSpec.describe Form, type: :model do
def answer_income_and_benefits(case_log) def answer_income_and_benefits(case_log)
case_log.earnings = 30_000 case_log.earnings = 30_000
case_log.incfreq = "Yearly" case_log.incfreq = 3
case_log.benefits = "Some" case_log.benefits = "Some"
case_log.hb = "Tenant prefers not to say" case_log.hb = "Tenant prefers not to say"
end end

8
spec/models/validations/financial_validations_spec.rb

@ -17,7 +17,7 @@ RSpec.describe Validations::FinancialValidations do
it "when income frequency is provided it validates that earnings must be provided" do it "when income frequency is provided it validates that earnings must be provided" do
record.earnings = nil record.earnings = nil
record.incfreq = 0 record.incfreq = 1
financial_validator.validate_net_income(record) financial_validator.validate_net_income(record)
expect(record.errors["earnings"]) expect(record.errors["earnings"])
.to include(match I18n.t("validations.financial.earnings.earnings_missing")) .to include(match I18n.t("validations.financial.earnings.earnings_missing"))
@ -124,7 +124,7 @@ RSpec.describe Validations::FinancialValidations do
describe "Net income validations" do describe "Net income validations" do
it "validates that the net income is within the expected range for the tenant's employment status" do it "validates that the net income is within the expected range for the tenant's employment status" do
record.earnings = 200 record.earnings = 200
record.incfreq = 0 record.incfreq = 1
record.ecstat1 = 1 record.ecstat1 = 1
financial_validator.validate_net_income(record) financial_validator.validate_net_income(record)
expect(record.errors["earnings"]).to be_empty expect(record.errors["earnings"]).to be_empty
@ -133,7 +133,7 @@ RSpec.describe Validations::FinancialValidations do
context "when the net income is higher than the hard max for their employment status" do context "when the net income is higher than the hard max for their employment status" do
it "adds an error" do it "adds an error" do
record.earnings = 5000 record.earnings = 5000
record.incfreq = 0 record.incfreq = 1
record.ecstat1 = 1 record.ecstat1 = 1
financial_validator.validate_net_income(record) financial_validator.validate_net_income(record)
expect(record.errors["earnings"]) expect(record.errors["earnings"])
@ -144,7 +144,7 @@ RSpec.describe Validations::FinancialValidations do
context "when the net income is lower than the hard min for their employment status" do context "when the net income is lower than the hard min for their employment status" do
it "adds an error" do it "adds an error" do
record.earnings = 50 record.earnings = 50
record.incfreq = 0 record.incfreq = 1
record.ecstat1 = 1 record.ecstat1 = 1
financial_validator.validate_net_income(record) financial_validator.validate_net_income(record)
expect(record.errors["earnings"]) expect(record.errors["earnings"])

18
spec/models/validations/household_validations_spec.rb

@ -58,7 +58,7 @@ RSpec.describe Validations::HouseholdValidations do
describe "pregnancy validations" do describe "pregnancy validations" do
context "when there are no female tenants" do context "when there are no female tenants" do
it "validates that pregnancy cannot be yes" do it "validates that pregnancy cannot be yes" do
record.preg_occ = 0 record.preg_occ = 1
record.sex1 = "M" record.sex1 = "M"
household_validator.validate_pregnancy(record) household_validator.validate_pregnancy(record)
expect(record.errors["preg_occ"]) expect(record.errors["preg_occ"])
@ -66,7 +66,7 @@ RSpec.describe Validations::HouseholdValidations do
end end
it "validates that pregnancy cannot be prefer not to say" do it "validates that pregnancy cannot be prefer not to say" do
record.preg_occ = 2 record.preg_occ = 3
record.sex1 = "M" record.sex1 = "M"
household_validator.validate_pregnancy(record) household_validator.validate_pregnancy(record)
expect(record.errors["preg_occ"]) expect(record.errors["preg_occ"])
@ -77,7 +77,7 @@ RSpec.describe Validations::HouseholdValidations do
context "when there are female tenants" do context "when there are female tenants" do
context "but they are older than 50" do context "but they are older than 50" do
it "validates that pregnancy cannot be yes" do it "validates that pregnancy cannot be yes" do
record.preg_occ = 0 record.preg_occ = 1
record.sex1 = "F" record.sex1 = "F"
record.age1 = 51 record.age1 = 51
household_validator.validate_pregnancy(record) household_validator.validate_pregnancy(record)
@ -248,7 +248,7 @@ RSpec.describe Validations::HouseholdValidations do
context "when the tenant prefers not to say if they were or are in the armed forces" do context "when the tenant prefers not to say if they were or are in the armed forces" do
it "validates that injured in the armed forces is not yes" do it "validates that injured in the armed forces is not yes" do
record.armedforces = 4 record.armedforces = 3
record.reservist = 0 record.reservist = 0
household_validator.validate_armed_forces(record) household_validator.validate_armed_forces(record)
expect(record.errors["reservist"]) expect(record.errors["reservist"])
@ -276,7 +276,7 @@ RSpec.describe Validations::HouseholdValidations do
context "when the tenant's partner was or is a member of the armed forces" do context "when the tenant's partner was or is a member of the armed forces" do
it "expects that injured in the armed forces can be yes" do it "expects that injured in the armed forces can be yes" do
record.armedforces = 2 record.armedforces = 5
record.reservist = 0 record.reservist = 0
household_validator.validate_armed_forces(record) household_validator.validate_armed_forces(record)
expect(record.errors["reservist"]).to be_empty expect(record.errors["reservist"]).to be_empty
@ -285,7 +285,7 @@ RSpec.describe Validations::HouseholdValidations do
context "when the tenant or partner has left the armed forces" do context "when the tenant or partner has left the armed forces" do
it "validates that they served in the armed forces" do it "validates that they served in the armed forces" do
record.armedforces = 3 record.armedforces = 2
record.leftreg = 0 record.leftreg = 0
household_validator.validate_armed_forces(record) household_validator.validate_armed_forces(record)
expect(record.errors["leftreg"]) expect(record.errors["leftreg"])
@ -293,14 +293,14 @@ RSpec.describe Validations::HouseholdValidations do
end end
it "expects that they served in the armed forces" do it "expects that they served in the armed forces" do
record.armedforces = 0 record.armedforces = 1
record.leftreg = 0 record.leftreg = 0
household_validator.validate_armed_forces(record) household_validator.validate_armed_forces(record)
expect(record.errors["leftreg"]).to be_empty expect(record.errors["leftreg"]).to be_empty
end end
it "expects that they served in the armed forces and may have been injured" do it "expects that they served in the armed forces and may have been injured" do
record.armedforces = 0 record.armedforces = 1
record.leftreg = 0 record.leftreg = 0
record.reservist = 0 record.reservist = 0
household_validator.validate_armed_forces(record) household_validator.validate_armed_forces(record)
@ -697,7 +697,7 @@ RSpec.describe Validations::HouseholdValidations do
describe "previous housing situation validations" do describe "previous housing situation validations" do
context "when the property is being relet to a previously temporary tenant" do context "when the property is being relet to a previously temporary tenant" do
it "validates that previous tenancy was temporary" do it "validates that previous tenancy was temporary" do
record.rsnvac = 2 record.rsnvac = 9
record.prevten = 4 record.prevten = 4
household_validator.validate_previous_housing_situation(record) household_validator.validate_previous_housing_situation(record)
expect(record.errors["prevten"]) expect(record.errors["prevten"])

18
spec/models/validations/property_validations_spec.rb

@ -43,7 +43,7 @@ RSpec.describe Validations::PropertyValidations do
context "when number of bedrooms has not been answered" do context "when number of bedrooms has not been answered" do
it "does not add an error" do it "does not add an error" do
record.beds = nil record.beds = nil
record.unittype_gn = 1 record.unittype_gn = 2
property_validator.validate_shared_housing_rooms(record) property_validator.validate_shared_housing_rooms(record)
expect(record.errors).to be_empty expect(record.errors).to be_empty
end end
@ -52,7 +52,7 @@ RSpec.describe Validations::PropertyValidations do
context "when unit type is shared and number of bedrooms has not been answered" do context "when unit type is shared and number of bedrooms has not been answered" do
it "does not add an error" do it "does not add an error" do
record.beds = nil record.beds = nil
record.unittype_gn = 6 record.unittype_gn = 10
property_validator.validate_shared_housing_rooms(record) property_validator.validate_shared_housing_rooms(record)
expect(record.errors).to be_empty expect(record.errors).to be_empty
end end
@ -72,7 +72,7 @@ RSpec.describe Validations::PropertyValidations do
it "adds an error" do it "adds an error" do
record.beds = 2 record.beds = 2
record.unittype_gn = 1 record.unittype_gn = 2
property_validator.validate_shared_housing_rooms(record) property_validator.validate_shared_housing_rooms(record)
expect(record.errors["unittype_gn"]).to include(match(expected_error)) expect(record.errors["unittype_gn"]).to include(match(expected_error))
expect(record.errors["beds"]).to include(I18n.t("validations.property.unittype_gn.one_bedroom_bedsit")) expect(record.errors["beds"]).to include(I18n.t("validations.property.unittype_gn.one_bedroom_bedsit"))
@ -84,7 +84,7 @@ RSpec.describe Validations::PropertyValidations do
it "adds an error" do it "adds an error" do
record.beds = 0 record.beds = 0
record.unittype_gn = 1 record.unittype_gn = 2
property_validator.validate_shared_housing_rooms(record) property_validator.validate_shared_housing_rooms(record)
expect(record.errors["unittype_gn"]).to include(match(expected_error)) expect(record.errors["unittype_gn"]).to include(match(expected_error))
expect(record.errors["beds"]).to include(I18n.t("validations.property.unittype_gn.one_bedroom_bedsit")) expect(record.errors["beds"]).to include(I18n.t("validations.property.unittype_gn.one_bedroom_bedsit"))
@ -96,7 +96,7 @@ RSpec.describe Validations::PropertyValidations do
it "adds an error if the number of bedrooms is not between 1 and 7" do it "adds an error if the number of bedrooms is not between 1 and 7" do
record.beds = 8 record.beds = 8
record.unittype_gn = 5 record.unittype_gn = 9
record.hhmemb = 3 record.hhmemb = 3
property_validator.validate_shared_housing_rooms(record) property_validator.validate_shared_housing_rooms(record)
expect(record.errors["unittype_gn"]).to include(match(expected_error)) expect(record.errors["unittype_gn"]).to include(match(expected_error))
@ -109,7 +109,7 @@ RSpec.describe Validations::PropertyValidations do
it "adds an error if the number of bedrooms is not between 1 and 7" do it "adds an error if the number of bedrooms is not between 1 and 7" do
record.beds = 0 record.beds = 0
record.unittype_gn = 5 record.unittype_gn = 9
record.hhmemb = 3 record.hhmemb = 3
property_validator.validate_shared_housing_rooms(record) property_validator.validate_shared_housing_rooms(record)
expect(record.errors["unittype_gn"]).to include(match(expected_error)) expect(record.errors["unittype_gn"]).to include(match(expected_error))
@ -122,7 +122,7 @@ RSpec.describe Validations::PropertyValidations do
it "adds an error" do it "adds an error" do
record.beds = 4 record.beds = 4
record.unittype_gn = 5 record.unittype_gn = 9
record.hhmemb = 1 record.hhmemb = 1
property_validator.validate_shared_housing_rooms(record) property_validator.validate_shared_housing_rooms(record)
expect(record.errors["unittype_gn"]).to include(match(expected_error)) expect(record.errors["unittype_gn"]).to include(match(expected_error))
@ -286,7 +286,7 @@ RSpec.describe Validations::PropertyValidations do
it "validates that the property is not being relet to tenant who occupied as temporary" do it "validates that the property is not being relet to tenant who occupied as temporary" do
non_temporary_previous_tenancies.each do |prevten| non_temporary_previous_tenancies.each do |prevten|
record.rsnvac = 2 record.rsnvac = 9
record.prevten = prevten record.prevten = prevten
property_validator.validate_rsnvac(record) property_validator.validate_rsnvac(record)
expect(record.errors["rsnvac"]) expect(record.errors["rsnvac"])
@ -296,7 +296,7 @@ RSpec.describe Validations::PropertyValidations do
it "validates that the letting source is not a referral" do it "validates that the letting source is not a referral" do
referral_sources.each do |src| referral_sources.each do |src|
record.rsnvac = 2 record.rsnvac = 9
record.referral = src record.referral = src
property_validator.validate_rsnvac(record) property_validator.validate_rsnvac(record)
expect(record.errors["rsnvac"]) expect(record.errors["rsnvac"])

20
spec/models/validations/tenancy_validations_spec.rb

@ -12,7 +12,7 @@ RSpec.describe Validations::TenancyValidations do
let(:expected_error) { I18n.t("validations.tenancy.length.fixed_term_not_required") } let(:expected_error) { I18n.t("validations.tenancy.length.fixed_term_not_required") }
it "tenancy length should not be present" do it "tenancy length should not be present" do
record.tenancy = 4 record.tenancy = 3
record.tenancylength = 10 record.tenancylength = 10
tenancy_validator.validate_fixed_term_tenancy(record) tenancy_validator.validate_fixed_term_tenancy(record)
expect(record.errors["tenancylength"]).to include(match(expected_error)) expect(record.errors["tenancylength"]).to include(match(expected_error))
@ -22,10 +22,10 @@ RSpec.describe Validations::TenancyValidations do
context "when type of tenancy is assured shorthold" do context "when type of tenancy is assured shorthold" do
let(:expected_error) { I18n.t("validations.tenancy.length.shorthold") } let(:expected_error) { I18n.t("validations.tenancy.length.shorthold") }
before { record.tenancy = 4 }
context "when tenancy length is greater than 1" do context "when tenancy length is greater than 1" do
it "adds an error" do it "adds an error" do
record.tenancy = 1
record.tenancylength = 1 record.tenancylength = 1
tenancy_validator.validate_fixed_term_tenancy(record) tenancy_validator.validate_fixed_term_tenancy(record)
expect(record.errors["tenancylength"]).to include(match(expected_error)) expect(record.errors["tenancylength"]).to include(match(expected_error))
@ -35,7 +35,6 @@ RSpec.describe Validations::TenancyValidations do
context "when tenancy length is less than 100" do context "when tenancy length is less than 100" do
it "adds an error" do it "adds an error" do
record.tenancy = 1
record.tenancylength = 100 record.tenancylength = 100
tenancy_validator.validate_fixed_term_tenancy(record) tenancy_validator.validate_fixed_term_tenancy(record)
expect(record.errors["tenancylength"]).to include(match(expected_error)) expect(record.errors["tenancylength"]).to include(match(expected_error))
@ -45,7 +44,6 @@ RSpec.describe Validations::TenancyValidations do
context "when tenancy length is between 2-99" do context "when tenancy length is between 2-99" do
it "does not add an error" do it "does not add an error" do
record.tenancy = 1
record.tenancylength = 3 record.tenancylength = 3
tenancy_validator.validate_fixed_term_tenancy(record) tenancy_validator.validate_fixed_term_tenancy(record)
expect(record.errors["tenancylength"]).to be_empty expect(record.errors["tenancylength"]).to be_empty
@ -55,7 +53,6 @@ RSpec.describe Validations::TenancyValidations do
context "when tenancy length has not been answered" do context "when tenancy length has not been answered" do
it "does not add an error" do it "does not add an error" do
record.tenancy = 1
record.tenancylength = nil record.tenancylength = nil
tenancy_validator.validate_fixed_term_tenancy(record) tenancy_validator.validate_fixed_term_tenancy(record)
expect(record.errors["tenancylength"]).to be_empty expect(record.errors["tenancylength"]).to be_empty
@ -66,10 +63,10 @@ RSpec.describe Validations::TenancyValidations do
context "when type of tenancy is secure" do context "when type of tenancy is secure" do
let(:expected_error) { I18n.t("validations.tenancy.length.secure") } let(:expected_error) { I18n.t("validations.tenancy.length.secure") }
before { record.tenancy = 1 }
context "when tenancy length is greater than 1" do context "when tenancy length is greater than 1" do
it "adds an error" do it "adds an error" do
record.tenancy = 3
record.tenancylength = 1 record.tenancylength = 1
tenancy_validator.validate_fixed_term_tenancy(record) tenancy_validator.validate_fixed_term_tenancy(record)
expect(record.errors["tenancylength"]).to include(match(expected_error)) expect(record.errors["tenancylength"]).to include(match(expected_error))
@ -79,7 +76,6 @@ RSpec.describe Validations::TenancyValidations do
context "when tenancy length is less than 100" do context "when tenancy length is less than 100" do
it "adds an error" do it "adds an error" do
record.tenancy = 3
record.tenancylength = 100 record.tenancylength = 100
tenancy_validator.validate_fixed_term_tenancy(record) tenancy_validator.validate_fixed_term_tenancy(record)
expect(record.errors["tenancylength"]).to include(match(expected_error)) expect(record.errors["tenancylength"]).to include(match(expected_error))
@ -89,7 +85,6 @@ RSpec.describe Validations::TenancyValidations do
context "when tenancy length is between 2-99" do context "when tenancy length is between 2-99" do
it "does not add an error" do it "does not add an error" do
record.tenancy = 3
record.tenancylength = 3 record.tenancylength = 3
tenancy_validator.validate_fixed_term_tenancy(record) tenancy_validator.validate_fixed_term_tenancy(record)
expect(record.errors["tenancylength"]).to be_empty expect(record.errors["tenancylength"]).to be_empty
@ -99,7 +94,6 @@ RSpec.describe Validations::TenancyValidations do
context "when tenancy length has not been answered" do context "when tenancy length has not been answered" do
it "does not add an error" do it "does not add an error" do
record.tenancy = 3
record.tenancylength = nil record.tenancylength = nil
tenancy_validator.validate_fixed_term_tenancy(record) tenancy_validator.validate_fixed_term_tenancy(record)
expect(record.errors["tenancylength"]).to be_empty expect(record.errors["tenancylength"]).to be_empty
@ -117,15 +111,15 @@ RSpec.describe Validations::TenancyValidations do
let(:expected_error) { I18n.t(field, main_field_label:, other_field_label:) } let(:expected_error) { I18n.t(field, main_field_label:, other_field_label:) }
context "when tenancy type is other" do context "when tenancy type is other" do
before { record.tenancy = 3 }
it "validates that other tenancy type is provided" do it "validates that other tenancy type is provided" do
record.tenancy = 4
record.tenancyother = nil record.tenancyother = nil
tenancy_validator.validate_other_tenancy_type(record) tenancy_validator.validate_other_tenancy_type(record)
expect(record.errors[other_field_label]).to include(match(expected_error)) expect(record.errors[other_field_label]).to include(match(expected_error))
end end
it "expects that other tenancy type is provided" do it "expects that other tenancy type is provided" do
record.tenancy = 4
record.tenancyother = "Some other tenancy type" record.tenancyother = "Some other tenancy type"
tenancy_validator.validate_other_tenancy_type(record) tenancy_validator.validate_other_tenancy_type(record)
expect(record.errors[other_field_label]).to be_empty expect(record.errors[other_field_label]).to be_empty
@ -136,14 +130,14 @@ RSpec.describe Validations::TenancyValidations do
let(:field) { "validations.other_field_not_required" } let(:field) { "validations.other_field_not_required" }
it "validates that other tenancy type is not provided" do it "validates that other tenancy type is not provided" do
record.tenancy = 0 record.tenancy = 2
record.tenancyother = "Some other tenancy type" record.tenancyother = "Some other tenancy type"
tenancy_validator.validate_other_tenancy_type(record) tenancy_validator.validate_other_tenancy_type(record)
expect(record.errors[other_field_label]).to include(match(expected_error)) expect(record.errors[other_field_label]).to include(match(expected_error))
end end
it "expects that other tenancy type is not provided" do it "expects that other tenancy type is not provided" do
record.tenancy = 3 record.tenancy = 1
record.tenancyother = nil record.tenancyother = nil
tenancy_validator.validate_other_tenancy_type(record) tenancy_validator.validate_other_tenancy_type(record)
expect(record.errors[other_field_label]).to be_empty expect(record.errors[other_field_label]).to be_empty

4
spec/requests/form_controller_spec.rb

@ -275,7 +275,7 @@ RSpec.describe FormController, type: :request do
id: case_log.id, id: case_log.id,
case_log: { case_log: {
page: "conditional_question", page: "conditional_question",
preg_occ: 0, preg_occ: 1,
}, },
} }
end end
@ -284,7 +284,7 @@ RSpec.describe FormController, type: :request do
id: case_log.id, id: case_log.id,
case_log: { case_log: {
page: "conditional_question", page: "conditional_question",
preg_occ: 1, preg_occ: 2,
}, },
} }
end end

1
spec/services/imports/case_logs_import_service_spec.rb

@ -24,6 +24,7 @@ RSpec.describe Imports::CaseLogsImportService do
it "successfully create a case log with the expected data" do it "successfully create a case log with the expected data" do
case_log_service.create_logs(remote_folder) case_log_service.create_logs(remote_folder)
end end
end end
end end

Loading…
Cancel
Save