Browse Source

Merge branch 'main' into update-test-file-generation

pull/2868/head
kosiakkatrina 6 months ago committed by GitHub
parent
commit
e75bb78933
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 12
      .github/workflows/run_tests.yml
  2. 2
      Gemfile
  3. 4
      Gemfile.lock
  4. 2
      app/controllers/lettings_logs_controller.rb
  5. 4
      app/controllers/organisations_controller.rb
  6. 2
      app/controllers/sales_logs_controller.rb
  7. 3
      app/models/lettings_log.rb
  8. 2
      app/models/log.rb
  9. 3
      app/models/sales_log.rb
  10. 6
      app/models/validations/financial_validations.rb
  11. 4
      app/models/validations/soft_validations.rb
  12. 6
      app/services/exports/organisation_export_service.rb
  13. 1
      app/services/exports/user_export_service.rb
  14. 16
      app/services/feature_toggle.rb
  15. 2
      app/views/locations/check_answers.html.erb
  16. 2
      app/views/locations/show.html.erb
  17. 2
      app/views/schemes/check_answers.html.erb
  18. 2
      app/views/schemes/show.html.erb
  19. 2
      app/views/users/show.html.erb
  20. 4
      config/environments/production.rb
  21. 4
      config/environments/review.rb
  22. 4
      config/environments/staging.rb
  23. 4
      config/locales/validations/sales/2024/bulk_upload.en.yml
  24. 2
      docker-compose.yml
  25. 20
      lib/tasks/clear_invalid_benefits.rake
  26. 2
      package.json
  27. 27
      spec/features/lettings_log_spec.rb
  28. 27
      spec/features/sales_log_spec.rb
  29. 2
      spec/fixtures/exports/user.xml
  30. 95
      spec/lib/tasks/clear_invalid_benefits_spec.rb
  31. 14
      spec/models/lettings_log_spec.rb
  32. 16
      spec/models/sales_log_spec.rb
  33. 14
      spec/models/validations/financial_validations_spec.rb
  34. 28
      spec/models/validations/soft_validations_spec.rb
  35. 2
      spec/requests/form_controller_spec.rb
  36. 2
      spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb
  37. 2
      spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb
  38. 2
      spec/services/exports/organisation_export_service_spec.rb
  39. 2
      spec/services/exports/user_export_service_spec.rb
  40. 1649
      yarn.lock

12
.github/workflows/run_tests.yml

@ -20,7 +20,7 @@ jobs:
services:
postgres:
image: postgres:13.5
image: postgres:13.18
env:
POSTGRES_PASSWORD: password
POSTGRES_USER: postgres
@ -79,7 +79,7 @@ jobs:
services:
postgres:
image: postgres:13.5
image: postgres:13.18
env:
POSTGRES_PASSWORD: password
POSTGRES_USER: postgres
@ -137,7 +137,7 @@ jobs:
services:
postgres:
image: postgres:13.5
image: postgres:13.18
env:
POSTGRES_PASSWORD: password
POSTGRES_USER: postgres
@ -195,7 +195,7 @@ jobs:
services:
postgres:
image: postgres:13.5
image: postgres:13.18
env:
POSTGRES_PASSWORD: password
POSTGRES_USER: postgres
@ -254,7 +254,7 @@ jobs:
services:
postgres:
image: postgres:13.5
image: postgres:13.18
env:
POSTGRES_PASSWORD: password
POSTGRES_USER: postgres
@ -313,7 +313,7 @@ jobs:
services:
postgres:
image: postgres:13.5
image: postgres:13.18
env:
POSTGRES_PASSWORD: password
POSTGRES_USER: postgres

2
Gemfile

@ -90,7 +90,7 @@ group :development do
# Display performance information such as SQL time and flame graphs for each request in your browser.
# Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
gem "erb_lint", require: false
gem "rack-mini-profiler", "~> 2.0"
gem "rack-mini-profiler", "~> 3.3.0"
gem "rubocop-govuk", "4.3.0", require: false
gem "rubocop-performance", require: false
gem "rubocop-rails", require: false

4
Gemfile.lock

