Browse Source

Merge branch 'main' into IncomeErrorMessages

pull/2270/head
Rachael Booth 2 years ago
parent
commit
081c616fde
  1. 333
      Gemfile.lock
  2. 38
      app/helpers/charges_helper.rb
  3. 34
      app/models/bulk_upload.rb
  4. 2
      app/models/form/lettings/pages/pscharge_value_check.rb
  5. 2
      app/models/form/lettings/pages/scharge_value_check.rb
  6. 2
      app/models/form/lettings/pages/supcharg_value_check.rb
  7. 2
      app/models/form/lettings/questions/person_working_situation.rb
  8. 2
      app/models/form/sales/questions/age1.rb
  9. 2
      app/models/form/sales/questions/buyer1_age_known.rb
  10. 2
      app/models/form/sales/questions/buyer1_working_situation.rb
  11. 2
      app/models/form/sales/questions/buyer2_working_situation.rb
  12. 9
      app/models/form/sales/questions/number_joint_buyers.rb
  13. 2
      app/models/form/sales/questions/person_working_situation.rb
  14. 2
      app/models/form/sales/questions/property_number_of_bedrooms.rb
  15. 4
      app/models/form/sales/questions/property_wheelchair_accessible.rb
  16. 1
      app/models/log.rb
  17. 38
      app/models/validations/financial_validations.rb
  18. 8
      app/models/validations/sales/soft_validations.rb
  19. 65
      app/models/validations/soft_validations.rb
  20. 21
      app/services/bulk_upload/lettings/year2023/row_parser.rb
  21. 20
      app/services/bulk_upload/lettings/year2024/row_parser.rb
  22. 6
      config/forms/2022_2023.json
  23. 1
      config/locales/en.yml
  24. 7
      spec/factories/lettings_log.rb
  25. 18
      spec/models/bulk_upload_spec.rb
  26. 2
      spec/models/form/sales/questions/age1_spec.rb
  27. 2
      spec/models/form/sales/questions/buyer1_age_known_spec.rb
  28. 2
      spec/models/form/sales/questions/buyer1_working_situation_spec.rb
  29. 2
      spec/models/form/sales/questions/buyer2_working_situation_spec.rb
  30. 16
      spec/models/form/sales/questions/number_joint_buyers_spec.rb
  31. 2
      spec/models/form/sales/questions/person_working_situation_spec.rb
  32. 4
      spec/models/form/sales/questions/property_wheelchair_accessible_spec.rb
  33. 20
      spec/models/lettings_log_spec.rb
  34. 50
      spec/models/log_spec.rb
  35. 23
      spec/models/validations/sales/soft_validations_spec.rb
  36. 318
      spec/models/validations/soft_validations_spec.rb
  37. 14
      spec/requests/duplicate_logs_controller_spec.rb
  38. 105
      spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb
  39. 59
      spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb

333
Gemfile.lock

