Browse Source

Merge branch 'main' into CLDC-3787-Autocomplete-address-search

CLDC-3787-Autocomplete-address-search
Manny Dinssa 2 weeks ago committed by GitHub
parent
commit
4eb152b99e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      .env.example
  2. 2
      Gemfile.lock
  3. 6
      app/components/bulk_upload_error_row_component.html.erb
  4. 2
      app/components/bulk_upload_summary_component.html.erb
  5. 6
      app/controllers/form_controller.rb
  6. 2
      app/helpers/tag_helper.rb
  7. 2
      app/mailers/bulk_upload_mailer.rb
  8. 1
      app/models/bulk_upload_error.rb
  9. 15
      app/models/derived_variables/lettings_log_variables.rb
  10. 3
      app/views/bulk_upload_lettings_results/show.html.erb
  11. 3
      app/views/bulk_upload_sales_results/show.html.erb
  12. 4
      db/migrate/20211126142105_user_case_logs_belong_to_organisation.rb
  13. 2
      db/migrate/20220323094418_create_data_protection_confirmation.rb
  14. 2
      db/migrate/20220427160536_add_created_by_to_case_logs.rb
  15. 6
      db/migrate/20220826093411_add_sales_log.rb
  16. 4
      db/migrate/20221207141947_add_updated_by_to_logs.rb
  17. 2
      db/migrate/20230530094653_add_data_sharing_agreement.rb
  18. 2
      db/migrate/20231121131725_add_sales_managing_organisation.rb
  19. 4
      db/migrate/20240408102550_add_created_by.rb
  20. 10
      db/schema.rb
  21. 20
      lib/tasks/correct_checkbox_values.rake
  22. 2
      spec/components/bulk_upload_error_row_component_spec.rb
  23. 4
      spec/components/bulk_upload_summary_component_spec.rb
  24. 2
      spec/fixtures/files/lettings_log_csv_export_codes_23.csv
  25. 2
      spec/fixtures/files/lettings_log_csv_export_codes_24.csv
  26. 2
      spec/fixtures/files/lettings_log_csv_export_labels_23.csv
  27. 2
      spec/fixtures/files/lettings_log_csv_export_labels_24.csv
  28. 2
      spec/fixtures/files/lettings_log_csv_export_non_support_codes_23.csv
  29. 2
      spec/fixtures/files/lettings_log_csv_export_non_support_codes_24.csv
  30. 2
      spec/fixtures/files/lettings_log_csv_export_non_support_labels_23.csv
  31. 2
      spec/fixtures/files/lettings_log_csv_export_non_support_labels_24.csv
  32. 216
      spec/lib/tasks/correct_checkbox_values_spec.rb
  33. 2
      spec/mailers/bulk_upload_mailer_spec.rb
  34. 62
      spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb

1
.env.example

@ -1,5 +1,6 @@
DB_USERNAME=postgres-user
DB_PASSWORD=postgres-password
DB_HOST=localhost
GOVUK_NOTIFY_API_KEY=<notify-key-here-if-testing-emails-or-admin-users>
OTP_SECRET_ENCRYPTION_KEY="<Generate this using bundle exec rake secret>"

2
Gemfile.lock

@ -337,7 +337,7 @@ GEM
activesupport (>= 3.0.0)
raabro (1.4.0)
racc (1.8.1)
rack (3.1.8)
rack (3.1.10)
rack-attack (6.7.0)
rack (>= 1.0, < 4)
rack-mini-profiler (3.3.1)

6
app/components/bulk_upload_error_row_component.html.erb