@ -340,7 +340,7 @@ GEM
rack (3.1.8)
rack-attack (6.7.0)
rack (>= 1.0, < 4)
rack-mini-profiler (2.3.4)
rack-mini-profiler (3.3.1)
rack (>= 1.2.0)
rack-session (2.0.0)
rack (>= 3.0.0)
@ -581,7 +581,7 @@ DEPENDENCIES
pundit
rack (>= 2.2.6.3)
rack-attack
rack-mini-profiler (~> 2.0)
rack-mini-profiler (~> 3.3.0)
rails (~> 7.2.2)
rails_admin (~> 3.1)
redcarpet (~> 3.6)

2
app/controllers/lettings_logs_controller.rb

@ -22,7 +22,7 @@ class LettingsLogsController < LogsController
@total_count = all_logs.size
@unresolved_count = all_logs.unresolved.assigned_to(current_user).count
@filter_type = "lettings_logs"
@duplicate_sets_count = FeatureToggle.duplicate_summary_enabled? && !current_user.support? ? duplicate_sets_count(current_user, current_user.organisation) : 0
@duplicate_sets_count = !current_user.support? ? duplicate_sets_count(current_user, current_user.organisation) : 0
render "logs/index"
end

4
app/controllers/organisations_controller.rb

@ -186,7 +186,7 @@ class OrganisationsController < ApplicationController
@total_count = organisation_logs.size
@log_type = :lettings
@filter_type = "lettings_logs"
@duplicate_sets_count = FeatureToggle.duplicate_summary_enabled? ? duplicate_sets_count(current_user, @organisation) : 0
@duplicate_sets_count = duplicate_sets_count(current_user, @organisation)
render "logs", layout: "application"
end
@ -218,7 +218,7 @@ class OrganisationsController < ApplicationController
@total_count = organisation_logs.size
@log_type = :sales
@filter_type = "sales_logs"
@duplicate_sets_count = FeatureToggle.duplicate_summary_enabled? ? duplicate_sets_count(current_user, @organisation) : 0
@duplicate_sets_count = duplicate_sets_count(current_user, @organisation)
render "logs", layout: "application"
end

2
app/controllers/sales_logs_controller.rb

@ -24,7 +24,7 @@ class SalesLogsController < LogsController
@searched = search_term.presence
@total_count = all_logs.size
@filter_type = "sales_logs"
@duplicate_sets_count = FeatureToggle.duplicate_summary_enabled? && !current_user.support? ? duplicate_sets_count(current_user, current_user.organisation) : 0
@duplicate_sets_count = !current_user.support? ? duplicate_sets_count(current_user, current_user.organisation) : 0
render "logs/index"
end

3
app/models/lettings_log.rb

@ -779,8 +779,7 @@ private
not_required << "previous_la_known" if postcode_known?
not_required << "tshortfall" if tshortfall_unknown?
not_required << "tenancylength" if tenancylength_optional?
not_required |= %w[address_line2 county postcode_full] if startdate && collection_start_year_for_date(startdate) >= 2023
not_required += %w[address_line2 county]
not_required
end

2
app/models/log.rb

@ -110,7 +110,7 @@ class Log < ApplicationRecord
self.address_line2 = nil
self.town_or_city = nil
self.county = nil
self.postcode_full = postcode_full_input
self.postcode_full = postcode_full_input if postcode_full_input.match(POSTCODE_REGEXP)
process_postcode_changes!
else
self.uprn = uprn_selection

3
app/models/sales_log.rb

@ -132,8 +132,7 @@ class SalesLog < Log
not_required << "mortlen" if mortlen_optional?
not_required << "frombeds" if frombeds_optional?
not_required << "deposit" if form.start_year_2024_or_later? && stairowned_100?
not_required |= %w[address_line2 county postcode_full] if saledate && collection_start_year_for_date(saledate) >= 2023
not_required += %w[address_line2 county]
not_required
end

6
app/models/validations/financial_validations.rb

@ -11,14 +11,14 @@ module Validations::FinancialValidations
end
end
EMPLOYED_STATUSES = [1, 0].freeze
EMPLOYED_STATUSES = [1, 2].freeze
def validate_net_income_uc_proportion(record)
(1..8).any? do |n|
economic_status = record["ecstat#{n}"]
is_employed = EMPLOYED_STATUSES.include?(economic_status)
relationship = record["relat#{n}"]
is_partner_or_main = relationship == "P" || (relationship.nil? && economic_status.present?)
if is_employed && is_partner_or_main && record.benefits&.zero?
is_partner_or_main = relationship == "P" || n == 1
if is_employed && is_partner_or_main && record.benefits == 1
record.errors.add :benefits, I18n.t("validations.lettings.financial.benefits.part_or_full_time")
end
end

