Browse Source

Merge branch 'main' into dependabot/npm_and_yarn/express-4.21.0

pull/2647/head
Rachael Booth 2 years ago committed by GitHub
parent
commit
e62a1b7958
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      Gemfile
  2. 6
      Gemfile.lock
  3. 4
      app/models/form/lettings/pages/no_females_pregnant_household_lead_age_value_check.rb
  4. 4
      app/models/form/lettings/pages/no_females_pregnant_household_lead_hhmemb_value_check.rb
  5. 4
      app/models/form/lettings/pages/no_females_pregnant_household_lead_value_check.rb
  6. 4
      app/models/form/lettings/pages/no_females_pregnant_household_person_age_value_check.rb
  7. 4
      app/models/form/lettings/pages/no_females_pregnant_household_person_value_check.rb
  8. 4
      app/models/form/lettings/pages/no_females_pregnant_household_value_check.rb
  9. 12
      app/models/validations/soft_validations.rb
  10. 24
      app/services/postcode_service.rb
  11. 36
      config/forms/2021_2022.json
  12. 36
      config/forms/2022_2023.json
  13. 2
      config/locales/en.yml
  14. 2
      spec/lib/tasks/update_schemes_and_locations_from_csv_spec.rb
  15. 8
      spec/models/form/lettings/pages/no_females_pregnant_household_person_age_value_check_spec.rb
  16. 8
      spec/models/form/lettings/pages/no_females_pregnant_household_person_value_check_spec.rb
  17. 11
      spec/models/lettings_log_spec.rb
  18. 11
      spec/models/sales_log_spec.rb
  19. 12
      spec/models/validations/soft_validations_spec.rb
  20. 2
      spec/request_helper.rb
  21. 77
      spec/services/postcode_service_spec.rb

3
Gemfile

@ -39,7 +39,6 @@ gem "devise_two_factor_authentication"
# UK postcode parsing and validation # UK postcode parsing and validation
gem "uk_postcode" gem "uk_postcode"
# Get rich data from postcode lookups. Wraps postcodes.io # Get rich data from postcode lookups. Wraps postcodes.io
gem "postcodes_io"
# Use Ruby objects to build reusable markup. A React inspired evolution of the presenter pattern # Use Ruby objects to build reusable markup. A React inspired evolution of the presenter pattern
gem "view_component", "~> 3.9" gem "view_component", "~> 3.9"
# Use the AWS S3 SDK as storage mechanism # Use the AWS S3 SDK as storage mechanism
@ -112,3 +111,5 @@ end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "cssbundling-rails" gem "cssbundling-rails"
gem "tzinfo-data", platforms: %i[mingw mswin x64_mingw jruby] gem "tzinfo-data", platforms: %i[mingw mswin x64_mingw jruby]
gem "excon", "~> 0.111.0"

6
Gemfile.lock

@ -183,7 +183,7 @@ GEM
et-orbi (1.2.11) et-orbi (1.2.11)
tzinfo tzinfo
event_stream_parser (1.0.0) event_stream_parser (1.0.0)
excon (0.109.0) excon (0.111.0)
factory_bot (6.4.6) factory_bot (6.4.6)
activesupport (>= 5.0.0) activesupport (>= 5.0.0)
factory_bot_rails (6.4.3) factory_bot_rails (6.4.3)
@ -302,8 +302,6 @@ GEM
racc racc
pg (1.5.5) pg (1.5.5)
possessive (1.0.1) possessive (1.0.1)
postcodes_io (0.4.0)
excon (~> 0.39)
propshaft (0.8.0) propshaft (0.8.0)
actionpack (>= 7.0.0) actionpack (>= 7.0.0)
activesupport (>= 7.0.0) activesupport (>= 7.0.0)
@ -533,6 +531,7 @@ DEPENDENCIES
devise_two_factor_authentication devise_two_factor_authentication
dotenv-rails dotenv-rails
erb_lint erb_lint
excon (~> 0.111.0)
factory_bot_rails factory_bot_rails
faker faker
govuk-components (~> 5.1) govuk-components (~> 5.1)
@ -549,7 +548,6 @@ DEPENDENCIES
parallel_tests parallel_tests
pg (~> 1.1) pg (~> 1.1)
possessive possessive
postcodes_io
propshaft propshaft
pry-byebug pry-byebug
puma (~> 5.6) puma (~> 5.6)

4
app/models/form/lettings/pages/no_females_pregnant_household_lead_age_value_check.rb