@ -1,134 +1,137 @@
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
actioncable (7.0.7.2) actioncable (7.0.8.1)
actionpack (= 7.0.7.2) actionpack (= 7.0.8.1)
activesupport (= 7.0.7.2) activesupport (= 7.0.8.1)
nio4r (~> 2.0) nio4r (~> 2.0)
websocket-driver (>= 0.6.1) websocket-driver (>= 0.6.1)
actionmailbox (7.0.7.2) actionmailbox (7.0.8.1)
actionpack (= 7.0.7.2) actionpack (= 7.0.8.1)
activejob (= 7.0.7.2) activejob (= 7.0.8.1)
activerecord (= 7.0.7.2) activerecord (= 7.0.8.1)
activestorage (= 7.0.7.2) activestorage (= 7.0.8.1)
activesupport (= 7.0.7.2) activesupport (= 7.0.8.1)
mail (>= 2.7.1) mail (>= 2.7.1)
net-imap net-imap
net-pop net-pop
net-smtp net-smtp
actionmailer (7.0.7.2) actionmailer (7.0.8.1)
actionpack (= 7.0.7.2) actionpack (= 7.0.8.1)
actionview (= 7.0.7.2) actionview (= 7.0.8.1)
activejob (= 7.0.7.2) activejob (= 7.0.8.1)
activesupport (= 7.0.7.2) activesupport (= 7.0.8.1)
mail (~> 2.5, >= 2.5.4) mail (~> 2.5, >= 2.5.4)
net-imap net-imap
net-pop net-pop
net-smtp net-smtp
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
actionpack (7.0.7.2) actionpack (7.0.8.1)
actionview (= 7.0.7.2) actionview (= 7.0.8.1)
activesupport (= 7.0.7.2) activesupport (= 7.0.8.1)
rack (~> 2.0, >= 2.2.4) rack (~> 2.0, >= 2.2.4)
rack-test (>= 0.6.3) rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (7.0.7.2) actiontext (7.0.8.1)
actionpack (= 7.0.7.2) actionpack (= 7.0.8.1)
activerecord (= 7.0.7.2) activerecord (= 7.0.8.1)
activestorage (= 7.0.7.2) activestorage (= 7.0.8.1)
activesupport (= 7.0.7.2) activesupport (= 7.0.8.1)
globalid (>= 0.6.0) globalid (>= 0.6.0)
nokogiri (>= 1.8.5) nokogiri (>= 1.8.5)
actionview (7.0.7.2) actionview (7.0.8.1)
activesupport (= 7.0.7.2) activesupport (= 7.0.8.1)
builder (~> 3.1) builder (~> 3.1)
erubi (~> 1.4) erubi (~> 1.4)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (7.0.7.2) activejob (7.0.8.1)
activesupport (= 7.0.7.2) activesupport (= 7.0.8.1)
globalid (>= 0.3.6) globalid (>= 0.3.6)
activemodel (7.0.7.2) activemodel (7.0.8.1)
activesupport (= 7.0.7.2) activesupport (= 7.0.8.1)
activerecord (7.0.7.2) activerecord (7.0.8.1)
activemodel (= 7.0.7.2) activemodel (= 7.0.8.1)
activesupport (= 7.0.7.2) activesupport (= 7.0.8.1)
activestorage (7.0.7.2) activestorage (7.0.8.1)
actionpack (= 7.0.7.2) actionpack (= 7.0.8.1)
activejob (= 7.0.7.2) activejob (= 7.0.8.1)
activerecord (= 7.0.7.2) activerecord (= 7.0.8.1)
activesupport (= 7.0.7.2) activesupport (= 7.0.8.1)
marcel (~> 1.0) marcel (~> 1.0)
mini_mime (>= 1.1.0) mini_mime (>= 1.1.0)
activesupport (7.0.7.2) activesupport (7.0.8.1)
concurrent-ruby (~> 1.0, >= 1.0.2) concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2) i18n (>= 1.6, < 2)
minitest (>= 5.1) minitest (>= 5.1)
tzinfo (~> 2.0) tzinfo (~> 2.0)
addressable (2.8.1) addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0) public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2) ast (2.4.2)
auto_strip_attributes (2.6.0) auto_strip_attributes (2.6.0)
activerecord (>= 4.0) activerecord (>= 4.0)
aws-eventstream (1.2.0) aws-eventstream (1.3.0)
aws-partitions (1.714.0) aws-partitions (1.894.0)
aws-sdk-core (3.170.0) aws-sdk-core (3.191.3)
aws-eventstream (~> 1, >= 1.0.2) aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.651.0) aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.5) aws-sigv4 (~> 1.8)
jmespath (~> 1, >= 1.6.1) jmespath (~> 1, >= 1.6.1)
aws-sdk-kms (1.62.0) aws-sdk-kms (1.77.0)
aws-sdk-core (~> 3, >= 3.165.0) aws-sdk-core (~> 3, >= 3.191.0)
aws-sigv4 (~> 1.1) aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.119.1) aws-sdk-s3 (1.143.0)
aws-sdk-core (~> 3, >= 3.165.0) aws-sdk-core (~> 3, >= 3.191.0)
aws-sdk-kms (~> 1) aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.4) aws-sigv4 (~> 1.8)
aws-sigv4 (1.5.2) aws-sigv4 (1.8.0)
aws-eventstream (~> 1, >= 1.0.2) aws-eventstream (~> 1, >= 1.0.2)
bcrypt (3.1.18) base64 (0.2.0)
better_html (2.0.1) bcrypt (3.1.20)
better_html (2.0.2)
actionview (>= 6.0) actionview (>= 6.0)
activesupport (>= 6.0) activesupport (>= 6.0)
ast (~> 2.0) ast (~> 2.0)
erubi (~> 1.4) erubi (~> 1.4)
parser (>= 2.4) parser (>= 2.4)
smart_properties smart_properties
bigdecimal (3.1.6)
bindex (0.8.1) bindex (0.8.1)
bootsnap (1.16.0) bootsnap (1.18.3)
msgpack (~> 1.2) msgpack (~> 1.2)
builder (3.2.4) builder (3.2.4)
bundler-audit (0.9.1) bundler-audit (0.9.1)
bundler (>= 1.2.0, < 3) bundler (>= 1.2.0, < 3)
thor (~> 1.0) thor (~> 1.0)
byebug (11.1.3) byebug (11.1.3)
capybara (3.38.0) capybara (3.40.0)
addressable addressable
matrix matrix
mini_mime (>= 0.1.3) mini_mime (>= 0.1.3)
nokogiri (~> 1.8) nokogiri (~> 1.11)
rack (>= 1.6.0) rack (>= 1.6.0)
rack-test (>= 0.6.3) rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0) regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2) xpath (~> 3.2)
capybara-lockstep (1.3.0) capybara-lockstep (2.2.0)
activesupport (>= 3.2) activesupport (>= 4.2)
capybara (>= 2.0) capybara (>= 3.0)
ruby2_keywords ruby2_keywords
selenium-webdriver (>= 3) selenium-webdriver (>= 4.0)
capybara-screenshot (1.0.26) capybara-screenshot (1.0.26)
capybara (>= 1.0, < 4) capybara (>= 1.0, < 4)
launchy launchy
childprocess (4.1.0) childprocess (5.0.0)
coderay (1.1.3) coderay (1.1.3)
concurrent-ruby (1.2.2) concurrent-ruby (1.2.3)
connection_pool (2.4.1) connection_pool (2.4.1)
crack (0.4.5) crack (1.0.0)
bigdecimal
rexml rexml
crass (1.0.6) crass (1.0.6)
date (3.3.3) date (3.3.4)
devise (4.8.1) devise (4.9.3)
bcrypt (~> 3.0) bcrypt (~> 3.0)
orm_adapter (~> 0.1) orm_adapter (~> 0.1)
railties (>= 4.1.0) railties (>= 4.1.0)
@ -140,14 +143,14 @@ GEM
rails (>= 3.1.1) rails (>= 3.1.1)
randexp randexp
rotp (>= 4.0.0) rotp (>= 4.0.0)
diff-lcs (1.5.0) diff-lcs (1.5.1)
docile (1.4.0) docile (1.4.0)
dotenv (2.8.1) dotenv (3.0.2)
dotenv-rails (2.8.1) dotenv-rails (3.0.2)
dotenv (= 2.8.1) dotenv (= 3.0.2)
railties (>= 3.2) railties (>= 6.1)
encryptor (3.0.0) encryptor (3.0.0)
erb_lint (0.3.1) erb_lint (0.5.0)
activesupport activesupport
better_html (>= 2.0.1) better_html (>= 2.0.1)
parser (>= 2.7.1.4) parser (>= 2.7.1.4)
@ -157,47 +160,48 @@ GEM
erubi (1.12.0) erubi (1.12.0)
et-orbi (1.2.7) et-orbi (1.2.7)
tzinfo tzinfo
excon (0.99.0) excon (0.109.0)
factory_bot (6.2.1) factory_bot (6.4.6)
activesupport (>= 5.0.0) activesupport (>= 5.0.0)
factory_bot_rails (6.2.0) factory_bot_rails (6.4.3)
factory_bot (~> 6.2.0) factory_bot (~> 6.4)
railties (>= 5.0.0) railties (>= 5.0.0)
faker (3.1.1) faker (3.2.3)
i18n (>= 1.8.11, < 2) i18n (>= 1.8.11, < 2)
ffi (1.15.5) ffi (1.16.3)
fugit (1.8.1) fugit (1.10.0)
et-orbi (~> 1, >= 1.2.7) et-orbi (~> 1, >= 1.2.7)
raabro (~> 1.4) raabro (~> 1.4)
globalid (1.1.0) globalid (1.2.1)
activesupport (>= 5.0) activesupport (>= 6.1)
govuk-components (5.1.0) govuk-components (5.2.1)
html-attributes-utils (~> 1.0.0, >= 1.0.0) html-attributes-utils (~> 1.0.0, >= 1.0.0)
pagy (~> 6.0) pagy (~> 6.0)
view_component (>= 3.9, < 3.11) view_component (>= 3.9, < 3.11)
govuk_design_system_formbuilder (5.0.0) govuk_design_system_formbuilder (5.2.0)
actionview (>= 6.1) actionview (>= 6.1)
activemodel (>= 6.1) activemodel (>= 6.1)
activesupport (>= 6.1) activesupport (>= 6.1)
html-attributes-utils (~> 1) html-attributes-utils (~> 1)
govuk_markdown (2.0.0) govuk_markdown (2.0.1)
activesupport activesupport
redcarpet redcarpet
hashdiff (1.0.1) hashdiff (1.1.0)
html-attributes-utils (1.0.2) html-attributes-utils (1.0.2)
activesupport (>= 6.1.4.4) activesupport (>= 6.1.4.4)
i18n (1.14.1) i18n (1.14.1)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
iniparse (1.5.0) iniparse (1.5.0)
jmespath (1.6.2) jmespath (1.6.2)
jsbundling-rails (1.1.1) jsbundling-rails (1.3.0)
railties (>= 6.0.0) railties (>= 6.0.0)
json-schema (3.0.0) json-schema (4.1.1)
addressable (>= 2.8) addressable (>= 2.8)
jwt (2.7.0) jwt (2.8.0)
base64
launchy (2.5.2) launchy (2.5.2)
addressable (~> 2.8) addressable (~> 2.8)
listen (3.8.0) listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3) rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10) rb-inotify (~> 0.9, >= 0.9.10)
loofah (2.22.0) loofah (2.22.0)
@ -212,16 +216,16 @@ GEM
matrix (0.4.2) matrix (0.4.2)
method_source (1.0.0) method_source (1.0.0)
mini_mime (1.1.5) mini_mime (1.1.5)
minitest (5.20.0) minitest (5.22.2)
msgpack (1.6.0) msgpack (1.7.2)
net-imap (0.3.7) net-imap (0.4.10)
date date
net-protocol net-protocol
net-pop (0.1.2) net-pop (0.1.2)
net-protocol net-protocol
net-protocol (0.2.1) net-protocol (0.2.2)
timeout timeout
net-smtp (0.3.3) net-smtp (0.4.0.1)
net-protocol net-protocol
nio4r (2.7.0) nio4r (2.7.0)
nokogiri (1.16.2-arm64-darwin) nokogiri (1.16.2-arm64-darwin)
@ -230,30 +234,31 @@ GEM
racc (~> 1.4) racc (~> 1.4)
nokogiri (1.16.2-x86_64-linux) nokogiri (1.16.2-x86_64-linux)
racc (~> 1.4) racc (~> 1.4)
notifications-ruby-client (5.4.0) notifications-ruby-client (6.0.0)
jwt (>= 1.5, < 3) jwt (>= 1.5, < 3)
orm_adapter (0.5.0) orm_adapter (0.5.0)
overcommit (0.60.0) overcommit (0.63.0)
childprocess (>= 0.6.3, < 5) childprocess (>= 0.6.3, < 6)
iniparse (~> 1.4) iniparse (~> 1.4)
rexml (~> 3.2) rexml (~> 3.2)
pagy (6.5.0) pagy (6.5.0)
paper_trail (14.0.0) paper_trail (15.1.0)
activerecord (>= 6.0) activerecord (>= 6.1)
request_store (~> 1.4) request_store (~> 1.4)
paper_trail-globalid (0.2.0) paper_trail-globalid (0.2.0)
globalid globalid
paper_trail (>= 3.0.0) paper_trail (>= 3.0.0)
parallel (1.22.1) parallel (1.24.0)
parallel_tests (4.2.0) parallel_tests (4.5.1)
parallel parallel
parser (3.2.1.0) parser (3.3.0.5)
ast (~> 2.4.1) ast (~> 2.4.1)
pg (1.4.5) racc
pg (1.5.5)
possessive (1.0.1) possessive (1.0.1)
postcodes_io (0.4.0) postcodes_io (0.4.0)
excon (~> 0.39) excon (~> 0.39)
propshaft (0.6.4) propshaft (0.8.0)
actionpack (>= 7.0.0) actionpack (>= 7.0.0)
activesupport (>= 7.0.0) activesupport (>= 7.0.0)
rack rack
@ -264,34 +269,34 @@ GEM
pry-byebug (3.10.1) pry-byebug (3.10.1)
byebug (~> 11.0) byebug (~> 11.0)
pry (>= 0.13, < 0.15) pry (>= 0.13, < 0.15)
public_suffix (5.0.1) public_suffix (5.0.4)
puma (5.6.8) puma (5.6.8)
nio4r (~> 2.0) nio4r (~> 2.0)
pundit (2.3.0) pundit (2.3.1)
activesupport (>= 3.0.0) activesupport (>= 3.0.0)
raabro (1.4.0) raabro (1.4.0)
racc (1.7.3) racc (1.7.3)
rack (2.2.8) rack (2.2.8.1)
rack-attack (6.6.1) rack-attack (6.7.0)
rack (>= 1.0, < 3) rack (>= 1.0, < 4)
rack-mini-profiler (2.3.4) rack-mini-profiler (2.3.4)
rack (>= 1.2.0) rack (>= 1.2.0)
rack-test (2.1.0) rack-test (2.1.0)
rack (>= 1.3) rack (>= 1.3)
rails (7.0.7.2) rails (7.0.8.1)
actioncable (= 7.0.7.2) actioncable (= 7.0.8.1)
actionmailbox (= 7.0.7.2) actionmailbox (= 7.0.8.1)
actionmailer (= 7.0.7.2) actionmailer (= 7.0.8.1)
actionpack (= 7.0.7.2) actionpack (= 7.0.8.1)
actiontext (= 7.0.7.2) actiontext (= 7.0.8.1)
actionview (= 7.0.7.2) actionview (= 7.0.8.1)
activejob (= 7.0.7.2) activejob (= 7.0.8.1)
activemodel (= 7.0.7.2) activemodel (= 7.0.8.1)
activerecord (= 7.0.7.2) activerecord (= 7.0.8.1)
activestorage (= 7.0.7.2) activestorage (= 7.0.8.1)
activesupport (= 7.0.7.2) activesupport (= 7.0.8.1)
bundler (>= 1.15.0) bundler (>= 1.15.0)
railties (= 7.0.7.2) railties (= 7.0.8.1)
rails-dom-testing (2.2.0) rails-dom-testing (2.2.0)
activesupport (>= 5.0.0) activesupport (>= 5.0.0)
minitest minitest
@ -299,51 +304,51 @@ GEM
rails-html-sanitizer (1.6.0) rails-html-sanitizer (1.6.0)
loofah (~> 2.21) loofah (~> 2.21)
nokogiri (~> 1.14) nokogiri (~> 1.14)
railties (7.0.7.2) railties (7.0.8.1)
actionpack (= 7.0.7.2) actionpack (= 7.0.8.1)
activesupport (= 7.0.7.2) activesupport (= 7.0.8.1)
method_source method_source
rake (>= 12.2) rake (>= 12.2)
thor (~> 1.0) thor (~> 1.0)
zeitwerk (~> 2.5) zeitwerk (~> 2.5)
rainbow (3.1.1) rainbow (3.1.1)
rake (13.0.6) rake (13.1.0)
randexp (0.1.7) randexp (0.1.7)
rb-fsevent (0.11.2) rb-fsevent (0.11.2)
rb-inotify (0.10.1) rb-inotify (0.10.1)
ffi (~> 1.0) ffi (~> 1.0)
redcarpet (3.6.0) redcarpet (3.6.0)
redis (4.8.1) redis (4.8.1)
redis-client (0.17.0) redis-client (0.20.0)
connection_pool connection_pool
regexp_parser (2.7.0) regexp_parser (2.9.0)
request_store (1.5.1) request_store (1.6.0)
rack (>= 1.4) rack (>= 1.4)
responders (3.1.0) responders (3.1.1)
actionpack (>= 5.2) actionpack (>= 5.2)
railties (>= 5.2) railties (>= 5.2)
rexml (3.2.5) rexml (3.2.6)
roo (2.10.0) roo (2.10.1)
nokogiri (~> 1) nokogiri (~> 1)
rubyzip (>= 1.3.0, < 3.0.0) rubyzip (>= 1.3.0, < 3.0.0)
rotp (6.2.2) rotp (6.3.0)
rspec-core (3.12.1) rspec-core (3.13.0)
rspec-support (~> 3.12.0) rspec-support (~> 3.13.0)
rspec-expectations (3.12.2) rspec-expectations (3.13.0)
diff-lcs (>= 1.2.0, < 2.0) diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0) rspec-support (~> 3.13.0)
rspec-mocks (3.12.3) rspec-mocks (3.13.0)
diff-lcs (>= 1.2.0, < 2.0) diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0) rspec-support (~> 3.13.0)
rspec-rails (6.0.1) rspec-rails (6.1.1)
actionpack (>= 6.1) actionpack (>= 6.1)
activesupport (>= 6.1) activesupport (>= 6.1)
railties (>= 6.1) railties (>= 6.1)
rspec-core (~> 3.11) rspec-core (~> 3.12)
rspec-expectations (~> 3.11) rspec-expectations (~> 3.12)
rspec-mocks (~> 3.11) rspec-mocks (~> 3.12)
rspec-support (~> 3.11) rspec-support (~> 3.12)
rspec-support (3.12.0) rspec-support (3.13.1)
rubocop (1.25.0) rubocop (1.25.0)
parallel (~> 1.10) parallel (~> 1.10)
parser (>= 3.1.0.0) parser (>= 3.1.0.0)
@ -361,7 +366,7 @@ GEM
rubocop-rails (= 2.13.2) rubocop-rails (= 2.13.2)
rubocop-rake (= 0.6.0) rubocop-rake (= 0.6.0)
rubocop-rspec (= 2.7.0) rubocop-rspec (= 2.7.0)
rubocop-performance (1.16.0) rubocop-performance (1.19.1)
rubocop (>= 1.7.0, < 2.0) rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0) rubocop-ast (>= 0.4.0)
rubocop-rails (2.13.2) rubocop-rails (2.13.2)
@ -372,26 +377,28 @@ GEM
rubocop (~> 1.0) rubocop (~> 1.0)
rubocop-rspec (2.7.0) rubocop-rspec (2.7.0)
rubocop (~> 1.19) rubocop (~> 1.19)
ruby-progressbar (1.11.0) ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5) ruby2_keywords (0.0.5)
rubyzip (2.3.2) rubyzip (2.3.2)
selenium-webdriver (4.8.1) selenium-webdriver (4.18.1)
base64 (~> 0.2)
rexml (~> 3.2, >= 3.2.5) rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0) rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0) websocket (~> 1.0)
sentry-rails (5.8.0) sentry-rails (5.16.1)
railties (>= 5.0) railties (>= 5.0)
sentry-ruby (~> 5.8.0) sentry-ruby (~> 5.16.1)
sentry-ruby (5.8.0) sentry-ruby (5.16.1)
concurrent-ruby (~> 1.0, >= 1.0.2) concurrent-ruby (~> 1.0, >= 1.0.2)
sidekiq (7.1.3) sidekiq (7.2.2)
concurrent-ruby (< 2) concurrent-ruby (< 2)
connection_pool (>= 2.3.0) connection_pool (>= 2.3.0)
rack (>= 2.2.4) rack (>= 2.2.4)
redis-client (>= 0.14.0) redis-client (>= 0.19.0)
sidekiq-cron (1.9.1) sidekiq-cron (1.12.0)
fugit (~> 1.8) fugit (~> 1.8)
sidekiq (>= 4.2.1) globalid (>= 1.0.1)
sidekiq (>= 6)
simplecov (0.22.0) simplecov (0.22.0)
docile (~> 1.1) docile (~> 1.1)
simplecov-html (~> 0.11) simplecov-html (~> 0.11)
@ -399,39 +406,39 @@ GEM
simplecov-html (0.12.3) simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4) simplecov_json_formatter (0.1.4)
smart_properties (1.17.0) smart_properties (1.17.0)
stimulus-rails (1.2.1) stimulus-rails (1.3.3)
railties (>= 6.0.0) railties (>= 6.0.0)
thor (1.2.2) thor (1.3.0)
timecop (0.9.6) timecop (0.9.8)
timeout (0.4.0) timeout (0.4.1)
tzinfo (2.0.6) tzinfo (2.0.6)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
uk_postcode (2.1.8) uk_postcode (2.1.8)
unicode-display_width (2.4.2) unicode-display_width (2.5.0)
unread (0.13.0) unread (0.13.1)
activerecord (>= 6.1) activerecord (>= 6.1)
view_component (3.9.0) view_component (3.10.0)
activesupport (>= 5.2.0, < 8.0) activesupport (>= 5.2.0, < 8.0)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
method_source (~> 1.0) method_source (~> 1.0)
warden (1.2.9) warden (1.2.9)
rack (>= 2.0.9) rack (>= 2.0.9)
web-console (4.2.0) web-console (4.2.1)
actionview (>= 6.0.0) actionview (>= 6.0.0)
activemodel (>= 6.0.0) activemodel (>= 6.0.0)
bindex (>= 0.4.0) bindex (>= 0.4.0)
railties (>= 6.0.0) railties (>= 6.0.0)
webmock (3.18.1) webmock (3.23.0)
addressable (>= 2.8.0) addressable (>= 2.8.0)
crack (>= 0.3.2) crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0) hashdiff (>= 0.4.0, < 2.0.0)
websocket (1.2.9) websocket (1.2.10)
websocket-driver (0.7.6) websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0) websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5) websocket-extensions (0.1.5)
xpath (3.2.0) xpath (3.2.0)
nokogiri (~> 1.8) nokogiri (~> 1.8)
zeitwerk (2.6.11) zeitwerk (2.6.13)
PLATFORMS PLATFORMS
arm64-darwin-21 arm64-darwin-21