4
app/models/validations/soft_validations.rb

@ -84,6 +84,8 @@ module Validations::SoftValidations
end
def all_tenants_age_and_gender_information_completed?
return false if hhmemb.present? && hhmemb > 8
person_count = hhmemb || 8
(1..person_count).all? do |n|
@ -235,6 +237,8 @@ private
end
def all_male_tenants_in_the_household?
return false if hhmemb.present? && hhmemb > 8
person_count = hhmemb || 8
(1..person_count).all? do |n|

6
app/services/exports/organisation_export_service.rb

@ -56,11 +56,13 @@ module Exports
def apply_cds_transformation(organisation)
attribute_hash = organisation.attributes
attribute_hash["deleted_at"] = organisation.discarded_at
attribute_hash["deleted_at"] = organisation.discarded_at&.iso8601
attribute_hash["dsa_signed"] = organisation.data_protection_confirmed?
attribute_hash["dsa_signed_at"] = organisation.data_protection_confirmation&.signed_at
attribute_hash["dsa_signed_at"] = organisation.data_protection_confirmation&.signed_at&.iso8601
attribute_hash["dpo_email"] = organisation.data_protection_confirmation&.data_protection_officer_email
attribute_hash["provider_type"] = organisation.provider_type_before_type_cast
attribute_hash["merge_date"] = organisation.merge_date&.iso8601
attribute_hash["available_from"] = organisation.available_from&.iso8601
attribute_hash["profit_status"] = nil # will need update when we add the field to the org
attribute_hash["group"] = nil # will need update when we add the field to the org

1
app/services/exports/user_export_service.rb

@ -60,6 +60,7 @@ module Exports
attribute_hash["organisation_name"] = user.organisation.name
attribute_hash["active"] = user.active?
attribute_hash["phone"] = [user.phone, user.phone_extension].compact.join(" ")
attribute_hash["last_sign_in_at"] = user.last_sign_in_at&.iso8601
attribute_hash
end
end

16
app/services/feature_toggle.rb

@ -11,10 +11,6 @@ class FeatureToggle
!Rails.env.development?
end
def self.duplicate_summary_enabled?
true
end
def self.service_unavailable?
false
end
@ -23,18 +19,6 @@ class FeatureToggle
false
end
def self.delete_scheme_enabled?
true
end
def self.delete_location_enabled?
true
end
def self.delete_user_enabled?
true
end
def self.local_storage?
Rails.env.development?
end

2
app/views/locations/check_answers.html.erb

@ -42,7 +42,7 @@
<% if LocationPolicy.new(current_user, @location).create? %>
<div class="govuk-button-group">
<%= govuk_button_to "Save and return to locations", scheme_location_confirm_path(@scheme, @location, route: params[:route]), method: :patch %>
<% if LocationPolicy.new(current_user, @location).delete? && FeatureToggle.delete_location_enabled? %>
<% if LocationPolicy.new(current_user, @location).delete? %>
<%= delete_location_link(@location) %>
<% end %>
<%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %>

2
app/views/locations/show.html.erb

@ -51,6 +51,6 @@
<%= toggle_location_link(@location) %>
<% end %>
<% if LocationPolicy.new(current_user, @location).delete? && FeatureToggle.delete_location_enabled? %>
<% if LocationPolicy.new(current_user, @location).delete? %>
<%= delete_location_link(@location) %>
<% end %>

2
app/views/schemes/check_answers.html.erb

@ -24,7 +24,7 @@
<%= f.govuk_submit button_label %>
<% end %>
<% if SchemePolicy.new(current_user, @scheme).delete? && FeatureToggle.delete_scheme_enabled? %>
<% if SchemePolicy.new(current_user, @scheme).delete? %>
<%= delete_scheme_link(@scheme) %>
<% end %>
<% end %>

2
app/views/schemes/show.html.erb

@ -56,6 +56,6 @@
<%= toggle_scheme_link(@scheme) %>
<% end %>
<% if SchemePolicy.new(current_user, @scheme).delete? && FeatureToggle.delete_scheme_enabled? %>
<% if SchemePolicy.new(current_user, @scheme).delete? %>
<%= delete_scheme_link(@scheme) %>
<% end %>