@ -2,13 +2,13 @@ class Form::Lettings::Pages::NoFemalesPregnantHouseholdLeadAgeValueCheck < ::For
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super(id, hsh, subsection) super(id, hsh, subsection)
@id = "no_females_pregnant_household_lead_age_value_check" @id = "no_females_pregnant_household_lead_age_value_check"
@depends_on = [{ "no_females_in_a_pregnant_household?" => true }] @depends_on = [{ "all_male_tenants_in_a_pregnant_household?" => true }]
@title_text = { @title_text = {
"translation" => "soft_validations.pregnancy.title", "translation" => "soft_validations.pregnancy.title",
"arguments" => [{ "key" => "sex1", "label" => true, "i18n_template" => "sex1" }], "arguments" => [{ "key" => "sex1", "label" => true, "i18n_template" => "sex1" }],
} }
@informative_text = { @informative_text = {
"translation" => "soft_validations.pregnancy.no_females", "translation" => "soft_validations.pregnancy.all_male_tenants",
"arguments" => [{ "key" => "sex1", "label" => true, "i18n_template" => "sex1" }], "arguments" => [{ "key" => "sex1", "label" => true, "i18n_template" => "sex1" }],
} }
end end

4
app/models/form/lettings/pages/no_females_pregnant_household_lead_hhmemb_value_check.rb

@ -2,13 +2,13 @@ class Form::Lettings::Pages::NoFemalesPregnantHouseholdLeadHhmembValueCheck < ::
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "no_females_pregnant_household_lead_hhmemb_value_check" @id = "no_females_pregnant_household_lead_hhmemb_value_check"
@depends_on = [{ "no_females_in_a_pregnant_household?" => true }] @depends_on = [{ "all_male_tenants_in_a_pregnant_household?" => true }]
@title_text = { @title_text = {
"translation" => "soft_validations.pregnancy.title", "translation" => "soft_validations.pregnancy.title",
"arguments" => [{ "key" => "sex1", "label" => true, "i18n_template" => "sex1" }], "arguments" => [{ "key" => "sex1", "label" => true, "i18n_template" => "sex1" }],
} }
@informative_text = { @informative_text = {
"translation" => "soft_validations.pregnancy.no_females", "translation" => "soft_validations.pregnancy.all_male_tenants",
"arguments" => [{ "key" => "sex1", "label" => true, "i18n_template" => "sex1" }], "arguments" => [{ "key" => "sex1", "label" => true, "i18n_template" => "sex1" }],
} }
end end

4
app/models/form/lettings/pages/no_females_pregnant_household_lead_value_check.rb

@ -2,13 +2,13 @@ class Form::Lettings::Pages::NoFemalesPregnantHouseholdLeadValueCheck < ::Form::
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "no_females_pregnant_household_lead_value_check" @id = "no_females_pregnant_household_lead_value_check"
@depends_on = [{ "no_females_in_a_pregnant_household?" => true }] @depends_on = [{ "all_male_tenants_in_a_pregnant_household?" => true }]
@title_text = { @title_text = {
"translation" => "soft_validations.pregnancy.title", "translation" => "soft_validations.pregnancy.title",
"arguments" => [{ "key" => "sex1", "label" => true, "i18n_template" => "sex1" }], "arguments" => [{ "key" => "sex1", "label" => true, "i18n_template" => "sex1" }],
} }
@informative_text = { @informative_text = {
"translation" => "soft_validations.pregnancy.no_females", "translation" => "soft_validations.pregnancy.all_male_tenants",
"arguments" => [{ "key" => "sex1", "label" => true, "i18n_template" => "sex1" }], "arguments" => [{ "key" => "sex1", "label" => true, "i18n_template" => "sex1" }],
} }
end end

4
app/models/form/lettings/pages/no_females_pregnant_household_person_age_value_check.rb