38
app/helpers/charges_helper.rb

@ -0,0 +1,38 @@
module ChargesHelper
CHARGE_MAXIMA_PER_WEEK = {
scharge: {
private_registered_provider: {
general_needs: 800,
supported_housing: 800,
},
local_authority: {
general_needs: 500,
supported_housing: 500,
},
},
pscharge: {
private_registered_provider: {
general_needs: 700,
supported_housing: 700,
},
local_authority: {
general_needs: 200,
supported_housing: 200,
},
},
supcharg: {
private_registered_provider: {
general_needs: 800,
supported_housing: 800,
},
local_authority: {
general_needs: 200,
supported_housing: 200,
},
},
}.freeze
PROVIDER_TYPE = { 1 => :local_authority, 2 => :private_registered_provider }.freeze
NEEDSTYPE_VALUES = { 2 => :supported_housing, 1 => :general_needs }.freeze
CHARGE_NAMES = { scharge: "service charge", pscharge: "personal service charge", supcharg: "support charge" }.freeze
end

34
app/models/bulk_upload.rb

@ -78,37 +78,13 @@ class BulkUpload < ApplicationRecord
end end
end end
def fields_to_confirm(log)
log.form.questions.select { |q| q.type == "interruption_screen" }.uniq(&:id).map(&:id)
end
def unpend_and_confirm_soft_validations def unpend_and_confirm_soft_validations
logs.find_each do |log| logs.find_each do |log|
log.retirement_value_check = 0 fields_to_confirm(log).each { |field| log[field] = 0 }
if log.lettings?
log.pregnancy_value_check = 0
log.major_repairs_date_value_check = 0
log.void_date_value_check = 0
log.rent_value_check = 0
log.net_income_value_check = 0
log.carehome_charges_value_check = 0
elsif log.sales?
log.mortgage_value_check = 0
log.shared_ownership_deposit_value_check = 0
log.value_value_check = 0
log.savings_value_check = 0
log.income1_value_check = 0
log.deposit_value_check = 0
log.wheel_value_check = 0
log.extrabor_value_check = 0
log.grant_value_check = 0
log.staircase_bought_value_check = 0
log.deposit_and_mortgage_value_check = 0
log.old_persons_shared_ownership_value_check = 0
log.income2_value_check = 0
log.monthly_charges_value_check = 0
log.student_not_child_value_check = 0
log.discounted_sale_value_check = 0
log.buyer_livein_value_check = 0
log.percentage_discount_value_check = 0
end
log.save! log.save!
end end
end end

2
app/models/form/lettings/pages/pscharge_value_check.rb