@ -37,14 +37,14 @@
<% end %>
<% if potential_errors.any? %>
<h2 class="govuk-heading-m">Potential errors</h2>
<p class="govuk-body">The following groups of cells might have conflicting data. Check the answers and fix any incorrect data.<br><br>If the answers are correct, fix the critical errors and upload the file again. You'll need to confirm that the following data is correct when the file only contains potential errors.</p>
<h2 class="govuk-heading-m">Confirmation needed</h2>
<p class="govuk-body">Potential data discrepancies exist in the following cells.<br><br>Please resolve all critical errors and review the cells with data discrepancies before re-uploading the file. Bulk confirmation of potential discrepancies is accessible only after all critical errors have been resolved.</p>
<%= govuk_table(html_attributes: { class: "no-bottom-border" }) do |table| %>
<%= table.with_head do |head| %>
<% head.with_row do |row| %>
<% row.with_cell(header: true, text: "Cell") %>
<% row.with_cell(header: true, text: "Question") %>
<% row.with_cell(header: true, text: "Potential error") %>
<% row.with_cell(header: true, text: "Confirmation needed") %>
<% row.with_cell(header: true, text: "Specification") %>
<% end %>
<% end %>

2
app/components/bulk_upload_summary_component.html.erb

@ -28,7 +28,7 @@
[bulk_upload.total_logs_count, "total log"],
[setup_errors_count, "error on important questions", "errors on important questions"],
[critical_errors_count, "critical error"],
[potential_errors_count, "potential error"],
[potential_errors_count, "confirmation needed", "confirmations needed"],
) %>
</div>
<% end %>

6
app/controllers/form_controller.rb

@ -155,9 +155,9 @@ private
next unless question_params
if %w[checkbox validation_override].include?(question.type)
if question.type == "checkbox"
question.answer_keys_without_dividers.each do |option|
result[option] = question_params.include?(option) ? 1 : 0
result[option] = 1 if question_params.include?(option)
end
elsif question.type != "date"
result[question.id] = question_params
@ -347,7 +347,7 @@ private
end
def question_missing_response?(responses_for_page, question)
if %w[checkbox validation_override].include?(question.type)
if question.type == "checkbox"
answered = question.answer_keys_without_dividers.map do |option|
session["fields"][option] = @log[option] = params[@log.log_type][question.id].include?(option) ? 1 : 0
params[@log.log_type][question.id].exclude?(option)

2
app/helpers/tag_helper.rb

@ -24,7 +24,7 @@ module TagHelper
processing_error: "Error processing CSV",
important_errors: "Errors on important questions in CSV",
critical_errors: "Critical errors in CSV",
potential_errors: "Potential errors in CSV",
potential_errors: "Confirmation needed in CSV",
logs_uploaded_with_errors: "Logs uploaded with errors",
errors_fixed_in_service: "Errors fixed on site",
logs_uploaded_no_errors: "Logs uploaded with no errors",

2
app/mailers/bulk_upload_mailer.rb

@ -29,7 +29,7 @@ class BulkUploadMailer < NotifyMailer
def send_check_soft_validations_mail(bulk_upload:)
title = "Check your file data"
description = "Some of your #{bulk_upload.year_combo} #{bulk_upload.log_type} data might not be right. Click the link below to review the potential errors, and check your file to see if the data is correct."
description = "We’ve identified potential discrepancies in your #{bulk_upload.year_combo} #{bulk_upload.log_type} data. Please review the flagged information via the link below and cross-reference it with your records to confirm data accuracy."
cta_link = if bulk_upload.lettings?
bulk_upload_lettings_soft_validations_check_url(bulk_upload, page: "confirm-soft-errors")
else

1
app/models/bulk_upload_error.rb

@ -6,6 +6,7 @@ class BulkUploadError < ApplicationRecord
scope :order_by_col, -> { order(Arel.sql("LPAD(col, 10, '0')")) }
scope :important, -> { where(category: "setup") }
scope :potential, -> { where(category: "soft_validation") }
scope :not_potential, -> { where.not(category: "soft_validation").or(where(category: nil)) }
scope :critical, -> { where(category: nil).or(where.not(category: %w[setup soft_validation])) }
scope :critical_or_important, -> { critical.or(important) }
end

15
app/models/derived_variables/lettings_log_variables.rb

@ -154,6 +154,8 @@ module DerivedVariables::LettingsLogVariables
end
reset_address_fields! if is_supported_housing?
set_checkbox_values!
end
private
@ -374,4 +376,17 @@ private
return 2 if rent_type == 4
return 3 if rent_type == 5
end
def set_checkbox_values!
form.questions.select { |q| q.type == "checkbox" }.each do |question|
options = question.answer_keys_without_dividers
next unless options.any? { |option| self[option] == 1 }
options.each do |option|
if self[option].nil?
self[option] = 0
end
end
end
end
end