@ -2,13 +2,13 @@ class Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonAgeValueCheck < ::F
def initialize(id, hsh, subsection, person_index:) def initialize(id, hsh, subsection, person_index:)
super(id, hsh, subsection) super(id, hsh, subsection)
@id = "no_females_pregnant_household_person_#{person_index}_age_value_check" @id = "no_females_pregnant_household_person_#{person_index}_age_value_check"
@depends_on = [{ "no_females_in_a_pregnant_household?" => true, "age#{person_index}_known" => 0 }] @depends_on = [{ "all_male_tenants_in_a_pregnant_household?" => true, "age#{person_index}_known" => 0 }]
@title_text = { @title_text = {
"translation" => "soft_validations.pregnancy.title", "translation" => "soft_validations.pregnancy.title",
"arguments" => [{ "key" => "sex1", "label" => true, "i18n_template" => "sex1" }], "arguments" => [{ "key" => "sex1", "label" => true, "i18n_template" => "sex1" }],
} }
@informative_text = { @informative_text = {
"translation" => "soft_validations.pregnancy.no_females", "translation" => "soft_validations.pregnancy.all_male_tenants",
"arguments" => [{ "key" => "sex1", "label" => true, "i18n_template" => "sex1" }], "arguments" => [{ "key" => "sex1", "label" => true, "i18n_template" => "sex1" }],
} }
@person_index = person_index @person_index = person_index

4
app/models/form/lettings/pages/no_females_pregnant_household_person_value_check.rb

@ -2,13 +2,13 @@ class Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonValueCheck < ::Form
def initialize(id, hsh, subsection, person_index:) def initialize(id, hsh, subsection, person_index:)
super(id, hsh, subsection) super(id, hsh, subsection)
@id = "no_females_pregnant_household_person_#{person_index}_value_check" @id = "no_females_pregnant_household_person_#{person_index}_value_check"
@depends_on = [{ "no_females_in_a_pregnant_household?" => true, "details_known_#{person_index}" => 0 }] @depends_on = [{ "all_male_tenants_in_a_pregnant_household?" => true, "details_known_#{person_index}" => 0 }]
@title_text = { @title_text = {
"translation" => "soft_validations.pregnancy.title", "translation" => "soft_validations.pregnancy.title",
"arguments" => [{ "key" => "sex1", "label" => true, "i18n_template" => "sex1" }], "arguments" => [{ "key" => "sex1", "label" => true, "i18n_template" => "sex1" }],
} }
@informative_text = { @informative_text = {
"translation" => "soft_validations.pregnancy.no_females", "translation" => "soft_validations.pregnancy.all_male_tenants",
"arguments" => [{ "key" => "sex1", "label" => true, "i18n_template" => "sex1" }], "arguments" => [{ "key" => "sex1", "label" => true, "i18n_template" => "sex1" }],
} }
@person_index = person_index @person_index = person_index

4
app/models/form/lettings/pages/no_females_pregnant_household_value_check.rb

@ -2,13 +2,13 @@ class Form::Lettings::Pages::NoFemalesPregnantHouseholdValueCheck < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "no_females_pregnant_household_value_check" @id = "no_females_pregnant_household_value_check"
@depends_on = [{ "no_females_in_a_pregnant_household?" => true }] @depends_on = [{ "all_male_tenants_in_a_pregnant_household?" => true }]
@title_text = { @title_text = {
"translation" => "soft_validations.pregnancy.title", "translation" => "soft_validations.pregnancy.title",
"arguments" => [{ "key" => "sex1", "label" => true, "i18n_template" => "sex1" }], "arguments" => [{ "key" => "sex1", "label" => true, "i18n_template" => "sex1" }],
} }
@informative_text = { @informative_text = {
"translation" => "soft_validations.pregnancy.no_females", "translation" => "soft_validations.pregnancy.all_male_tenants",
"arguments" => [{ "key" => "sex1", "label" => true, "i18n_template" => "sex1" }], "arguments" => [{ "key" => "sex1", "label" => true, "i18n_template" => "sex1" }],
} }
end end

12
app/models/validations/soft_validations.rb

@ -67,8 +67,8 @@ module Validations::SoftValidations
end end
end end
def no_females_in_a_pregnant_household? def all_male_tenants_in_a_pregnant_household?
!females_in_the_household? && all_tenants_gender_information_completed? && preg_occ == 1 all_male_tenants_in_the_household? && all_tenants_gender_information_completed? && preg_occ == 1
end end
def female_in_pregnant_household_in_soft_validation_range? def female_in_pregnant_household_in_soft_validation_range?
@ -226,6 +226,14 @@ private
end end
end end
def all_male_tenants_in_the_household?
person_count = hhmemb || 8
(1..person_count).all? do |n|
public_send("sex#{n}") == "M"
end
end
def tenant_is_retired?(economic_status) def tenant_is_retired?(economic_status)
economic_status == 5 economic_status == 5
end end

24
app/services/postcode_service.rb