2
app/views/users/show.html.erb

@ -157,7 +157,7 @@
</span>
<% end %>
<% end %>
<% if UserPolicy.new(current_user, @user).delete? && FeatureToggle.delete_user_enabled? %>
<% if UserPolicy.new(current_user, @user).delete? %>
<%= delete_user_link(@user) %>
<% end %>
</div>

4
config/environments/production.rb

@ -35,10 +35,10 @@ Rails.application.configure do
# Assume all access to the app is happening through a SSL-terminating reverse proxy.
# Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies.
# config.assume_ssl = true
config.assume_ssl = true
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = true
# config.force_ssl = true
# Skip http-to-https redirect for the default health check endpoint.
# config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } }

4
config/environments/review.rb

@ -39,6 +39,10 @@ Rails.application.configure do
# config.action_cable.url = 'wss://example.com/cable'
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
# Assume all access to the app is happening through a SSL-terminating reverse proxy.
# Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies.
config.assume_ssl = true
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true

4
config/environments/staging.rb

@ -39,6 +39,10 @@ Rails.application.configure do
# config.action_cable.url = 'wss://example.com/cable'
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
# Assume all access to the app is happening through a SSL-terminating reverse proxy.
# Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies.
config.assume_ssl = true
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true

4
config/locales/validations/sales/2024/bulk_upload.en.yml

@ -18,8 +18,8 @@ en:
owning_organisation:
not_found: "The owning organisation code is incorrect."
not_stock_owner: "The owning organisation code provided is for an organisation that does not own stock."
not_permitted:
support: "This owning organisation is not affiliated with %(name)."
not_permitted:
support: "This owning organisation is not affiliated with %{name}."
not_support: "You do not have permission to add logs for this owning organisation."
assigned_to:
not_found: "User with the specified email could not be found."

2
docker-compose.yml

@ -5,7 +5,7 @@ volumes:
services:
db:
image: postgres:13.5-alpine
image: postgres:13.18-alpine
restart: always
# To preserve data between runs of docker-compose, we mount a folder from the host machine.
volumes:

20
lib/tasks/clear_invalid_benefits.rake

@ -0,0 +1,20 @@
desc "clear benefit value for logs that would trigger the validation"
task clear_invalid_benefits: :environment do
validation_trigger_condition = "ecstat1 = 1 OR ecstat1 = 2 OR (ecstat2 = 1 AND relat2 = 'P') OR (ecstat2 = 2 AND relat2 = 'P') OR (ecstat3 = 1 AND relat3 = 'P') OR (ecstat3 = 2 AND relat3 = 'P') OR (ecstat4 = 1 AND relat4 = 'P') OR (ecstat4 = 2 AND relat4 = 'P') OR (ecstat5 = 1 AND relat5 = 'P') OR (ecstat5 = 2 AND relat5 = 'P') OR (ecstat6 = 1 AND relat6 = 'P') OR (ecstat6 = 2 AND relat6 = 'P') OR (ecstat7 = 1 AND relat7 = 'P') OR (ecstat7 = 2 AND relat7 = 'P') OR (ecstat8 = 1 AND relat8 = 'P') OR (ecstat8 = 2 AND relat8 = 'P')"
LettingsLog.filter_by_year(2024).where(status: "pending", status_cache: "completed", benefits: 1).where(validation_trigger_condition).find_each do |log|
log.benefits = nil
log.status_cache = log.calculate_status
log.skip_update_status = true
unless log.save
Rails.logger.info "Could not save changes to pending lettings log #{log.id}"
end
end
LettingsLog.filter_by_year(2024).visible.where(benefits: 1).where(validation_trigger_condition).find_each do |log|
log.benefits = nil
unless log.save
Rails.logger.info "Could not save changes to lettings log #{log.id}"
end
end
end

2
package.json

@ -11,7 +11,7 @@
"@hotwired/stimulus": "^3.0.0",
"@stimulus/polyfills": "^2.0.0",
"@webcomponents/webcomponentsjs": "^2.6.0",
"@x-govuk/govuk-prototype-components": "^3.0.1",
"@x-govuk/govuk-prototype-components": "^3.0.9",
"accessible-autocomplete": "^2.0.3",
"babel-loader": "^8.2.3",
"babel-plugin-macros": "^3.1.0",