3
app/views/bulk_upload_lettings_results/show.html.erb

@ -7,7 +7,8 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<span class="govuk-caption-l">Upload lettings logs in bulk (<%= @bulk_upload.year_combo %>)</span>
<h1 class="govuk-heading-l">We found <%= pluralize(@bulk_upload.bulk_upload_errors.count, "error") %> in your file</h1>
<% error_word = @bulk_upload.bulk_upload_errors.not_potential.any? ? "error" : "discrepancy" %>
<h1 class="govuk-heading-l">We found <%= pluralize(@bulk_upload.bulk_upload_errors.count, error_word) %> in your file</h1>
<div class="govuk-body">
Here’s a list of everything that you need to fix your spreadsheet. You can download the <%= govuk_link_to "specification", Forms::BulkUploadForm::PrepareYourFile.new(year: @bulk_upload.year, log_type: "lettings").specification_path, target: "_blank" %> to help you fix the cells in your CSV file.

3
app/views/bulk_upload_sales_results/show.html.erb

@ -7,7 +7,8 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<span class="govuk-caption-l">Upload sales logs in bulk (<%= @bulk_upload.year_combo %>)</span>
<h1 class="govuk-heading-l">We found <%= pluralize(@bulk_upload.bulk_upload_errors.count, "error") %> in your file</h1>
<% error_word = @bulk_upload.bulk_upload_errors.not_potential.any? ? "error" : "discrepancy" %>
<h1 class="govuk-heading-l">We found <%= pluralize(@bulk_upload.bulk_upload_errors.count, error_word) %> in your file</h1>
<div class="govuk-body">
Here’s a list of everything that you need to fix your spreadsheet. You can download the <%= govuk_link_to "specification", Forms::BulkUploadForm::PrepareYourFile.new(year: @bulk_upload.year, log_type: "sales").specification_path, target: "_blank" %> to help you fix the cells in your CSV file.

4
db/migrate/20211126142105_user_case_logs_belong_to_organisation.rb

@ -5,8 +5,8 @@ class UserCaseLogsBelongToOrganisation < ActiveRecord::Migration[6.1]
t.belongs_to :organisation
end
change_table :case_logs, bulk: true do |t|
t.belongs_to :owning_organisation, class_name: "Organisation"
t.belongs_to :managing_organisation, class_name: "Organisation"
t.belongs_to :owning_organisation
t.belongs_to :managing_organisation
end
end

2
db/migrate/20220323094418_create_data_protection_confirmation.rb

@ -2,7 +2,7 @@ class CreateDataProtectionConfirmation < ActiveRecord::Migration[7.0]
def change
create_table :data_protection_confirmations do |t|
t.belongs_to :organisation
t.belongs_to :data_protection_officer, class_name: "User", index: { name: :dpo_user_id }
t.belongs_to :data_protection_officer, index: { name: :dpo_user_id }
t.column :confirmed, :boolean
t.column :old_id, :string
t.column :old_org_id, :string

2
db/migrate/20220427160536_add_created_by_to_case_logs.rb

@ -1,7 +1,7 @@
class AddCreatedByToCaseLogs < ActiveRecord::Migration[7.0]
def change
change_table :case_logs, bulk: true do |t|
t.belongs_to :created_by, class_name: "User"
t.belongs_to :created_by
end
end
end

6
db/migrate/20220826093411_add_sales_log.rb

@ -4,9 +4,9 @@ class AddSalesLog < ActiveRecord::Migration[7.0]
t.integer :status, default: 0
t.datetime :saledate
t.timestamps
t.references :owning_organisation, class_name: "Organisation", foreign_key: { to_table: :organisations, on_delete: :cascade }
t.references :managing_organisation, class_name: "Organisation"
t.references :created_by, class_name: "User"
t.references :owning_organisation, foreign_key: { to_table: :organisations, on_delete: :cascade }
t.references :managing_organisation
t.references :created_by
end
end
end

