Browse Source

Merge branch 'main' into AllowStagingTesting

pull/2279/head
Rachael Booth 2 years ago committed by GitHub
parent
commit
b502c0ae85
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      .cfignore
  2. 16
      app/models/validations/sales/financial_validations.rb
  3. 14
      app/services/bulk_upload/lettings/year2024/row_parser.rb
  4. 22
      app/services/bulk_upload/sales/year2024/row_parser.rb
  5. 22
      app/views/organisation_relationships/_managing_agent_list.erb
  6. 36
      app/views/organisation_relationships/_related_org_list.erb
  7. 22
      app/views/organisation_relationships/_stock_owner_list.erb
  8. 11
      app/views/organisation_relationships/managing_agents.html.erb
  9. 11
      app/views/organisation_relationships/stock_owners.html.erb
  10. 21
      config/cloud_foundry/review_manifest.yml
  11. 5
      config/locales/en.yml
  12. 8
      lib/tasks/cf.rake
  13. 46
      manifest.yml
  14. 76
      spec/models/validations/sales/financial_validations_spec.rb
  15. 6
      spec/requests/organisation_relationships_controller_spec.rb
  16. 13
      spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb
  17. 26
      spec/services/bulk_upload/sales/year2024/row_parser_spec.rb
  18. 15
      spec/services/merge/merge_organisations_service_spec.rb

2
.cfignore