27
spec/features/lettings_log_spec.rb

@ -1018,6 +1018,33 @@ RSpec.describe "Lettings Log Features" do
end
end
context "and the user selects 'address_not_listed' when partial postcode is entered" do
before do
fill_in("lettings_log[address_line1_input]", with: "Address line 1")
fill_in("lettings_log[postcode_full_input]", with: "AA1")
click_button("Search")
choose "The address is not listed, I want to enter the address manually"
click_button("Save and continue")
end
it "sets correct address fields" do
lettings_log.reload
expect(lettings_log.uprn_known).to eq(0) # no
expect(lettings_log.uprn).to eq(nil)
expect(lettings_log.uprn_confirmed).to eq(nil)
expect(lettings_log.uprn_selection).to eq("uprn_not_listed")
expect(lettings_log.postcode_known).to eq(nil)
expect(lettings_log.postcode_full).to eq(nil)
expect(lettings_log.address_line1).to eq("Address line 1")
expect(lettings_log.address_line2).to eq(nil)
expect(lettings_log.town_or_city).to eq(nil)
expect(lettings_log.address_line1_input).to eq("Address line 1")
expect(lettings_log.postcode_full_input).to eq("AA1")
expect(lettings_log.address_search_value_check).to eq(nil)
expect(lettings_log.la).to eq(nil)
end
end
context "and the user selects 'address_not_listed' and then changes their mind and selects an address" do
before do
fill_in("lettings_log[address_line1_input]", with: "Address line 1")

27
spec/features/sales_log_spec.rb

@ -599,6 +599,33 @@ RSpec.describe "Sales Log Features" do
end
end
context "and the user selects 'address_not_listed' when partial postcode is given" do
before do
fill_in("sales_log[address_line1_input]", with: "Address line 1")
fill_in("sales_log[postcode_full_input]", with: "1AA")
click_button("Search")
choose "The address is not listed, I want to enter the address manually"
click_button("Save and continue")
end
it "sets correct address fields" do
sales_log.reload
expect(sales_log.uprn_known).to eq(0) # no
expect(sales_log.uprn).to eq(nil)
expect(sales_log.uprn_confirmed).to eq(nil)
expect(sales_log.uprn_selection).to eq("uprn_not_listed")
expect(sales_log.pcodenk).to eq(nil)
expect(sales_log.postcode_full).to eq(nil)
expect(sales_log.address_line1).to eq("Address line 1")
expect(sales_log.address_line2).to eq(nil)
expect(sales_log.town_or_city).to eq(nil)
expect(sales_log.address_line1_input).to eq("Address line 1")
expect(sales_log.postcode_full_input).to eq("1AA")
expect(sales_log.address_search_value_check).to eq(nil)
expect(sales_log.la).to eq(nil)
end
end
context "and the user selects 'address_not_listed' and then changes their mind and selects an address" do
before do
fill_in("sales_log[address_line1_input]", with: "Address line 1")

2
spec/fixtures/exports/user.xml vendored

@ -6,7 +6,7 @@
<name>Danny Rojas</name>
<organisation_id>{organisation_id}</organisation_id>
<sign_in_count>5</sign_in_count>
<last_sign_in_at/>
<last_sign_in_at>2022-03-03T00:00:00+00:00</last_sign_in_at>
<role>data_provider</role>
<phone>1234512345123 123</phone>
<is_dpo>false</is_dpo>

95
spec/lib/tasks/clear_invalid_benefits_spec.rb