4
db/migrate/20221207141947_add_updated_by_to_logs.rb

@ -1,10 +1,10 @@
class AddUpdatedByToLogs < ActiveRecord::Migration[7.0]
def change
change_table :lettings_logs, bulk: true do |t|
t.belongs_to :updated_by, class_name: "User"
t.belongs_to :updated_by
end
change_table :sales_logs, bulk: true do |t|
t.belongs_to :updated_by, class_name: "User"
t.belongs_to :updated_by
end
end
end

2
db/migrate/20230530094653_add_data_sharing_agreement.rb

@ -2,7 +2,7 @@ class AddDataSharingAgreement < ActiveRecord::Migration[7.0]
def change
create_table :data_sharing_agreements do |t|
t.belongs_to :organisation
t.belongs_to :data_protection_officer, class_name: "User"
t.belongs_to :data_protection_officer
t.datetime :signed_at, null: false
t.string :organisation_name, null: false

2
db/migrate/20231121131725_add_sales_managing_organisation.rb

@ -1,7 +1,7 @@
class AddSalesManagingOrganisation < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.references :managing_organisation, class_name: "Organisation"
t.references :managing_organisation
end
end
end

4
db/migrate/20240408102550_add_created_by.rb

@ -1,11 +1,11 @@
class AddCreatedBy < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs do |t|
t.references :created_by, class_name: "User"
t.references :created_by
end
change_table :lettings_logs do |t|
t.references :created_by, class_name: "User"
t.references :created_by
end
end
end

10
db/schema.rb

@ -245,14 +245,14 @@ ActiveRecord::Schema[7.2].define(version: 2025_02_17_230008) do
t.integer "hb"
t.integer "hbrentshortfall"
t.integer "property_relet"
t.datetime "mrcdate"
t.datetime "mrcdate", precision: nil
t.integer "incref"
t.datetime "startdate"
t.datetime "startdate", precision: nil
t.integer "armedforces"
t.integer "first_time_property_let_as_social_housing"
t.integer "unitletas"
t.integer "builtype"
t.datetime "voiddate"
t.datetime "voiddate", precision: nil
t.bigint "owning_organisation_id"
t.bigint "managing_organisation_id"
t.integer "renttype"
@ -824,8 +824,8 @@ ActiveRecord::Schema[7.2].define(version: 2025_02_17_230008) do
t.string "name"
t.bigint "organisation_id"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.datetime "current_sign_in_at", precision: nil
t.datetime "last_sign_in_at", precision: nil
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.integer "role"

20
lib/tasks/correct_checkbox_values.rake

@ -0,0 +1,20 @@
desc "Update BU reasonable preference and illness type checkbox values"
task correct_checkbox_values: :environment do
any_reasonpref_selected = "rp_homeless = 1 OR rp_hardship = 1 OR rp_medwel = 1 OR rp_insan_unsat = 1 OR rp_dontknow = 1"
any_reasonpref_is_null = "rp_homeless IS NULL OR rp_hardship IS NULL OR rp_medwel IS NULL OR rp_insan_unsat IS NULL OR rp_dontknow IS NULL"
LettingsLog.filter_by_year(2024).where(reasonpref: 1).where(any_reasonpref_selected).where(any_reasonpref_is_null).find_each do |lettings_log|
unless lettings_log.save
Rails.logger.info("Failed to save reasonpref for LettingsLog with id #{lettings_log.id}: #{lettings_log.errors.full_messages}")
end
end
any_illness_selected = "illness_type_1 = 1 OR illness_type_2 = 1 OR illness_type_3 = 1 OR illness_type_4 = 1 OR illness_type_5 = 1 OR illness_type_6 = 1 OR illness_type_7 = 1 OR illness_type_8 = 1 OR illness_type_9 = 1 OR illness_type_10 = 1"
any_illness_is_null = "illness_type_1 IS NULL OR illness_type_2 IS NULL OR illness_type_3 IS NULL OR illness_type_4 IS NULL OR illness_type_5 IS NULL OR illness_type_6 IS NULL OR illness_type_7 IS NULL OR illness_type_8 IS NULL OR illness_type_9 IS NULL OR illness_type_10 IS NULL"
LettingsLog.filter_by_year(2024).where(illness: 1).where(any_illness_selected).where(any_illness_is_null).find_each do |lettings_log|
unless lettings_log.save
Rails.logger.info("Failed to save illness for LettingsLog with id #{lettings_log.id}: #{lettings_log.errors.full_messages}")
end
end
end