@ -1,26 +1,24 @@
class PostcodeService class PostcodeService
def initialize
@pio = Postcodes::IO.new
end
def lookup(postcode) def lookup(postcode)
# Avoid network calls when postcode is invalid # Avoid network calls when postcode is invalid
return unless postcode.match(POSTCODE_REGEXP) return unless postcode.match(POSTCODE_REGEXP)
postcode_lookup = nil result = nil
begin begin
# URI encoding only supports ASCII characters # URI encoding only supports ASCII characters
ascii_postcode = self.class.clean(postcode) ascii_postcode = self.class.clean(postcode)
Timeout.timeout(30) { postcode_lookup = @pio.lookup(ascii_postcode) } response = Excon.get("https://api.postcodes.io/postcodes/#{ascii_postcode}", idempotent: true, timeout: 30, expects: [200])
rescue Timeout::Error parsed_response = JSON.parse(response.body)
Rails.logger.warn("Postcodes.io lookup timed out") result = {
end location_code: parsed_response["result"]["codes"]["admin_district"],
if postcode_lookup && postcode_lookup.info.present? location_admin_district: parsed_response["result"]["admin_district"],
{
location_code: postcode_lookup.codes["admin_district"],
location_admin_district: postcode_lookup&.admin_district,
} }
rescue Excon::Error => e
Rails.logger.warn("Postcode lookup request was not successful: #{e} #{e.response.body}")
rescue StandardError => e
Rails.logger.error("Unexpected error with postcode lookup request: #{e}")
end end
result
end end
def self.clean(postcode) def self.clean(postcode)

36
config/forms/2021_2022.json