@ -0,0 +1,95 @@
require "rails_helper"
require "rake"
RSpec.describe "clear_invalid_benefits" do
describe ":clear_invalid_benefits", type: :task do
subject(:task) { Rake::Task["clear_invalid_benefits"] }
before do
Rake.application.rake_require("tasks/clear_invalid_benefits")
Rake::Task.define_task(:environment)
task.reenable
end
context "when the rake task is run" do
context "and there is a completed lettings log that trips the validation" do
let(:log) { build(:lettings_log, :completed, ecstat1: 1, benefits: 1, assigned_to: create(:user), period: nil) }
before do
log.status = "completed"
log.skip_update_status = true
log.save!(validate: false)
end
it "clear benefits and sets the log to in progress" do
expect(log.reload.benefits).to eq(1)
task.invoke
log.reload
expect(log.benefits).to eq(nil)
expect(log.status).to eq("in_progress")
end
end
context "and there is a lettings log that trips the validation for person 2" do
let(:log) { build(:lettings_log, :completed, ecstat2: 2, benefits: 1, relat2: "P", assigned_to: create(:user), period: nil) }
before do
log.status = "completed"
log.skip_update_status = true
log.save!(validate: false)
end
it "clear benefits and sets the log to in progress" do
expect(log.reload.benefits).to eq(1)
task.invoke
log.reload
expect(log.benefits).to eq(nil)
expect(log.status).to eq("in_progress")
end
end
context "and there is a lettings log that trips the validation for person 8" do
let(:log) { build(:lettings_log, :completed, ecstat8: 1, benefits: 1, relat8: "P", assigned_to: create(:user), period: nil) }
before do
log.status = "completed"
log.skip_update_status = true
log.save!(validate: false)
end
it "clear benefits and sets the log to in progress" do
expect(log.reload.benefits).to eq(1)
task.invoke
log.reload
expect(log.benefits).to eq(nil)
expect(log.status).to eq("in_progress")
end
end
context "and there is a pending lettings log that trips the validation" do
let(:log) { build(:lettings_log, :completed, ecstat1: 1, benefits: 1, assigned_to: create(:user), period: nil) }
before do
log.status = "pending"
log.status_cache = "completed"
log.skip_update_status = true
log.save!(validate: false)
end
it "clears benefits and updates the status cache" do
expect(log.reload.benefits).to eq(1)
task.invoke
log.reload
expect(log.benefits).to eq(nil)
expect(log.status_cache).to eq("in_progress")
end
it "does not change the log status" do
task.invoke
log.reload
expect(log.status).to eq("pending")
end
end
end
end
end

14
spec/models/lettings_log_spec.rb

@ -861,19 +861,6 @@ RSpec.describe LettingsLog do
end
end
context "when startdate is before 2023" do
let(:lettings_log) { build(:lettings_log, startdate: Time.zone.parse("2022-07-01")) }
it "returns optional fields" do
expect(lettings_log.optional_fields).to eq(%w[
tenancycode
propcode
chcharge
tenancylength
])
end
end
context "when startdate is after 2023" do
let(:lettings_log) { build(:lettings_log, startdate: Time.zone.parse("2023-07-01")) }
@ -885,7 +872,6 @@ RSpec.describe LettingsLog do
tenancylength
address_line2
county
postcode_full
])
end
end

16
spec/models/sales_log_spec.rb

@ -76,21 +76,6 @@ RSpec.describe SalesLog, type: :model do
end
describe "#optional_fields" do
context "when saledate is before 2023" do
let(:sales_log) { build(:sales_log, saledate: Time.zone.parse("2022-07-01")) }
it "returns optional fields" do
expect(sales_log.optional_fields).to eq(%w[
purchid
othtype
buyers_organisations
proplen
mortlen
frombeds
])
end
end
context "when saledate is after 2023" do
let(:sales_log) { build(:sales_log, saledate: Time.zone.parse("2023-07-01")) }
@ -101,7 +86,6 @@ RSpec.describe SalesLog, type: :model do
buyers_organisations
address_line2
county
postcode_full
])
end
end

14
spec/models/validations/financial_validations_spec.rb

@ -36,36 +36,36 @@ RSpec.describe Validations::FinancialValidations do
describe "benefits proportion validations" do
context "when the proportion is all" do
it "validates that the lead tenant is not in full time employment" do
record.benefits = 0
record.benefits = 1
record.ecstat1 = 1
financial_validator.validate_net_income_uc_proportion(record)
expect(record.errors["benefits"]).to include(match I18n.t("validations.lettings.financial.benefits.part_or_full_time"))
end
it "validates that the lead tenant is not in part time employment" do
record.benefits = 0
record.ecstat1 = 0
record.benefits = 1
record.ecstat1 = 2
financial_validator.validate_net_income_uc_proportion(record)
expect(record.errors["benefits"]).to include(match I18n.t("validations.lettings.financial.benefits.part_or_full_time"))
end
it "expects that the lead tenant is not in full-time or part-time employment" do
record.benefits = 0
record.benefits = 1
record.ecstat1 = 4
financial_validator.validate_net_income_uc_proportion(record)
expect(record.errors["benefits"]).to be_empty
end
it "validates that the tenant’s partner is not in full time employment" do
record.benefits = 0
record.ecstat2 = 0
record.benefits = 1
record.ecstat2 = 2
record.relat2 = "P"
financial_validator.validate_net_income_uc_proportion(record)
expect(record.errors["benefits"]).to include(match I18n.t("validations.lettings.financial.benefits.part_or_full_time"))
end
it "expects that the tenant’s partner is not in full-time or part-time employment" do
record.benefits = 0
record.benefits = 1
record.ecstat2 = 4
record.relat2 = "P"
financial_validator.validate_net_income_uc_proportion(record)