2
spec/components/bulk_upload_error_row_component_spec.rb

@ -148,7 +148,7 @@ RSpec.describe BulkUploadErrorRowComponent, type: :component do
it "renders the potential errors section" do
result = render_inline(described_class.new(bulk_upload_errors:))
expect(result).to have_content("Potential errors")
expect(result).to have_content("Confirmation needed")
end
it "renders the potential error message" do

4
spec/components/bulk_upload_summary_component_spec.rb

@ -64,8 +64,8 @@ RSpec.describe BulkUploadSummaryComponent, type: :component do
it "shows the potential errors status and error count" do
result = render_inline(described_class.new(bulk_upload:))
expect(result).to have_content("Potential errors in CSV")
expect(result).to have_content("2 potential errors")
expect(result).to have_content("Confirmation needed in CSV")
expect(result).to have_content("2 confirmations needed")
expect(result).to have_content("16 total logs")
expect(result).to have_no_content("errors on important")
expect(result).to have_no_content("critical")

2
spec/fixtures/files/lettings_log_csv_export_codes_23.csv vendored

File diff suppressed because one or more lines are too long

2
spec/fixtures/files/lettings_log_csv_export_codes_24.csv vendored

File diff suppressed because one or more lines are too long

2
spec/fixtures/files/lettings_log_csv_export_labels_23.csv vendored

File diff suppressed because one or more lines are too long

2
spec/fixtures/files/lettings_log_csv_export_labels_24.csv vendored

File diff suppressed because one or more lines are too long

2
spec/fixtures/files/lettings_log_csv_export_non_support_codes_23.csv vendored

File diff suppressed because one or more lines are too long

2
spec/fixtures/files/lettings_log_csv_export_non_support_codes_24.csv vendored

File diff suppressed because one or more lines are too long

2
spec/fixtures/files/lettings_log_csv_export_non_support_labels_23.csv vendored

File diff suppressed because one or more lines are too long

2
spec/fixtures/files/lettings_log_csv_export_non_support_labels_24.csv vendored

File diff suppressed because one or more lines are too long

216
spec/lib/tasks/correct_checkbox_values_spec.rb