@ -1,2 +0,0 @@
docs/*
spec/*

16
app/models/validations/sales/financial_validations.rb

@ -6,10 +6,10 @@ module Validations::Sales::FinancialValidations
return unless record.income1 && record.la && record.shared_ownership_scheme? return unless record.income1 && record.la && record.shared_ownership_scheme?
relevant_fields = %i[income1 ownershipsch uprn la postcode_full] relevant_fields = %i[income1 ownershipsch uprn la postcode_full]
if record.london_property? && record.income1 > 90_000 if record.london_property? && !record.income1.between?(0, 90_000)
relevant_fields.each { |field| record.errors.add field, :over_hard_max_for_london, message: I18n.t("validations.financial.income.over_hard_max_for_london") } relevant_fields.each { |field| record.errors.add field, :outside_london_income_range, message: I18n.t("validations.financial.income.outside_london_income_range") }
elsif record.property_not_in_london? && record.income1 > 80_000 elsif record.property_not_in_london? && !record.income1.between?(0, 80_000)
relevant_fields.each { |field| record.errors.add field, :over_hard_max_for_outside_london, message: I18n.t("validations.financial.income.over_hard_max_for_outside_london") } relevant_fields.each { |field| record.errors.add field, :outside_non_london_income_range, message: I18n.t("validations.financial.income.outside_non_london_income_range") }
end end
end end
@ -17,10 +17,10 @@ module Validations::Sales::FinancialValidations
return unless record.income2 && record.la && record.shared_ownership_scheme? return unless record.income2 && record.la && record.shared_ownership_scheme?
relevant_fields = %i[income2 ownershipsch uprn la postcode_full] relevant_fields = %i[income2 ownershipsch uprn la postcode_full]
if record.london_property? && record.income2 > 90_000 if record.london_property? && !record.income2.between?(0, 90_000)
relevant_fields.each { |field| record.errors.add field, :over_hard_max_for_london, message: I18n.t("validations.financial.income.over_hard_max_for_london") } relevant_fields.each { |field| record.errors.add field, :outside_london_income_range, message: I18n.t("validations.financial.income.outside_london_income_range") }
elsif record.property_not_in_london? && record.income2 > 80_000 elsif record.property_not_in_london? && !record.income2.between?(0, 80_000)
relevant_fields.each { |field| record.errors.add field, :over_hard_max_for_outside_london, message: I18n.t("validations.financial.income.over_hard_max_for_outside_london") } relevant_fields.each { |field| record.errors.add field, :outside_non_london_income_range, message: I18n.t("validations.financial.income.outside_non_london_income_range") }
end end
end end

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

@ -383,6 +383,7 @@ class BulkUpload::Lettings::Year2024::RowParser
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? } validate :validate_all_charges_given, on: :after_log, if: proc { is_carehome.zero? }
validate :validate_nationality, on: :after_log
def self.question_for_field(field) def self.question_for_field(field)
QUESTIONS[field] QUESTIONS[field]
@ -557,6 +558,12 @@ private
end end
end end
def validate_nationality
if field_45.present? && !valid_nationality_options.include?(field_45.to_s)
errors.add(:field_45, I18n.t("validations.household.nationality"))
end
end
def duplicate_check_fields def duplicate_check_fields
[ [
"startdate", "startdate",
@ -914,6 +921,7 @@ private
ethnic_group: %i[field_44], ethnic_group: %i[field_44],
ethnic: %i[field_44], ethnic: %i[field_44],
nationality_all: %i[field_45], nationality_all: %i[field_45],
nationality_all_group: %i[field_45],
relat2: %i[field_47], relat2: %i[field_47],
relat3: %i[field_51], relat3: %i[field_51],
@ -1087,7 +1095,7 @@ private
attributes["ethnic_group"] = ethnic_group_from_ethnic attributes["ethnic_group"] = ethnic_group_from_ethnic
attributes["ethnic"] = field_44 attributes["ethnic"] = field_44
attributes["nationality_all"] = field_45 attributes["nationality_all"] = field_45 if field_45.present? && valid_nationality_options.include?(field_45.to_s)
attributes["nationality_all_group"] = nationality_group(attributes["nationality_all"]) attributes["nationality_all_group"] = nationality_group(attributes["nationality_all"])
attributes["relat2"] = field_47 attributes["relat2"] = field_47
@ -1486,6 +1494,10 @@ private
end end
end end
def valid_nationality_options
%w[0] + GlobalConstants::COUNTRIES_ANSWER_OPTIONS.keys # 0 is "Prefers not to say"
end
def nationality_group(nationality_value) def nationality_group(nationality_value)
return unless nationality_value return unless nationality_value
return 0 if nationality_value.zero? return 0 if nationality_value.zero?

22
app/services/bulk_upload/sales/year2024/row_parser.rb

@ -469,6 +469,8 @@ class BulkUpload::Sales::Year2024::RowParser
validate :validate_if_log_already_exists, on: :after_log, if: -> { FeatureToggle.bulk_upload_duplicate_log_check_enabled? } validate :validate_if_log_already_exists, on: :after_log, if: -> { FeatureToggle.bulk_upload_duplicate_log_check_enabled? }
validate :validate_buyers_organisations, on: :after_log validate :validate_buyers_organisations, on: :after_log
validate :validate_nationality, on: :after_log
validate :validate_buyer_2_nationality, on: :after_log
def self.question_for_field(field) def self.question_for_field(field)
QUESTIONS[field] QUESTIONS[field]
@ -834,7 +836,7 @@ private
attributes["ethnic_group"] = ethnic_group_from_ethnic attributes["ethnic_group"] = ethnic_group_from_ethnic
attributes["ethnic"] = field_33 attributes["ethnic"] = field_33
attributes["nationality_all"] = field_34 attributes["nationality_all"] = field_34 if field_34.present? && valid_nationality_options.include?(field_34.to_s)
attributes["nationality_all_group"] = nationality_group(attributes["nationality_all"]) attributes["nationality_all_group"] = nationality_group(attributes["nationality_all"])
attributes["income1nk"] = field_77 == "R" ? 1 : 0 attributes["income1nk"] = field_77 == "R" ? 1 : 0
@ -942,7 +944,7 @@ private
attributes["ethnic_group2"] = infer_buyer2_ethnic_group_from_ethnic attributes["ethnic_group2"] = infer_buyer2_ethnic_group_from_ethnic
attributes["ethnicbuy2"] = field_40 attributes["ethnicbuy2"] = field_40
attributes["nationality_all_buyer2"] = field_41 attributes["nationality_all_buyer2"] = field_41 if field_41.present? && valid_nationality_options.include?(field_41.to_s)
attributes["nationality_all_buyer2_group"] = nationality_group(attributes["nationality_all_buyer2"]) attributes["nationality_all_buyer2_group"] = nationality_group(attributes["nationality_all_buyer2"])
attributes["buy2living"] = field_70 attributes["buy2living"] = field_70
@ -1341,4 +1343,20 @@ private
errors.add(:field_35, "Buyer 1 cannot be a child under 16") errors.add(:field_35, "Buyer 1 cannot be a child under 16")
end end
end end
def validate_nationality
if field_34.present? && !valid_nationality_options.include?(field_34.to_s)
errors.add(:field_34, I18n.t("validations.household.nationality"))
end
end
def validate_buyer_2_nationality
if field_41.present? && !valid_nationality_options.include?(field_41.to_s)
errors.add(:field_41, I18n.t("validations.household.nationality"))
end
end
def valid_nationality_options
%w[0] + GlobalConstants::COUNTRIES_ANSWER_OPTIONS.keys # 0 is "Prefers not to say"
end
end end

22
app/views/organisation_relationships/_managing_agent_list.erb

@ -1,22 +0,0 @@
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>">
<%= govuk_table do |table| %>
<%= table.with_caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %>
<%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "agents", filters_count: 0)) %>
<% end %>
<% @managing_agents.each do |managing_agent| %>
<%= table.with_body do |body| %>
<%= body.with_row do |row| %>
<% row.with_cell(text: managing_agent.name) %>
<% if current_user.data_coordinator? || current_user.support? %>
<% row.with_cell(html_attributes: {
scope: "row",
class: "govuk-!-text-align-right",
}) do %>
<%= govuk_link_to("Remove", managing_agents_remove_organisation_path(target_organisation_id: managing_agent.id)) %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
</section>

36
app/views/organisation_relationships/_related_org_list.erb

@ -0,0 +1,36 @@
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>">
<%= govuk_table do |table| %>
<%= table.with_caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %>
<%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: search_item, filters_count: 0)) %>
<% end %>
<%= table.with_head do |head| %>
<%= head.with_row do |row| %>
<% row.with_cell(header: true, text: "Organisation name", html_attributes: { scope: "col", class: "govuk-!-width-one-half" }) %>
<% row.with_cell(header: true, text: "Organisation ID", html_attributes: { scope: "col", class: "govuk-!-width-one-half" }) %>
<% if current_user.data_coordinator? || current_user.support? %>
<% row.with_cell %>
<% end %>
<% end %>
<% end %>
<%= table.with_body do |body| %>
<% related_orgs.each do |org| %>
<%= body.with_row do |row| %>
<% if current_user.support? %>
<% row.with_cell(text: simple_format(govuk_link_to(org.name, organisation_path(org)), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
<% else %>
<% row.with_cell(text: org.name) %>
<% end %>
<% row.with_cell(text: "ORG#{org.id}") %>
<% if current_user.data_coordinator? || current_user.support? %>
<% row.with_cell(html_attributes: {
scope: "row",
class: "govuk-!-text-align-right",
}) do %>
<%= govuk_link_to("Remove", remove_path.call(org.id)) %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
</section>

22
app/views/organisation_relationships/_stock_owner_list.erb

@ -1,22 +0,0 @@
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>">
<%= govuk_table do |table| %>
<%= table.with_caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %>
<%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "stock owners", filters_count: 0)) %>
<% end %>
<% @stock_owners.each do |stock_owner| %>
<%= table.with_body do |body| %>
<%= body.with_row do |row| %>
<% row.with_cell(text: stock_owner.name) %>
<% if current_user.data_coordinator? || current_user.support? %>
<% row.with_cell(html_attributes: {
scope: "row",
class: "govuk-!-text-align-right",
}) do %>
<%= govuk_link_to("Remove", stock_owners_remove_organisation_path(target_organisation_id: stock_owner.id)) %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
</section>

11
app/views/organisation_relationships/managing_agents.html.erb

@ -22,6 +22,15 @@
<% end %> <% end %>
<% if @total_count != 0 %> <% if @total_count != 0 %>
<%= render SearchComponent.new(current_user:, search_label: "Search for a managing agent", value: @searched) %> <%= render SearchComponent.new(current_user:, search_label: "Search for a managing agent", value: @searched) %>
<%= render partial: "organisation_relationships/managing_agent_list", locals: { index: @managing_agents, title: "Managing agents", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %> <%= render partial: "organisation_relationships/related_org_list", locals: {
related_orgs: @managing_agents,
title: "Managing agents",
pagy: @pagy,
searched: @searched,
item_label:,
search_item: "managing agents",
total_count: @total_count,
remove_path: ->(org_id) { managing_agents_remove_organisation_path(target_organisation_id: org_id) },
} %>
<%= render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "managing agents" } %> <%= render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "managing agents" } %>
<% end %> <% end %>

11
app/views/organisation_relationships/stock_owners.html.erb

@ -19,6 +19,15 @@
<% end %> <% end %>
<% if @total_count != 0 %> <% if @total_count != 0 %>
<%= render SearchComponent.new(current_user:, search_label: "Search for a stock owner", value: @searched) %> <%= render SearchComponent.new(current_user:, search_label: "Search for a stock owner", value: @searched) %>
<%= render partial: "organisation_relationships/stock_owner_list", locals: { index: @stock_owners, title: "Stock owners", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %> <%= render partial: "organisation_relationships/related_org_list", locals: {
related_orgs: @stock_owners,
title: "Stock owners",
pagy: @pagy,
searched: @searched,
item_label:,
search_item: "stock owners",
total_count: @total_count,
remove_path: ->(org_id) { stock_owners_remove_organisation_path(target_organisation_id: org_id) },
} %>
<%= render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "stock owners" } %> <%= render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "stock owners" } %>
<% end %> <% end %>

21
config/cloud_foundry/review_manifest.yml

@ -1,21 +0,0 @@
---
defaults: &defaults
buildpacks:
- https://github.com/cloudfoundry/ruby-buildpack.git
processes:
- type: web
command: bundle exec rake cf:on_first_instance db:migrate db:seed && bin/rails server
instances: 1
memory: 1G
- type: worker
command: bundle exec sidekiq -t 3
health-check-type: process
instances: 1
health-check-type: http
health-check-http-endpoint: /health
applications:
- name: dluhc-core-review
<<: *defaults
env:
RAILS_ENV: review

5
config/locales/en.yml

@ -368,8 +368,8 @@ en:
freq_missing: "Select how often the household receives income" freq_missing: "Select how often the household receives income"
earnings_missing: "Enter how much income the household has in total" earnings_missing: "Enter how much income the household has in total"
income: income:
over_hard_max_for_london: "Income must be £90,000 or lower for properties within a London local authority" outside_london_income_range: "Income must be between £0 and £90,000 for properties within a London local authority"
over_hard_max_for_outside_london: "Income must be £80,000 or lower for properties outside London local authority" outside_non_london_income_range: "Income must be between £0 and £80,000 for properties in a non-London local authority"
combined_over_hard_max_for_london: "Combined income must be £90,000 or lower for properties within a London local authority" combined_over_hard_max_for_london: "Combined income must be £90,000 or lower for properties within a London local authority"
combined_over_hard_max_for_outside_london: "Combined income must be £80,000 or lower for properties outside London local authorities" combined_over_hard_max_for_outside_london: "Combined income must be £80,000 or lower for properties outside London local authorities"
child_has_income: "Child's income must be £0" child_has_income: "Child's income must be £0"
@ -552,6 +552,7 @@ en:
buylivein: buylivein:
buyers_will_live_in_property_values_inconsistent_setup: "You have already told us that both buyer 1 and buyer 2 will not live in the property" buyers_will_live_in_property_values_inconsistent_setup: "You have already told us that both buyer 1 and buyer 2 will not live in the property"
buyers_will_live_in_property_values_inconsistent: "You have already told us that the buyers will live in the property. Either buyer 1 or buyer 2 must live in the property" buyers_will_live_in_property_values_inconsistent: "You have already told us that the buyers will live in the property. Either buyer 1 or buyer 2 must live in the property"
nationality: "Select a valid nationality"
tenancy: tenancy:
length: length:

8
lib/tasks/cf.rake

@ -1,8 +0,0 @@
namespace :cf do
desc "Only run on the first application instance"
task on_first_instance: :environment do
# We expect this information to be always available or break otherwise
instance_index = JSON.parse(ENV["VCAP_APPLICATION"])["instance_index"]
exit(0) unless instance_index.zero?
end
end

46
manifest.yml

@ -1,46 +0,0 @@
---
defaults: &defaults
buildpacks:
- https://github.com/cloudfoundry/ruby-buildpack.git
processes:
- type: web
command: bundle exec rake cf:on_first_instance db:migrate && bin/rails server
instances: 2
memory: 1G
- type: worker
command: bundle exec sidekiq -t 3
disk_quota: 4G
health-check-type: process
instances: 2
memory: 8G
health-check-type: http
health-check-http-endpoint: /health
applications:
- name: dluhc-core-staging
<<: *defaults
env:
RAILS_ENV: staging
services:
- dluhc-core-staging-postgres
- dluhc-core-staging-redis
- name: dluhc-core-production
<<: *defaults
processes:
- type: web
command: bundle exec rake cf:on_first_instance db:migrate && bin/rails server
instances: 4
memory: 1G
- type: worker
command: bundle exec sidekiq -t 3
disk_quota: 4G
health-check-type: process
instances: 2
memory: 8G
env:
RAILS_ENV: production
host: submit-social-housing-lettings-sales-data
services:
- dluhc-core-production-postgres
- dluhc-core-production-redis

76
spec/models/validations/sales/financial_validations_spec.rb

@ -17,33 +17,51 @@ RSpec.describe Validations::Sales::FinancialValidations do
it "adds errors if buyer 1 has income over 80,000" do it "adds errors if buyer 1 has income over 80,000" do
record.income1 = 85_000 record.income1 = 85_000
financial_validator.validate_income1(record) financial_validator.validate_income1(record)
expect(record.errors["income1"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_outside_london")) expect(record.errors["income1"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_outside_london")) expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_outside_london")) expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_outside_london")) expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
end end
it "adds errors if buyer 2 has income over 80,000" do it "adds errors if buyer 2 has income over 80,000" do
record.income2 = 85_000 record.income2 = 85_000
financial_validator.validate_income2(record) financial_validator.validate_income2(record)
expect(record.errors["income2"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_outside_london")) expect(record.errors["income2"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_outside_london")) expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_outside_london")) expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_outside_london")) expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
end end
it "does not add errors if buyer 1 has income below 80_000" do it "does not add errors if buyer 1 has income above 0 and below 80_000" do
record.income1 = 75_000 record.income1 = 75_000
financial_validator.validate_income1(record) financial_validator.validate_income1(record)
expect(record.errors).to be_empty expect(record.errors).to be_empty
end end
it "does not add errors if buyer 2 has income below 80_000" do it "does not add errors if buyer 2 has income above 0 and below 80_000" do
record.income2 = 75_000 record.income2 = 75_000
financial_validator.validate_income2(record) financial_validator.validate_income2(record)
expect(record.errors).to be_empty expect(record.errors).to be_empty
end end
it "adds errors if buyer 1 has income below 0" do
record.income1 = -500
financial_validator.validate_income1(record)
expect(record.errors["income1"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
end
it "adds errors if buyer 2 has income below 0" do
record.income2 = -5
financial_validator.validate_income2(record)
expect(record.errors["income2"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.outside_non_london_income_range"))
end
it "adds errors when combined income is over 80_000" do it "adds errors when combined income is over 80_000" do
record.income1 = 45_000 record.income1 = 45_000
record.income2 = 40_000 record.income2 = 40_000
@ -69,33 +87,51 @@ RSpec.describe Validations::Sales::FinancialValidations do
it "adds errors if buyer 1 has income over 90,000" do it "adds errors if buyer 1 has income over 90,000" do
record.income1 = 95_000 record.income1 = 95_000
financial_validator.validate_income1(record) financial_validator.validate_income1(record)
expect(record.errors["income1"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_london")) expect(record.errors["income1"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_london")) expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_london")) expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_london")) expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
end end
it "adds errors if buyer 2 has income over 90,000" do it "adds errors if buyer 2 has income over 90,000" do
record.income2 = 95_000 record.income2 = 95_000
financial_validator.validate_income2(record) financial_validator.validate_income2(record)
expect(record.errors["income2"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_london")) expect(record.errors["income2"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_london")) expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_london")) expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.over_hard_max_for_london")) expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
end end
it "does not add errors if buyer 1 has income below 90_000" do it "does not add errors if buyer 1 has income above 0 and below 90_000" do
record.income1 = 75_000 record.income1 = 75_000
financial_validator.validate_income1(record) financial_validator.validate_income1(record)
expect(record.errors).to be_empty expect(record.errors).to be_empty
end end
it "does not add errors if buyer 2 has income below 90_000" do it "does not add errors if buyer 2 has income above 0 and below 90_000" do
record.income2 = 75_000 record.income2 = 75_000
financial_validator.validate_income2(record) financial_validator.validate_income2(record)
expect(record.errors).to be_empty expect(record.errors).to be_empty
end end
it "adds errors if buyer 1 has income below 0" do
record.income1 = -500
financial_validator.validate_income1(record)
expect(record.errors["income1"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
end
it "adds errors if buyer 2 has income below 0" do
record.income2 = -2
financial_validator.validate_income2(record)
expect(record.errors["income2"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.outside_london_income_range"))
end
it "adds errors when combined income is over 90_000" do it "adds errors when combined income is over 90_000" do
record.income1 = 55_000 record.income1 = 55_000
record.income2 = 40_000 record.income2 = 40_000

6
spec/requests/organisation_relationships_controller_spec.rb

@ -113,7 +113,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end end
it "shows the pagination count" do it "shows the pagination count" do
expect(page).to have_content("1 total agents") expect(page).to have_content("1 total managing agents")
end end
end end
@ -421,7 +421,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end end
it "shows the pagination count" do it "shows the pagination count" do
expect(page).to have_content("1 total agents") expect(page).to have_content("1 total managing agents")
end end
end end
@ -637,7 +637,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end end
it "shows the pagination count" do it "shows the pagination count" do
expect(page).to have_content("1 total agents") expect(page).to have_content("1 total managing agents")
end end
it "shows remove link(s)" do it "shows remove link(s)" do

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

@ -149,7 +149,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
field_73: "M", field_73: "M",
field_44: "17", field_44: "17",
field_45: "18", field_45: "826",
field_47: "P", field_47: "P",
field_51: "C", field_51: "C",
@ -1594,6 +1594,17 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
expect(parser.log.nationality_all_group).to be(826) expect(parser.log.nationality_all_group).to be(826)
end end
end end
context "when field_45 is not a valid option" do
let(:attributes) { setup_section_params.merge({ field_45: "123123" }) }
it "is correctly set" do
parser.log.save!
expect(parser.log.nationality_all).to be(nil)
expect(parser.log.nationality_all_group).to be(nil)
expect(parser.errors["field_45"]).to include("Select a valid nationality")
end
end
end end
describe "soft validations" do describe "soft validations" do

26
spec/services/bulk_upload/sales/year2024/row_parser_spec.rb

@ -57,14 +57,14 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do
field_31: "32", field_31: "32",
field_32: "M", field_32: "M",
field_33: "12", field_33: "12",
field_34: "18", field_34: "28",
field_35: "1", field_35: "1",
field_36: "1", field_36: "1",
field_37: "R", field_37: "R",
field_38: "32", field_38: "32",
field_39: "F", field_39: "F",
field_40: "17", field_40: "17",
field_41: "13", field_41: "28",
field_42: "2", field_42: "2",
field_43: "1", field_43: "1",
field_44: "0", field_44: "0",
@ -1208,6 +1208,17 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do
expect(parser.log.nationality_all_group).to be(826) expect(parser.log.nationality_all_group).to be(826)
end end
end end
context "when field_34 is not a valid option" do
let(:attributes) { setup_section_params.merge({ field_34: "123123" }) }
it "is correctly set" do
parser.valid?
expect(parser.log.nationality_all).to be(nil)
expect(parser.log.nationality_all_group).to be(nil)
expect(parser.errors["field_34"]).to include("Select a valid nationality")
end
end
end end
describe "#nationality_all_buyer2" do describe "#nationality_all_buyer2" do
@ -1282,6 +1293,17 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do
expect(parser.log.nationality_all_buyer2_group).to be(826) expect(parser.log.nationality_all_buyer2_group).to be(826)
end end
end end
context "when field_41 is not a valid option" do
let(:attributes) { setup_section_params.merge({ field_41: "123123" }) }
it "is correctly set" do
parser.valid?
expect(parser.log.nationality_all_buyer2).to be(nil)
expect(parser.log.nationality_all_buyer2_group).to be(nil)
expect(parser.errors["field_41"]).to include("Select a valid nationality")
end
end
end end
describe "#buy2living" do describe "#buy2living" do

15
spec/services/merge/merge_organisations_service_spec.rb

@ -221,19 +221,21 @@ RSpec.describe Merge::MergeOrganisationsService do
expect(absorbed_scheme.locations.count).to eq(1) expect(absorbed_scheme.locations.count).to eq(1)
absorbed_location = absorbed_scheme.locations.first absorbed_location = absorbed_scheme.locations.first
expect(absorbed_scheme.startdate).to eq(Time.zone.today + 1.month) expected_date = Time.zone.today + 1.month
expect(absorbed_location.startdate).to eq(Time.zone.today + 1.month) expect(absorbed_scheme.startdate).to eq(expected_date.in_time_zone)
expect(absorbed_location.startdate).to eq(expected_date.in_time_zone)
end end
it "deactivates schemes and locations on the merged organisation on the startdate" do it "deactivates schemes and locations on the merged organisation on the startdate" do
merge_organisations_service.call merge_organisations_service.call
expected_date = Time.zone.today + 1.month
expect(scheme.owning_organisation).to eq(merging_organisation) expect(scheme.owning_organisation).to eq(merging_organisation)
expect(location.scheme).to eq(scheme) expect(location.scheme).to eq(scheme)
expect(scheme.scheme_deactivation_periods.count).to eq(1) expect(scheme.scheme_deactivation_periods.count).to eq(1)
expect(scheme.scheme_deactivation_periods.first.deactivation_date).to eq(Time.zone.today + 1.month) expect(scheme.scheme_deactivation_periods.first.deactivation_date).to eq(expected_date.in_time_zone)
expect(location.location_deactivation_periods.count).to eq(1) expect(location.location_deactivation_periods.count).to eq(1)
expect(location.location_deactivation_periods.first.deactivation_date).to eq(Time.zone.today + 1.month) expect(location.location_deactivation_periods.first.deactivation_date).to eq(expected_date.in_time_zone)
end end
end end
end end
@ -376,15 +378,16 @@ RSpec.describe Merge::MergeOrganisationsService do
expect(absorbed_scheme.locations.count).to eq(1) expect(absorbed_scheme.locations.count).to eq(1)
absorbed_location = absorbed_scheme.locations.first absorbed_location = absorbed_scheme.locations.first
expected_reactivation_date = Time.zone.today + 1.month
expect(absorbed_scheme.startdate).to eq(Time.zone.today) expect(absorbed_scheme.startdate).to eq(Time.zone.today)
expect(absorbed_scheme.scheme_deactivation_periods.count).to eq(1) expect(absorbed_scheme.scheme_deactivation_periods.count).to eq(1)
expect(absorbed_scheme.scheme_deactivation_periods.first.deactivation_date).to eq(Time.zone.today) expect(absorbed_scheme.scheme_deactivation_periods.first.deactivation_date).to eq(Time.zone.today)
expect(absorbed_scheme.scheme_deactivation_periods.first.reactivation_date).to eq(Time.zone.today + 1.month) expect(absorbed_scheme.scheme_deactivation_periods.first.reactivation_date).to eq(expected_reactivation_date.in_time_zone)
expect(absorbed_location.startdate).to eq(Time.zone.today) expect(absorbed_location.startdate).to eq(Time.zone.today)
expect(absorbed_location.location_deactivation_periods.count).to eq(1) expect(absorbed_location.location_deactivation_periods.count).to eq(1)
expect(absorbed_location.location_deactivation_periods.first.deactivation_date).to eq(Time.zone.today) expect(absorbed_location.location_deactivation_periods.first.deactivation_date).to eq(Time.zone.today)
expect(absorbed_location.location_deactivation_periods.first.reactivation_date).to eq(Time.zone.today + 1.month) expect(absorbed_location.location_deactivation_periods.first.reactivation_date).to eq(expected_reactivation_date.in_time_zone)
end end
it "deactivates schemes and locations on the merged organisation" do it "deactivates schemes and locations on the merged organisation" do

Loading…
Cancel
Save