28
spec/models/validations/soft_validations_spec.rb

@ -174,6 +174,20 @@ RSpec.describe Validations::SoftValidations do
end
end
context "when all tenants are male and household members are over 8" do
it "does not show the interruption screen" do
(1..8).each do |n|
record.send("sex#{n}=", "M")
record.send("age#{n}=", 30)
record.send("age#{n}_known=", 0)
record.send("details_known_#{n}=", 0) unless n == 1
end
record.preg_occ = 1
record.hhmemb = 9
expect(record.all_male_tenants_in_a_pregnant_household?).to be false
end
end
context "when female tenants are under 16" do
it "shows the interruption screen" do
record.age2 = 14
@ -219,6 +233,20 @@ RSpec.describe Validations::SoftValidations do
expect(record.female_in_pregnant_household_in_soft_validation_range?).to be false
end
end
context "when number of household members is over 8" do
it "does not show the interruption screen" do
(1..8).each do |n|
record.send("sex#{n}=", "F")
record.send("age#{n}=", 50)
record.send("age#{n}_known=", 0)
record.send("details_known_#{n}=", 0) unless n == 1
end
record.preg_occ = 1
record.hhmemb = 9
expect(record.female_in_pregnant_household_in_soft_validation_range?).to be false
end
end
end
describe "major repairs date soft validations" do

2
spec/requests/form_controller_spec.rb

@ -1681,7 +1681,7 @@ RSpec.describe FormController, type: :request do
end
before do
completed_lettings_log.update!(ecstat1: 1, earnings: 130, hhmemb: 1) # we're not routing to that page, so it gets cleared?
completed_lettings_log.update!(ecstat1: 1, earnings: 130, hhmemb: 1, benefits: 4) # we're not routing to that page, so it gets cleared?
allow(completed_lettings_log).to receive(:net_income_soft_validation_triggered?).and_return(true)
allow(completed_lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day)
allow(completed_lettings_log.form).to receive(:edit_end_date).and_return(Time.zone.today + 2.months)

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

@ -206,7 +206,7 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
field_122: "2300",
field_121: "2",
field_123: "1",
field_124: "1",
field_124: "4",
field_126: "4",
field_128: "1234.56",

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

@ -227,7 +227,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
field_118: "2",
field_119: "2300",
field_120: "1",
field_121: "1",
field_121: "4",
field_123: "4",
field_125: "1234.56",

2
spec/services/exports/organisation_export_service_spec.rb

@ -17,7 +17,7 @@ RSpec.describe Exports::OrganisationExportService do
def replace_entity_ids(organisation, export_template)
export_template.sub!(/\{id\}/, organisation["id"].to_s)
export_template.sub!(/\{name\}/, organisation["name"])
export_template.sub!(/\{dsa_signed_at\}/, organisation.data_protection_confirmation&.signed_at.to_s)
export_template.sub!(/\{dsa_signed_at\}/, organisation.data_protection_confirmation&.signed_at&.iso8601)
export_template.sub!(/\{dpo_email\}/, organisation.data_protection_confirmation&.data_protection_officer_email)
end

2
spec/services/exports/user_export_service_spec.rb

@ -43,7 +43,7 @@ RSpec.describe Exports::UserExportService do
end
context "and one user is available for export" do
let!(:user) { create(:user, organisation:, name: "Danny Rojas", phone_extension: "123") }
let!(:user) { create(:user, organisation:, name: "Danny Rojas", phone_extension: "123", last_sign_in_at: Time.zone.local(2022, 3, 3)) }
it "generates a ZIP export file with the expected filename" do
expect(storage_service).to receive(:write_file).with(expected_zip_filename, any_args)

1649
yarn.lock

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save