@ -0,0 +1,216 @@
require "rails_helper"
require "rake"
RSpec.describe "correct_checkbox_values" do
describe ":correct_checkbox_values", type: :task do
subject(:task) { Rake::Task["correct_checkbox_values"] }
let(:organisation) { create(:organisation, rent_periods: [2]) }
let(:user) { create(:user, organisation:) }
before do
Rake.application.rake_require("tasks/correct_checkbox_values")
Rake::Task.define_task(:environment)
task.reenable
end
context "when the rake task is run" do
context "and any of the reasonable_preference_reason options are 1" do
let(:bulk_upload) { create(:bulk_upload, :lettings, year: 2024, rent_type_fix_status: BulkUpload.rent_type_fix_statuses[:not_applied]) }
it "sets the remaining options to 0" do
log = build(:lettings_log, :completed, reasonpref: 1, rp_homeless: 1, rp_hardship: nil, rp_medwel: nil, rp_insan_unsat: nil, rp_dontknow: nil,
bulk_upload:, assigned_to: user)
log.save!(validate: false)
initial_updated_at = log.updated_at
task.invoke
log.reload
expect(log.updated_at).not_to eq(initial_updated_at)
expect(log.status).to eq("completed")
expect(log.rp_homeless).to be(1)
expect(log.rp_hardship).to be(0)
expect(log.rp_medwel).to be(0)
expect(log.rp_insan_unsat).to be(0)
expect(log.rp_dontknow).to be(0)
end
it "updates the reasonable preference reason values on a pending log" do
log = build(:lettings_log, :completed, status: "pending", reasonpref: 1, rp_homeless: 1, rp_hardship: nil, rp_medwel: 1, rp_insan_unsat: nil, rp_dontknow: nil, bulk_upload:, assigned_to: user)
log.save!(validate: false)
initial_updated_at = log.updated_at
expect(log.status).to eq("pending")
task.invoke
log.reload
expect(log.rp_homeless).to be(1)
expect(log.rp_hardship).to be(0)
expect(log.rp_medwel).to be(1)
expect(log.rp_insan_unsat).to be(0)
expect(log.rp_dontknow).to be(0)
expect(log.status).to eq("pending")
expect(log.updated_at).not_to eq(initial_updated_at)
end
it "does not update logs if all unselected reasonable preference reason are alredy 0" do
log = build(:lettings_log, :completed, reasonpref: 1, rp_homeless: 0, rp_hardship: 1, rp_medwel: 0, rp_insan_unsat: 0, rp_dontknow: 0, bulk_upload:, assigned_to: user)
log.save!(validate: false)
initial_updated_at = log.updated_at
expect(log.status).to eq("completed")
task.invoke
log.reload
expect(log.status).to eq("completed")
expect(log.updated_at).to eq(initial_updated_at)
end
it "updates the reasonable preference reason values if some of the checkbox values are nil" do
log = build(:lettings_log, :completed, status: "pending", reasonpref: 1, rp_homeless: 0, rp_hardship: nil, rp_medwel: 1, rp_insan_unsat: 0, rp_dontknow: 0, bulk_upload:, assigned_to: user)
log.save!(validate: false)
initial_updated_at = log.updated_at
expect(log.status).to eq("pending")
task.invoke
log.reload
expect(log.rp_homeless).to be(0)
expect(log.rp_hardship).to be(0)
expect(log.rp_medwel).to be(1)
expect(log.rp_insan_unsat).to be(0)
expect(log.rp_dontknow).to be(0)
expect(log.status).to eq("pending")
expect(log.updated_at).not_to eq(initial_updated_at)
end
it "does not update the reasonable preference reason values on a 2023 log" do
log = build(:lettings_log, :completed, startdate: Time.zone.local(2023, 6, 6), reasonpref: 1, rp_homeless: 0, rp_hardship: nil, rp_medwel: 1, rp_insan_unsat: 0, rp_dontknow: 0, bulk_upload:, assigned_to: user)
log.save!(validate: false)
initial_updated_at = log.updated_at
task.invoke
log.reload
expect(log.updated_at).to eq(initial_updated_at)
end
it "does not update and logs error if a validation triggers" do
log = build(:lettings_log, :completed, postcode_full: "0", reasonpref: 1, rp_homeless: 0, rp_hardship: nil, rp_medwel: 1, rp_insan_unsat: 0, rp_dontknow: 0, bulk_upload:, assigned_to: user)
log.save!(validate: false)
initial_updated_at = log.updated_at
task.invoke
log.reload
expect(log.updated_at).to eq(initial_updated_at)
end
end
context "and any of the illness_type options are 1" do
let(:bulk_upload) { create(:bulk_upload, :lettings, year: 2024, rent_type_fix_status: BulkUpload.rent_type_fix_statuses[:not_applied]) }
it "sets the remaining options to 0" do
log = build(:lettings_log, :completed, illness: 1, illness_type_1: 1, illness_type_2: nil, illness_type_3: nil, illness_type_4: nil, illness_type_5: nil, illness_type_6: nil, illness_type_7: nil, illness_type_8: nil, illness_type_9: nil, illness_type_10: nil,
bulk_upload:, assigned_to: user)
log.save!(validate: false)
initial_updated_at = log.updated_at
task.invoke
log.reload
expect(log.updated_at).not_to eq(initial_updated_at)
expect(log.status).to eq("completed")
expect(log.illness_type_1).to be(1)
expect(log.illness_type_2).to be(0)
expect(log.illness_type_3).to be(0)
expect(log.illness_type_4).to be(0)
expect(log.illness_type_5).to be(0)
expect(log.illness_type_6).to be(0)
expect(log.illness_type_7).to be(0)
expect(log.illness_type_8).to be(0)
expect(log.illness_type_9).to be(0)
expect(log.illness_type_10).to be(0)
end
it "updates the reasonable preference reason values on a pending log" do
log = build(:lettings_log, :completed, status: "pending", illness: 1, illness_type_1: 1, illness_type_2: nil, illness_type_3: nil, illness_type_4: nil, illness_type_5: nil, illness_type_6: nil, illness_type_7: nil, illness_type_8: nil, illness_type_9: nil, illness_type_10: nil, bulk_upload:, assigned_to: user)
log.save!(validate: false)
initial_updated_at = log.updated_at
expect(log.status).to eq("pending")
task.invoke
log.reload
expect(log.illness_type_1).to be(1)
expect(log.illness_type_2).to be(0)
expect(log.illness_type_3).to be(0)
expect(log.illness_type_4).to be(0)
expect(log.illness_type_5).to be(0)
expect(log.illness_type_6).to be(0)
expect(log.illness_type_7).to be(0)
expect(log.illness_type_8).to be(0)
expect(log.illness_type_9).to be(0)
expect(log.illness_type_10).to be(0)
expect(log.status).to eq("pending")
expect(log.updated_at).not_to eq(initial_updated_at)
end
it "does not update logs if all unselected reasonable preference reason are alredy 0" do
log = build(:lettings_log, :completed, illness: 1, illness_type_1: 0, illness_type_2: 1, illness_type_3: 0, illness_type_4: 0, illness_type_5: 0, illness_type_6: 0, illness_type_7: 0, illness_type_8: 0, illness_type_9: 0, illness_type_10: 0, bulk_upload:, assigned_to: user)
log.save!(validate: false)
initial_updated_at = log.updated_at
expect(log.status).to eq("completed")
task.invoke
log.reload
expect(log.status).to eq("completed")
expect(log.updated_at).to eq(initial_updated_at)
end
it "updates the reasonable preference reason values if some of the checkbox values are nil" do
log = build(:lettings_log, :completed, status: "pending", illness: 1, illness_type_1: 0, illness_type_2: nil, illness_type_3: 1, illness_type_4: 0, illness_type_5: 0, illness_type_6: nil, illness_type_7: nil, illness_type_8: nil, illness_type_9: nil, illness_type_10: nil, bulk_upload:, assigned_to: user)
log.save!(validate: false)
initial_updated_at = log.updated_at
expect(log.status).to eq("pending")
task.invoke
log.reload
expect(log.illness_type_1).to be(0)
expect(log.illness_type_2).to be(0)
expect(log.illness_type_3).to be(1)
expect(log.illness_type_4).to be(0)
expect(log.illness_type_5).to be(0)
expect(log.illness_type_6).to be(0)
expect(log.illness_type_7).to be(0)
expect(log.illness_type_8).to be(0)
expect(log.illness_type_9).to be(0)
expect(log.illness_type_10).to be(0)
expect(log.status).to eq("pending")
expect(log.updated_at).not_to eq(initial_updated_at)
end
it "does not update the reasonable preference reason values on a 2023 log" do
log = build(:lettings_log, :completed, startdate: Time.zone.local(2023, 6, 6), illness: 1, illness_type_1: 0, illness_type_2: nil, illness_type_3: 1, illness_type_4: 0, illness_type_5: 0, illness_type_6: nil, illness_type_7: nil, illness_type_8: nil, illness_type_9: nil, illness_type_10: nil, bulk_upload:, assigned_to: user)
log.save!(validate: false)
initial_updated_at = log.updated_at
task.invoke
log.reload
expect(log.updated_at).to eq(initial_updated_at)
end
it "does not update and logs error if a validation triggers" do
log = build(:lettings_log, :completed, postcode_full: "0", illness: 1, illness_type_1: 0, illness_type_2: nil, illness_type_3: 1, illness_type_4: 0, illness_type_5: 0, illness_type_6: nil, illness_type_7: nil, illness_type_8: nil, illness_type_9: nil, illness_type_10: nil, bulk_upload:, assigned_to: user)
log.save!(validate: false)
initial_updated_at = log.updated_at
task.invoke
log.reload
expect(log.updated_at).to eq(initial_updated_at)
end
end
end
end
end