@ -2,7 +2,7 @@ class Form::Lettings::Pages::PschargeValueCheck < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "pscharge_value_check" @id = "pscharge_value_check"
@depends_on = [{ "pscharge_over_soft_max?" => true }] @depends_on = [{ "pscharge_in_soft_max_range?" => true }]
@title_text = { @title_text = {
"translation" => "soft_validations.pscharge.over_soft_max_title", "translation" => "soft_validations.pscharge.over_soft_max_title",
"arguments" => [{ "arguments" => [{

2
app/models/form/lettings/pages/scharge_value_check.rb

@ -2,7 +2,7 @@ class Form::Lettings::Pages::SchargeValueCheck < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "scharge_value_check" @id = "scharge_value_check"
@depends_on = [{ "scharge_over_soft_max?" => true }] @depends_on = [{ "scharge_in_soft_max_range?" => true }]
@title_text = { @title_text = {
"translation" => "soft_validations.scharge.over_soft_max_title", "translation" => "soft_validations.scharge.over_soft_max_title",
"arguments" => [{ "arguments" => [{

2
app/models/form/lettings/pages/supcharg_value_check.rb

@ -2,7 +2,7 @@ class Form::Lettings::Pages::SupchargValueCheck < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "supcharg_value_check" @id = "supcharg_value_check"
@depends_on = [{ "supcharg_over_soft_max?" => true }] @depends_on = [{ "supcharg_in_soft_max_range?" => true }]
@title_text = { @title_text = {
"translation" => "soft_validations.supcharg.over_soft_max_title", "translation" => "soft_validations.supcharg.over_soft_max_title",
"arguments" => [{ "arguments" => [{

2
app/models/form/lettings/questions/person_working_situation.rb

@ -12,8 +12,8 @@ class Form::Lettings::Questions::PersonWorkingSituation < ::Form::Question
end end
ANSWER_OPTIONS = { ANSWER_OPTIONS = {
"2" => { "value" => "Part-time – Less than 30 hours" },
"1" => { "value" => "Full-time – 30 hours or more" }, "1" => { "value" => "Full-time – 30 hours or more" },
"2" => { "value" => "Part-time – Less than 30 hours" },
"7" => { "value" => "Full-time student" }, "7" => { "value" => "Full-time student" },
"3" => { "value" => "In government training into work, such as New Deal" }, "3" => { "value" => "In government training into work, such as New Deal" },
"4" => { "value" => "Jobseeker" }, "4" => { "value" => "Jobseeker" },

2
app/models/form/sales/questions/age1.rb

@ -2,7 +2,7 @@ class Form::Sales::Questions::Age1 < ::Form::Question
def initialize(id, hsh, page) def initialize(id, hsh, page)
super super
@id = "age1" @id = "age1"
@check_answer_label = "Lead buyer’s age" @check_answer_label = "Buyer 1’s age"
@header = "Age" @header = "Age"
@type = "numeric" @type = "numeric"
@width = 2 @width = 2

2
app/models/form/sales/questions/buyer1_age_known.rb

@ -2,7 +2,7 @@ class Form::Sales::Questions::Buyer1AgeKnown < ::Form::Question
def initialize(id, hsh, page) def initialize(id, hsh, page)
super super
@id = "age1_known" @id = "age1_known"
@check_answer_label = "Lead buyer’s age" @check_answer_label = "Buyer 1’s age"
@header = "Do you know buyer 1’s age?" @header = "Do you know buyer 1’s age?"
@type = "radio" @type = "radio"
@answer_options = ANSWER_OPTIONS @answer_options = ANSWER_OPTIONS

2
app/models/form/sales/questions/buyer1_working_situation.rb

@ -18,8 +18,8 @@ class Form::Sales::Questions::Buyer1WorkingSituation < ::Form::Question
end end
ANSWER_OPTIONS = { ANSWER_OPTIONS = {
"2" => { "value" => "Part-time - Less than 30 hours" },
"1" => { "value" => "Full-time - 30 hours or more" }, "1" => { "value" => "Full-time - 30 hours or more" },
"2" => { "value" => "Part-time - Less than 30 hours" },
"3" => { "value" => "In government training into work, such as New Deal" }, "3" => { "value" => "In government training into work, such as New Deal" },
"4" => { "value" => "Jobseeker" }, "4" => { "value" => "Jobseeker" },
"6" => { "value" => "Not seeking work" }, "6" => { "value" => "Not seeking work" },

2
app/models/form/sales/questions/buyer2_working_situation.rb

@ -17,8 +17,8 @@ class Form::Sales::Questions::Buyer2WorkingSituation < ::Form::Question
end end
ANSWER_OPTIONS = { ANSWER_OPTIONS = {
"2" => { "value" => "Part-time - Less than 30 hours" },
"1" => { "value" => "Full-time - 30 hours or more" }, "1" => { "value" => "Full-time - 30 hours or more" },
"2" => { "value" => "Part-time - Less than 30 hours" },
"3" => { "value" => "In government training into work, such as New Deal" }, "3" => { "value" => "In government training into work, such as New Deal" },
"4" => { "value" => "Jobseeker" }, "4" => { "value" => "Jobseeker" },
"6" => { "value" => "Not seeking work" }, "6" => { "value" => "Not seeking work" },

9
app/models/form/sales/questions/number_joint_buyers.rb

@ -4,7 +4,6 @@ class Form::Sales::Questions::NumberJointBuyers < ::Form::Question
@id = "jointmore" @id = "jointmore"
@check_answer_label = "More than 2 joint buyers" @check_answer_label = "More than 2 joint buyers"
@header = "Are there more than 2 joint buyers of this property?" @header = "Are there more than 2 joint buyers of this property?"
@hint_text = "You should still try to answer all questions even if the buyer wasn't interviewed in person"
@type = "radio" @type = "radio"
@answer_options = ANSWER_OPTIONS @answer_options = ANSWER_OPTIONS
@question_number = 10 @question_number = 10
@ -15,4 +14,12 @@ class Form::Sales::Questions::NumberJointBuyers < ::Form::Question
"2" => { "value" => "No" }, "2" => { "value" => "No" },
"3" => { "value" => "Don’t know" }, "3" => { "value" => "Don’t know" },
}.freeze }.freeze
def hint_text
if form.start_year_after_2024?
nil
else
"You should still try to answer all questions even if the buyer wasn't interviewed in person"
end
end
end end

2
app/models/form/sales/questions/person_working_situation.rb

@ -16,8 +16,8 @@ class Form::Sales::Questions::PersonWorkingSituation < ::Form::Question
end end
ANSWER_OPTIONS = { ANSWER_OPTIONS = {
"2" => { "value" => "Part-time - Less than 30 hours" },
"1" => { "value" => "Full-time - 30 hours or more" }, "1" => { "value" => "Full-time - 30 hours or more" },
"2" => { "value" => "Part-time - Less than 30 hours" },
"3" => { "value" => "In government training into work, such as New Deal" }, "3" => { "value" => "In government training into work, such as New Deal" },
"4" => { "value" => "Jobseeker" }, "4" => { "value" => "Jobseeker" },
"6" => { "value" => "Not seeking work" }, "6" => { "value" => "Not seeking work" },

2
app/models/form/sales/questions/property_number_of_bedrooms.rb

@ -6,7 +6,7 @@ class Form::Sales::Questions::PropertyNumberOfBedrooms < ::Form::Question
@header = "How many bedrooms does the property have?" @header = "How many bedrooms does the property have?"
@hint_text = "A bedsit has 1 bedroom" @hint_text = "A bedsit has 1 bedroom"
@type = "numeric" @type = "numeric"
@width = 10 @width = 2
@min = 1 @min = 1
@max = 9 @max = 9
@step = 1 @step = 1

4
app/models/form/sales/questions/property_wheelchair_accessible.rb

@ -2,8 +2,8 @@ class Form::Sales::Questions::PropertyWheelchairAccessible < ::Form::Question
def initialize(id, hsh, page) def initialize(id, hsh, page)
super super
@id = "wchair" @id = "wchair"
@check_answer_label = "Property build or adapted to wheelchair-user standards" @check_answer_label = "Property built or adapted to wheelchair-user standards"
@header = "Is the property build or adapted to wheelchair-user standards?" @header = "Is the property built or adapted to wheelchair-user standards?"
@type = "radio" @type = "radio"
@answer_options = ANSWER_OPTIONS @answer_options = ANSWER_OPTIONS
@question_number = 17 @question_number = 17

1
app/models/log.rb

@ -179,6 +179,7 @@ class Log < ApplicationRecord
def blank_compound_invalid_non_setup_fields! def blank_compound_invalid_non_setup_fields!
self.ppcodenk = nil if errors.attribute_names.include? :ppostcode_full self.ppcodenk = nil if errors.attribute_names.include? :ppostcode_full
self.previous_la_known = nil if errors.attribute_names.include? :prevloc
if errors.of_kind?(:uprn, :uprn_error) if errors.of_kind?(:uprn, :uprn_error)
self.uprn_known = nil self.uprn_known = nil

38
app/models/validations/financial_validations.rb

@ -1,6 +1,7 @@
module Validations::FinancialValidations module Validations::FinancialValidations
include Validations::SharedValidations include Validations::SharedValidations
include MoneyFormattingHelper include MoneyFormattingHelper
include ChargesHelper
# Validations methods need to be called 'validate_<page_name>' to run on model save # Validations methods need to be called 'validate_<page_name>' to run on model save
# or 'validate_' to run on submit as well # or 'validate_' to run on submit as well
def validate_outstanding_rent_amount(record) def validate_outstanding_rent_amount(record)
@ -175,43 +176,6 @@ module Validations::FinancialValidations
private private
CHARGE_MAXIMA_PER_WEEK = {
scharge: {
private_registered_provider: {
general_needs: 800,
supported_housing: 800,
},
local_authority: {
general_needs: 500,
supported_housing: 500,
},
},
pscharge: {
private_registered_provider: {
general_needs: 700,
supported_housing: 700,
},
local_authority: {
general_needs: 200,
supported_housing: 200,
},
},
supcharg: {
private_registered_provider: {
general_needs: 800,
supported_housing: 800,
},
local_authority: {
general_needs: 200,
supported_housing: 200,
},
},
}.freeze
PROVIDER_TYPE = { 1 => :local_authority, 2 => :private_registered_provider }.freeze
NEEDSTYPE_VALUES = { 2 => :supported_housing, 1 => :general_needs }.freeze
CHARGE_NAMES = { scharge: "service charge", pscharge: "personal service charge", supcharg: "support charge" }.freeze
def validate_charges(record) def validate_charges(record)
return unless record.owning_organisation return unless record.owning_organisation

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

@ -89,9 +89,11 @@ module Validations::Sales::SoftValidations
return unless cashdis || !is_type_discount? return unless cashdis || !is_type_discount?
return unless deposit && value && equity return unless deposit && value && equity
cash_discount = cashdis || 0 !within_tolerance?(mortgage_deposit_and_discount_total, value * equity / 100, 1)
mortgage_value = mortgage || 0 end
mortgage_value + deposit + cash_discount != value * equity / 100
def within_tolerance?(expected, actual, tolerance)
(expected - actual).abs <= tolerance
end end
def mortgage_plus_deposit_less_than_discounted_value? def mortgage_plus_deposit_less_than_discounted_value?

65
app/models/validations/soft_validations.rb

@ -1,4 +1,6 @@
module Validations::SoftValidations module Validations::SoftValidations
include ChargesHelper
ALLOWED_INCOME_RANGES = { ALLOWED_INCOME_RANGES = {
1 => OpenStruct.new(soft_min: 143, soft_max: 730, hard_min: 90, hard_max: 1230), 1 => OpenStruct.new(soft_min: 143, soft_max: 730, hard_min: 90, hard_max: 1230),
2 => OpenStruct.new(soft_min: 67, soft_max: 620, hard_min: 50, hard_max: 950), 2 => OpenStruct.new(soft_min: 67, soft_max: 620, hard_min: 50, hard_max: 950),
@ -97,40 +99,55 @@ module Validations::SoftValidations
net_income_in_soft_max_range? ? "higher" : "lower" net_income_in_soft_max_range? ? "higher" : "lower"
end end
def scharge_over_soft_max? def scharge_in_soft_max_range?
return unless scharge && period && needstype return unless scharge && period && needstype && owning_organisation
return if weekly_value(scharge).blank? return if weekly_value(scharge).blank?
max = if needstype == 1 soft_max = if needstype == 1
owning_organisation.provider_type == "LA" ? 25 : 35 owning_organisation.provider_type == "LA" ? 25 : 35
else else
owning_organisation.provider_type == "LA" ? 100 : 200 owning_organisation.provider_type == "LA" ? 100 : 200
end end
weekly_value(scharge) > max
provider_type = owning_organisation.provider_type_before_type_cast
hard_max = CHARGE_MAXIMA_PER_WEEK.dig(:scharge, PROVIDER_TYPE[provider_type], NEEDSTYPE_VALUES[needstype])
weekly_scharge = weekly_value(scharge)
weekly_scharge > soft_max && weekly_scharge <= hard_max
end end
def pscharge_over_soft_max? def pscharge_in_soft_max_range?
return unless pscharge && period && needstype return unless pscharge && period && needstype && owning_organisation
return if weekly_value(pscharge).blank? return if weekly_value(pscharge).blank?
max = if needstype == 1 soft_max = if needstype == 1
owning_organisation.provider_type == "LA" ? 25 : 35 owning_organisation.provider_type == "LA" ? 25 : 35
else else
owning_organisation.provider_type == "LA" ? 75 : 100 owning_organisation.provider_type == "LA" ? 75 : 100
end end
weekly_value(pscharge) > max
provider_type = owning_organisation.provider_type_before_type_cast
hard_max = CHARGE_MAXIMA_PER_WEEK.dig(:pscharge, PROVIDER_TYPE[provider_type], NEEDSTYPE_VALUES[needstype])
weekly_pscharge = weekly_value(pscharge)
weekly_pscharge > soft_max && weekly_pscharge <= hard_max
end end
def supcharg_over_soft_max? def supcharg_in_soft_max_range?
return unless supcharg && period && needstype return unless supcharg && period && needstype && owning_organisation
return if weekly_value(supcharg).blank? return if weekly_value(supcharg).blank?
max = if needstype == 1 soft_max = if needstype == 1
owning_organisation.provider_type == "LA" ? 25 : 35 owning_organisation.provider_type == "LA" ? 25 : 35
else else
owning_organisation.provider_type == "LA" ? 75 : 85 owning_organisation.provider_type == "LA" ? 75 : 85
end end
weekly_value(supcharg) > max
provider_type = owning_organisation.provider_type_before_type_cast
hard_max = CHARGE_MAXIMA_PER_WEEK.dig(:supcharg, PROVIDER_TYPE[provider_type], NEEDSTYPE_VALUES[needstype])
weekly_supcharg = weekly_value(supcharg)
weekly_supcharg > soft_max && weekly_supcharg <= hard_max
end end
PHRASES_LIKELY_TO_INDICATE_EXISTING_REASON_CATEGORY = [ PHRASES_LIKELY_TO_INDICATE_EXISTING_REASON_CATEGORY = [

21
app/services/bulk_upload/lettings/year2023/row_parser.rb

@ -391,6 +391,7 @@ class BulkUpload::Lettings::Year2023::RowParser
validate :validate_correct_intermediate_rent_type, on: :after_log, if: proc { renttype == :intermediate } validate :validate_correct_intermediate_rent_type, on: :after_log, if: proc { renttype == :intermediate }
validate :validate_correct_affordable_rent_type, on: :after_log, if: proc { renttype == :affordable } validate :validate_correct_affordable_rent_type, on: :after_log, if: proc { renttype == :affordable }
validate :validate_all_charges_given, on: :after_log, if: proc { is_carehome.zero? }
def self.question_for_field(field) def self.question_for_field(field)
QUESTIONS[field] QUESTIONS[field]
@ -854,6 +855,20 @@ private
end end
end end
def validate_all_charges_given
return if supported_housing? && field_125 == 1
{ field_128: "basic rent",
field_129: "service charge",
field_130: "personal service charge",
field_131: "support charge",
field_132: "total charge" }.each do |field, charge|
if public_send(field.to_sym).blank?
errors.add(field, I18n.t("validations.financial.charges.missing_charges", question: charge))
end
end
end
def setup_question?(question) def setup_question?(question)
log.form.setup_sections[0].subsections[0].questions.include?(question) log.form.setup_sections[0].subsections[0].questions.include?(question)
end end
@ -1192,7 +1207,7 @@ private
attributes["supcharg"] = field_131 attributes["supcharg"] = field_131
attributes["tcharge"] = field_132 attributes["tcharge"] = field_132
attributes["chcharge"] = field_127 attributes["chcharge"] = field_127
attributes["is_carehome"] = field_127.present? ? 1 : 0 attributes["is_carehome"] = is_carehome
attributes["household_charge"] = supported_housing? ? field_125 : nil attributes["household_charge"] = supported_housing? ? field_125 : nil
attributes["hbrentshortfall"] = field_133 attributes["hbrentshortfall"] = field_133
attributes["tshortfall_known"] = tshortfall_known attributes["tshortfall_known"] = tshortfall_known
@ -1574,4 +1589,8 @@ private
0 0
end end
end end
def is_carehome
field_127.present? ? 1 : 0
end
end end

20
app/services/bulk_upload/lettings/year2024/row_parser.rb

@ -382,6 +382,7 @@ class BulkUpload::Lettings::Year2024::RowParser
validate :validate_uprn_exists_if_any_key_address_fields_are_blank, on: :after_log, unless: -> { supported_housing? } validate :validate_uprn_exists_if_any_key_address_fields_are_blank, on: :after_log, unless: -> { supported_housing? }
validate :validate_incomplete_soft_validations, on: :after_log validate :validate_incomplete_soft_validations, on: :after_log
validate :validate_all_charges_given, on: :after_log, if: proc { is_carehome.zero? }
def self.question_for_field(field) def self.question_for_field(field)
QUESTIONS[field] QUESTIONS[field]
@ -810,6 +811,19 @@ private
end end
end end
def validate_all_charges_given
return if supported_housing? && field_125 == 1
{ field_125: "basic rent",
field_126: "service charge",
field_127: "personal service charge",
field_128: "support charge" }.each do |field, charge|
if public_send(field.to_sym).blank?
errors.add(field, I18n.t("validations.financial.charges.missing_charges", question: charge))
end
end
end
def setup_question?(question) def setup_question?(question)
log.form.setup_sections[0].subsections[0].questions.include?(question) log.form.setup_sections[0].subsections[0].questions.include?(question)
end end
@ -1152,7 +1166,7 @@ private
attributes["pscharge"] = field_127 attributes["pscharge"] = field_127
attributes["supcharg"] = field_128 attributes["supcharg"] = field_128
attributes["chcharge"] = field_124 attributes["chcharge"] = field_124
attributes["is_carehome"] = field_124.present? ? 1 : 0 attributes["is_carehome"] = is_carehome
attributes["household_charge"] = supported_housing? ? field_122 : nil attributes["household_charge"] = supported_housing? ? field_122 : nil
attributes["hbrentshortfall"] = field_129 attributes["hbrentshortfall"] = field_129
attributes["tshortfall_known"] = tshortfall_known attributes["tshortfall_known"] = tshortfall_known
@ -1479,4 +1493,8 @@ private
12 12
end end
def is_carehome
field_124.present? ? 1 : 0
end
end end

6
config/forms/2022_2023.json

@ -8370,7 +8370,7 @@
"scharge_value_check": { "scharge_value_check": {
"depends_on": [ "depends_on": [
{ {
"scharge_over_soft_max?": true "scharge_in_soft_max_range?": true
} }
], ],
"title_text": { "title_text": {
@ -8415,7 +8415,7 @@
"pscharge_value_check": { "pscharge_value_check": {
"depends_on": [ "depends_on": [
{ {
"pscharge_over_soft_max?": true "pscharge_in_soft_max_range?": true
} }
], ],
"title_text": { "title_text": {
@ -8460,7 +8460,7 @@
"supcharg_value_check": { "supcharg_value_check": {
"depends_on": [ "depends_on": [
{ {
"supcharg_over_soft_max?": true "supcharg_in_soft_max_range?": true
} }
], ],
"title_text": { "title_text": {

1
config/locales/en.yml

@ -418,6 +418,7 @@ en:
above_hard_max: "Rent is higher than the absolute maximum expected for a property of this type based on this period" above_hard_max: "Rent is higher than the absolute maximum expected for a property of this type based on this period"
charges: charges:
complete_1_of_3: "Answer either the ‘household rent and charges’ question or ‘is this accommodation a care home‘, or select ‘no’ for ‘does the household pay rent or charges for the accommodation?’" complete_1_of_3: "Answer either the ‘household rent and charges’ question or ‘is this accommodation a care home‘, or select ‘no’ for ‘does the household pay rent or charges for the accommodation?’"
missing_charges: "Please enter the %{question}. If there is no %{question}, please enter '0'."
tcharge: tcharge:
under_10: "Enter a total charge that is at least £10.00 per week" under_10: "Enter a total charge that is at least £10.00 per week"
rent_period: rent_period:

7
spec/factories/lettings_log.rb

@ -24,13 +24,6 @@ FactoryBot.define do
rent_type { 1 } rent_type { 1 }
startdate { Time.zone.today } startdate { Time.zone.today }
end end
trait :soft_validations_triggered do
status { 1 }
hhmemb { 1 }
ecstat1 { 1 }
earnings { 750 }
incfreq { 1 }
end
trait :conditional_section_complete do trait :conditional_section_complete do
tenancycode { Faker::Name.initials(number: 10) } tenancycode { Faker::Name.initials(number: 10) }
age1 { 34 } age1 { 34 }

18
spec/models/bulk_upload_spec.rb

@ -18,4 +18,22 @@ RSpec.describe BulkUpload, type: :model do
end end
end end
end end
describe "value check clearing" do
context "with a lettings log bulk upload" do
let(:log) { create(:lettings_log, bulk_upload:) }
it "has the correct number of value checks to be set as confirmed" do
expect(bulk_upload.fields_to_confirm(log).sort).to eq(%w[rent_value_check void_date_value_check major_repairs_date_value_check pregnancy_value_check retirement_value_check referral_value_check net_income_value_check carehome_charges_value_check scharge_value_check pscharge_value_check supcharg_value_check].sort)
end
end
context "with a sales log bulk upload" do
let(:log) { create(:sales_log, bulk_upload:) }
it "has the correct number of value checks to be set as confirmed" do
expect(bulk_upload.fields_to_confirm(log).sort).to eq(%w[value_value_check monthly_charges_value_check percentage_discount_value_check income1_value_check income2_value_check combined_income_value_check retirement_value_check old_persons_shared_ownership_value_check buyer_livein_value_check student_not_child_value_check wheel_value_check mortgage_value_check savings_value_check deposit_value_check staircase_bought_value_check stairowned_value_check hodate_check shared_ownership_deposit_value_check extrabor_value_check grant_value_check discounted_sale_value_check deposit_and_mortgage_value_check].sort)
end
end
end
end end

2
spec/models/form/sales/questions/age1_spec.rb

@ -20,7 +20,7 @@ RSpec.describe Form::Sales::Questions::Age1, type: :model do
end end
it "has the correct check_answer_label" do it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Lead buyer’s age") expect(question.check_answer_label).to eq("Buyer 1’s age")
end end
it "has the correct type" do it "has the correct type" do

2
spec/models/form/sales/questions/buyer1_age_known_spec.rb

@ -20,7 +20,7 @@ RSpec.describe Form::Sales::Questions::Buyer1AgeKnown, type: :model do
end end
it "has the correct check_answer_label" do it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Lead buyer’s age") expect(question.check_answer_label).to eq("Buyer 1’s age")
end end
it "has the correct type" do it "has the correct type" do

2
spec/models/form/sales/questions/buyer1_working_situation_spec.rb

@ -33,8 +33,8 @@ RSpec.describe Form::Sales::Questions::Buyer1WorkingSituation, type: :model do
it "has the correct answer_options" do it "has the correct answer_options" do
expect(question.answer_options).to eq({ expect(question.answer_options).to eq({
"2" => { "value" => "Part-time - Less than 30 hours" },
"1" => { "value" => "Full-time - 30 hours or more" }, "1" => { "value" => "Full-time - 30 hours or more" },
"2" => { "value" => "Part-time - Less than 30 hours" },
"3" => { "value" => "In government training into work, such as New Deal" }, "3" => { "value" => "In government training into work, such as New Deal" },
"4" => { "value" => "Jobseeker" }, "4" => { "value" => "Jobseeker" },
"6" => { "value" => "Not seeking work" }, "6" => { "value" => "Not seeking work" },

2
spec/models/form/sales/questions/buyer2_working_situation_spec.rb

@ -37,8 +37,8 @@ RSpec.describe Form::Sales::Questions::Buyer2WorkingSituation, type: :model do
it "has the correct answer_options" do it "has the correct answer_options" do
expect(question.answer_options).to eq({ expect(question.answer_options).to eq({
"2" => { "value" => "Part-time - Less than 30 hours" },
"1" => { "value" => "Full-time - 30 hours or more" }, "1" => { "value" => "Full-time - 30 hours or more" },
"2" => { "value" => "Part-time - Less than 30 hours" },
"3" => { "value" => "In government training into work, such as New Deal" }, "3" => { "value" => "In government training into work, such as New Deal" },
"4" => { "value" => "Jobseeker" }, "4" => { "value" => "Jobseeker" },
"6" => { "value" => "Not seeking work" }, "6" => { "value" => "Not seeking work" },

16
spec/models/form/sales/questions/number_joint_buyers_spec.rb

@ -6,6 +6,12 @@ RSpec.describe Form::Sales::Questions::NumberJointBuyers, type: :model do
let(:question_id) { nil } let(:question_id) { nil }
let(:question_definition) { nil } let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) } let(:page) { instance_double(Form::Page) }
let(:subsection) { instance_double(Form::Subsection) }
before do
allow(page).to receive(:subsection).and_return(subsection)
allow(subsection).to receive(:form).and_return(instance_double(Form, start_year_after_2024?: false))
end
it "has correct page" do it "has correct page" do
expect(question.page).to eq(page) expect(question.page).to eq(page)
@ -42,4 +48,14 @@ RSpec.describe Form::Sales::Questions::NumberJointBuyers, type: :model do
"3" => { "value" => "Don’t know" }, "3" => { "value" => "Don’t know" },
}) })
end end
context "with 2024 form" do
before do
allow(subsection).to receive(:form).and_return(instance_double(Form, start_year_after_2024?: true))
end
it "has no hint_text" do
expect(question.hint_text).to be_nil
end
end
end end

2
spec/models/form/sales/questions/person_working_situation_spec.rb

@ -22,8 +22,8 @@ RSpec.describe Form::Sales::Questions::PersonWorkingSituation, type: :model do
it "has the correct answer_options" do it "has the correct answer_options" do
expect(question.answer_options).to eq({ expect(question.answer_options).to eq({
"2" => { "value" => "Part-time - Less than 30 hours" },
"1" => { "value" => "Full-time - 30 hours or more" }, "1" => { "value" => "Full-time - 30 hours or more" },
"2" => { "value" => "Part-time - Less than 30 hours" },
"3" => { "value" => "In government training into work, such as New Deal" }, "3" => { "value" => "In government training into work, such as New Deal" },
"4" => { "value" => "Jobseeker" }, "4" => { "value" => "Jobseeker" },
"6" => { "value" => "Not seeking work" }, "6" => { "value" => "Not seeking work" },

4
spec/models/form/sales/questions/property_wheelchair_accessible_spec.rb

@ -22,11 +22,11 @@ RSpec.describe Form::Sales::Questions::PropertyWheelchairAccessible, type: :mode
end end
it "has the correct header" do it "has the correct header" do
expect(question.header).to eq("Is the property build or adapted to wheelchair-user standards?") expect(question.header).to eq("Is the property built or adapted to wheelchair-user standards?")
end end
it "has the correct check_answer_label" do it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Property build or adapted to wheelchair-user standards") expect(question.check_answer_label).to eq("Property built or adapted to wheelchair-user standards")
end end
it "has the correct type" do it "has the correct type" do

20
spec/models/lettings_log_spec.rb

@ -3382,26 +3382,6 @@ RSpec.describe LettingsLog do
end end
end end
describe "#blank_invalid_non_setup_fields!" do
context "when a setup field is invalid" do
subject(:model) { described_class.new(needstype: 404) }
it "does not blank it" do
model.valid?
expect { model.blank_invalid_non_setup_fields! }.not_to change(model, :needstype)
end
end
context "when a non setup field is invalid" do
subject(:model) { build(:lettings_log, :completed, offered: 234) }
it "blanks it" do
model.valid?
expect { model.blank_invalid_non_setup_fields! }.to change(model, :offered)
end
end
end
describe "#beds_for_la_rent_range" do describe "#beds_for_la_rent_range" do
context "when beds nil" do context "when beds nil" do
let(:lettings_log) { build(:lettings_log, beds: nil) } let(:lettings_log) { build(:lettings_log, beds: nil) }

50
spec/models/log_spec.rb

@ -27,4 +27,54 @@ RSpec.describe Log, type: :model do
expect(in_progress_lettings_log.calculate_status).to eq "in_progress" expect(in_progress_lettings_log.calculate_status).to eq "in_progress"
end end
end end
describe "#blank_invalid_non_setup_fields!" do
context "when a setup field is invalid for a lettings log" do
subject(:model) { build(:lettings_log, needstype: 404) }
it "does not blank it" do
model.valid?
expect { model.blank_invalid_non_setup_fields! }.not_to change(model, :needstype)
end
end
context "when a setup field is invalid for a sales log" do
subject(:model) { build(:sales_log, companybuy: 404) }
it "does not blank it" do
model.valid?
expect { model.blank_invalid_non_setup_fields! }.not_to change(model, :companybuy)
end
end
context "when a non setup field is invalid for a lettings log" do
subject(:model) { build(:lettings_log, :completed, offered: 234) }
it "blanks it" do
model.valid?
model.blank_invalid_non_setup_fields!
expect(model.offered).to be_nil
end
end
context "when a non setup field is invalid for a sales log" do
subject(:model) { build(:sales_log, :completed, age1: 10) }
it "blanks it" do
model.valid?
model.blank_invalid_non_setup_fields!
expect(model.age1).to be_nil
end
end
context "when prevloc is invalid for a lettings log" do
subject(:model) { build(:lettings_log, :completed, previous_la_known: 1, prevloc: nil) }
it "blanks previous_la_known" do
model.valid?
model.blank_invalid_non_setup_fields!
expect(model.previous_la_known).to be_nil
end
end
end
end end

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

@ -415,6 +415,17 @@ RSpec.describe Validations::Sales::SoftValidations do
.not_to be_shared_ownership_deposit_invalid .not_to be_shared_ownership_deposit_invalid
end end
it "returns false if MORTGAGE + DEPOSIT + CASHDIS are within 1£ of VALUE * EQUITY/100" do
record.mortgage = 500
record.deposit = 500
record.cashdis = 500
record.value = 3001
record.equity = 50
expect(record)
.not_to be_shared_ownership_deposit_invalid
end
it "returns false if mortgage is used and no mortgage is given" do it "returns false if mortgage is used and no mortgage is given" do
record.mortgage = nil record.mortgage = nil
record.deposit = 1000 record.deposit = 1000
@ -473,6 +484,18 @@ RSpec.describe Validations::Sales::SoftValidations do
.to be_shared_ownership_deposit_invalid .to be_shared_ownership_deposit_invalid
end end
it "returns false if no cashdis not routed to and MORTGAGE + DEPOSIT are within 1£ of VALUE * EQUITY/100" do
record.mortgage = 500
record.deposit = 500
record.type = 2
record.cashdis = nil
record.value = 1999
record.equity = 50
expect(record)
.not_to be_shared_ownership_deposit_invalid
end
it "returns false if no value is given" do it "returns false if no value is given" do
record.mortgage = 1000 record.mortgage = 1000
record.deposit = 1000 record.deposit = 1000

318
spec/models/validations/soft_validations_spec.rb

@ -376,7 +376,7 @@ RSpec.describe Validations::SoftValidations do
end end
end end
describe "scharge_over_soft_max?" do describe "scharge_in_soft_max_range?" do
context "and organisation is PRP" do context "and organisation is PRP" do
before do before do
record.owning_organisation.update(provider_type: "PRP") record.owning_organisation.update(provider_type: "PRP")
@ -387,7 +387,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = 1 record.period = 1
expect(record).not_to be_scharge_over_soft_max expect(record).not_to be_scharge_in_soft_max_range
end end
it "returns false if period is not given" do it "returns false if period is not given" do
@ -395,48 +395,84 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = nil record.period = nil
expect(record).not_to be_scharge_over_soft_max expect(record).not_to be_scharge_in_soft_max_range
end end
[{ [{
period: { label: "weekly", value: 1 }, period: { label: "weekly", value: 1 },
scharge: 34, scharge: 34,
description: "under soft max (35)",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "monthly", value: 4 },
scharge: 100, scharge: 100,
description: "under soft max (35)",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
scharge: 69, scharge: 69,
description: "under soft max (35)",
},
{
period: { label: "weekly", value: 1 },
scharge: 801,
description: "over hard max (800)",
},
{
period: { label: "monthly", value: 4 },
scharge: 3471,
description: "over hard max (800)",
},
{
period: { label: "every 2 weeks", value: 2 },
scharge: 1601,
description: "over hard max (800)",
}].each do |test_case| }].each do |test_case|
it "returns false if scharge is under soft max for general needs #{test_case[:period][:label]}(35)" do it "returns false if scharge is #{test_case[:description]} for general needs #{test_case[:period][:label]}" do
record.scharge = test_case[:scharge] record.scharge = test_case[:scharge]
record.needstype = 1 record.needstype = 1
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
expect(record).not_to be_scharge_over_soft_max expect(record).not_to be_scharge_in_soft_max_range
end end
end end
[{ [{
period: { label: "weekly", value: 1 }, period: { label: "weekly", value: 1 },
scharge: 199, scharge: 199,
description: "under soft max (200)",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "monthly", value: 4 },
scharge: 400, scharge: 400,
description: "under soft max (200)",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
scharge: 399, scharge: 399,
description: "under soft max (200)",
},
{
period: { label: "weekly", value: 1 },
scharge: 801,
description: "over hard max (800)",
},
{
period: { label: "monthly", value: 4 },
scharge: 3471,
description: "over hard max (800)",
},
{
period: { label: "every 2 weeks", value: 2 },
scharge: 1601,
description: "over hard max (800)",
}].each do |test_case| }].each do |test_case|
it "returns false if scharge is under soft max for supported housing #{test_case[:period][:label]} (200)" do it "returns false if scharge is #{test_case[:description]} for supported housing #{test_case[:period][:label]}" do
record.scharge = test_case[:scharge] record.scharge = test_case[:scharge]
record.needstype = 2 record.needstype = 2
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
expect(record).not_to be_scharge_over_soft_max expect(record).not_to be_scharge_in_soft_max_range
end end
end end
@ -457,7 +493,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
expect(record).to be_scharge_over_soft_max expect(record).to be_scharge_in_soft_max_range
end end
end end
@ -478,7 +514,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 2 record.needstype = 2
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
expect(record).to be_scharge_over_soft_max expect(record).to be_scharge_in_soft_max_range
end end
end end
end end
@ -493,7 +529,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = 1 record.period = 1
expect(record).not_to be_scharge_over_soft_max expect(record).not_to be_scharge_in_soft_max_range
end end
it "returns false if period is not given" do it "returns false if period is not given" do
@ -501,48 +537,84 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = nil record.period = nil
expect(record).not_to be_scharge_over_soft_max expect(record).not_to be_scharge_in_soft_max_range
end end
[{ [{
period: { label: "weekly", value: 1 }, period: { label: "weekly", value: 1 },
scharge: 24, scharge: 24,
description: "under soft max (25)",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "monthly", value: 4 },
scharge: 88, scharge: 88,
description: "under soft max (25)",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
scharge: 49, scharge: 49,
description: "under soft max (25)",
},
{
period: { label: "weekly", value: 1 },
scharge: 501,
description: "over hard max (500)",
},
{
period: { label: "monthly", value: 4 },
scharge: 2167,
description: "over hard max (500)",
},
{
period: { label: "every 2 weeks", value: 2 },
scharge: 1001,
description: "over hard max (500)",
}].each do |test_case| }].each do |test_case|
it "returns false if scharge is under soft max for general needs #{test_case[:period][:label]}(25)" do it "returns false if scharge is #{test_case[:description]} for general needs #{test_case[:period][:label]}" do
record.scharge = test_case[:scharge] record.scharge = test_case[:scharge]
record.needstype = 1 record.needstype = 1
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
expect(record).not_to be_scharge_over_soft_max expect(record).not_to be_scharge_in_soft_max_range
end end
end end
[{ [{
period: { label: "weekly", value: 1 }, period: { label: "weekly", value: 1 },
scharge: 99, scharge: 99,
description: "under soft max (100)",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "monthly", value: 4 },
scharge: 400, scharge: 400,
description: "under soft max (100)",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
scharge: 199, scharge: 199,
description: "under soft max (100)",
},
{
period: { label: "weekly", value: 1 },
scharge: 501,
description: "over hard max (500)",
},
{
period: { label: "monthly", value: 4 },
scharge: 2167,
description: "over hard max (500)",
},
{
period: { label: "every 2 weeks", value: 2 },
scharge: 1001,
description: "over hard max (500)",
}].each do |test_case| }].each do |test_case|
it "returns false if scharge is under soft max for supported housing #{test_case[:period][:label]} (100)" do it "returns false if scharge is #{test_case[:description]} for supported housing #{test_case[:period][:label]}" do
record.scharge = test_case[:scharge] record.scharge = test_case[:scharge]
record.needstype = 2 record.needstype = 2
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
expect(record).not_to be_scharge_over_soft_max expect(record).not_to be_scharge_in_soft_max_range
end end
end end
@ -563,7 +635,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
expect(record).to be_scharge_over_soft_max expect(record).to be_scharge_in_soft_max_range
end end
end end
@ -584,13 +656,13 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 2 record.needstype = 2
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
expect(record).to be_scharge_over_soft_max expect(record).to be_scharge_in_soft_max_range
end end
end end
end end
end end
describe "pscharge_over_soft_max?" do describe "pscharge_in_soft_max_range?" do
context "and organisation is PRP" do context "and organisation is PRP" do
before do before do
record.owning_organisation.update(provider_type: "PRP") record.owning_organisation.update(provider_type: "PRP")
@ -601,7 +673,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = 1 record.period = 1
expect(record).not_to be_pscharge_over_soft_max expect(record).not_to be_pscharge_in_soft_max_range
end end
it "returns false if period is not given" do it "returns false if period is not given" do
@ -609,48 +681,84 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = nil record.period = nil
expect(record).not_to be_pscharge_over_soft_max expect(record).not_to be_pscharge_in_soft_max_range
end end
[{ [{
period: { label: "weekly", value: 1 }, period: { label: "weekly", value: 1 },
pscharge: 34, pscharge: 34,
description: "under soft max (35)",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "monthly", value: 4 },
pscharge: 100, pscharge: 100,
description: "under soft max (35)",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
pscharge: 69, pscharge: 69,
description: "under soft max (35)",
},
{
period: { label: "weekly", value: 1 },
pscharge: 701,
description: "over hard max (700)",
},
{
period: { label: "monthly", value: 4 },
pscharge: 3034,
description: "over hard max (700)",
},
{
period: { label: "every 2 weeks", value: 2 },
pscharge: 1401,
description: "over hard max (700)",
}].each do |test_case| }].each do |test_case|
it "returns false if pscharge is under soft max for general needs #{test_case[:period][:label]}(35)" do it "returns false if pscharge is #{test_case[:description]} for general needs #{test_case[:period][:label]}" do
record.pscharge = test_case[:pscharge] record.pscharge = test_case[:pscharge]
record.needstype = 1 record.needstype = 1
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
expect(record).not_to be_pscharge_over_soft_max expect(record).not_to be_pscharge_in_soft_max_range
end end
end end
[{ [{
period: { label: "weekly", value: 1 }, period: { label: "weekly", value: 1 },
pscharge: 99, pscharge: 99,
description: "under soft max (100)",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "monthly", value: 4 },
pscharge: 400, pscharge: 400,
description: "under soft max (100)",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
pscharge: 199, pscharge: 199,
description: "under soft max (100)",
},
{
period: { label: "weekly", value: 1 },
pscharge: 701,
description: "over hard max (700)",
},
{
period: { label: "monthly", value: 4 },
pscharge: 3034,
description: "over hard max (700)",
},
{
period: { label: "every 2 weeks", value: 2 },
pscharge: 1401,
description: "over hard max (700)",
}].each do |test_case| }].each do |test_case|
it "returns false if pscharge is under soft max for supported housing #{test_case[:period][:label]} (100)" do it "returns false if pscharge is #{test_case[:description]} for supported housing #{test_case[:period][:label]}" do
record.pscharge = test_case[:pscharge] record.pscharge = test_case[:pscharge]
record.needstype = 2 record.needstype = 2
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
expect(record).not_to be_pscharge_over_soft_max expect(record).not_to be_pscharge_in_soft_max_range
end end
end end
@ -671,7 +779,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
expect(record).to be_pscharge_over_soft_max expect(record).to be_pscharge_in_soft_max_range
end end
end end
@ -692,7 +800,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 2 record.needstype = 2
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
expect(record).to be_pscharge_over_soft_max expect(record).to be_pscharge_in_soft_max_range
end end
end end
end end
@ -707,7 +815,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = 1 record.period = 1
expect(record).not_to be_pscharge_over_soft_max expect(record).not_to be_pscharge_in_soft_max_range
end end
it "returns false if period is not given" do it "returns false if period is not given" do
@ -715,48 +823,84 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = nil record.period = nil
expect(record).not_to be_pscharge_over_soft_max expect(record).not_to be_pscharge_in_soft_max_range
end end
[{ [{
period: { label: "weekly", value: 1 }, period: { label: "weekly", value: 1 },
pscharge: 24, pscharge: 24,
description: "under soft max (25)",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "monthly", value: 4 },
pscharge: 88, pscharge: 88,
description: "under soft max (25)",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
pscharge: 49, pscharge: 49,
description: "under soft max (25)",
},
{
period: { label: "weekly", value: 1 },
pscharge: 201,
description: "over hard max (200)",
},
{
period: { label: "monthly", value: 4 },
pscharge: 867,
description: "over hard max (200)",
},
{
period: { label: "every 2 weeks", value: 2 },
pscharge: 401,
description: "over hard max (200)",
}].each do |test_case| }].each do |test_case|
it "returns false if pscharge is under soft max for general needs #{test_case[:period][:label]}(25)" do it "returns false if pscharge is #{test_case[:description]} for general needs #{test_case[:period][:label]}" do
record.pscharge = test_case[:pscharge] record.pscharge = test_case[:pscharge]
record.needstype = 1 record.needstype = 1
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
expect(record).not_to be_pscharge_over_soft_max expect(record).not_to be_pscharge_in_soft_max_range
end end
end end
[{ [{
period: { label: "weekly", value: 1 }, period: { label: "weekly", value: 1 },
pscharge: 74, pscharge: 74,
description: "under soft max (75)",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "monthly", value: 4 },
pscharge: 250, pscharge: 250,
description: "under soft max (75)",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
pscharge: 149, pscharge: 149,
description: "under soft max (75)",
},
{
period: { label: "weekly", value: 1 },
pscharge: 201,
description: "over hard max (200)",
},
{
period: { label: "monthly", value: 4 },
pscharge: 867,
description: "over hard max (200)",
},
{
period: { label: "every 2 weeks", value: 2 },
pscharge: 401,
description: "over hard max (200)",
}].each do |test_case| }].each do |test_case|
it "returns false if pscharge is under soft max for supported housing #{test_case[:period][:label]} (75)" do it "returns false if pscharge is #{test_case[:description]} for supported housing #{test_case[:period][:label]}" do
record.pscharge = test_case[:pscharge] record.pscharge = test_case[:pscharge]
record.needstype = 2 record.needstype = 2
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
expect(record).not_to be_pscharge_over_soft_max expect(record).not_to be_pscharge_in_soft_max_range
end end
end end
@ -777,7 +921,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
expect(record).to be_pscharge_over_soft_max expect(record).to be_pscharge_in_soft_max_range
end end
end end
@ -798,13 +942,13 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 2 record.needstype = 2
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
expect(record).to be_pscharge_over_soft_max expect(record).to be_pscharge_in_soft_max_range
end end
end end
end end
end end
describe "supcharg_over_soft_max?" do describe "supcharg_in_soft_max_range?" do
context "and organisation is PRP" do context "and organisation is PRP" do
before do before do
record.owning_organisation.update(provider_type: "PRP") record.owning_organisation.update(provider_type: "PRP")
@ -815,7 +959,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = 1 record.period = 1
expect(record).not_to be_supcharg_over_soft_max expect(record).not_to be_supcharg_in_soft_max_range
end end
it "returns false if period is not given" do it "returns false if period is not given" do
@ -823,48 +967,84 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = nil record.period = nil
expect(record).not_to be_supcharg_over_soft_max expect(record).not_to be_supcharg_in_soft_max_range
end end
[{ [{
period: { label: "weekly", value: 1 }, period: { label: "weekly", value: 1 },
supcharg: 34, supcharg: 34,
description: "under soft max (35)",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "monthly", value: 4 },
supcharg: 100, supcharg: 100,
description: "under soft max (35)",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
supcharg: 69, supcharg: 69,
description: "under soft max (35)",
},
{
period: { label: "weekly", value: 1 },
supcharg: 801,
description: "over hard max (800)",
},
{
period: { label: "monthly", value: 4 },
supcharg: 3467,
description: "over hard max (800)",
},
{
period: { label: "every 2 weeks", value: 2 },
supcharg: 1601,
description: "over hard max (800)",
}].each do |test_case| }].each do |test_case|
it "returns false if supcharg is under soft max for general needs #{test_case[:period][:label]}(35)" do it "returns false if supcharg is #{test_case[:description]} for general needs #{test_case[:period][:label]}" do
record.supcharg = test_case[:supcharg] record.supcharg = test_case[:supcharg]
record.needstype = 1 record.needstype = 1
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
expect(record).not_to be_supcharg_over_soft_max expect(record).not_to be_supcharg_in_soft_max_range
end end
end end
[{ [{
period: { label: "weekly", value: 1 }, period: { label: "weekly", value: 1 },
supcharg: 84, supcharg: 84,
description: "under soft max (85)",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "monthly", value: 4 },
supcharg: 320, supcharg: 320,
description: "under soft max (85)",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
supcharg: 169, supcharg: 169,
description: "under soft max (85)",
},
{
period: { label: "weekly", value: 1 },
supcharg: 801,
description: "over hard max (800)",
},
{
period: { label: "monthly", value: 4 },
supcharg: 3467,
description: "over hard max (800)",
},
{
period: { label: "every 2 weeks", value: 2 },
supcharg: 1601,
description: "over hard max (800)",
}].each do |test_case| }].each do |test_case|
it "returns false if supcharg is under soft max for supported housing #{test_case[:period][:label]} (85)" do it "returns false if supcharg is #{test_case[:description]} for supported housing #{test_case[:period][:label]}" do
record.supcharg = test_case[:supcharg] record.supcharg = test_case[:supcharg]
record.needstype = 2 record.needstype = 2
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
expect(record).not_to be_supcharg_over_soft_max expect(record).not_to be_supcharg_in_soft_max_range
end end
end end
@ -885,7 +1065,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
expect(record).to be_supcharg_over_soft_max expect(record).to be_supcharg_in_soft_max_range
end end
end end
@ -906,7 +1086,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 2 record.needstype = 2
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
expect(record).to be_supcharg_over_soft_max expect(record).to be_supcharg_in_soft_max_range
end end
end end
end end
@ -921,7 +1101,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = 1 record.period = 1
expect(record).not_to be_supcharg_over_soft_max expect(record).not_to be_supcharg_in_soft_max_range
end end
it "returns false if period is not given" do it "returns false if period is not given" do
@ -929,48 +1109,84 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = nil record.period = nil
expect(record).not_to be_supcharg_over_soft_max expect(record).not_to be_supcharg_in_soft_max_range
end end
[{ [{
period: { label: "weekly", value: 1 }, period: { label: "weekly", value: 1 },
supcharg: 24, supcharg: 24,
description: "under soft max (25)",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "monthly", value: 4 },
supcharg: 88, supcharg: 88,
description: "under soft max (25)",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
supcharg: 49, supcharg: 49,
description: "under soft max (25)",
},
{
period: { label: "weekly", value: 1 },
supcharg: 201,
description: "over hard max (200)",
},
{
period: { label: "monthly", value: 4 },
supcharg: 867,
description: "over hard max (200)",
},
{
period: { label: "every 2 weeks", value: 2 },
supcharg: 401,
description: "over hard max (200)",
}].each do |test_case| }].each do |test_case|
it "returns false if supcharg is under soft max for general needs #{test_case[:period][:label]}(25)" do it "returns false if supcharg is #{test_case[:description]} for general needs #{test_case[:period][:label]}" do
record.supcharg = test_case[:supcharg] record.supcharg = test_case[:supcharg]
record.needstype = 1 record.needstype = 1
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
expect(record).not_to be_supcharg_over_soft_max expect(record).not_to be_supcharg_in_soft_max_range
end end
end end
[{ [{
period: { label: "weekly", value: 1 }, period: { label: "weekly", value: 1 },
supcharg: 74, supcharg: 74,
description: "under soft max (75)",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "monthly", value: 4 },
supcharg: 250, supcharg: 250,
description: "under soft max (75)",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
supcharg: 149, supcharg: 149,
description: "under soft max (75)",
},
{
period: { label: "weekly", value: 1 },
supcharg: 201,
description: "over hard max (200)",
},
{
period: { label: "monthly", value: 4 },
supcharg: 867,
description: "over hard max (200)",
},
{
period: { label: "every 2 weeks", value: 2 },
supcharg: 401,
description: "over hard max (200)",
}].each do |test_case| }].each do |test_case|
it "returns false if supcharg is under soft max for supported housing #{test_case[:period][:label]} (75)" do it "returns false if supcharg is #{test_case[:description]} for supported housing #{test_case[:period][:label]}" do
record.supcharg = test_case[:supcharg] record.supcharg = test_case[:supcharg]
record.needstype = 2 record.needstype = 2
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
expect(record).not_to be_supcharg_over_soft_max expect(record).not_to be_supcharg_in_soft_max_range
end end
end end
@ -991,7 +1207,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
expect(record).to be_supcharg_over_soft_max expect(record).to be_supcharg_in_soft_max_range
end end
end end
@ -1012,7 +1228,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 2 record.needstype = 2
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
expect(record).to be_supcharg_over_soft_max expect(record).to be_supcharg_in_soft_max_range
end end
end end
end end

14
spec/requests/duplicate_logs_controller_spec.rb

@ -169,7 +169,7 @@ RSpec.describe DuplicateLogsController, type: :request do
it "displays check your answers for each log with correct questions" do it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q1 - Sale completion date", count: 3) expect(page).to have_content("Q1 - Sale completion date", count: 3)
expect(page).to have_content("Q2 - Purchaser code", count: 3) expect(page).to have_content("Q2 - Purchaser code", count: 3)
expect(page).to have_content("Q20 - Lead buyer’s age", count: 3) expect(page).to have_content("Q20 - Buyer 1’s age", count: 3)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 3) expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 3)
expect(page).to have_content("Q25 - Buyer 1's working situation", count: 3) expect(page).to have_content("Q25 - Buyer 1's working situation", count: 3)
expect(page).to have_content("Q15 - Postcode", count: 3) expect(page).to have_content("Q15 - Postcode", count: 3)
@ -187,7 +187,7 @@ RSpec.describe DuplicateLogsController, type: :request do
expect(page).to have_content("Q1 - Sale completion date", count: 3) expect(page).to have_content("Q1 - Sale completion date", count: 3)
expect(page).to have_content("Q2 - Purchaser code", count: 3) expect(page).to have_content("Q2 - Purchaser code", count: 3)
expect(page).to have_content("Q20 - Lead buyer’s age", count: 3) expect(page).to have_content("Q20 - Buyer 1’s age", count: 3)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 3) expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 3)
expect(page).to have_content("Q25 - Buyer 1's working situation", count: 3) expect(page).to have_content("Q25 - Buyer 1's working situation", count: 3)
expect(page).to have_content("Postcode (from UPRN)", count: 3) expect(page).to have_content("Postcode (from UPRN)", count: 3)
@ -215,7 +215,7 @@ RSpec.describe DuplicateLogsController, type: :request do
it "displays check your answers for each log with correct questions" do it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q1 - Sale completion date", count: 1) expect(page).to have_content("Q1 - Sale completion date", count: 1)
expect(page).to have_content("Q2 - Purchaser code", count: 1) expect(page).to have_content("Q2 - Purchaser code", count: 1)
expect(page).to have_content("Q20 - Lead buyer’s age", count: 1) expect(page).to have_content("Q20 - Buyer 1’s age", count: 1)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1) expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1)
expect(page).to have_content("Q25 - Buyer 1's working situation", count: 1) expect(page).to have_content("Q25 - Buyer 1's working situation", count: 1)
expect(page).to have_content("Q15 - Postcode", count: 1) expect(page).to have_content("Q15 - Postcode", count: 1)
@ -241,7 +241,7 @@ RSpec.describe DuplicateLogsController, type: :request do
it "displays check your answers for each log with correct questions" do it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q1 - Sale completion date", count: 1) expect(page).to have_content("Q1 - Sale completion date", count: 1)
expect(page).to have_content("Q2 - Purchaser code", count: 1) expect(page).to have_content("Q2 - Purchaser code", count: 1)
expect(page).to have_content("Q20 - Lead buyer’s age", count: 1) expect(page).to have_content("Q20 - Buyer 1’s age", count: 1)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1) expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1)
expect(page).to have_content("Q25 - Buyer 1's working situation", count: 1) expect(page).to have_content("Q25 - Buyer 1's working situation", count: 1)
expect(page).to have_content("Q15 - Postcode", count: 1) expect(page).to have_content("Q15 - Postcode", count: 1)
@ -379,7 +379,7 @@ RSpec.describe DuplicateLogsController, type: :request do
it "displays check your answers for each log with correct questions" do it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q1 - Sale completion date", count: 3) expect(page).to have_content("Q1 - Sale completion date", count: 3)
expect(page).to have_content("Q2 - Purchaser code", count: 3) expect(page).to have_content("Q2 - Purchaser code", count: 3)
expect(page).to have_content("Q20 - Lead buyer’s age", count: 3) expect(page).to have_content("Q20 - Buyer 1’s age", count: 3)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 3) expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 3)
expect(page).to have_content("Q25 - Buyer 1's working situation", count: 3) expect(page).to have_content("Q25 - Buyer 1's working situation", count: 3)
expect(page).to have_content("Q15 - Postcode", count: 3) expect(page).to have_content("Q15 - Postcode", count: 3)
@ -407,7 +407,7 @@ RSpec.describe DuplicateLogsController, type: :request do
it "displays check your answers for each log with correct questions" do it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q1 - Sale completion date", count: 1) expect(page).to have_content("Q1 - Sale completion date", count: 1)
expect(page).to have_content("Q2 - Purchaser code", count: 1) expect(page).to have_content("Q2 - Purchaser code", count: 1)
expect(page).to have_content("Q20 - Lead buyer’s age", count: 1) expect(page).to have_content("Q20 - Buyer 1’s age", count: 1)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1) expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1)
expect(page).to have_content("Q25 - Buyer 1's working situation", count: 1) expect(page).to have_content("Q25 - Buyer 1's working situation", count: 1)
expect(page).to have_content("Q15 - Postcode", count: 1) expect(page).to have_content("Q15 - Postcode", count: 1)
@ -433,7 +433,7 @@ RSpec.describe DuplicateLogsController, type: :request do
it "displays check your answers for each log with correct questions" do it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q1 - Sale completion date", count: 1) expect(page).to have_content("Q1 - Sale completion date", count: 1)
expect(page).to have_content("Q2 - Purchaser code", count: 1) expect(page).to have_content("Q2 - Purchaser code", count: 1)
expect(page).to have_content("Q20 - Lead buyer’s age", count: 1) expect(page).to have_content("Q20 - Buyer 1’s age", count: 1)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1) expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1)
expect(page).to have_content("Q25 - Buyer 1's working situation", count: 1) expect(page).to have_content("Q25 - Buyer 1's working situation", count: 1)
expect(page).to have_content("Q15 - Postcode", count: 1) expect(page).to have_content("Q15 - Postcode", count: 1)

105
spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb

@ -2294,19 +2294,76 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
end end
describe "#chcharge" do describe "#chcharge" do
let(:attributes) { { bulk_upload:, field_127: "123.45" } } let(:attributes) { { bulk_upload:, field_127: "123.45", field_131: "123.45", field_130: "123.45", field_129: "123.45", field_128: "123.45" } }
it "sets value given" do it "sets value given" do
expect(parser.log.chcharge).to eq(123.45) expect(parser.log.chcharge).to eq(123.45)
end end
it "sets is care home to yes" do
expect(parser.log.is_carehome).to eq(1)
end
it "clears any other given charges" do
parser.log.save!
expect(parser.log.tcharge).to be_nil
expect(parser.log.brent).to be_nil
expect(parser.log.supcharg).to be_nil
expect(parser.log.pscharge).to be_nil
expect(parser.log.scharge).to be_nil
end
end end
describe "#tcharge" do describe "#tcharge" do
let(:attributes) { { bulk_upload:, field_132: "123.45" } } let(:attributes) { { bulk_upload:, field_132: "123.45", field_127: "123.45", field_128: "123.45", field_129: "123.45", field_130: "123.45", field_131: "123.45" } }
it "sets value given" do it "sets value given" do
expect(parser.log.tcharge).to eq(123.45) expect(parser.log.tcharge).to eq(123.45)
end end
context "when other charges are not given" do
context "and it is carehome" do
let(:attributes) { { bulk_upload:, field_132: "123.45", field_127: "123.45", field_128: nil, field_129: nil, field_130: nil, field_131: nil } }
it "does not set charges values" do
parser.log.save!
expect(parser.log.tcharge).to be_nil
expect(parser.log.brent).to be_nil
expect(parser.log.supcharg).to be_nil
expect(parser.log.pscharge).to be_nil
expect(parser.log.scharge).to be_nil
end
it "does not add errors to missing charges" do
parser.valid?
expect(parser.errors[:field_128]).to be_empty
expect(parser.errors[:field_129]).to be_empty
expect(parser.errors[:field_130]).to be_empty
expect(parser.errors[:field_131]).to be_empty
end
end
context "and it is not carehome" do
let(:attributes) { { bulk_upload:, field_132: "123.45", field_127: nil, field_128: nil, field_129: nil, field_130: nil, field_131: nil } }
it "does not set charges values" do
parser.log.save!
expect(parser.log.tcharge).to be_nil
expect(parser.log.brent).to be_nil
expect(parser.log.supcharg).to be_nil
expect(parser.log.pscharge).to be_nil
expect(parser.log.scharge).to be_nil
end
it "adds an error to all missing charges" do
parser.valid?
expect(parser.errors[:field_128]).to eql(["Please enter the basic rent. If there is no basic rent, please enter '0'."])
expect(parser.errors[:field_129]).to eql(["Please enter the service charge. If there is no service charge, please enter '0'."])
expect(parser.errors[:field_130]).to eql(["Please enter the personal service charge. If there is no personal service charge, please enter '0'."])
expect(parser.errors[:field_131]).to eql(["Please enter the support charge. If there is no support charge, please enter '0'."])
end
end
end
end end
describe "#supcharg" do describe "#supcharg" do
@ -2315,6 +2372,50 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
it "sets value given" do it "sets value given" do
expect(parser.log.supcharg).to eq(123.45) expect(parser.log.supcharg).to eq(123.45)
end end
context "when other charges are not given" do
context "and it is carehome" do
let(:attributes) { { bulk_upload:, field_132: nil, field_127: "123.45", field_128: nil, field_129: nil, field_130: nil, field_131: "123.45" } }
it "does not set charges values" do
parser.log.save!
expect(parser.log.tcharge).to be_nil
expect(parser.log.brent).to be_nil
expect(parser.log.supcharg).to be_nil
expect(parser.log.pscharge).to be_nil
expect(parser.log.scharge).to be_nil
end
it "does not add errors to missing charges" do
parser.valid?
expect(parser.errors[:field_128]).to be_empty
expect(parser.errors[:field_129]).to be_empty
expect(parser.errors[:field_130]).to be_empty
expect(parser.errors[:field_131]).to be_empty
end
end
context "and it is not carehome" do
let(:attributes) { { bulk_upload:, field_132: "123.45", field_127: nil, field_128: nil, field_129: nil, field_130: nil, field_131: nil } }
it "does not set charges values" do
parser.log.save!
expect(parser.log.tcharge).to be_nil
expect(parser.log.brent).to be_nil
expect(parser.log.supcharg).to be_nil
expect(parser.log.pscharge).to be_nil
expect(parser.log.scharge).to be_nil
end
it "adds an error to all missing charges" do
parser.valid?
expect(parser.errors[:field_128]).to eql(["Please enter the basic rent. If there is no basic rent, please enter '0'."])
expect(parser.errors[:field_129]).to eql(["Please enter the service charge. If there is no service charge, please enter '0'."])
expect(parser.errors[:field_130]).to eql(["Please enter the personal service charge. If there is no personal service charge, please enter '0'."])
expect(parser.errors[:field_131]).to eql(["Please enter the support charge. If there is no support charge, please enter '0'."])
end
end
end
end end
describe "#pscharge" do describe "#pscharge" do

59
spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb

@ -2159,11 +2159,24 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
end end
describe "#chcharge" do describe "#chcharge" do
let(:attributes) { { bulk_upload:, field_124: "123.45" } } let(:attributes) { { bulk_upload:, field_124: "123.45", field_125: "123.45", field_126: "123.45", field_127: "123.45", field_128: "123.45" } }
it "sets value given" do it "sets value given" do
expect(parser.log.chcharge).to eq(123.45) expect(parser.log.chcharge).to eq(123.45)
end end
it "sets is care home to yes" do
expect(parser.log.is_carehome).to eq(1)
end
it "clears any other given charges" do
parser.log.save!
expect(parser.log.tcharge).to be_nil
expect(parser.log.brent).to be_nil
expect(parser.log.supcharg).to be_nil
expect(parser.log.pscharge).to be_nil
expect(parser.log.scharge).to be_nil
end
end end
describe "#supcharg" do describe "#supcharg" do
@ -2172,6 +2185,50 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
it "sets value given" do it "sets value given" do
expect(parser.log.supcharg).to eq(123.45) expect(parser.log.supcharg).to eq(123.45)
end end
context "when other charges are not given" do
context "and it is carehome" do
let(:attributes) { { bulk_upload:, field_128: "123.45", field_124: "123.45", field_125: nil, field_126: nil, field_127: nil } }
it "does not set charges values" do
parser.log.save!
expect(parser.log.tcharge).to be_nil
expect(parser.log.brent).to be_nil
expect(parser.log.supcharg).to be_nil
expect(parser.log.pscharge).to be_nil
expect(parser.log.scharge).to be_nil
end
it "does not add errors to missing charges" do
parser.valid?
expect(parser.errors[:field_125]).to be_empty
expect(parser.errors[:field_126]).to be_empty
expect(parser.errors[:field_127]).to be_empty
expect(parser.errors[:field_128]).to be_empty
end
end
context "and it is not carehome" do
let(:attributes) { { bulk_upload:, field_128: "123.45", field_124: nil, field_125: nil, field_126: nil, field_127: nil } }
it "does not set charges values" do
parser.log.save!
expect(parser.log.tcharge).to be_nil
expect(parser.log.brent).to be_nil
expect(parser.log.supcharg).to be_nil
expect(parser.log.pscharge).to be_nil
expect(parser.log.scharge).to be_nil
end
it "adds an error to all missing charges" do
parser.valid?
expect(parser.errors[:field_125]).to eql(["Please enter the basic rent. If there is no basic rent, please enter '0'."])
expect(parser.errors[:field_126]).to eql(["Please enter the service charge. If there is no service charge, please enter '0'."])
expect(parser.errors[:field_127]).to eql(["Please enter the personal service charge. If there is no personal service charge, please enter '0'."])
expect(parser.errors[:field_128]).to be_empty
end
end
end
end end
describe "#pscharge" do describe "#pscharge" do

Loading…
Cancel
Save