@ -1170,7 +1170,7 @@
"no_females_pregnant_household_lead_hhmemb_value_check": { "no_females_pregnant_household_lead_hhmemb_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true "all_male_tenants_in_a_pregnant_household?": true
} }
], ],
"title_text": { "title_text": {
@ -1312,7 +1312,7 @@
"no_females_pregnant_household_lead_age_value_check": { "no_females_pregnant_household_lead_age_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true "all_male_tenants_in_a_pregnant_household?": true
} }
], ],
"title_text": { "title_text": {
@ -1433,7 +1433,7 @@
"no_females_pregnant_household_lead_value_check": { "no_females_pregnant_household_lead_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true "all_male_tenants_in_a_pregnant_household?": true
} }
], ],
"title_text": { "title_text": {
@ -2091,7 +2091,7 @@
"no_females_pregnant_household_person_2_age_value_check": { "no_females_pregnant_household_person_2_age_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"age2_known": 0 "age2_known": 0
} }
], ],
@ -2214,7 +2214,7 @@
"no_females_pregnant_household_person_2_value_check": { "no_females_pregnant_household_person_2_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"details_known_2": 0 "details_known_2": 0
} }
], ],
@ -2626,7 +2626,7 @@
"no_females_pregnant_household_person_3_age_value_check": { "no_females_pregnant_household_person_3_age_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"age3_known": 0 "age3_known": 0
} }
], ],
@ -2749,7 +2749,7 @@
"no_females_pregnant_household_person_3_value_check": { "no_females_pregnant_household_person_3_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"details_known_3": 0 "details_known_3": 0
} }
], ],
@ -3158,7 +3158,7 @@
"no_females_pregnant_household_person_4_age_value_check": { "no_females_pregnant_household_person_4_age_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"age4_known": 0 "age4_known": 0
} }
], ],
@ -3281,7 +3281,7 @@
"no_females_pregnant_household_person_4_value_check": { "no_females_pregnant_household_person_4_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"details_known_4": 0 "details_known_4": 0
} }
], ],
@ -3687,7 +3687,7 @@
"no_females_pregnant_household_person_5_age_value_check": { "no_females_pregnant_household_person_5_age_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"age5_known": 0 "age5_known": 0
} }
], ],
@ -3810,7 +3810,7 @@
"no_females_pregnant_household_person_5_value_check": { "no_females_pregnant_household_person_5_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"details_known_5": 0 "details_known_5": 0
} }
], ],
@ -4213,7 +4213,7 @@
"no_females_pregnant_household_person_6_age_value_check": { "no_females_pregnant_household_person_6_age_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"age6_known": 0 "age6_known": 0
} }
], ],
@ -4336,7 +4336,7 @@
"no_females_pregnant_household_person_6_value_check": { "no_females_pregnant_household_person_6_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"details_known_6": 0 "details_known_6": 0
} }
], ],
@ -4736,7 +4736,7 @@
"no_females_pregnant_household_person_7_age_value_check": { "no_females_pregnant_household_person_7_age_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"age7_known": 0 "age7_known": 0
} }
], ],
@ -4859,7 +4859,7 @@
"no_females_pregnant_household_person_7_value_check": { "no_females_pregnant_household_person_7_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"details_known_7": 0 "details_known_7": 0
} }
], ],
@ -5256,7 +5256,7 @@
"no_females_pregnant_household_person_8_age_value_check": { "no_females_pregnant_household_person_8_age_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"age8_known": 0 "age8_known": 0
} }
], ],
@ -5379,7 +5379,7 @@
"no_females_pregnant_household_person_8_value_check": { "no_females_pregnant_household_person_8_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"details_known_8": 0 "details_known_8": 0
} }
], ],
@ -5794,7 +5794,7 @@
"no_females_pregnant_household_value_check": { "no_females_pregnant_household_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true "all_male_tenants_in_a_pregnant_household?": true
} }
], ],
"title_text": { "title_text": {

36
config/forms/2022_2023.json

@ -1200,7 +1200,7 @@
"no_females_pregnant_household_lead_hhmemb_value_check": { "no_females_pregnant_household_lead_hhmemb_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true "all_male_tenants_in_a_pregnant_household?": true
} }
], ],
"title_text": { "title_text": {
@ -1372,7 +1372,7 @@
"no_females_pregnant_household_lead_age_value_check": { "no_females_pregnant_household_lead_age_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true "all_male_tenants_in_a_pregnant_household?": true
} }
], ],
"title_text": { "title_text": {
@ -1523,7 +1523,7 @@
"no_females_pregnant_household_lead_value_check": { "no_females_pregnant_household_lead_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true "all_male_tenants_in_a_pregnant_household?": true
} }
], ],
"title_text": { "title_text": {
@ -2163,7 +2163,7 @@
"no_females_pregnant_household_person_2_age_value_check": { "no_females_pregnant_household_person_2_age_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"age2_known": 0 "age2_known": 0
} }
], ],
@ -2316,7 +2316,7 @@
"no_females_pregnant_household_person_2_value_check": { "no_females_pregnant_household_person_2_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"details_known_2": 0 "details_known_2": 0
} }
], ],
@ -2746,7 +2746,7 @@
"no_females_pregnant_household_person_3_age_value_check": { "no_females_pregnant_household_person_3_age_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"age3_known": 0 "age3_known": 0
} }
], ],
@ -2899,7 +2899,7 @@
"no_females_pregnant_household_person_3_value_check": { "no_females_pregnant_household_person_3_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"details_known_3": 0 "details_known_3": 0
} }
], ],
@ -3326,7 +3326,7 @@
"no_females_pregnant_household_person_4_age_value_check": { "no_females_pregnant_household_person_4_age_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"age4_known": 0 "age4_known": 0
} }
], ],
@ -3479,7 +3479,7 @@
"no_females_pregnant_household_person_4_value_check": { "no_females_pregnant_household_person_4_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"details_known_4": 0 "details_known_4": 0
} }
], ],
@ -3903,7 +3903,7 @@
"no_females_pregnant_household_person_5_age_value_check": { "no_females_pregnant_household_person_5_age_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"age5_known": 0 "age5_known": 0
} }
], ],
@ -4056,7 +4056,7 @@
"no_females_pregnant_household_person_5_value_check": { "no_females_pregnant_household_person_5_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"details_known_5": 0 "details_known_5": 0
} }
], ],
@ -4477,7 +4477,7 @@
"no_females_pregnant_household_person_6_age_value_check": { "no_females_pregnant_household_person_6_age_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"age6_known": 0 "age6_known": 0
} }
], ],
@ -4630,7 +4630,7 @@
"no_females_pregnant_household_person_6_value_check": { "no_females_pregnant_household_person_6_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"details_known_6": 0 "details_known_6": 0
} }
], ],
@ -5048,7 +5048,7 @@
"no_females_pregnant_household_person_7_age_value_check": { "no_females_pregnant_household_person_7_age_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"age7_known": 0 "age7_known": 0
} }
], ],
@ -5201,7 +5201,7 @@
"no_females_pregnant_household_person_7_value_check": { "no_females_pregnant_household_person_7_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"details_known_7": 0 "details_known_7": 0
} }
], ],
@ -5616,7 +5616,7 @@
"no_females_pregnant_household_person_8_age_value_check": { "no_females_pregnant_household_person_8_age_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"age8_known": 0 "age8_known": 0
} }
], ],
@ -5769,7 +5769,7 @@
"no_females_pregnant_household_person_8_value_check": { "no_females_pregnant_household_person_8_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true, "all_male_tenants_in_a_pregnant_household?": true,
"details_known_8": 0 "details_known_8": 0
} }
], ],
@ -6205,7 +6205,7 @@
"no_females_pregnant_household_value_check": { "no_females_pregnant_household_value_check": {
"depends_on": [ "depends_on": [
{ {
"no_females_in_a_pregnant_household?": true "all_male_tenants_in_a_pregnant_household?": true
} }
], ],
"title_text": { "title_text": {

2
config/locales/en.yml

@ -723,7 +723,7 @@ Make sure these answers are correct."
hint_text: "This is higher than the purchase price minus the discount." hint_text: "This is higher than the purchase price minus the discount."
pregnancy: pregnancy:
title: "You told us somebody in the household is pregnant" title: "You told us somebody in the household is pregnant"
no_females: "You also told us there are no female tenants living at the property." all_male_tenants: "You also told us that all the tenants living at the property are male."
females_not_in_soft_age_range: "You also told us that any female tenants living at the property are in the following age ranges:<ul><li>under 16 years old</li><li>over 50 years old</li></ul>" females_not_in_soft_age_range: "You also told us that any female tenants living at the property are in the following age ranges:<ul><li>under 16 years old</li><li>over 50 years old</li></ul>"
major_repairs_date: major_repairs_date:
title_text: "You told us the property has been vacant for 2 years." title_text: "You told us the property has been vacant for 2 years."

2
spec/lib/tasks/update_schemes_and_locations_from_csv_spec.rb

@ -25,7 +25,7 @@ RSpec.describe "bulk_update" do
allow(ENV).to receive(:[]).with("BULK_UPLOAD_BUCKET").and_return(instance_name) allow(ENV).to receive(:[]).with("BULK_UPLOAD_BUCKET").and_return(instance_name)
WebMock.stub_request(:get, /api\.postcodes\.io/) WebMock.stub_request(:get, /api\.postcodes\.io/)
.to_return(status: 200, body: "{\"status\":404,\"error\":\"Postcode not found\"}", headers: {}) .to_return(status: 404, body: "{\"status\":404,\"error\":\"Postcode not found\"}", headers: {})
WebMock.stub_request(:get, /api\.postcodes\.io\/postcodes\/B11BB/) WebMock.stub_request(:get, /api\.postcodes\.io\/postcodes\/B11BB/)
.to_return(status: 200, body: '{"status":200,"result":{"admin_district":"Westminster","codes":{"admin_district":"E09000033"}}}', headers: {}) .to_return(status: 200, body: '{"status":200,"result":{"admin_district":"Westminster","codes":{"admin_district":"E09000033"}}}', headers: {})
end end

8
spec/models/form/lettings/pages/no_females_pregnant_household_person_age_value_check_spec.rb

@ -33,7 +33,7 @@ RSpec.describe Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonAgeValueCh
[ [
{ {
"age2_known" => 0, "age2_known" => 0,
"no_females_in_a_pregnant_household?" => true, "all_male_tenants_in_a_pregnant_household?" => true,
}, },
], ],
) )
@ -54,7 +54,7 @@ RSpec.describe Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonAgeValueCh
it "has the correct informative_text" do it "has the correct informative_text" do
expect(page.informative_text).to eq({ expect(page.informative_text).to eq({
"translation" => "soft_validations.pregnancy.no_females", "translation" => "soft_validations.pregnancy.all_male_tenants",
"arguments" => [ "arguments" => [
{ {
"key" => "sex1", "key" => "sex1",
@ -78,7 +78,7 @@ RSpec.describe Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonAgeValueCh
[ [
{ {
"age3_known" => 0, "age3_known" => 0,
"no_females_in_a_pregnant_household?" => true, "all_male_tenants_in_a_pregnant_household?" => true,
}, },
], ],
) )
@ -99,7 +99,7 @@ RSpec.describe Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonAgeValueCh
it "has the correct informative_text" do it "has the correct informative_text" do
expect(page.informative_text).to eq({ expect(page.informative_text).to eq({
"translation" => "soft_validations.pregnancy.no_females", "translation" => "soft_validations.pregnancy.all_male_tenants",
"arguments" => [ "arguments" => [
{ {
"key" => "sex1", "key" => "sex1",

8
spec/models/form/lettings/pages/no_females_pregnant_household_person_value_check_spec.rb

@ -33,7 +33,7 @@ RSpec.describe Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonValueCheck
[ [
{ {
"details_known_2" => 0, "details_known_2" => 0,
"no_females_in_a_pregnant_household?" => true, "all_male_tenants_in_a_pregnant_household?" => true,
}, },
], ],
) )
@ -54,7 +54,7 @@ RSpec.describe Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonValueCheck
it "has the correct informative_text" do it "has the correct informative_text" do
expect(page.informative_text).to eq({ expect(page.informative_text).to eq({
"translation" => "soft_validations.pregnancy.no_females", "translation" => "soft_validations.pregnancy.all_male_tenants",
"arguments" => [ "arguments" => [
{ {
"key" => "sex1", "key" => "sex1",
@ -78,7 +78,7 @@ RSpec.describe Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonValueCheck
[ [
{ {
"details_known_3" => 0, "details_known_3" => 0,
"no_females_in_a_pregnant_household?" => true, "all_male_tenants_in_a_pregnant_household?" => true,
}, },
], ],
) )
@ -99,7 +99,7 @@ RSpec.describe Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonValueCheck
it "has the correct informative_text" do it "has the correct informative_text" do
expect(page.informative_text).to eq({ expect(page.informative_text).to eq({
"translation" => "soft_validations.pregnancy.no_females", "translation" => "soft_validations.pregnancy.all_male_tenants",
"arguments" => [ "arguments" => [
{ {
"key" => "sex1", "key" => "sex1",

11
spec/models/lettings_log_spec.rb

@ -329,17 +329,6 @@ RSpec.describe LettingsLog do
.to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/) .to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/)
end end
context "when the local authority lookup times out" do
before do
allow(Timeout).to receive(:timeout).and_raise(Timeout::Error)
end
it "logs a warning" do
expect(Rails.logger).to receive(:warn).with("Postcodes.io lookup timed out")
address_lettings_log.update!({ postcode_known: 1, postcode_full: "M1 1AD" })
end
end
it "correctly resets all fields if property postcode not known" do it "correctly resets all fields if property postcode not known" do
address_lettings_log.update!({ postcode_known: 0 }) address_lettings_log.update!({ postcode_known: 0 })

11
spec/models/sales_log_spec.rb

@ -628,17 +628,6 @@ RSpec.describe SalesLog, type: :model do
.to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/) .to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/)
end end
context "when the local authority lookup times out" do
before do
allow(Timeout).to receive(:timeout).and_raise(Timeout::Error)
end
it "logs a warning" do
expect(Rails.logger).to receive(:warn).with("Postcodes.io lookup timed out")
address_sales_log.update!({ pcodenk: 1, postcode_full: "M1 1AD" })
end
end
it "correctly resets all fields if property postcode not known" do it "correctly resets all fields if property postcode not known" do
address_sales_log.update!({ pcodenk: 1 }) address_sales_log.update!({ pcodenk: 1 })

12
spec/models/validations/soft_validations_spec.rb

@ -153,24 +153,24 @@ RSpec.describe Validations::SoftValidations do
end end
describe "pregnancy soft validations" do describe "pregnancy soft validations" do
context "when there are no female tenants" do context "when all tenants are male" do
it "shows the interruption screen" do it "shows the interruption screen" do
record.age1 = 43 record.age1 = 43
record.sex1 = "M" record.sex1 = "M"
record.preg_occ = 1 record.preg_occ = 1
record.hhmemb = 1 record.hhmemb = 1
record.age1_known = 0 record.age1_known = 0
expect(record.no_females_in_a_pregnant_household?).to be true expect(record.all_male_tenants_in_a_pregnant_household?).to be true
end end
end end
context "when there are no female tenants and age of other tenants is unknown" do context "when there all tenants are male and age of tenants is unknown" do
it "shows the interruption screen" do it "shows the interruption screen" do
record.sex1 = "M" record.sex1 = "M"
record.preg_occ = 1 record.preg_occ = 1
record.hhmemb = 1 record.hhmemb = 1
record.age1_known = 1 record.age1_known = 1
expect(record.no_females_in_a_pregnant_household?).to be true expect(record.all_male_tenants_in_a_pregnant_household?).to be true
end end
end end
@ -206,7 +206,7 @@ RSpec.describe Validations::SoftValidations do
record.sex1 = "F" record.sex1 = "F"
record.preg_occ = 1 record.preg_occ = 1
record.hhmemb = 1 record.hhmemb = 1
expect(record.no_females_in_a_pregnant_household?).to be false expect(record.all_male_tenants_in_a_pregnant_household?).to be false
expect(record.female_in_pregnant_household_in_soft_validation_range?).to be false expect(record.female_in_pregnant_household_in_soft_validation_range?).to be false
end end
end end
@ -215,7 +215,7 @@ RSpec.describe Validations::SoftValidations do
it "does not show the interruption screen" do it "does not show the interruption screen" do
record.preg_occ = 1 record.preg_occ = 1
record.hhmemb = 2 record.hhmemb = 2
expect(record.no_females_in_a_pregnant_household?).to be false expect(record.all_male_tenants_in_a_pregnant_household?).to be false
expect(record.female_in_pregnant_household_in_soft_validation_range?).to be false expect(record.female_in_pregnant_household_in_soft_validation_range?).to be false
end end
end end

2
spec/request_helper.rb

@ -4,7 +4,7 @@ module RequestHelper
def self.stub_http_requests def self.stub_http_requests
WebMock.disable_net_connect!(allow_localhost: true) WebMock.disable_net_connect!(allow_localhost: true)
WebMock.stub_request(:get, /api\.postcodes\.io/) WebMock.stub_request(:get, /api\.postcodes\.io/)
.to_return(status: 200, body: "{\"status\":404,\"error\":\"Postcode not found\"}", headers: {}) .to_return(status: 404, body: "{\"status\":404,\"error\":\"Postcode not found\"}", headers: {})
WebMock.stub_request(:get, "https://api.postcodes.io/postcodes/AA11AA") WebMock.stub_request(:get, "https://api.postcodes.io/postcodes/AA11AA")
.to_return(status: 200, body: "{\"status\":200,\"result\":{\"postcode\":\"AA1 1AA\",\"admin_district\":\"Westminster\",\"codes\":{\"admin_district\":\"E09000033\"}}}", headers: {}) .to_return(status: 200, body: "{\"status\":200,\"result\":{\"postcode\":\"AA1 1AA\",\"admin_district\":\"Westminster\",\"codes\":{\"admin_district\":\"E09000033\"}}}", headers: {})

77
spec/services/postcode_service_spec.rb

@ -1,9 +1,80 @@
require "rails_helper" require "rails_helper"
describe PostcodeService do describe PostcodeService do
let(:postcode) { "s r81LS\u00A0" } let(:service) { described_class.new }
it "returns clean postcode" do describe "clean" do
expect(described_class.clean(postcode)).to eq "SR81LS" let(:postcode) { "s r81LS\u00A0" }
it "returns clean postcode" do
expect(described_class.clean(postcode)).to eq "SR81LS"
end
end
describe "lookup" do
before do
Excon.defaults[:mock] = true
Excon.defaults[:stubs] = :local
end
context "when the request returns a success response" do
before do
Excon.stub({}, { body: '{"result": { "admin_district": "District", "codes": { "admin_district": "123" } } }', status: 200 })
end
it "returns the admin district and admin district code" do
result = service.lookup("A00 0AA")
expect(result[:location_code]).to eq("123")
expect(result[:location_admin_district]).to eq("District")
end
end
context "when the request returns a not found response" do
before do
Excon.stub({}, { status: 404 })
end
it "returns nil" do
result = service.lookup("A00 0AA")
expect(result).to be_nil
end
it "logs the error at warning level" do
expect(Rails.logger).to receive(:warn).with(match "404 Not Found")
service.lookup("A00 0AA")
end
end
context "when the request returns an error response" do
before do
Excon.stub({}, { body: "This is an error message that is not valid json", status: 500 })
end
it "returns nil" do
result = service.lookup("A00 0AA")
expect(result).to be_nil
end
it "logs the error at warning level" do
expect(Rails.logger).to receive(:warn).with(match "This is an error message that is not valid json")
service.lookup("A00 0AA")
end
end
context "when the request returns a success response that causes later errors" do
before do
Excon.stub({}, { body: '{"result": { "admin_district": "District" } }', status: 200 })
end
it "returns nil" do
result = service.lookup("A00 0AA")
expect(result).to be_nil
end
it "logs the error at error level" do
expect(Rails.logger).to receive(:error).with(match "Unexpected error with postcode lookup request")
service.lookup("A00 0AA")
end
end
end end
end end

Loading…
Cancel
Save