2
spec/mailers/bulk_upload_mailer_spec.rb

@ -113,7 +113,7 @@ RSpec.describe BulkUploadMailer do
title: "Check your file data",
filename: bulk_upload.filename,
upload_timestamp: bulk_upload.created_at.to_fs(:govuk_date_and_time),
description: "Some of your #{bulk_upload.year_combo} lettings data might not be right. Click the link below to review the potential errors, and check your file to see if the data is correct.",
description: "We’ve identified potential discrepancies in your #{bulk_upload.year_combo} lettings data. Please review the flagged information via the link below and cross-reference it with your records to confirm data accuracy.",
cta_link: bulk_upload_lettings_soft_validations_check_url(bulk_upload, page: "confirm-soft-errors"),
},
)

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

@ -1246,6 +1246,32 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
expect(parser.errors[:field_111]).to be_present
end
end
context "when some reasonable preference options are seleceted" do
let(:attributes) { setup_section_params.merge({ bulk_upload:, field_106: "1", field_107: "1", field_108: nil, field_109: "1", field_110: nil, field_111: nil }) }
it "sets the rest of the options to 0" do
parser.valid?
expect(parser.log.rp_homeless).to eq(1)
expect(parser.log.rp_insan_unsat).to eq(0)
expect(parser.log.rp_medwel).to eq(1)
expect(parser.log.rp_hardship).to eq(0)
expect(parser.log.rp_dontknow).to eq(0)
end
end
context "when some reasonable preference options are seleceted but reasonpref is No" do
let(:attributes) { setup_section_params.merge({ bulk_upload:, field_106: "2", field_107: "1", field_108: nil, field_109: "1", field_110: nil, field_111: nil }) }
it "sets the options to nil" do
parser.valid?
expect(parser.log.rp_homeless).to be_nil
expect(parser.log.rp_insan_unsat).to be_nil
expect(parser.log.rp_medwel).to be_nil
expect(parser.log.rp_hardship).to be_nil
expect(parser.log.rp_dontknow).to be_nil
end
end
end
describe "#field_116" do # referral
@ -2484,6 +2510,42 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
end
end
end
context "when some illness type values are seleceted" do
let(:attributes) { setup_section_params.merge({ bulk_upload:, field_85: "1", field_94: "1", field_87: "1" }) }
it "sets the rest of the values to 0" do
parser.valid?
expect(parser.log.illness_type_1).to eq(1)
expect(parser.log.illness_type_2).to eq(0)
expect(parser.log.illness_type_3).to eq(0)
expect(parser.log.illness_type_4).to eq(0)
expect(parser.log.illness_type_5).to eq(1)
expect(parser.log.illness_type_6).to eq(0)
expect(parser.log.illness_type_7).to eq(0)
expect(parser.log.illness_type_8).to eq(0)
expect(parser.log.illness_type_9).to eq(0)
expect(parser.log.illness_type_10).to eq(0)
end
end
context "when none of the illness type values are seleceted" do
let(:attributes) { setup_section_params.merge({ bulk_upload:, field_85: "1" }) }
it "sets the values to nil" do
parser.valid?
expect(parser.log.illness_type_1).to be_nil
expect(parser.log.illness_type_2).to be_nil
expect(parser.log.illness_type_3).to be_nil
expect(parser.log.illness_type_4).to be_nil
expect(parser.log.illness_type_5).to be_nil
expect(parser.log.illness_type_6).to be_nil
expect(parser.log.illness_type_7).to be_nil
expect(parser.log.illness_type_8).to be_nil
expect(parser.log.illness_type_9).to be_nil
expect(parser.log.illness_type_10).to be_nil
end
end
end
describe "#irproduct_other" do

Loading…
Cancel
Save