From 830adc0dd7bf813b80162ffb3076744c07a335c6 Mon Sep 17 00:00:00 2001
From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>
Date: Fri, 20 Dec 2024 08:51:24 +0000
Subject: [PATCH 01/17] Update test file generation (#2868)
* Extract test file generation
* Remove secondary
* Make link shorter
* Move log_to_csv classes to helpers
---
.../create_log_actions_component.html.erb | 5 +-
.../create_log_actions_component.rb | 4 ++
app/controllers/lettings_logs_controller.rb | 14 ----
app/controllers/sales_logs_controller.rb | 14 ----
app/controllers/test_data_controller.rb | 68 +++++++++++++++++++
.../bulk_upload/lettings_log_to_csv.rb | 14 ++--
.../helpers}/bulk_upload/sales_log_to_csv.rb | 12 ++--
config/routes.rb | 14 ++--
8 files changed, 99 insertions(+), 46 deletions(-)
create mode 100644 app/controllers/test_data_controller.rb
rename {spec/support => app/helpers}/bulk_upload/lettings_log_to_csv.rb (96%)
rename {spec/support => app/helpers}/bulk_upload/sales_log_to_csv.rb (97%)
diff --git a/app/components/create_log_actions_component.html.erb b/app/components/create_log_actions_component.html.erb
index a600f3290..4b74c8901 100644
--- a/app/components/create_log_actions_component.html.erb
+++ b/app/components/create_log_actions_component.html.erb
@@ -9,8 +9,9 @@
<% end %>
<% if FeatureToggle.create_test_logs_enabled? %>
- <%= govuk_button_link_to "Create test log", create_test_log_href, secondary: true %>
- <%= govuk_button_link_to "Create test log (setup only)", create_setup_test_log_href, secondary: true %>
+ <%= govuk_link_to "Create test log", create_test_log_href %>
+ <%= govuk_link_to "Create test log (setup only)", create_setup_test_log_href %>
+ <%= govuk_link_to "Get test BU file (2024)", create_2024_test_bulk_upload_href %>
<% end %>
<% end %>
diff --git a/app/components/create_log_actions_component.rb b/app/components/create_log_actions_component.rb
index 896bfe97e..0abbfd385 100644
--- a/app/components/create_log_actions_component.rb
+++ b/app/components/create_log_actions_component.rb
@@ -42,6 +42,10 @@ class CreateLogActionsComponent < ViewComponent::Base
send("create_setup_test_#{log_type}_log_path")
end
+ def create_2024_test_bulk_upload_href
+ send("create_2024_test_#{log_type}_bulk_upload_path")
+ end
+
def view_uploads_button_copy
"View #{log_type} bulk uploads"
end
diff --git a/app/controllers/lettings_logs_controller.rb b/app/controllers/lettings_logs_controller.rb
index 7fef9499b..38a89b682 100644
--- a/app/controllers/lettings_logs_controller.rb
+++ b/app/controllers/lettings_logs_controller.rb
@@ -149,20 +149,6 @@ class LettingsLogsController < LogsController
end
end
- def create_test_log
- return render_not_found unless FeatureToggle.create_test_logs_enabled?
-
- log = FactoryBot.create(:lettings_log, :completed, assigned_to: current_user, ppostcode_full: "SW1A 1AA")
- redirect_to lettings_log_path(log)
- end
-
- def create_setup_test_log
- return render_not_found unless FeatureToggle.create_test_logs_enabled?
-
- log = FactoryBot.create(:lettings_log, :setup_completed, assigned_to: current_user)
- redirect_to lettings_log_path(log)
- end
-
private
def session_filters
diff --git a/app/controllers/sales_logs_controller.rb b/app/controllers/sales_logs_controller.rb
index 237fd94d7..3c389ccf1 100644
--- a/app/controllers/sales_logs_controller.rb
+++ b/app/controllers/sales_logs_controller.rb
@@ -119,20 +119,6 @@ class SalesLogsController < LogsController
end
end
- def create_test_log
- return render_not_found unless FeatureToggle.create_test_logs_enabled?
-
- log = FactoryBot.create(:sales_log, :completed, assigned_to: current_user)
- redirect_to sales_log_path(log)
- end
-
- def create_setup_test_log
- return render_not_found unless FeatureToggle.create_test_logs_enabled?
-
- log = FactoryBot.create(:sales_log, :shared_ownership_setup_complete, assigned_to: current_user)
- redirect_to sales_log_path(log)
- end
-
private
def session_filters
diff --git a/app/controllers/test_data_controller.rb b/app/controllers/test_data_controller.rb
new file mode 100644
index 000000000..2b049f176
--- /dev/null
+++ b/app/controllers/test_data_controller.rb
@@ -0,0 +1,68 @@
+class TestDataController < ApplicationController
+ rescue_from ActiveRecord::RecordNotFound, with: :render_not_found
+
+ def create_test_lettings_log
+ return render_not_found unless FeatureToggle.create_test_logs_enabled?
+
+ log = FactoryBot.create(:lettings_log, :completed, assigned_to: current_user, ppostcode_full: "SW1A 1AA")
+ redirect_to lettings_log_path(log)
+ end
+
+ def create_setup_test_lettings_log
+ return render_not_found unless FeatureToggle.create_test_logs_enabled?
+
+ log = FactoryBot.create(:lettings_log, :setup_completed, assigned_to: current_user)
+ redirect_to lettings_log_path(log)
+ end
+
+ def create_2024_test_lettings_bulk_upload
+ return render_not_found unless FeatureToggle.create_test_logs_enabled?
+
+ file = Tempfile.new("test_lettings_log.csv")
+ log = FactoryBot.create(:lettings_log, :completed, assigned_to: current_user, ppostcode_full: "SW1A 1AA")
+ log_to_csv = BulkUpload::LettingsLogToCsv.new(log:, line_ending: "\n", overrides: { organisation_id: "ORG#{log.owning_organisation_id}", managing_organisation_id: "ORG#{log.owning_organisation_id}" })
+ file.write(log_to_csv.default_field_numbers_row)
+ file.write(log_to_csv.to_csv_row)
+ file.rewind
+ send_file file.path, type: "text/csv",
+ filename: "test_lettings_log.csv",
+ disposition: "attachment",
+ after_send: lambda {
+ file.close
+ file.unlink
+ }
+ end
+
+ def create_test_sales_log
+ return render_not_found unless FeatureToggle.create_test_logs_enabled?
+
+ log = FactoryBot.create(:sales_log, :completed, assigned_to: current_user)
+ redirect_to sales_log_path(log)
+ end
+
+ def create_setup_test_sales_log
+ return render_not_found unless FeatureToggle.create_test_logs_enabled?
+
+ log = FactoryBot.create(:sales_log, :shared_ownership_setup_complete, assigned_to: current_user)
+ redirect_to sales_log_path(log)
+ end
+
+ def create_2024_test_sales_bulk_upload
+ return render_not_found unless FeatureToggle.create_test_logs_enabled?
+
+ file = Tempfile.new("test_sales_log.csv")
+
+ log = FactoryBot.create(:sales_log, :completed, assigned_to: current_user, value: 180_000, deposit: 150_000)
+ log_to_csv = BulkUpload::SalesLogToCsv.new(log:, line_ending: "\n", overrides: { organisation_id: "ORG#{log.owning_organisation_id}", managing_organisation_id: "ORG#{log.owning_organisation_id}" })
+ file.write(log_to_csv.default_field_numbers_row)
+ file.write(log_to_csv.to_csv_row)
+ file.rewind
+ send_file file.path, type: "text/csv",
+ filename: "test_sales_log.csv",
+ disposition: "attachment",
+ after_send: lambda {
+ file.close
+ file.unlink
+ }
+ end
+end
diff --git a/spec/support/bulk_upload/lettings_log_to_csv.rb b/app/helpers/bulk_upload/lettings_log_to_csv.rb
similarity index 96%
rename from spec/support/bulk_upload/lettings_log_to_csv.rb
rename to app/helpers/bulk_upload/lettings_log_to_csv.rb
index 18c367ffc..cdf38db17 100644
--- a/spec/support/bulk_upload/lettings_log_to_csv.rb
+++ b/app/helpers/bulk_upload/lettings_log_to_csv.rb
@@ -2,10 +2,12 @@ class BulkUpload::LettingsLogToCsv
attr_reader :log, :line_ending, :col_offset, :overrides
def initialize(log:, line_ending: "\n", col_offset: 1, overrides: {})
+ # rubocop:disable Rails/HelperInstanceVariable
@log = log
@line_ending = line_ending
@col_offset = col_offset
@overrides = overrides
+ # rubocop:enable Rails/HelperInstanceVariable
end
def row_prefix
@@ -145,8 +147,8 @@ class BulkUpload::LettingsLogToCsv
def to_2024_row
[
- log.owning_organisation&.old_visible_id, # 1
- log.managing_organisation&.old_visible_id,
+ overrides[:organisation_id] || log.owning_organisation&.old_visible_id, # 1
+ overrides[:managing_organisation_id] || log.managing_organisation&.old_visible_id,
log.assigned_to&.email,
log.needstype,
log.scheme&.id ? "S#{log.scheme&.id}" : "",
@@ -162,10 +164,10 @@ class BulkUpload::LettingsLogToCsv
log.propcode,
log.declaration,
log.uprn,
- log.address_line1,
- log.address_line2,
- log.town_or_city,
- log.county, # 20
+ log.address_line1&.tr(",", " "),
+ log.address_line2&.tr(",", " "),
+ log.town_or_city&.tr(",", " "),
+ log.county&.tr(",", " "), # 20
((log.postcode_full || "").split(" ") || [""]).first,
((log.postcode_full || "").split(" ") || [""]).last,
diff --git a/spec/support/bulk_upload/sales_log_to_csv.rb b/app/helpers/bulk_upload/sales_log_to_csv.rb
similarity index 97%
rename from spec/support/bulk_upload/sales_log_to_csv.rb
rename to app/helpers/bulk_upload/sales_log_to_csv.rb
index 8e2f1be0c..0d37fe344 100644
--- a/spec/support/bulk_upload/sales_log_to_csv.rb
+++ b/app/helpers/bulk_upload/sales_log_to_csv.rb
@@ -2,10 +2,12 @@ class BulkUpload::SalesLogToCsv
attr_reader :log, :line_ending, :col_offset, :overrides
def initialize(log:, line_ending: "\n", col_offset: 1, overrides: {})
+ # rubocop:disable Rails/HelperInstanceVariable
@log = log
@line_ending = line_ending
@col_offset = col_offset
@overrides = overrides
+ # rubocop:enable Rails/HelperInstanceVariable
end
def row_prefix
@@ -187,7 +189,7 @@ class BulkUpload::SalesLogToCsv
log.prevloc, # 40
((log.ppostcode_full || "").split(" ") || [""]).first,
((log.ppostcode_full || "").split(" ") || [""]).last,
- log.ppcodenk == 0 ? 1 : nil,
+ log.ppcodenk&.zero? ? 1 : nil,
log.pregyrha,
log.pregla,
@@ -311,10 +313,10 @@ class BulkUpload::SalesLogToCsv
log.builtype,
log.uprn,
- log.address_line1,
- log.address_line2,
- log.town_or_city,
- log.county,
+ log.address_line1&.tr(",", " "),
+ log.address_line2&.tr(",", " "),
+ log.town_or_city&.tr(",", " "),
+ log.county&.tr(",", " "),
((log.postcode_full || "").split(" ") || [""]).first,
((log.postcode_full || "").split(" ") || [""]).last,
log.la,
diff --git a/config/routes.rb b/config/routes.rb
index 55d58b41b..ab31b6b1b 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -389,15 +389,19 @@ Rails.application.routes.draw do
end
end
- get "create-test-lettings-log", to: "lettings_logs#create_test_log"
- get "create-test-sales-log", to: "sales_logs#create_test_log"
- get "create-setup-test-lettings-log", to: "lettings_logs#create_setup_test_log"
- get "create-setup-test-sales-log", to: "sales_logs#create_setup_test_log"
-
scope via: :all do
match "/404", to: "errors#not_found"
match "/429", to: "errors#too_many_requests", status: 429
match "/422", to: "errors#unprocessable_entity"
match "/500", to: "errors#internal_server_error"
end
+
+ if FeatureToggle.create_test_logs_enabled?
+ get "create-test-lettings-log", to: "test_data#create_test_lettings_log"
+ get "create-setup-test-lettings-log", to: "test_data#create_setup_test_lettings_log"
+ get "create-2024-test-lettings-bulk-upload", to: "test_data#create_2024_test_lettings_bulk_upload"
+ get "create-test-sales-log", to: "test_data#create_test_sales_log"
+ get "create-setup-test-sales-log", to: "test_data#create_setup_test_sales_log"
+ get "create-2024-test-sales-bulk-upload", to: "test_data#create_2024_test_sales_bulk_upload"
+ end
end
From a43767087411b7b97cdc4f4d7db35ec9840c4aa0 Mon Sep 17 00:00:00 2001
From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>
Date: Fri, 20 Dec 2024 08:51:46 +0000
Subject: [PATCH 02/17] CLDC-3239 Deduplicate BU forms (#2873)
* Deduplicate BU forms
* Update and fix specs
* Update missed files
* Deduplicate resume forms
* Update copy
* Deduplicate soft validations forms
---
.../bulk_upload_lettings_logs_controller.rb | 10 +-
.../bulk_upload_lettings_resume_controller.rb | 8 +-
...tings_soft_validations_check_controller.rb | 6 +-
.../bulk_upload_sales_logs_controller.rb | 10 +-
.../bulk_upload_sales_resume_controller.rb | 8 +-
...sales_soft_validations_check_controller.rb | 6 +-
.../checking_file.rb | 9 +-
.../guidance.rb | 13 +-
.../prepare_your_file.rb | 21 ++--
.../upload_your_file.rb | 13 +-
.../year.rb | 17 +--
.../bulk_upload_lettings/prepare_your_file.rb | 60 ---------
.../bulk_upload_lettings_resume/confirm.rb | 55 --------
.../deletion_report.rb | 28 -----
.../bulk_upload_lettings_resume/fix_choice.rb | 74 -----------
.../chosen.rb | 31 -----
.../chosen.rb | 9 +-
.../confirm.rb | 17 +--
.../deletion_report.rb | 9 +-
.../fix_choice.rb | 17 +--
.../forms/bulk_upload_sales/checking_file.rb | 32 -----
.../forms/bulk_upload_sales/guidance.rb | 51 --------
.../bulk_upload_sales/upload_your_file.rb | 83 -------------
app/models/forms/bulk_upload_sales/year.rb | 50 --------
.../chosen.rb | 31 -----
.../confirm.rb | 47 -------
.../confirm_soft_errors.rb | 53 --------
.../chosen.rb | 9 +-
.../confirm.rb | 13 +-
.../confirm_soft_errors.rb | 13 +-
.../show.html.erb | 2 +-
.../summary.html.erb | 2 +-
.../bulk_upload_sales_results/show.html.erb | 2 +-
.../summary.html.erb | 2 +-
config/locales/en.yml | 29 +----
.../bulk_upload_lettings_logs_spec.rb | 8 +-
spec/features/bulk_upload_sales_logs_spec.rb | 8 +-
.../forms/bulk_upload_form/guidance_spec.rb | 117 ++++++++++++++++++
.../bulk_upload_form/upload_your_file_spec.rb | 100 +++++++++++++++
.../forms/bulk_upload_form/year_spec.rb | 101 +++++++++++++++
.../bulk_upload_lettings/guidance_spec.rb | 60 ---------
.../upload_your_file_spec.rb | 61 ---------
.../forms/bulk_upload_lettings/year_spec.rb | 47 -------
.../forms/bulk_upload_sales/guidance_spec.rb | 60 ---------
.../upload_your_file_spec.rb | 59 ---------
.../forms/bulk_upload_sales/year_spec.rb | 51 --------
46 files changed, 444 insertions(+), 1068 deletions(-)
rename app/models/forms/{bulk_upload_lettings => bulk_upload_form}/checking_file.rb (66%)
rename app/models/forms/{bulk_upload_lettings => bulk_upload_form}/guidance.rb (61%)
rename app/models/forms/{bulk_upload_sales => bulk_upload_form}/prepare_your_file.rb (55%)
rename app/models/forms/{bulk_upload_lettings => bulk_upload_form}/upload_your_file.rb (82%)
rename app/models/forms/{bulk_upload_lettings => bulk_upload_form}/year.rb (50%)
delete mode 100644 app/models/forms/bulk_upload_lettings/prepare_your_file.rb
delete mode 100644 app/models/forms/bulk_upload_lettings_resume/confirm.rb
delete mode 100644 app/models/forms/bulk_upload_lettings_resume/deletion_report.rb
delete mode 100644 app/models/forms/bulk_upload_lettings_resume/fix_choice.rb
delete mode 100644 app/models/forms/bulk_upload_lettings_soft_validations_check/chosen.rb
rename app/models/forms/{bulk_upload_lettings_resume => bulk_upload_resume}/chosen.rb (60%)
rename app/models/forms/{bulk_upload_sales_resume => bulk_upload_resume}/confirm.rb (62%)
rename app/models/forms/{bulk_upload_sales_resume => bulk_upload_resume}/deletion_report.rb (65%)
rename app/models/forms/{bulk_upload_sales_resume => bulk_upload_resume}/fix_choice.rb (76%)
delete mode 100644 app/models/forms/bulk_upload_sales/checking_file.rb
delete mode 100644 app/models/forms/bulk_upload_sales/guidance.rb
delete mode 100644 app/models/forms/bulk_upload_sales/upload_your_file.rb
delete mode 100644 app/models/forms/bulk_upload_sales/year.rb
delete mode 100644 app/models/forms/bulk_upload_sales_soft_validations_check/chosen.rb
delete mode 100644 app/models/forms/bulk_upload_sales_soft_validations_check/confirm.rb
delete mode 100644 app/models/forms/bulk_upload_sales_soft_validations_check/confirm_soft_errors.rb
rename app/models/forms/{bulk_upload_sales_resume => bulk_upload_soft_validations_check}/chosen.rb (65%)
rename app/models/forms/{bulk_upload_lettings_soft_validations_check => bulk_upload_soft_validations_check}/confirm.rb (65%)
rename app/models/forms/{bulk_upload_lettings_soft_validations_check => bulk_upload_soft_validations_check}/confirm_soft_errors.rb (65%)
create mode 100644 spec/models/forms/bulk_upload_form/guidance_spec.rb
create mode 100644 spec/models/forms/bulk_upload_form/upload_your_file_spec.rb
create mode 100644 spec/models/forms/bulk_upload_form/year_spec.rb
delete mode 100644 spec/models/forms/bulk_upload_lettings/guidance_spec.rb
delete mode 100644 spec/models/forms/bulk_upload_lettings/upload_your_file_spec.rb
delete mode 100644 spec/models/forms/bulk_upload_lettings/year_spec.rb
delete mode 100644 spec/models/forms/bulk_upload_sales/guidance_spec.rb
delete mode 100644 spec/models/forms/bulk_upload_sales/upload_your_file_spec.rb
delete mode 100644 spec/models/forms/bulk_upload_sales/year_spec.rb
diff --git a/app/controllers/bulk_upload_lettings_logs_controller.rb b/app/controllers/bulk_upload_lettings_logs_controller.rb
index 39bc05f7e..4acdbbcb0 100644
--- a/app/controllers/bulk_upload_lettings_logs_controller.rb
+++ b/app/controllers/bulk_upload_lettings_logs_controller.rb
@@ -58,15 +58,15 @@ private
def form
@form ||= case params[:id]
when "year"
- Forms::BulkUploadLettings::Year.new(form_params)
+ Forms::BulkUploadForm::Year.new(form_params.merge(log_type: "lettings"))
when "prepare-your-file"
- Forms::BulkUploadLettings::PrepareYourFile.new(form_params)
+ Forms::BulkUploadForm::PrepareYourFile.new(form_params.merge(log_type: "lettings"))
when "guidance"
- Forms::BulkUploadLettings::Guidance.new(form_params.merge(referrer: params[:referrer]))
+ Forms::BulkUploadForm::Guidance.new(form_params.merge(referrer: params[:referrer], log_type: "lettings"))
when "upload-your-file"
- Forms::BulkUploadLettings::UploadYourFile.new(form_params.merge(current_user:))
+ Forms::BulkUploadForm::UploadYourFile.new(form_params.merge(current_user:, log_type: "lettings"))
when "checking-file"
- Forms::BulkUploadLettings::CheckingFile.new(form_params)
+ Forms::BulkUploadForm::CheckingFile.new(form_params.merge(log_type: "lettings"))
else
raise "Page not found for path #{params[:id]}"
end
diff --git a/app/controllers/bulk_upload_lettings_resume_controller.rb b/app/controllers/bulk_upload_lettings_resume_controller.rb
index 9003c8ced..756e26baa 100644
--- a/app/controllers/bulk_upload_lettings_resume_controller.rb
+++ b/app/controllers/bulk_upload_lettings_resume_controller.rb
@@ -42,13 +42,13 @@ private
def form
@form ||= case params[:page]
when "fix-choice"
- Forms::BulkUploadLettingsResume::FixChoice.new(form_params.merge(bulk_upload: @bulk_upload))
+ Forms::BulkUploadResume::FixChoice.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "lettings"))
when "chosen"
- Forms::BulkUploadLettingsResume::Chosen.new(form_params.merge(bulk_upload: @bulk_upload))
+ Forms::BulkUploadResume::Chosen.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "lettings"))
when "confirm"
- Forms::BulkUploadLettingsResume::Confirm.new(form_params.merge(bulk_upload: @bulk_upload))
+ Forms::BulkUploadResume::Confirm.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "lettings"))
when "deletion-report"
- Forms::BulkUploadLettingsResume::DeletionReport.new(form_params.merge(bulk_upload: @bulk_upload))
+ Forms::BulkUploadResume::DeletionReport.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "lettings"))
else
raise "invalid form"
end
diff --git a/app/controllers/bulk_upload_lettings_soft_validations_check_controller.rb b/app/controllers/bulk_upload_lettings_soft_validations_check_controller.rb
index a70af3c4b..faaf60302 100644
--- a/app/controllers/bulk_upload_lettings_soft_validations_check_controller.rb
+++ b/app/controllers/bulk_upload_lettings_soft_validations_check_controller.rb
@@ -36,11 +36,11 @@ private
def form
@form ||= case params[:page]
when "confirm-soft-errors"
- Forms::BulkUploadLettingsSoftValidationsCheck::ConfirmSoftErrors.new(form_params.merge(bulk_upload: @bulk_upload))
+ Forms::BulkUploadSoftValidationsCheck::ConfirmSoftErrors.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "lettings"))
when "chosen"
- Forms::BulkUploadLettingsSoftValidationsCheck::Chosen.new(form_params.merge(bulk_upload: @bulk_upload))
+ Forms::BulkUploadSoftValidationsCheck::Chosen.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "lettings"))
when "confirm"
- Forms::BulkUploadLettingsSoftValidationsCheck::Confirm.new(form_params.merge(bulk_upload: @bulk_upload))
+ Forms::BulkUploadSoftValidationsCheck::Confirm.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "lettings"))
else
raise "invalid form"
end
diff --git a/app/controllers/bulk_upload_sales_logs_controller.rb b/app/controllers/bulk_upload_sales_logs_controller.rb
index cb04cea95..61eb59fbd 100644
--- a/app/controllers/bulk_upload_sales_logs_controller.rb
+++ b/app/controllers/bulk_upload_sales_logs_controller.rb
@@ -58,15 +58,15 @@ private
def form
@form ||= case params[:id]
when "year"
- Forms::BulkUploadSales::Year.new(form_params)
+ Forms::BulkUploadForm::Year.new(form_params.merge(log_type: "sales"))
when "prepare-your-file"
- Forms::BulkUploadSales::PrepareYourFile.new(form_params)
+ Forms::BulkUploadForm::PrepareYourFile.new(form_params.merge(log_type: "sales"))
when "guidance"
- Forms::BulkUploadSales::Guidance.new(form_params.merge(referrer: params[:referrer]))
+ Forms::BulkUploadForm::Guidance.new(form_params.merge(referrer: params[:referrer], log_type: "sales"))
when "upload-your-file"
- Forms::BulkUploadSales::UploadYourFile.new(form_params.merge(current_user:))
+ Forms::BulkUploadForm::UploadYourFile.new(form_params.merge(current_user:, log_type: "sales"))
when "checking-file"
- Forms::BulkUploadSales::CheckingFile.new(form_params)
+ Forms::BulkUploadForm::CheckingFile.new(form_params.merge(log_type: "sales"))
else
raise "Page not found for path #{params[:id]}"
end
diff --git a/app/controllers/bulk_upload_sales_resume_controller.rb b/app/controllers/bulk_upload_sales_resume_controller.rb
index 7514d2515..ad786f4a1 100644
--- a/app/controllers/bulk_upload_sales_resume_controller.rb
+++ b/app/controllers/bulk_upload_sales_resume_controller.rb
@@ -42,13 +42,13 @@ private
def form
@form ||= case params[:page]
when "fix-choice"
- Forms::BulkUploadSalesResume::FixChoice.new(form_params.merge(bulk_upload: @bulk_upload))
+ Forms::BulkUploadResume::FixChoice.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "sales"))
when "chosen"
- Forms::BulkUploadSalesResume::Chosen.new(form_params.merge(bulk_upload: @bulk_upload))
+ Forms::BulkUploadResume::Chosen.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "sales"))
when "confirm"
- Forms::BulkUploadSalesResume::Confirm.new(form_params.merge(bulk_upload: @bulk_upload))
+ Forms::BulkUploadResume::Confirm.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "sales"))
when "deletion-report"
- Forms::BulkUploadSalesResume::DeletionReport.new(form_params.merge(bulk_upload: @bulk_upload))
+ Forms::BulkUploadResume::DeletionReport.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "sales"))
else
raise "invalid form"
end
diff --git a/app/controllers/bulk_upload_sales_soft_validations_check_controller.rb b/app/controllers/bulk_upload_sales_soft_validations_check_controller.rb
index 5b71b2c40..0795ad81e 100644
--- a/app/controllers/bulk_upload_sales_soft_validations_check_controller.rb
+++ b/app/controllers/bulk_upload_sales_soft_validations_check_controller.rb
@@ -36,11 +36,11 @@ private
def form
@form ||= case params[:page]
when "confirm-soft-errors"
- Forms::BulkUploadSalesSoftValidationsCheck::ConfirmSoftErrors.new(form_params.merge(bulk_upload: @bulk_upload))
+ Forms::BulkUploadSoftValidationsCheck::ConfirmSoftErrors.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "sales"))
when "chosen"
- Forms::BulkUploadSalesSoftValidationsCheck::Chosen.new(form_params.merge(bulk_upload: @bulk_upload))
+ Forms::BulkUploadSoftValidationsCheck::Chosen.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "sales"))
when "confirm"
- Forms::BulkUploadSalesSoftValidationsCheck::Confirm.new(form_params.merge(bulk_upload: @bulk_upload))
+ Forms::BulkUploadSoftValidationsCheck::Confirm.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "sales"))
else
raise "invalid form"
end
diff --git a/app/models/forms/bulk_upload_lettings/checking_file.rb b/app/models/forms/bulk_upload_form/checking_file.rb
similarity index 66%
rename from app/models/forms/bulk_upload_lettings/checking_file.rb
rename to app/models/forms/bulk_upload_form/checking_file.rb
index 2ce12df46..6efecc008 100644
--- a/app/models/forms/bulk_upload_lettings/checking_file.rb
+++ b/app/models/forms/bulk_upload_form/checking_file.rb
@@ -1,22 +1,23 @@
module Forms
- module BulkUploadLettings
+ module BulkUploadForm
class CheckingFile
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
+ attribute :log_type
attribute :year, :integer
attribute :organisation_id, :integer
def view_path
- "bulk_upload_lettings_logs/forms/checking_file"
+ "bulk_upload_#{log_type}_logs/forms/checking_file"
end
def back_path
if organisation_id.present?
- lettings_logs_organisation_path(organisation_id)
+ send("#{log_type}_logs_organisation_path", organisation_id)
else
- bulk_upload_lettings_log_path(id: "start")
+ send("bulk_upload_#{log_type}_log_path", id: "start")
end
end
diff --git a/app/models/forms/bulk_upload_lettings/guidance.rb b/app/models/forms/bulk_upload_form/guidance.rb
similarity index 61%
rename from app/models/forms/bulk_upload_lettings/guidance.rb
rename to app/models/forms/bulk_upload_form/guidance.rb
index b2fcf947e..4b62caa21 100644
--- a/app/models/forms/bulk_upload_lettings/guidance.rb
+++ b/app/models/forms/bulk_upload_form/guidance.rb
@@ -1,11 +1,12 @@
module Forms
- module BulkUploadLettings
+ module BulkUploadForm
class Guidance
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
include CollectionTimeHelper
+ attribute :log_type
attribute :year, :integer
attribute :referrer
attribute :organisation_id, :integer
@@ -23,7 +24,7 @@ module Forms
def back_path
case referrer
when "prepare-your-file"
- bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year:, organisation_id: }.compact)
+ send("bulk_upload_#{log_type}_log_path", id: "prepare-your-file", form: { year:, organisation_id: }.compact)
when "home"
root_path
else
@@ -32,19 +33,19 @@ module Forms
end
def lettings_template_path
- Forms::BulkUploadLettings::PrepareYourFile.new(year:).template_path
+ Forms::BulkUploadForm::PrepareYourFile.new(year:, log_type: "lettings").template_path
end
def lettings_specification_path
- Forms::BulkUploadLettings::PrepareYourFile.new(year:).specification_path
+ Forms::BulkUploadForm::PrepareYourFile.new(year:, log_type: "lettings").specification_path
end
def sales_template_path
- Forms::BulkUploadSales::PrepareYourFile.new(year:).template_path
+ Forms::BulkUploadForm::PrepareYourFile.new(year:, log_type: "sales").template_path
end
def sales_specification_path
- Forms::BulkUploadSales::PrepareYourFile.new(year:).specification_path
+ Forms::BulkUploadForm::PrepareYourFile.new(year:, log_type: "sales").specification_path
end
end
end
diff --git a/app/models/forms/bulk_upload_sales/prepare_your_file.rb b/app/models/forms/bulk_upload_form/prepare_your_file.rb
similarity index 55%
rename from app/models/forms/bulk_upload_sales/prepare_your_file.rb
rename to app/models/forms/bulk_upload_form/prepare_your_file.rb
index aaca752a2..b89367d9f 100644
--- a/app/models/forms/bulk_upload_sales/prepare_your_file.rb
+++ b/app/models/forms/bulk_upload_form/prepare_your_file.rb
@@ -1,42 +1,43 @@
module Forms
- module BulkUploadSales
+ module BulkUploadForm
class PrepareYourFile
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
+ attribute :log_type
attribute :year, :integer
attribute :organisation_id, :integer
def view_path
case year
when 2023
- "bulk_upload_sales_logs/forms/prepare_your_file_2023"
+ "bulk_upload_#{log_type}_logs/forms/prepare_your_file_2023"
when 2024
- "bulk_upload_sales_logs/forms/prepare_your_file_2024"
+ "bulk_upload_#{log_type}_logs/forms/prepare_your_file_2024"
end
end
def back_path
if have_choice_of_year?
- Rails.application.routes.url_helpers.bulk_upload_sales_log_path(id: "year", form: { year: }.compact)
+ Rails.application.routes.url_helpers.send("bulk_upload_#{log_type}_log_path", id: "year", form: { year: }.compact)
elsif organisation_id.present?
- sales_logs_organisation_path(organisation_id)
+ send("#{log_type}_logs_organisation_path", organisation_id)
else
- Rails.application.routes.url_helpers.sales_logs_path
+ Rails.application.routes.url_helpers.send("#{log_type}_logs_path")
end
end
def next_path
- bulk_upload_sales_log_path(id: "upload-your-file", form: { year:, organisation_id: }.compact)
+ send("bulk_upload_#{log_type}_log_path", id: "upload-your-file", form: { year:, organisation_id: }.compact)
end
def template_path
- download_mandatory_collection_resource_path(year:, log_type: "sales", resource_type: "bulk_upload_template")
+ download_mandatory_collection_resource_path(year:, log_type:, resource_type: "bulk_upload_template")
end
def specification_path
- download_mandatory_collection_resource_path(year:, log_type: "sales", resource_type: "bulk_upload_specification")
+ download_mandatory_collection_resource_path(year:, log_type:, resource_type: "bulk_upload_specification")
end
def year_combo
@@ -52,7 +53,7 @@ module Forms
def have_choice_of_year?
return true if FeatureToggle.allow_future_form_use?
- FormHandler.instance.sales_in_crossover_period?
+ FormHandler.instance.send("#{log_type}_in_crossover_period?")
end
end
end
diff --git a/app/models/forms/bulk_upload_lettings/upload_your_file.rb b/app/models/forms/bulk_upload_form/upload_your_file.rb
similarity index 82%
rename from app/models/forms/bulk_upload_lettings/upload_your_file.rb
rename to app/models/forms/bulk_upload_form/upload_your_file.rb
index 552710885..3207b1822 100644
--- a/app/models/forms/bulk_upload_lettings/upload_your_file.rb
+++ b/app/models/forms/bulk_upload_form/upload_your_file.rb
@@ -1,14 +1,14 @@
require "shellwords"
module Forms
- module BulkUploadLettings
+ module BulkUploadForm
class UploadYourFile
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
+ attribute :log_type
attribute :year, :integer
- attribute :needstype, :integer
attribute :file
attribute :current_user
attribute :organisation_id, :integer
@@ -18,11 +18,11 @@ module Forms
validate :validate_file_size
def view_path
- "bulk_upload_lettings_logs/forms/upload_your_file"
+ "bulk_upload_#{log_type}_logs/forms/upload_your_file"
end
def back_path
- bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year:, needstype:, organisation_id: }.compact)
+ send("bulk_upload_#{log_type}_log_path", id: "prepare-your-file", form: { year:, organisation_id: }.compact)
end
def year_combo
@@ -30,15 +30,14 @@ module Forms
end
def next_path
- bulk_upload_lettings_log_path(id: "checking-file", form: { year:, organisation_id: }.compact)
+ send("bulk_upload_#{log_type}_log_path", id: "checking-file", form: { year:, organisation_id: }.compact)
end
def save!
bulk_upload = BulkUpload.create!(
user: current_user,
- log_type: BulkUpload.log_types[:lettings],
+ log_type: BulkUpload.log_types[log_type.to_sym],
year:,
- needstype:,
filename: file.original_filename,
organisation_id: (organisation_id if current_user.support?) || current_user.organisation_id,
)
diff --git a/app/models/forms/bulk_upload_lettings/year.rb b/app/models/forms/bulk_upload_form/year.rb
similarity index 50%
rename from app/models/forms/bulk_upload_lettings/year.rb
rename to app/models/forms/bulk_upload_form/year.rb
index ca2e9c144..ecc3acb5b 100644
--- a/app/models/forms/bulk_upload_lettings/year.rb
+++ b/app/models/forms/bulk_upload_form/year.rb
@@ -1,17 +1,18 @@
module Forms
- module BulkUploadLettings
+ module BulkUploadForm
class Year
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
+ attribute :log_type
attribute :year, :integer
attribute :organisation_id, :integer
validates :year, presence: true
def view_path
- "bulk_upload_lettings_logs/forms/year"
+ "bulk_upload_#{log_type}_logs/forms/year"
end
def options
@@ -22,14 +23,14 @@ module Forms
def back_path
if organisation_id.present?
- lettings_logs_organisation_path(organisation_id)
+ send("#{log_type}_logs_organisation_path", organisation_id)
else
- lettings_logs_path
+ send("#{log_type}_logs_path")
end
end
def next_path
- bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year:, organisation_id: }.compact)
+ send("bulk_upload_#{log_type}_log_path", id: "prepare-your-file", form: { year:, organisation_id: }.compact)
end
def save!
@@ -40,9 +41,9 @@ module Forms
def possible_years
[
- FormHandler.instance.lettings_forms["current_lettings"].start_date.year,
- (FormHandler.instance.previous_lettings_form.start_date.year if FormHandler.instance.lettings_in_crossover_period?),
- (FormHandler.instance.next_lettings_form.start_date.year if FeatureToggle.allow_future_form_use?),
+ FormHandler.instance.send("#{log_type}_forms")["current_#{log_type}"].start_date.year,
+ (FormHandler.instance.send("previous_#{log_type}_form").start_date.year if FormHandler.instance.send("#{log_type}_in_crossover_period?")),
+ (FormHandler.instance.send("next_#{log_type}_form").start_date.year if FeatureToggle.allow_future_form_use?),
].compact
end
end
diff --git a/app/models/forms/bulk_upload_lettings/prepare_your_file.rb b/app/models/forms/bulk_upload_lettings/prepare_your_file.rb
deleted file mode 100644
index d0a577ee1..000000000
--- a/app/models/forms/bulk_upload_lettings/prepare_your_file.rb
+++ /dev/null
@@ -1,60 +0,0 @@
-module Forms
- module BulkUploadLettings
- class PrepareYourFile
- include ActiveModel::Model
- include ActiveModel::Attributes
- include Rails.application.routes.url_helpers
-
- attribute :year, :integer
- attribute :needstype, :integer
- attribute :organisation_id, :integer
-
- def view_path
- case year
- when 2023
- "bulk_upload_lettings_logs/forms/prepare_your_file_2023"
- when 2024
- "bulk_upload_lettings_logs/forms/prepare_your_file_2024"
- end
- end
-
- def back_path
- if have_choice_of_year?
- Rails.application.routes.url_helpers.bulk_upload_lettings_log_path(id: "year", form: { year:, organisation_id: }.compact)
- elsif organisation_id.present?
- lettings_logs_organisation_path(organisation_id)
- else
- Rails.application.routes.url_helpers.lettings_logs_path
- end
- end
-
- def next_path
- bulk_upload_lettings_log_path(id: "upload-your-file", form: { year:, needstype:, organisation_id: }.compact)
- end
-
- def template_path
- download_mandatory_collection_resource_path(year:, log_type: "lettings", resource_type: "bulk_upload_template")
- end
-
- def specification_path
- download_mandatory_collection_resource_path(year:, log_type: "lettings", resource_type: "bulk_upload_specification")
- end
-
- def year_combo
- "#{year} to #{year + 1}"
- end
-
- def save!
- true
- end
-
- private
-
- def have_choice_of_year?
- return true if FeatureToggle.allow_future_form_use?
-
- FormHandler.instance.lettings_in_crossover_period?
- end
- end
- end
-end
diff --git a/app/models/forms/bulk_upload_lettings_resume/confirm.rb b/app/models/forms/bulk_upload_lettings_resume/confirm.rb
deleted file mode 100644
index 3419e794f..000000000
--- a/app/models/forms/bulk_upload_lettings_resume/confirm.rb
+++ /dev/null
@@ -1,55 +0,0 @@
-module Forms
- module BulkUploadLettingsResume
- class Confirm
- include ActiveModel::Model
- include ActiveModel::Attributes
- include Rails.application.routes.url_helpers
-
- attribute :bulk_upload
-
- def view_path
- "bulk_upload_lettings_resume/confirm"
- end
-
- def back_path
- page_bulk_upload_lettings_resume_path(bulk_upload, page: "fix-choice")
- end
-
- def next_path
- resume_bulk_upload_lettings_result_path(bulk_upload)
- end
-
- def error_report_path
- if BulkUploadErrorSummaryTableComponent.new(bulk_upload:).errors?
- summary_bulk_upload_lettings_result_path(bulk_upload)
- else
- bulk_upload_lettings_result_path(bulk_upload)
- end
- end
-
- def save!
- ApplicationRecord.transaction do
- processor = BulkUpload::Processor.new(bulk_upload:)
- processor.approve
-
- bulk_upload.update!(choice: "create-fix-inline")
- end
-
- true
- end
-
- def preflight_valid?
- bulk_upload.choice != "create-fix-inline" && bulk_upload.choice != "bulk-confirm-soft-validations"
- end
-
- def preflight_redirect
- case bulk_upload.choice
- when "create-fix-inline"
- page_bulk_upload_lettings_resume_path(bulk_upload, :chosen)
- when "bulk-confirm-soft-validations"
- page_bulk_upload_lettings_soft_validations_check_path(bulk_upload, :chosen)
- end
- end
- end
- end
-end
diff --git a/app/models/forms/bulk_upload_lettings_resume/deletion_report.rb b/app/models/forms/bulk_upload_lettings_resume/deletion_report.rb
deleted file mode 100644
index 61e7c54cd..000000000
--- a/app/models/forms/bulk_upload_lettings_resume/deletion_report.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-module Forms
- module BulkUploadLettingsResume
- class DeletionReport
- include ActiveModel::Model
- include ActiveModel::Attributes
- include Rails.application.routes.url_helpers
-
- attribute :bulk_upload
-
- def view_path
- "bulk_upload_lettings_resume/deletion_report"
- end
-
- def preflight_valid?
- bulk_upload.choice != "create-fix-inline" && bulk_upload.choice != "bulk-confirm-soft-validations"
- end
-
- def preflight_redirect
- case bulk_upload.choice
- when "create-fix-inline"
- page_bulk_upload_lettings_resume_path(bulk_upload, :chosen)
- when "bulk-confirm-soft-validations"
- page_bulk_upload_lettings_soft_validations_check_path(bulk_upload, :chosen)
- end
- end
- end
- end
-end
diff --git a/app/models/forms/bulk_upload_lettings_resume/fix_choice.rb b/app/models/forms/bulk_upload_lettings_resume/fix_choice.rb
deleted file mode 100644
index 40ada602e..000000000
--- a/app/models/forms/bulk_upload_lettings_resume/fix_choice.rb
+++ /dev/null
@@ -1,74 +0,0 @@
-module Forms
- module BulkUploadLettingsResume
- class FixChoice
- include ActiveModel::Model
- include ActiveModel::Attributes
- include Rails.application.routes.url_helpers
-
- attribute :bulk_upload
- attribute :choice, :string
-
- validates :choice, presence: true,
- inclusion: { in: %w[create-fix-inline upload-again] }
-
- def options
- [
- OpenStruct.new(id: "create-fix-inline", name: "Upload these logs and fix errors on CORE site"),
- OpenStruct.new(id: "upload-again", name: "Fix errors in the CSV and upload the file again"),
- ]
- end
-
- def view_path
- "bulk_upload_lettings_resume/fix_choice"
- end
-
- def next_path
- case choice
- when "create-fix-inline"
- page_bulk_upload_lettings_resume_path(bulk_upload, page: "confirm")
- when "upload-again"
- error_report_path
- else
- raise "invalid choice"
- end
- end
-
- def error_report_path
- if BulkUploadErrorSummaryTableComponent.new(bulk_upload:).errors?
- summary_bulk_upload_lettings_result_path(bulk_upload)
- else
- bulk_upload_lettings_result_path(bulk_upload)
- end
- end
-
- def recommendation
- if BulkUploadErrorSummaryTableComponent.new(bulk_upload:).errors?
- "We recommend fixing these errors in the CSV, as you may be able to edit multiple fields at once. However, you can also upload these logs and fix the errors on the CORE site."
- else
- "We recommend uploading logs and fixing errors on site as you can easily see the questions and select the appropriate answer. However, you can also fix these errors in the CSV."
- end
- end
-
- def save!
- bulk_upload.update!(choice:) if choice == "upload-again"
-
- true
- end
-
- def preflight_valid?
- bulk_upload.choice.blank?
- end
-
- def preflight_redirect
- case bulk_upload.choice
- when "create-fix-inline"
- page_bulk_upload_lettings_resume_path(bulk_upload, :chosen)
- when "bulk-confirm-soft-validations"
- page_bulk_upload_lettings_soft_validations_check_path(bulk_upload, :chosen)
- else
- bulk_upload_lettings_result_path(bulk_upload)
- end
- end
- end
- end
-end
diff --git a/app/models/forms/bulk_upload_lettings_soft_validations_check/chosen.rb b/app/models/forms/bulk_upload_lettings_soft_validations_check/chosen.rb
deleted file mode 100644
index b3091bc51..000000000
--- a/app/models/forms/bulk_upload_lettings_soft_validations_check/chosen.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-module Forms
- module BulkUploadLettingsSoftValidationsCheck
- class Chosen
- include ActiveModel::Model
- include ActiveModel::Attributes
- include Rails.application.routes.url_helpers
-
- attribute :bulk_upload
-
- def view_path
- "bulk_upload_lettings_soft_validations_check/chosen"
- end
-
- def back_path
- lettings_logs_path
- end
-
- def next_path
- lettings_logs_path
- end
-
- def save!
- true
- end
-
- def preflight_valid?
- true
- end
- end
- end
-end
diff --git a/app/models/forms/bulk_upload_lettings_resume/chosen.rb b/app/models/forms/bulk_upload_resume/chosen.rb
similarity index 60%
rename from app/models/forms/bulk_upload_lettings_resume/chosen.rb
rename to app/models/forms/bulk_upload_resume/chosen.rb
index b795d8d4b..935d29178 100644
--- a/app/models/forms/bulk_upload_lettings_resume/chosen.rb
+++ b/app/models/forms/bulk_upload_resume/chosen.rb
@@ -1,22 +1,23 @@
module Forms
- module BulkUploadLettingsResume
+ module BulkUploadResume
class Chosen
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
+ attribute :log_type
attribute :bulk_upload
def view_path
- bulk_upload.completed? ? "bulk_upload_lettings_resume/completed" : "bulk_upload_lettings_resume/chosen"
+ bulk_upload.completed? ? "bulk_upload_#{log_type}_resume/completed" : "bulk_upload_#{log_type}_resume/chosen"
end
def back_path
- lettings_logs_path
+ send("#{log_type}_logs_path")
end
def next_path
- lettings_logs_path
+ send("#{log_type}_logs_path")
end
def save!
diff --git a/app/models/forms/bulk_upload_sales_resume/confirm.rb b/app/models/forms/bulk_upload_resume/confirm.rb
similarity index 62%
rename from app/models/forms/bulk_upload_sales_resume/confirm.rb
rename to app/models/forms/bulk_upload_resume/confirm.rb
index a84272682..96a1fe1bc 100644
--- a/app/models/forms/bulk_upload_sales_resume/confirm.rb
+++ b/app/models/forms/bulk_upload_resume/confirm.rb
@@ -1,29 +1,30 @@
module Forms
- module BulkUploadSalesResume
+ module BulkUploadResume
class Confirm
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
+ attribute :log_type
attribute :bulk_upload
def view_path
- "bulk_upload_sales_resume/confirm"
+ "bulk_upload_#{log_type}_resume/confirm"
end
def back_path
- page_bulk_upload_sales_resume_path(bulk_upload, page: "fix-choice")
+ send("page_bulk_upload_#{log_type}_resume_path", bulk_upload, page: "fix-choice")
end
def next_path
- resume_bulk_upload_sales_result_path(bulk_upload)
+ send("resume_bulk_upload_#{log_type}_result_path", bulk_upload)
end
def error_report_path
if BulkUploadErrorSummaryTableComponent.new(bulk_upload:).errors?
- summary_bulk_upload_sales_result_path(bulk_upload)
+ send("summary_bulk_upload_#{log_type}_result_path", bulk_upload)
else
- bulk_upload_sales_result_path(bulk_upload)
+ send("bulk_upload_#{log_type}_result_path", bulk_upload)
end
end
@@ -45,9 +46,9 @@ module Forms
def preflight_redirect
case bulk_upload.choice
when "create-fix-inline"
- page_bulk_upload_sales_resume_path(bulk_upload, :chosen)
+ send("page_bulk_upload_#{log_type}_resume_path", bulk_upload, :chosen)
when "bulk-confirm-soft-validations"
- page_bulk_upload_sales_soft_validations_check_path(bulk_upload, :chosen)
+ send("page_bulk_upload_#{log_type}_soft_validations_check_path", bulk_upload, :chosen)
end
end
end
diff --git a/app/models/forms/bulk_upload_sales_resume/deletion_report.rb b/app/models/forms/bulk_upload_resume/deletion_report.rb
similarity index 65%
rename from app/models/forms/bulk_upload_sales_resume/deletion_report.rb
rename to app/models/forms/bulk_upload_resume/deletion_report.rb
index 93b466b51..40c532553 100644
--- a/app/models/forms/bulk_upload_sales_resume/deletion_report.rb
+++ b/app/models/forms/bulk_upload_resume/deletion_report.rb
@@ -1,14 +1,15 @@
module Forms
- module BulkUploadSalesResume
+ module BulkUploadResume
class DeletionReport
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
+ attribute :log_type
attribute :bulk_upload
def view_path
- "bulk_upload_sales_resume/deletion_report"
+ "bulk_upload_#{log_type}_resume/deletion_report"
end
def preflight_valid?
@@ -18,9 +19,9 @@ module Forms
def preflight_redirect
case bulk_upload.choice
when "create-fix-inline"
- page_bulk_upload_sales_resume_path(bulk_upload, :chosen)
+ send("page_bulk_upload_#{log_type}_resume_path", bulk_upload, :chosen)
when "bulk-confirm-soft-validations"
- page_bulk_upload_sales_soft_validations_check_path(bulk_upload, :chosen)
+ send("page_bulk_upload_#{log_type}_soft_validations_check_path", bulk_upload, :chosen)
end
end
end
diff --git a/app/models/forms/bulk_upload_sales_resume/fix_choice.rb b/app/models/forms/bulk_upload_resume/fix_choice.rb
similarity index 76%
rename from app/models/forms/bulk_upload_sales_resume/fix_choice.rb
rename to app/models/forms/bulk_upload_resume/fix_choice.rb
index 79d06529a..c731dbf93 100644
--- a/app/models/forms/bulk_upload_sales_resume/fix_choice.rb
+++ b/app/models/forms/bulk_upload_resume/fix_choice.rb
@@ -1,10 +1,11 @@
module Forms
- module BulkUploadSalesResume
+ module BulkUploadResume
class FixChoice
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
+ attribute :log_type
attribute :bulk_upload
attribute :choice, :string
@@ -19,13 +20,13 @@ module Forms
end
def view_path
- "bulk_upload_sales_resume/fix_choice"
+ "bulk_upload_#{log_type}_resume/fix_choice"
end
def next_path
case choice
when "create-fix-inline"
- page_bulk_upload_sales_resume_path(bulk_upload, page: "confirm")
+ send("page_bulk_upload_#{log_type}_resume_path", bulk_upload, page: "confirm")
when "upload-again"
error_report_path
else
@@ -35,9 +36,9 @@ module Forms
def error_report_path
if BulkUploadErrorSummaryTableComponent.new(bulk_upload:).errors?
- summary_bulk_upload_sales_result_path(bulk_upload)
+ send("summary_bulk_upload_#{log_type}_result_path", bulk_upload)
else
- bulk_upload_sales_result_path(bulk_upload)
+ send("bulk_upload_#{log_type}_result_path", bulk_upload)
end
end
@@ -62,11 +63,11 @@ module Forms
def preflight_redirect
case bulk_upload.choice
when "create-fix-inline"
- page_bulk_upload_sales_resume_path(bulk_upload, :chosen)
+ send("page_bulk_upload_#{log_type}_resume_path", bulk_upload, :chosen)
when "bulk-confirm-soft-validations"
- page_bulk_upload_sales_soft_validations_check_path(bulk_upload, :chosen)
+ send("page_bulk_upload_#{log_type}_soft_validations_check_path", bulk_upload, :chosen)
else
- bulk_upload_sales_result_path(bulk_upload)
+ send("bulk_upload_#{log_type}_result_path", bulk_upload)
end
end
end
diff --git a/app/models/forms/bulk_upload_sales/checking_file.rb b/app/models/forms/bulk_upload_sales/checking_file.rb
deleted file mode 100644
index 4e512b29b..000000000
--- a/app/models/forms/bulk_upload_sales/checking_file.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-module Forms
- module BulkUploadSales
- class CheckingFile
- include ActiveModel::Model
- include ActiveModel::Attributes
- include Rails.application.routes.url_helpers
-
- attribute :year, :integer
- attribute :organisation_id, :integer
-
- def view_path
- "bulk_upload_sales_logs/forms/checking_file"
- end
-
- def back_path
- if organisation_id.present?
- sales_logs_organisation_path(organisation_id)
- else
- bulk_upload_sales_log_path(id: "start")
- end
- end
-
- def year_combo
- "#{year} to #{year + 1}"
- end
-
- def save!
- true
- end
- end
- end
-end
diff --git a/app/models/forms/bulk_upload_sales/guidance.rb b/app/models/forms/bulk_upload_sales/guidance.rb
deleted file mode 100644
index 80cfc5143..000000000
--- a/app/models/forms/bulk_upload_sales/guidance.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-module Forms
- module BulkUploadSales
- class Guidance
- include ActiveModel::Model
- include ActiveModel::Attributes
- include Rails.application.routes.url_helpers
- include CollectionTimeHelper
-
- attribute :year, :integer
- attribute :referrer
- attribute :organisation_id, :integer
-
- def initialize(params)
- super(params)
-
- self.year = current_collection_start_year if year.nil?
- end
-
- def view_path
- "bulk_upload_shared/guidance"
- end
-
- def back_path
- case referrer
- when "prepare-your-file"
- bulk_upload_sales_log_path(id: "prepare-your-file", form: { year:, organisation_id: }.compact)
- when "home"
- root_path
- else
- guidance_path
- end
- end
-
- def lettings_template_path
- Forms::BulkUploadLettings::PrepareYourFile.new(year:).template_path
- end
-
- def lettings_specification_path
- Forms::BulkUploadLettings::PrepareYourFile.new(year:).specification_path
- end
-
- def sales_template_path
- Forms::BulkUploadSales::PrepareYourFile.new(year:).template_path
- end
-
- def sales_specification_path
- Forms::BulkUploadSales::PrepareYourFile.new(year:).specification_path
- end
- end
- end
-end
diff --git a/app/models/forms/bulk_upload_sales/upload_your_file.rb b/app/models/forms/bulk_upload_sales/upload_your_file.rb
deleted file mode 100644
index 447574d1a..000000000
--- a/app/models/forms/bulk_upload_sales/upload_your_file.rb
+++ /dev/null
@@ -1,83 +0,0 @@
-require "shellwords"
-
-module Forms
- module BulkUploadSales
- class UploadYourFile
- include ActiveModel::Model
- include ActiveModel::Attributes
- include Rails.application.routes.url_helpers
-
- attribute :year, :integer
- attribute :file
- attribute :current_user
- attribute :organisation_id, :integer
-
- validates :file, presence: true
- validate :validate_file_is_csv
- validate :validate_file_size
-
- def view_path
- "bulk_upload_sales_logs/forms/upload_your_file"
- end
-
- def back_path
- bulk_upload_sales_log_path(id: "prepare-your-file", form: { year:, organisation_id: }.compact)
- end
-
- def year_combo
- "#{year} to #{year + 1}"
- end
-
- def next_path
- bulk_upload_sales_log_path(id: "checking-file", form: { year:, organisation_id: }.compact)
- end
-
- def save!
- bulk_upload = BulkUpload.create!(
- user: current_user,
- log_type: BulkUpload.log_types[:sales],
- year:,
- filename: file.original_filename,
- organisation_id: (organisation_id if current_user.support?) || current_user.organisation_id,
- )
-
- storage_service.write_file(bulk_upload.identifier, File.read(file.path))
-
- ProcessBulkUploadJob.perform_later(bulk_upload:)
-
- true
- end
-
- private
-
- def storage_service
- @storage_service ||= if FeatureToggle.upload_enabled?
- Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["BULK_UPLOAD_BUCKET"])
- else
- Storage::LocalDiskService.new
- end
- end
-
- def validate_file_is_csv
- return unless file
-
- argv = %W[file --brief --mime-type -- #{file.path}]
- output = `#{argv.shelljoin}`
-
- unless output.match?(/text\/csv|text\/plain/)
- errors.add(:file, :not_csv)
- end
- end
-
- MAX_FILE_SIZE = 10.megabytes
-
- def validate_file_size
- return unless file
-
- if file.size > MAX_FILE_SIZE
- errors.add(:file, :file_too_large)
- end
- end
- end
- end
-end
diff --git a/app/models/forms/bulk_upload_sales/year.rb b/app/models/forms/bulk_upload_sales/year.rb
deleted file mode 100644
index ecf74c636..000000000
--- a/app/models/forms/bulk_upload_sales/year.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-module Forms
- module BulkUploadSales
- class Year
- include ActiveModel::Model
- include ActiveModel::Attributes
- include Rails.application.routes.url_helpers
-
- attribute :year, :integer
- attribute :organisation_id, :integer
-
- validates :year, presence: true
-
- def view_path
- "bulk_upload_sales_logs/forms/year"
- end
-
- def options
- possible_years.map do |year|
- OpenStruct.new(id: year, name: "#{year} to #{year + 1}")
- end
- end
-
- def back_path
- if organisation_id.present?
- sales_logs_organisation_path(organisation_id)
- else
- sales_logs_path
- end
- end
-
- def next_path
- bulk_upload_sales_log_path(id: "prepare-your-file", form: { year:, organisation_id: }.compact)
- end
-
- def save!
- true
- end
-
- private
-
- def possible_years
- [
- FormHandler.instance.current_sales_form.start_date.year,
- (FormHandler.instance.previous_sales_form.start_date.year if FormHandler.instance.sales_in_crossover_period?),
- (FormHandler.instance.next_sales_form.start_date.year if FeatureToggle.allow_future_form_use?),
- ].compact
- end
- end
- end
-end
diff --git a/app/models/forms/bulk_upload_sales_soft_validations_check/chosen.rb b/app/models/forms/bulk_upload_sales_soft_validations_check/chosen.rb
deleted file mode 100644
index 2286d3b39..000000000
--- a/app/models/forms/bulk_upload_sales_soft_validations_check/chosen.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-module Forms
- module BulkUploadSalesSoftValidationsCheck
- class Chosen
- include ActiveModel::Model
- include ActiveModel::Attributes
- include Rails.application.routes.url_helpers
-
- attribute :bulk_upload
-
- def view_path
- "bulk_upload_sales_soft_validations_check/chosen"
- end
-
- def back_path
- sales_logs_path
- end
-
- def next_path
- sales_logs_path
- end
-
- def save!
- true
- end
-
- def preflight_valid?
- true
- end
- end
- end
-end
diff --git a/app/models/forms/bulk_upload_sales_soft_validations_check/confirm.rb b/app/models/forms/bulk_upload_sales_soft_validations_check/confirm.rb
deleted file mode 100644
index 894f55123..000000000
--- a/app/models/forms/bulk_upload_sales_soft_validations_check/confirm.rb
+++ /dev/null
@@ -1,47 +0,0 @@
-module Forms
- module BulkUploadSalesSoftValidationsCheck
- class Confirm
- include ActiveModel::Model
- include ActiveModel::Attributes
- include Rails.application.routes.url_helpers
-
- attribute :bulk_upload
-
- def view_path
- "bulk_upload_sales_soft_validations_check/confirm"
- end
-
- def back_path
- page_bulk_upload_sales_soft_validations_check_path(bulk_upload, page: "confirm-soft-errors")
- end
-
- def next_path
- sales_logs_path
- end
-
- def save!
- ApplicationRecord.transaction do
- processor = BulkUpload::Processor.new(bulk_upload:)
- processor.approve_and_confirm_soft_validations
-
- bulk_upload.update!(choice: "bulk-confirm-soft-validations")
- end
-
- true
- end
-
- def preflight_valid?
- bulk_upload.choice != "bulk-confirm-soft-validations" && bulk_upload.choice != "create-fix-inline"
- end
-
- def preflight_redirect
- case bulk_upload.choice
- when "bulk-confirm-soft-validations"
- page_bulk_upload_sales_soft_validations_check_path(bulk_upload, :chosen)
- when "create-fix-inline"
- page_bulk_upload_sales_resume_path(bulk_upload, :chosen)
- end
- end
- end
- end
-end
diff --git a/app/models/forms/bulk_upload_sales_soft_validations_check/confirm_soft_errors.rb b/app/models/forms/bulk_upload_sales_soft_validations_check/confirm_soft_errors.rb
deleted file mode 100644
index 041647cf0..000000000
--- a/app/models/forms/bulk_upload_sales_soft_validations_check/confirm_soft_errors.rb
+++ /dev/null
@@ -1,53 +0,0 @@
-module Forms
- module BulkUploadSalesSoftValidationsCheck
- class ConfirmSoftErrors
- include ActiveModel::Model
- include ActiveModel::Attributes
- include Rails.application.routes.url_helpers
-
- attribute :bulk_upload
- attribute :confirm_soft_errors, :string
-
- validates :confirm_soft_errors, presence: true
-
- def options
- [
- OpenStruct.new(id: "yes", name: "Yes, these fields are correct"),
- OpenStruct.new(id: "no", name: "No, there are errors"),
- ]
- end
-
- def view_path
- "bulk_upload_sales_soft_validations_check/confirm_soft_errors"
- end
-
- def next_path
- case confirm_soft_errors
- when "no"
- page_bulk_upload_sales_resume_path(bulk_upload, page: "fix-choice", soft_errors_only: true)
- when "yes"
- page_bulk_upload_sales_soft_validations_check_path(bulk_upload, page: "confirm")
- else
- raise "invalid choice"
- end
- end
-
- def save!
- true
- end
-
- def preflight_valid?
- bulk_upload.choice != "bulk-confirm-soft-validations" && bulk_upload.choice != "create-fix-inline"
- end
-
- def preflight_redirect
- case bulk_upload.choice
- when "bulk-confirm-soft-validations"
- page_bulk_upload_sales_soft_validations_check_path(bulk_upload, :chosen)
- when "create-fix-inline"
- page_bulk_upload_sales_resume_path(bulk_upload, :chosen)
- end
- end
- end
- end
-end
diff --git a/app/models/forms/bulk_upload_sales_resume/chosen.rb b/app/models/forms/bulk_upload_soft_validations_check/chosen.rb
similarity index 65%
rename from app/models/forms/bulk_upload_sales_resume/chosen.rb
rename to app/models/forms/bulk_upload_soft_validations_check/chosen.rb
index 3bf32ee71..359eea9dd 100644
--- a/app/models/forms/bulk_upload_sales_resume/chosen.rb
+++ b/app/models/forms/bulk_upload_soft_validations_check/chosen.rb
@@ -1,22 +1,23 @@
module Forms
- module BulkUploadSalesResume
+ module BulkUploadSoftValidationsCheck
class Chosen
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
+ attribute :log_type
attribute :bulk_upload
def view_path
- bulk_upload.completed? ? "bulk_upload_sales_resume/completed" : "bulk_upload_sales_resume/chosen"
+ "bulk_upload_#{log_type}_soft_validations_check/chosen"
end
def back_path
- sales_logs_path
+ send("#{log_type}_logs_path")
end
def next_path
- sales_logs_path
+ send("#{log_type}_logs_path")
end
def save!
diff --git a/app/models/forms/bulk_upload_lettings_soft_validations_check/confirm.rb b/app/models/forms/bulk_upload_soft_validations_check/confirm.rb
similarity index 65%
rename from app/models/forms/bulk_upload_lettings_soft_validations_check/confirm.rb
rename to app/models/forms/bulk_upload_soft_validations_check/confirm.rb
index aba75791e..8700937cb 100644
--- a/app/models/forms/bulk_upload_lettings_soft_validations_check/confirm.rb
+++ b/app/models/forms/bulk_upload_soft_validations_check/confirm.rb
@@ -1,22 +1,23 @@
module Forms
- module BulkUploadLettingsSoftValidationsCheck
+ module BulkUploadSoftValidationsCheck
class Confirm
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
+ attribute :log_type
attribute :bulk_upload
def view_path
- "bulk_upload_lettings_soft_validations_check/confirm"
+ "bulk_upload_#{log_type}_soft_validations_check/confirm"
end
def back_path
- page_bulk_upload_lettings_soft_validations_check_path(bulk_upload, page: "confirm-soft-errors")
+ send("page_bulk_upload_#{log_type}_soft_validations_check_path", bulk_upload, page: "confirm-soft-errors")
end
def next_path
- lettings_logs_path
+ send("#{log_type}_logs_path")
end
def save!
@@ -37,9 +38,9 @@ module Forms
def preflight_redirect
case bulk_upload.choice
when "bulk-confirm-soft-validations"
- page_bulk_upload_lettings_soft_validations_check_path(bulk_upload, :chosen)
+ send("page_bulk_upload_#{log_type}_soft_validations_check_path", bulk_upload, :chosen)
when "create-fix-inline"
- page_bulk_upload_lettings_resume_path(bulk_upload, :chosen)
+ send("page_bulk_upload_#{log_type}_resume_path", bulk_upload, :chosen)
end
end
end
diff --git a/app/models/forms/bulk_upload_lettings_soft_validations_check/confirm_soft_errors.rb b/app/models/forms/bulk_upload_soft_validations_check/confirm_soft_errors.rb
similarity index 65%
rename from app/models/forms/bulk_upload_lettings_soft_validations_check/confirm_soft_errors.rb
rename to app/models/forms/bulk_upload_soft_validations_check/confirm_soft_errors.rb
index 34b4b97f3..aeb072152 100644
--- a/app/models/forms/bulk_upload_lettings_soft_validations_check/confirm_soft_errors.rb
+++ b/app/models/forms/bulk_upload_soft_validations_check/confirm_soft_errors.rb
@@ -1,10 +1,11 @@
module Forms
- module BulkUploadLettingsSoftValidationsCheck
+ module BulkUploadSoftValidationsCheck
class ConfirmSoftErrors
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
+ attribute :log_type
attribute :bulk_upload
attribute :confirm_soft_errors, :string
@@ -18,15 +19,15 @@ module Forms
end
def view_path
- "bulk_upload_lettings_soft_validations_check/confirm_soft_errors"
+ "bulk_upload_#{log_type}_soft_validations_check/confirm_soft_errors"
end
def next_path
case confirm_soft_errors
when "no"
- page_bulk_upload_lettings_resume_path(bulk_upload, page: "fix-choice", soft_errors_only: true)
+ send("page_bulk_upload_#{log_type}_resume_path", bulk_upload, page: "fix-choice", soft_errors_only: true)
when "yes"
- page_bulk_upload_lettings_soft_validations_check_path(bulk_upload, page: "confirm")
+ send("page_bulk_upload_#{log_type}_soft_validations_check_path", bulk_upload, page: "confirm")
else
raise "invalid choice"
end
@@ -43,9 +44,9 @@ module Forms
def preflight_redirect
case bulk_upload.choice
when "bulk-confirm-soft-validations"
- page_bulk_upload_lettings_soft_validations_check_path(bulk_upload, :chosen)
+ send("page_bulk_upload_#{log_type}_soft_validations_check_path", bulk_upload, :chosen)
when "create-fix-inline"
- page_bulk_upload_lettings_resume_path(bulk_upload, :chosen)
+ send("page_bulk_upload_#{log_type}_resume_path", bulk_upload, :chosen)
end
end
end
diff --git a/app/views/bulk_upload_lettings_results/show.html.erb b/app/views/bulk_upload_lettings_results/show.html.erb
index b1f9eb6f6..8aba5eaf7 100644
--- a/app/views/bulk_upload_lettings_results/show.html.erb
+++ b/app/views/bulk_upload_lettings_results/show.html.erb
@@ -10,7 +10,7 @@
We found <%= pluralize(@bulk_upload.bulk_upload_errors.count, "error") %> in your file
- Here’s a list of everything that you need to fix your spreadsheet. You can download the <%= govuk_link_to "specification", Forms::BulkUploadLettings::PrepareYourFile.new(year: @bulk_upload.year).specification_path, target: "_blank" %> to help you fix the cells in your CSV file.
+ 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.
File name: <%= @bulk_upload.filename %>
diff --git a/app/views/bulk_upload_lettings_results/summary.html.erb b/app/views/bulk_upload_lettings_results/summary.html.erb
index 2f565ed59..ab60212e9 100644
--- a/app/views/bulk_upload_lettings_results/summary.html.erb
+++ b/app/views/bulk_upload_lettings_results/summary.html.erb
@@ -6,7 +6,7 @@
Fix <%= pluralize(@bulk_upload.bulk_upload_errors.count, "error") %> and upload file again
- We could not create logs from your bulk upload because of the following errors. Download the <%= govuk_link_to "specification", Forms::BulkUploadLettings::PrepareYourFile.new(year: @bulk_upload.year).specification_path, target: "_blank" %> to help you fix the cells in your CSV file.
+ We could not create logs from your bulk upload because of the following errors. 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.
File name: <%= @bulk_upload.filename %>
diff --git a/app/views/bulk_upload_sales_results/show.html.erb b/app/views/bulk_upload_sales_results/show.html.erb
index 24b09ce6a..f455ad849 100644
--- a/app/views/bulk_upload_sales_results/show.html.erb
+++ b/app/views/bulk_upload_sales_results/show.html.erb
@@ -10,7 +10,7 @@
We found <%= pluralize(@bulk_upload.bulk_upload_errors.count, "error") %> in your file
- Here’s a list of everything that you need to fix your spreadsheet. You can download the <%= govuk_link_to "specification", Forms::BulkUploadSales::PrepareYourFile.new(year: @bulk_upload.year).specification_path, target: "_blank" %> to help you fix the cells in your CSV file.
+ 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.
File name: <%= @bulk_upload.filename %>
diff --git a/app/views/bulk_upload_sales_results/summary.html.erb b/app/views/bulk_upload_sales_results/summary.html.erb
index 2ae2a915b..ed2ec14b3 100644
--- a/app/views/bulk_upload_sales_results/summary.html.erb
+++ b/app/views/bulk_upload_sales_results/summary.html.erb
@@ -6,7 +6,7 @@
Fix <%= pluralize(@bulk_upload.bulk_upload_errors.count, "error") %> and upload file again
- We could not create logs from your bulk upload because of the following errors. Download the <%= govuk_link_to "specification", Forms::BulkUploadSales::PrepareYourFile.new(year: @bulk_upload.year).specification_path, target: "_blank" %> to help you fix the cells in your CSV file.
+ We could not create logs from your bulk upload because of the following errors. 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.
File name: <%= @bulk_upload.filename %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 7a95aa6fd..97a6a4bff 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -61,45 +61,26 @@ en:
<<: *bulk_upload__row_parser__base
bulk_upload/sales/year2023/row_parser:
<<: *bulk_upload__row_parser__base
- forms/bulk_upload_lettings/year:
+ forms/bulk_upload_form/year:
attributes:
year:
blank: "You must select a collection period to upload for."
- forms/bulk_upload_sales/year:
- attributes:
- year:
- blank: "You must select a collection period to upload for."
- forms/bulk_upload_lettings/upload_your_file:
- attributes:
- file:
- blank: "Select which file to upload."
- not_csv: "Your file must be in CSV format."
- file_too_large: "File must be 10MB or less. Check your file and delete data that does not need to be uploaded."
- forms/bulk_upload_sales/upload_your_file:
+ forms/bulk_upload_form/upload_your_file:
attributes:
file:
blank: "Select which file to upload."
not_csv: "Your file must be in CSV format."
file_too_large: "File must be 10MB or less. Check your file and delete data that does not need to be uploaded."
- forms/bulk_upload_lettings/needstype:
+ forms/bulk_upload_form/needstype:
attributes:
needstype:
blank: "You must answer needs type."
- forms/bulk_upload_lettings_resume/fix_choice:
+ forms/bulk_upload_resume/fix_choice:
attributes:
choice:
blank: "Select how you would like to fix these errors."
inclusion: "You must select one of the following options for how you would like to fix these errors."
- forms/bulk_upload_sales_resume/fix_choice:
- attributes:
- choice:
- blank: "Select how you would like to fix these errors."
- inclusion: "You must select one of the following options for how you would like to fix these errors."
- forms/bulk_upload_lettings_soft_validations_check/confirm_soft_errors:
- attributes:
- confirm_soft_errors:
- blank: "You must select if there are errors in these fields."
- forms/bulk_upload_sales_soft_validations_check/confirm_soft_errors:
+ forms/bulk_upload_soft_validations_check/confirm_soft_errors:
attributes:
confirm_soft_errors:
blank: "You must select if there are errors in these fields."
diff --git a/spec/features/bulk_upload_lettings_logs_spec.rb b/spec/features/bulk_upload_lettings_logs_spec.rb
index b3e403cbf..3dabfdeac 100644
--- a/spec/features/bulk_upload_lettings_logs_spec.rb
+++ b/spec/features/bulk_upload_lettings_logs_spec.rb
@@ -55,13 +55,13 @@ RSpec.describe "Bulk upload lettings log" do
expect(page).to have_content("Upload your file")
click_button("Upload")
- allow_any_instance_of(Forms::BulkUploadLettings::UploadYourFile).to receive(:`).and_return("not a csv")
+ allow_any_instance_of(Forms::BulkUploadForm::UploadYourFile).to receive(:`).and_return("not a csv")
expect(page).to have_content("Select which file to upload")
attach_file "file", file_fixture("2023_24_lettings_bulk_upload.xlsx")
click_button("Upload")
- allow_any_instance_of(Forms::BulkUploadLettings::UploadYourFile).to receive(:`).and_return("text/csv")
+ allow_any_instance_of(Forms::BulkUploadForm::UploadYourFile).to receive(:`).and_return("text/csv")
expect(page).to have_content("Your file must be in CSV format")
attach_file "file", file_fixture("blank_bulk_upload_sales.csv")
@@ -76,7 +76,7 @@ RSpec.describe "Bulk upload lettings log" do
end
it "shows file to large error" do
- stub_const("Forms::BulkUploadLettings::UploadYourFile::MAX_FILE_SIZE", 1.bytes)
+ stub_const("Forms::BulkUploadForm::UploadYourFile::MAX_FILE_SIZE", 1.bytes)
visit("/lettings-logs")
click_link("Upload lettings logs in bulk")
@@ -86,7 +86,7 @@ RSpec.describe "Bulk upload lettings log" do
click_button("Continue")
click_button("Continue")
- allow_any_instance_of(Forms::BulkUploadLettings::UploadYourFile).to receive(:`).and_return("text/csv")
+ allow_any_instance_of(Forms::BulkUploadForm::UploadYourFile).to receive(:`).and_return("text/csv")
attach_file "file", file_fixture("2023_24_lettings_bulk_upload.xlsx")
click_button("Upload")
diff --git a/spec/features/bulk_upload_sales_logs_spec.rb b/spec/features/bulk_upload_sales_logs_spec.rb
index b32df43e1..1ff0d9fb0 100644
--- a/spec/features/bulk_upload_sales_logs_spec.rb
+++ b/spec/features/bulk_upload_sales_logs_spec.rb
@@ -52,13 +52,13 @@ RSpec.describe "Bulk upload sales log" do
expect(page).to have_content("Upload your file")
click_button("Upload")
- allow_any_instance_of(Forms::BulkUploadSales::UploadYourFile).to receive(:`).and_return("not a csv")
+ allow_any_instance_of(Forms::BulkUploadForm::UploadYourFile).to receive(:`).and_return("not a csv")
expect(page).to have_content("Select which file to upload")
attach_file "file", file_fixture("2023_24_lettings_bulk_upload.xlsx")
click_button("Upload")
- allow_any_instance_of(Forms::BulkUploadSales::UploadYourFile).to receive(:`).and_return("text/csv")
+ allow_any_instance_of(Forms::BulkUploadForm::UploadYourFile).to receive(:`).and_return("text/csv")
expect(page).to have_content("Your file must be in CSV format")
attach_file "file", file_fixture("blank_bulk_upload_sales.csv")
@@ -73,7 +73,7 @@ RSpec.describe "Bulk upload sales log" do
end
it "shows file to large error" do
- stub_const("Forms::BulkUploadSales::UploadYourFile::MAX_FILE_SIZE", 1.bytes)
+ stub_const("Forms::BulkUploadForm::UploadYourFile::MAX_FILE_SIZE", 1.bytes)
visit("/sales-logs")
click_link("Upload sales logs in bulk")
@@ -84,7 +84,7 @@ RSpec.describe "Bulk upload sales log" do
click_button("Continue")
click_button("Continue")
- allow_any_instance_of(Forms::BulkUploadSales::UploadYourFile).to receive(:`).and_return("text/csv")
+ allow_any_instance_of(Forms::BulkUploadForm::UploadYourFile).to receive(:`).and_return("text/csv")
attach_file "file", file_fixture("2023_24_lettings_bulk_upload.xlsx")
click_button("Upload")
diff --git a/spec/models/forms/bulk_upload_form/guidance_spec.rb b/spec/models/forms/bulk_upload_form/guidance_spec.rb
new file mode 100644
index 000000000..8dee1563d
--- /dev/null
+++ b/spec/models/forms/bulk_upload_form/guidance_spec.rb
@@ -0,0 +1,117 @@
+require "rails_helper"
+
+RSpec.describe Forms::BulkUploadForm::Guidance do
+ include Rails.application.routes.url_helpers
+
+ subject(:bu_guidance) { described_class.new(year:, referrer:, log_type:) }
+
+ let(:year) { 2024 }
+ let(:log_type) { "sales" }
+ let(:referrer) { nil }
+
+ describe "sales" do
+ describe "#back_path" do
+ context "when referrer is prepare-your-file" do
+ let(:referrer) { "prepare-your-file" }
+
+ it "returns the prepare your file path" do
+ expect(bu_guidance.back_path).to eq bulk_upload_sales_log_path(id: "prepare-your-file", form: { year: })
+ end
+ end
+
+ context "when referrer is home" do
+ let(:referrer) { "home" }
+
+ it "returns the root path" do
+ expect(bu_guidance.back_path).to eq root_path
+ end
+ end
+
+ context "when referrer is guidance" do
+ let(:referrer) { "guidance" }
+
+ it "returns the main guidance page path" do
+ expect(bu_guidance.back_path).to eq guidance_path
+ end
+ end
+
+ context "when referrer is absent" do
+ let(:referrer) { nil }
+
+ it "returns the main guidance page path" do
+ expect(bu_guidance.back_path).to eq guidance_path
+ end
+ end
+ end
+
+ describe "year" do
+ context "when year is not provided" do
+ let(:year) { nil }
+
+ before do
+ # rubocop:disable RSpec/AnyInstance
+ allow_any_instance_of(CollectionTimeHelper).to receive(:current_collection_start_year).and_return(2030)
+ # rubocop:enable RSpec/AnyInstance
+ end
+
+ it "is set to the current collection start year" do
+ expect(bu_guidance.year).to eq(2030)
+ end
+ end
+ end
+ end
+
+ describe "lettings" do
+ let(:log_type) { "lettings" }
+
+ describe "#back_path" do
+ context "when referrer is prepare-your-file" do
+ let(:referrer) { "prepare-your-file" }
+
+ it "returns the prepare your file path" do
+ expect(bu_guidance.back_path).to eq bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year: })
+ end
+ end
+
+ context "when referrer is home" do
+ let(:referrer) { "home" }
+
+ it "returns the root path" do
+ expect(bu_guidance.back_path).to eq root_path
+ end
+ end
+
+ context "when referrer is guidance" do
+ let(:referrer) { "guidance" }
+
+ it "returns the main guidance page path" do
+ expect(bu_guidance.back_path).to eq guidance_path
+ end
+ end
+
+ context "when referrer is absent" do
+ let(:referrer) { nil }
+
+ it "returns the main guidance page path" do
+ expect(bu_guidance.back_path).to eq guidance_path
+ end
+ end
+ end
+
+ describe "year" do
+ context "when year is not provided" do
+ let(:year) { nil }
+
+ before do
+ # rubocop:disable RSpec/AnyInstance
+ allow_any_instance_of(CollectionTimeHelper).to receive(:current_collection_start_year).and_return(2030)
+ # rubocop:enable RSpec/AnyInstance
+ end
+
+ it "is set to the current collection start year" do
+ expect(bu_guidance.year).to eq(2030)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/models/forms/bulk_upload_form/upload_your_file_spec.rb b/spec/models/forms/bulk_upload_form/upload_your_file_spec.rb
new file mode 100644
index 000000000..dbfc06777
--- /dev/null
+++ b/spec/models/forms/bulk_upload_form/upload_your_file_spec.rb
@@ -0,0 +1,100 @@
+require "rails_helper"
+
+RSpec.describe Forms::BulkUploadForm::UploadYourFile do
+ subject(:form) { described_class.new(year:, file:, current_user:, log_type:) }
+
+ let(:year) { 2022 }
+ let(:actual_file) { File.open(file_fixture("blank_bulk_upload_sales.csv")) }
+ let(:file) do
+ ActionDispatch::Http::UploadedFile.new(
+ tempfile: actual_file,
+ filename: "my-file.csv",
+ )
+ end
+ let(:current_user) { create(:user) }
+ let(:mock_storage_service) { instance_double("S3Service") }
+
+ before do
+ vcap_services = { "aws-s3-bucket" => {} }
+
+ allow(ENV).to receive(:[])
+ allow(ENV).to receive(:[]).with("VCAP_SERVICES").and_return(vcap_services.to_json)
+
+ allow(Storage::S3Service).to receive(:new).and_return(mock_storage_service)
+ allow(mock_storage_service).to receive(:write_file)
+ end
+
+ describe "lettings" do
+ let(:log_type) { "lettings" }
+
+ describe "#save" do
+ it "persists a BulkUpload" do
+ expect { form.save! }.to change(BulkUpload, :count).by(1)
+ end
+
+ it "persists a BulkUpload correctly" do
+ form.save!
+
+ bulk_upload = BulkUpload.last
+
+ expect(bulk_upload.user).to eql(current_user)
+ expect(bulk_upload.log_type).to eql("lettings")
+ expect(bulk_upload.year).to eql(year)
+ expect(bulk_upload.filename).to eql("my-file.csv")
+ expect(bulk_upload.identifier).to be_present
+ end
+
+ it "uploads file via storage service" do
+ form.save!
+
+ bulk_upload = BulkUpload.last
+
+ expect(Storage::S3Service).to have_received(:new)
+ expect(mock_storage_service).to have_received(:write_file).with(bulk_upload.identifier, actual_file.read)
+ end
+
+ it "enqueues job to process bulk upload" do
+ expect {
+ form.save!
+ }.to have_enqueued_job(ProcessBulkUploadJob)
+ end
+ end
+ end
+
+ describe "sales" do
+ let(:log_type) { "sales" }
+
+ describe "#save" do
+ it "persists a BulkUpload" do
+ expect { form.save! }.to change(BulkUpload, :count).by(1)
+ end
+
+ it "persists a BulkUpload correctly" do
+ form.save!
+
+ bulk_upload = BulkUpload.last
+
+ expect(bulk_upload.user).to eql(current_user)
+ expect(bulk_upload.log_type).to eql("sales")
+ expect(bulk_upload.year).to eql(year)
+ expect(bulk_upload.filename).to eql("my-file.csv")
+ expect(bulk_upload.identifier).to be_present
+ end
+
+ it "uploads file via storage service" do
+ form.save!
+
+ bulk_upload = BulkUpload.last
+
+ expect(Storage::S3Service).to have_received(:new)
+ expect(mock_storage_service).to have_received(:write_file).with(bulk_upload.identifier, actual_file.read)
+ end
+
+ it "enqueues job to process bulk upload" do
+ expect {
+ form.save!
+ }.to have_enqueued_job(ProcessBulkUploadJob)
+ end
+ end
+ end
+end
diff --git a/spec/models/forms/bulk_upload_form/year_spec.rb b/spec/models/forms/bulk_upload_form/year_spec.rb
new file mode 100644
index 000000000..ac0c443f5
--- /dev/null
+++ b/spec/models/forms/bulk_upload_form/year_spec.rb
@@ -0,0 +1,101 @@
+require "rails_helper"
+
+RSpec.describe Forms::BulkUploadForm::Year do
+ subject(:form) { described_class.new(log_type:) }
+
+ describe "lettings" do
+ let(:log_type) { "lettings" }
+
+ describe "#options" do
+ before do
+ allow(FormHandler.instance).to receive(:lettings_forms).and_return({ "current_lettings" => instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) })
+ allow(FormHandler.instance).to receive(:previous_lettings_form).and_return(instance_double(Form, start_date: Time.zone.local(2023, 4, 1)))
+ allow(FormHandler.instance).to receive(:next_lettings_form).and_return(instance_double(Form, start_date: Time.zone.local(2025, 4, 1)))
+ end
+
+ context "when in a crossover period" do
+ before do
+ allow(FormHandler.instance).to receive(:lettings_in_crossover_period?).and_return(true)
+ end
+
+ it "returns current and previous years" do
+ expect(form.options.map(&:id)).to eql([2024, 2023])
+ expect(form.options.map(&:name)).to eql(["2024 to 2025", "2023 to 2024"])
+ end
+ end
+
+ context "when not in a crossover period" do
+ before do
+ allow(FormHandler.instance).to receive(:lettings_in_crossover_period?).and_return(false)
+ end
+
+ it "returns the current year" do
+ expect(form.options.map(&:id)).to eql([2024])
+ expect(form.options.map(&:name)).to eql(["2024 to 2025"])
+ end
+ end
+
+ context "when allow_future_form_use is toggled on" do
+ before do
+ allow(FormHandler.instance).to receive(:lettings_in_crossover_period?).and_return(false)
+ allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(true)
+ end
+
+ it "returns current and next years" do
+ expect(form.options.map(&:id)).to eql([2024, 2025])
+ expect(form.options.map(&:name)).to eql(["2024 to 2025", "2025 to 2026"])
+ end
+ end
+ end
+ end
+
+ describe "sales" do
+ let(:log_type) { "sales" }
+
+ describe "#options" do
+ before do
+ allow(FormHandler.instance).to receive(:sales_forms).and_return({ "current_sales" => instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) })
+ allow(FormHandler.instance).to receive(:previous_sales_form).and_return(instance_double(Form, start_date: Time.zone.local(2023, 4, 1)))
+ allow(FormHandler.instance).to receive(:next_sales_form).and_return(instance_double(Form, start_date: Time.zone.local(2025, 4, 1)))
+ end
+
+ context "when in a crossover period" do
+ before do
+ allow(FormHandler.instance).to receive(:sales_in_crossover_period?).and_return(true)
+ end
+
+ it "returns current and previous years" do
+ expect(form.options.map(&:id)).to eql([2024, 2023])
+ expect(form.options.map(&:name)).to eql(["2024 to 2025", "2023 to 2024"])
+ end
+ end
+
+ context "when not in a crossover period" do
+ before do
+ allow(FormHandler.instance).to receive(:sales_in_crossover_period?).and_return(false)
+ end
+
+ it "returns the current year" do
+ expect(form.options.map(&:id)).to eql([2024])
+ expect(form.options.map(&:name)).to eql(["2024 to 2025"])
+ end
+ end
+
+ context "when allow_future_form_use is toggled on" do
+ before do
+ allow(FormHandler.instance).to receive(:sales_in_crossover_period?).and_return(false)
+ allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(true)
+ end
+
+ after do
+ Timecop.return
+ end
+
+ it "returns current and next years" do
+ expect(form.options.map(&:id)).to eql([2024, 2025])
+ expect(form.options.map(&:name)).to eql(["2024 to 2025", "2025 to 2026"])
+ end
+ end
+ end
+ end
+end
diff --git a/spec/models/forms/bulk_upload_lettings/guidance_spec.rb b/spec/models/forms/bulk_upload_lettings/guidance_spec.rb
deleted file mode 100644
index 41e74c50c..000000000
--- a/spec/models/forms/bulk_upload_lettings/guidance_spec.rb
+++ /dev/null
@@ -1,60 +0,0 @@
-require "rails_helper"
-
-RSpec.describe Forms::BulkUploadLettings::Guidance do
- include Rails.application.routes.url_helpers
-
- subject(:bu_guidance) { described_class.new(year:, referrer:) }
-
- let(:year) { 2024 }
- let(:referrer) { nil }
-
- describe "#back_path" do
- context "when referrer is prepare-your-file" do
- let(:referrer) { "prepare-your-file" }
-
- it "returns the prepare your file path" do
- expect(bu_guidance.back_path).to eq bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year: })
- end
- end
-
- context "when referrer is home" do
- let(:referrer) { "home" }
-
- it "returns the root path" do
- expect(bu_guidance.back_path).to eq root_path
- end
- end
-
- context "when referrer is guidance" do
- let(:referrer) { "guidance" }
-
- it "returns the main guidance page path" do
- expect(bu_guidance.back_path).to eq guidance_path
- end
- end
-
- context "when referrer is absent" do
- let(:referrer) { nil }
-
- it "returns the main guidance page path" do
- expect(bu_guidance.back_path).to eq guidance_path
- end
- end
- end
-
- describe "year" do
- context "when year is not provided" do
- let(:year) { nil }
-
- before do
- # rubocop:disable RSpec/AnyInstance
- allow_any_instance_of(CollectionTimeHelper).to receive(:current_collection_start_year).and_return(2030)
- # rubocop:enable RSpec/AnyInstance
- end
-
- it "is set to the current collection start year" do
- expect(bu_guidance.year).to eq(2030)
- end
- end
- end
-end
diff --git a/spec/models/forms/bulk_upload_lettings/upload_your_file_spec.rb b/spec/models/forms/bulk_upload_lettings/upload_your_file_spec.rb
deleted file mode 100644
index a71d446fe..000000000
--- a/spec/models/forms/bulk_upload_lettings/upload_your_file_spec.rb
+++ /dev/null
@@ -1,61 +0,0 @@
-require "rails_helper"
-
-RSpec.describe Forms::BulkUploadLettings::UploadYourFile do
- subject(:form) { described_class.new(year:, needstype:, file:, current_user:) }
-
- let(:year) { 2022 }
- let(:needstype) { 2 }
- let(:actual_file) { File.open(file_fixture("blank_bulk_upload_sales.csv")) }
- let(:file) do
- ActionDispatch::Http::UploadedFile.new(
- tempfile: actual_file,
- filename: "my-file.csv",
- )
- end
- let(:current_user) { create(:user) }
- let(:mock_storage_service) { instance_double("S3Service") }
-
- before do
- vcap_services = { "aws-s3-bucket" => {} }
-
- allow(ENV).to receive(:[])
- allow(ENV).to receive(:[]).with("VCAP_SERVICES").and_return(vcap_services.to_json)
-
- allow(Storage::S3Service).to receive(:new).and_return(mock_storage_service)
- allow(mock_storage_service).to receive(:write_file)
- end
-
- describe "#save" do
- it "persists a BulkUpload" do
- expect { form.save! }.to change(BulkUpload, :count).by(1)
- end
-
- it "persists a BulkUpload correctly" do
- form.save!
-
- bulk_upload = BulkUpload.last
-
- expect(bulk_upload.user).to eql(current_user)
- expect(bulk_upload.log_type).to eql("lettings")
- expect(bulk_upload.year).to eql(year)
- expect(bulk_upload.needstype).to eql(needstype)
- expect(bulk_upload.filename).to eql("my-file.csv")
- expect(bulk_upload.identifier).to be_present
- end
-
- it "uploads file via storage service" do
- form.save!
-
- bulk_upload = BulkUpload.last
-
- expect(Storage::S3Service).to have_received(:new)
- expect(mock_storage_service).to have_received(:write_file).with(bulk_upload.identifier, actual_file.read)
- end
-
- it "enqueues job to process bulk upload" do
- expect {
- form.save!
- }.to have_enqueued_job(ProcessBulkUploadJob)
- end
- end
-end
diff --git a/spec/models/forms/bulk_upload_lettings/year_spec.rb b/spec/models/forms/bulk_upload_lettings/year_spec.rb
deleted file mode 100644
index c4429b98b..000000000
--- a/spec/models/forms/bulk_upload_lettings/year_spec.rb
+++ /dev/null
@@ -1,47 +0,0 @@
-require "rails_helper"
-
-RSpec.describe Forms::BulkUploadLettings::Year do
- subject(:form) { described_class.new }
-
- describe "#options" do
- before do
- allow(FormHandler.instance).to receive(:lettings_forms).and_return({ "current_lettings" => instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) })
- allow(FormHandler.instance).to receive(:previous_lettings_form).and_return(instance_double(Form, start_date: Time.zone.local(2023, 4, 1)))
- allow(FormHandler.instance).to receive(:next_lettings_form).and_return(instance_double(Form, start_date: Time.zone.local(2025, 4, 1)))
- end
-
- context "when in a crossover period" do
- before do
- allow(FormHandler.instance).to receive(:lettings_in_crossover_period?).and_return(true)
- end
-
- it "returns current and previous years" do
- expect(form.options.map(&:id)).to eql([2024, 2023])
- expect(form.options.map(&:name)).to eql(["2024 to 2025", "2023 to 2024"])
- end
- end
-
- context "when not in a crossover period" do
- before do
- allow(FormHandler.instance).to receive(:lettings_in_crossover_period?).and_return(false)
- end
-
- it "returns the current year" do
- expect(form.options.map(&:id)).to eql([2024])
- expect(form.options.map(&:name)).to eql(["2024 to 2025"])
- end
- end
-
- context "when allow_future_form_use is toggled on" do
- before do
- allow(FormHandler.instance).to receive(:lettings_in_crossover_period?).and_return(false)
- allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(true)
- end
-
- it "returns current and next years" do
- expect(form.options.map(&:id)).to eql([2024, 2025])
- expect(form.options.map(&:name)).to eql(["2024 to 2025", "2025 to 2026"])
- end
- end
- end
-end
diff --git a/spec/models/forms/bulk_upload_sales/guidance_spec.rb b/spec/models/forms/bulk_upload_sales/guidance_spec.rb
deleted file mode 100644
index f9c986cb2..000000000
--- a/spec/models/forms/bulk_upload_sales/guidance_spec.rb
+++ /dev/null
@@ -1,60 +0,0 @@
-require "rails_helper"
-
-RSpec.describe Forms::BulkUploadSales::Guidance do
- include Rails.application.routes.url_helpers
-
- subject(:bu_guidance) { described_class.new(year:, referrer:) }
-
- let(:year) { 2024 }
- let(:referrer) { nil }
-
- describe "#back_path" do
- context "when referrer is prepare-your-file" do
- let(:referrer) { "prepare-your-file" }
-
- it "returns the prepare your file path" do
- expect(bu_guidance.back_path).to eq bulk_upload_sales_log_path(id: "prepare-your-file", form: { year: })
- end
- end
-
- context "when referrer is home" do
- let(:referrer) { "home" }
-
- it "returns the root path" do
- expect(bu_guidance.back_path).to eq root_path
- end
- end
-
- context "when referrer is guidance" do
- let(:referrer) { "guidance" }
-
- it "returns the main guidance page path" do
- expect(bu_guidance.back_path).to eq guidance_path
- end
- end
-
- context "when referrer is absent" do
- let(:referrer) { nil }
-
- it "returns the main guidance page path" do
- expect(bu_guidance.back_path).to eq guidance_path
- end
- end
- end
-
- describe "year" do
- context "when year is not provided" do
- let(:year) { nil }
-
- before do
- # rubocop:disable RSpec/AnyInstance
- allow_any_instance_of(CollectionTimeHelper).to receive(:current_collection_start_year).and_return(2030)
- # rubocop:enable RSpec/AnyInstance
- end
-
- it "is set to the current collection start year" do
- expect(bu_guidance.year).to eq(2030)
- end
- end
- end
-end
diff --git a/spec/models/forms/bulk_upload_sales/upload_your_file_spec.rb b/spec/models/forms/bulk_upload_sales/upload_your_file_spec.rb
deleted file mode 100644
index 512e85aa2..000000000
--- a/spec/models/forms/bulk_upload_sales/upload_your_file_spec.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-require "rails_helper"
-
-RSpec.describe Forms::BulkUploadSales::UploadYourFile do
- subject(:form) { described_class.new(year:, file:, current_user:) }
-
- let(:year) { 2022 }
- let(:actual_file) { File.open(file_fixture("blank_bulk_upload_sales.csv")) }
- let(:file) do
- ActionDispatch::Http::UploadedFile.new(
- tempfile: actual_file,
- filename: "my-file.csv",
- )
- end
- let(:current_user) { create(:user) }
- let(:mock_storage_service) { instance_double("S3Service") }
-
- before do
- vcap_services = { "aws-s3-bucket" => {} }
-
- allow(ENV).to receive(:[])
- allow(ENV).to receive(:[]).with("VCAP_SERVICES").and_return(vcap_services.to_json)
-
- allow(Storage::S3Service).to receive(:new).and_return(mock_storage_service)
- allow(mock_storage_service).to receive(:write_file)
- end
-
- describe "#save" do
- it "persists a BulkUpload" do
- expect { form.save! }.to change(BulkUpload, :count).by(1)
- end
-
- it "persists a BulkUpload correctly" do
- form.save!
-
- bulk_upload = BulkUpload.last
-
- expect(bulk_upload.user).to eql(current_user)
- expect(bulk_upload.log_type).to eql("sales")
- expect(bulk_upload.year).to eql(year)
- expect(bulk_upload.filename).to eql("my-file.csv")
- expect(bulk_upload.identifier).to be_present
- end
-
- it "uploads file via storage service" do
- form.save!
-
- bulk_upload = BulkUpload.last
-
- expect(Storage::S3Service).to have_received(:new)
- expect(mock_storage_service).to have_received(:write_file).with(bulk_upload.identifier, actual_file.read)
- end
-
- it "enqueues job to process bulk upload" do
- expect {
- form.save!
- }.to have_enqueued_job(ProcessBulkUploadJob)
- end
- end
-end
diff --git a/spec/models/forms/bulk_upload_sales/year_spec.rb b/spec/models/forms/bulk_upload_sales/year_spec.rb
deleted file mode 100644
index b1b22bb8d..000000000
--- a/spec/models/forms/bulk_upload_sales/year_spec.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-require "rails_helper"
-
-RSpec.describe Forms::BulkUploadSales::Year do
- subject(:form) { described_class.new }
-
- describe "#options" do
- before do
- allow(FormHandler.instance).to receive(:sales_forms).and_return({ "current_sales" => instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) })
- allow(FormHandler.instance).to receive(:previous_sales_form).and_return(instance_double(Form, start_date: Time.zone.local(2023, 4, 1)))
- allow(FormHandler.instance).to receive(:next_sales_form).and_return(instance_double(Form, start_date: Time.zone.local(2025, 4, 1)))
- end
-
- context "when in a crossover period" do
- before do
- allow(FormHandler.instance).to receive(:sales_in_crossover_period?).and_return(true)
- end
-
- it "returns current and previous years" do
- expect(form.options.map(&:id)).to eql([2024, 2023])
- expect(form.options.map(&:name)).to eql(["2024 to 2025", "2023 to 2024"])
- end
- end
-
- context "when not in a crossover period" do
- before do
- allow(FormHandler.instance).to receive(:sales_in_crossover_period?).and_return(false)
- end
-
- it "returns the current year" do
- expect(form.options.map(&:id)).to eql([2024])
- expect(form.options.map(&:name)).to eql(["2024 to 2025"])
- end
- end
-
- context "when allow_future_form_use is toggled on" do
- before do
- allow(FormHandler.instance).to receive(:sales_in_crossover_period?).and_return(false)
- allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(true)
- end
-
- after do
- Timecop.return
- end
-
- it "returns current and next years" do
- expect(form.options.map(&:id)).to eql([2024, 2025])
- expect(form.options.map(&:name)).to eql(["2024 to 2025", "2025 to 2026"])
- end
- end
- end
-end
From 9c41d0cca350daac356f5e98fdbf13ca45f702f6 Mon Sep 17 00:00:00 2001
From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>
Date: Fri, 20 Dec 2024 10:01:57 +0000
Subject: [PATCH 03/17] CLDC-2041 Display all errors for the page (#2840)
* Display all errors for the page
* Fix world
* Update the test
---------
Co-authored-by: Rachael Booth
---
app/controllers/form_controller.rb | 1 +
spec/requests/form_controller_spec.rb | 29 +++++++++++++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb
index f31662c4f..54988e71d 100644
--- a/app/controllers/form_controller.rb
+++ b/app/controllers/form_controller.rb
@@ -32,6 +32,7 @@ class FormController < ApplicationController
pages_requiring_update = pages_requiring_update(shown_page_ids_with_unanswered_questions_before_update)
redirect_to(successful_redirect_path(pages_requiring_update))
else
+ @log.valid? if mandatory_questions_with_no_response.any?
mandatory_questions_with_no_response.map do |question|
@log.errors.add question.id.to_sym, question.unanswered_error_message, category: :not_answered
end
diff --git a/spec/requests/form_controller_spec.rb b/spec/requests/form_controller_spec.rb
index f6ecfa2b5..2b7d4c65f 100644
--- a/spec/requests/form_controller_spec.rb
+++ b/spec/requests/form_controller_spec.rb
@@ -744,6 +744,35 @@ RSpec.describe FormController, type: :request do
end
end
+ context "with invalid multiple question answers" do
+ let(:page) { Capybara::Node::Simple.new(response.body) }
+ let(:page_id) { "rent" }
+ let(:params) do
+ {
+ id: lettings_log.id,
+ lettings_log: {
+ page: page_id,
+ "period" => 10,
+ "supcharg" => 1_000_000,
+ },
+ }
+ end
+
+ before do
+ allow(Rails.logger).to receive(:info)
+ end
+
+ it "shows not answered and invalid answer errors at the same time" do
+ post "/lettings-logs/#{lettings_log.id}/#{page_id.dasherize}", params: params
+ follow_redirect!
+ expect(page).to have_content("There is a problem")
+ expect(page).to have_content("Support Charge must be between 0 and 300.")
+ expect(page).to have_content("You must answer basic rent.")
+ expect(page).to have_content("You must answer personal service charge.")
+ expect(page).to have_content("You must answer service charge.")
+ end
+ end
+
context "with invalid organisation answers" do
let(:page) { Capybara::Node::Simple.new(response.body) }
let(:managing_organisation) { create(:organisation) }
From bef5e84b7a4430d3936309e5f4950de9350a95df Mon Sep 17 00:00:00 2001
From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>
Date: Mon, 23 Dec 2024 10:51:57 +0000
Subject: [PATCH 04/17] Update some tests that would fail in 2025 collection
(#2875)
* Update some tests that would fail in 2025 collection
* Update derived sales fields tests
* Update a few feature tests
---
app/models/form_handler.rb | 8 +++++
app/models/sales_log.rb | 5 +--
spec/factories/sales_log.rb | 2 ++
spec/features/organisation_spec.rb | 10 +++---
spec/features/sales_log_spec.rb | 3 +-
.../collection_resources_helper_spec.rb | 25 +++++++++-----
spec/models/sales_log_derived_fields_spec.rb | 34 +++++++++++--------
spec/models/sales_log_spec.rb | 11 +++++-
.../sales/setup_validations_spec.rb | 18 +++++-----
9 files changed, 75 insertions(+), 41 deletions(-)
diff --git a/app/models/form_handler.rb b/app/models/form_handler.rb
index 02f3a9d70..9a10dc894 100644
--- a/app/models/form_handler.rb
+++ b/app/models/form_handler.rb
@@ -36,6 +36,10 @@ class FormHandler
forms["next_lettings"]
end
+ def archived_lettings_form
+ forms["archived_lettings"]
+ end
+
def current_sales_form
forms["current_sales"]
end
@@ -44,6 +48,10 @@ class FormHandler
forms["previous_sales"]
end
+ def archived_sales_form
+ forms["archived_sales"]
+ end
+
def next_sales_form
forms["next_sales"]
end
diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb
index 3064cba31..d03425ee4 100644
--- a/app/models/sales_log.rb
+++ b/app/models/sales_log.rb
@@ -61,13 +61,14 @@ class SalesLog < Log
[by_postcode, param_without_spaces, param_without_spaces])
}
scope :age1_answered, -> { where.not(age1: nil).or(where(age1_known: [1, 2])) }
+ scope :ecstat1_answered, -> { where.not(ecstat1: nil).or(where("saledate >= ?", Time.zone.local(2025, 4, 1))) }
scope :duplicate_logs, lambda { |log|
visible.where(log.slice(*DUPLICATE_LOG_ATTRIBUTES))
.where.not(id: log.id)
.where.not(saledate: nil)
.where.not(sex1: nil)
- .where.not(ecstat1: nil)
.where.not(postcode_full: nil)
+ .ecstat1_answered
.age1_answered
}
scope :after_date, ->(date) { where("saledate >= ?", date) }
@@ -77,9 +78,9 @@ class SalesLog < Log
.group(*DUPLICATE_LOG_ATTRIBUTES)
.where.not(saledate: nil)
.where.not(sex1: nil)
- .where.not(ecstat1: nil)
.where.not(postcode_full: nil)
.age1_answered
+ .ecstat1_answered
.having("COUNT(*) > 1")
if assigned_to_id
diff --git a/spec/factories/sales_log.rb b/spec/factories/sales_log.rb
index 687b042a4..d59a03907 100644
--- a/spec/factories/sales_log.rb
+++ b/spec/factories/sales_log.rb
@@ -33,6 +33,7 @@ FactoryBot.define do
noint { 2 }
privacynotice { 1 }
purchid { rand(999_999_999).to_s }
+ staircase { 1 }
end
trait :discounted_ownership_setup_complete do
saledate_today
@@ -66,6 +67,7 @@ FactoryBot.define do
postcode_full { "A1 1AA" }
noint { 2 }
uprn_known { 0 }
+ staircase { 1 }
end
trait :completed do
purchid { rand(999_999_999).to_s }
diff --git a/spec/features/organisation_spec.rb b/spec/features/organisation_spec.rb
index 15bfecf39..336ae51af 100644
--- a/spec/features/organisation_spec.rb
+++ b/spec/features/organisation_spec.rb
@@ -132,6 +132,7 @@ RSpec.describe "User Features" do
let!(:other_general_needs_logs) { FactoryBot.create_list(:lettings_log, 4, assigned_to: user, needstype: 1) }
let!(:other_supported_housing_logs) { FactoryBot.create_list(:lettings_log, 4, assigned_to: user, needstype: 2) }
let(:number_of_lettings_logs) { LettingsLog.count }
+ let(:previous_year) { FormHandler.instance.previous_lettings_form.start_date.year }
before do
allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(true)
@@ -204,9 +205,9 @@ RSpec.describe "User Features" do
end
it "can filter lettings logs by year" do
- check("years-2022-field")
+ check("years-#{previous_year}-field")
click_button("Apply filters")
- expect(page).to have_current_path("/organisations/#{org_id}/lettings-logs?%5Byears%5D[]=&years[]=2022&%5Bstatus%5D[]=&%5Bneedstypes%5D[]=&assigned_to=all&user_text_search=&user=&owning_organisation_select=all&owning_organisation_text_search=&owning_organisation=&managing_organisation_select=all&managing_organisation_text_search=&managing_organisation=")
+ expect(page).to have_current_path("/organisations/#{org_id}/lettings-logs?%5Byears%5D[]=&years[]=#{previous_year}&%5Bstatus%5D[]=&%5Bneedstypes%5D[]=&assigned_to=all&user_text_search=&user=&owning_organisation_select=all&owning_organisation_text_search=&owning_organisation=&managing_organisation_select=all&managing_organisation_text_search=&managing_organisation=")
expect(page).not_to have_link first_log.id.to_s, href: "/lettings-logs/#{first_log.id}"
end
@@ -226,6 +227,7 @@ RSpec.describe "User Features" do
context "when viewing sales logs for specific organisation" do
let(:first_log) { organisation.sales_logs.first }
let(:number_of_sales_logs) { SalesLog.count }
+ let(:previous_year) { FormHandler.instance.previous_sales_form.start_date.year }
before do
allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(true)
@@ -254,9 +256,9 @@ RSpec.describe "User Features" do
organisation.sales_logs.map(&:id).each do |sales_log_id|
expect(page).to have_link sales_log_id.to_s, href: "/sales-logs/#{sales_log_id}"
end
- check("years-2022-field")
+ check("years-#{previous_year}-field")
click_button("Apply filters")
- expect(page).to have_current_path("/organisations/#{org_id}/sales-logs?%5Byears%5D[]=&years[]=2022&%5Bstatus%5D[]=&assigned_to=all&user_text_search=&user=&owning_organisation_select=all&owning_organisation_text_search=&owning_organisation=&managing_organisation_select=all&managing_organisation_text_search=&managing_organisation=")
+ expect(page).to have_current_path("/organisations/#{org_id}/sales-logs?%5Byears%5D[]=&years[]=#{previous_year}&%5Bstatus%5D[]=&assigned_to=all&user_text_search=&user=&owning_organisation_select=all&owning_organisation_text_search=&owning_organisation=&managing_organisation_select=all&managing_organisation_text_search=&managing_organisation=")
expect(page).not_to have_link first_log.id.to_s, href: "/sales-logs/#{first_log.id}"
end
end
diff --git a/spec/features/sales_log_spec.rb b/spec/features/sales_log_spec.rb
index 663a4f7ac..c226c6bd3 100644
--- a/spec/features/sales_log_spec.rb
+++ b/spec/features/sales_log_spec.rb
@@ -142,6 +142,7 @@ RSpec.describe "Sales Log Features" do
context "when downloading logs" do
let(:user) { create(:user, :support) }
let(:other_user) { create(:user, organisation: user.organisation) }
+ let(:current_year) { FormHandler.instance.current_sales_form.start_date.year }
context "when I am signed in" do
before do
@@ -191,7 +192,7 @@ RSpec.describe "Sales Log Features" do
context "when one year filter is selected" do
before do
- check("2024 to 2025")
+ check("#{current_year} to #{current_year + 1}")
click_button("Apply filters")
end
diff --git a/spec/helpers/collection_resources_helper_spec.rb b/spec/helpers/collection_resources_helper_spec.rb
index 05c164fc1..a146e43cc 100644
--- a/spec/helpers/collection_resources_helper_spec.rb
+++ b/spec/helpers/collection_resources_helper_spec.rb
@@ -4,10 +4,18 @@ RSpec.describe CollectionResourcesHelper do
let(:current_user) { create(:user, :data_coordinator) }
let(:user) { create(:user, :data_coordinator) }
let(:storage_service) { instance_double(Storage::S3Service, get_file_metadata: nil) }
+ let(:current_date) { Time.zone.local(2024, 8, 8) }
before do
allow(Storage::S3Service).to receive(:new).and_return(storage_service)
allow(storage_service).to receive(:configuration).and_return(OpenStruct.new(bucket_name: "core-test-collection-resources"))
+ Timecop.travel(current_date)
+ Singleton.__init__(FormHandler)
+ end
+
+ after do
+ Timecop.return
+ Singleton.__init__(FormHandler)
end
describe "when displaying file metadata" do
@@ -34,9 +42,10 @@ RSpec.describe CollectionResourcesHelper do
describe "#editable_collection_resource_years" do
context "when in crossover period" do
+ let(:current_date) { Time.zone.local(2024, 4, 8) }
+
before do
allow(FormHandler.instance).to receive(:in_edit_crossover_period?).and_return(true)
- allow(Time.zone).to receive(:today).and_return(Time.zone.local(2024, 4, 8))
end
it "returns previous and current years" do
@@ -50,9 +59,7 @@ RSpec.describe CollectionResourcesHelper do
end
context "and after 1st January" do
- before do
- allow(Time.zone).to receive(:today).and_return(Time.zone.local(2025, 2, 1))
- end
+ let(:current_date) { Time.zone.local(2025, 2, 1) }
it "returns current and next years" do
expect(editable_collection_resource_years).to match_array([2024, 2025])
@@ -60,9 +67,7 @@ RSpec.describe CollectionResourcesHelper do
end
context "and before 1st January" do
- before do
- allow(Time.zone).to receive(:today).and_return(Time.zone.local(2024, 12, 1))
- end
+ let(:current_date) { Time.zone.local(2024, 12, 1) }
it "returns current year" do
expect(editable_collection_resource_years).to eq([2024])
@@ -73,9 +78,10 @@ RSpec.describe CollectionResourcesHelper do
describe "#displayed_collection_resource_years" do
context "when in crossover period" do
+ let(:current_date) { Time.zone.local(2024, 4, 8) }
+
before do
allow(FormHandler.instance).to receive(:in_edit_crossover_period?).and_return(true)
- allow(Time.zone).to receive(:today).and_return(Time.zone.local(2024, 4, 8))
end
it "returns previous and current years" do
@@ -188,9 +194,10 @@ RSpec.describe CollectionResourcesHelper do
end
context "when next year is editable" do
+ let(:current_date) { Time.zone.local(2025, 1, 1) }
+
before do
allow(FormHandler.instance).to receive(:in_edit_crossover_period?).and_return(false)
- allow(Time.zone).to receive(:today).and_return(Time.zone.local(2025, 1, 1))
end
it "returns true" do
diff --git a/spec/models/sales_log_derived_fields_spec.rb b/spec/models/sales_log_derived_fields_spec.rb
index ce34c8ca5..8eda0c36f 100644
--- a/spec/models/sales_log_derived_fields_spec.rb
+++ b/spec/models/sales_log_derived_fields_spec.rb
@@ -67,13 +67,13 @@ RSpec.describe SalesLog, type: :model do
end
it "clears mortgage value if mortgage used is changed from no to don't know" do
- log = create(:sales_log, :outright_sale_setup_complete, mortgage: 0, mortgageused: 2)
+ log = create(:sales_log, :shared_ownership_setup_complete, stairowned: 100, mortgage: 0, mortgageused: 2)
log.mortgageused = 3
expect { log.set_derived_fields! }.to change(log, :mortgage).from(0).to(nil)
end
it "clears mortgage value if mortgage used is changed from yes to don't know" do
- log = create(:sales_log, :outright_sale_setup_complete, mortgage: 50_000, mortgageused: 1)
+ log = create(:sales_log, :shared_ownership_setup_complete, staircase: 2, mortgage: 50_000, mortgageused: 1)
log.mortgageused = 3
expect { log.set_derived_fields! }.to change(log, :mortgage).from(50_000).to(nil)
end
@@ -101,30 +101,36 @@ RSpec.describe SalesLog, type: :model do
expect { log.set_derived_fields! }.to change(log, :deposit).from(0).to(nil)
end
- it "clears derived deposit when setting mortgage used to yes" do
- log = create(:sales_log, :outright_sale_setup_complete, value: 123_400, deposit: 123_400, mortgageused: 2)
- log.mortgageused = 1
- expect { log.set_derived_fields! }.to change(log, :deposit).from(123_400).to(nil)
+ context "with outright sales log" do
+ before do
+ allow(Time).to receive(:now).and_return(Time.zone.local(2024, 5, 4))
+ end
+
+ it "clears derived deposit when setting mortgage used to yes" do
+ log = create(:sales_log, :outright_sale_setup_complete, value: 123_400, deposit: 123_400, mortgageused: 2)
+ log.mortgageused = 1
+ expect { log.set_derived_fields! }.to change(log, :deposit).from(123_400).to(nil)
+ end
+
+ it "clears that buyer 1 will live in the property if joint purchase is updated" do
+ log = create(:sales_log, :outright_sale_setup_complete, buylivein: 1, jointpur: 2)
+ log.jointpur = 1
+ expect { log.set_derived_fields! }.to change(log, :buy1livein).from(1).to(nil)
+ end
end
context "when buyers will live in the property" do
context "and the sale is not a joint purchase" do
it "derives that buyer 1 will live in the property" do
- log = build(:sales_log, :outright_sale_setup_complete, buylivein: 1, jointpur: 2)
+ log = build(:sales_log, :shared_ownership_setup_complete, staircase: 2, buylivein: 1, jointpur: 2)
expect { log.set_derived_fields! }.to change(log, :buy1livein).from(nil).to(1)
end
it "does not derive a value for whether buyer 2 will live in the property" do
- log = build(:sales_log, :outright_sale_setup_complete, buylivein: 1, jointpur: 2)
+ log = build(:sales_log, :shared_ownership_setup_complete, staircase: 2, buylivein: 1, jointpur: 2)
log.set_derived_fields!
expect(log.buy2livein).to be_nil
end
-
- it "clears that buyer 1 will live in the property if joint purchase is updated" do
- log = create(:sales_log, :outright_sale_setup_complete, buylivein: 1, jointpur: 2)
- log.jointpur = 1
- expect { log.set_derived_fields! }.to change(log, :buy1livein).from(1).to(nil)
- end
end
context "and the sale is a joint purchase" do
diff --git a/spec/models/sales_log_spec.rb b/spec/models/sales_log_spec.rb
index 0c854c221..20eb0b2a6 100644
--- a/spec/models/sales_log_spec.rb
+++ b/spec/models/sales_log_spec.rb
@@ -281,9 +281,18 @@ RSpec.describe SalesLog, type: :model do
end
end
- context "when there is a log with a different ecstat1" do
+ context "when there is a 2024 log with a different ecstat1" do
let!(:different_ecstat1) { create(:sales_log, :duplicate, ecstat1: 0, owning_organisation: organisation) }
+ before do
+ Timecop.freeze(Time.zone.local(2024, 5, 2))
+ Singleton.__init__(FormHandler)
+ end
+
+ after do
+ Timecop.return
+ end
+
it "does not return a log with a different ecstat1 as a duplicate" do
expect(described_class.duplicate_logs(log)).not_to include(different_ecstat1)
end
diff --git a/spec/models/validations/sales/setup_validations_spec.rb b/spec/models/validations/sales/setup_validations_spec.rb
index 659cde23f..45579ca42 100644
--- a/spec/models/validations/sales/setup_validations_spec.rb
+++ b/spec/models/validations/sales/setup_validations_spec.rb
@@ -4,6 +4,8 @@ RSpec.describe Validations::Sales::SetupValidations do
subject(:setup_validator) { validator_class.new }
let(:validator_class) { Class.new { include Validations::Sales::SetupValidations } }
+ let(:current_year) { FormHandler.instance.current_sales_form.start_date.year }
+ let(:previous_year) { FormHandler.instance.previous_sales_form.start_date.year }
describe "#validate_saledate_collection_year" do
context "with sales_in_crossover_period == false" do
@@ -68,7 +70,7 @@ RSpec.describe Validations::Sales::SetupValidations do
end
context "when saledate is in an open previous collection year" do
- let(:record) { build(:sales_log, saledate: Time.zone.local(2024, 1, 1)) }
+ let(:record) { build(:sales_log, saledate: Time.zone.local(current_year, 1, 1)) }
before do
allow(FormHandler.instance).to receive(:sales_in_crossover_period?).and_return(true)
@@ -91,12 +93,12 @@ RSpec.describe Validations::Sales::SetupValidations do
it "adds error" do
setup_validator.validate_saledate_collection_year(record)
- expect(record.errors[:saledate]).to include("Enter a date within the 2023 to 2024 or 2024 to 2025 collection years, which is between 1st April 2023 and 31st March 2025.")
+ expect(record.errors[:saledate]).to include("Enter a date within the #{previous_year} to #{previous_year + 1} or #{current_year} to #{current_year + 1} collection years, which is between 1st April #{previous_year} and 31st March #{current_year + 1}.")
end
end
context "when saledate is after an open collection year" do
- let(:record) { build(:sales_log, saledate: Time.zone.local(2025, 4, 1)) }
+ let(:record) { build(:sales_log, saledate: Time.zone.local(current_year + 1, 4, 1)) }
before do
allow(FormHandler.instance).to receive(:sales_in_crossover_period?).and_return(true)
@@ -105,21 +107,17 @@ RSpec.describe Validations::Sales::SetupValidations do
it "adds error" do
setup_validator.validate_saledate_collection_year(record)
- expect(record.errors[:saledate]).to include("Enter a date within the 2023 to 2024 or 2024 to 2025 collection years, which is between 1st April 2023 and 31st March 2025.")
+ expect(record.errors[:saledate]).to include("Enter a date within the #{previous_year} to #{previous_year + 1} or #{current_year} to #{current_year + 1} collection years, which is between 1st April #{previous_year} and 31st March #{current_year + 1}.")
end
end
context "when current time is after the new logs end date but before edit end date for the previous period" do
let(:record) { build(:sales_log, saledate: nil) }
- before do
- allow(Time).to receive(:now).and_return(Time.zone.local(2025, 1, 8))
- end
-
it "cannot create new logs for the archived collection year" do
record.saledate = Time.zone.local(2023, 1, 1)
setup_validator.validate_saledate_collection_year(record)
- expect(record.errors["saledate"]).to include(match "Enter a date within the 2023 to 2024 or 2024 to 2025 collection years, which is between 1st April 2023 and 31st March 2025.")
+ expect(record.errors["saledate"]).to include(match "Enter a date within the #{previous_year} to #{previous_year + 1} or #{current_year} to #{current_year + 1} collection years, which is between 1st April #{previous_year} and 31st March #{current_year + 1}.")
end
it "can edit already created logs for the previous collection year" do
@@ -127,7 +125,7 @@ RSpec.describe Validations::Sales::SetupValidations do
record.save!(validate: false)
record.saledate = Time.zone.local(2024, 1, 1)
setup_validator.validate_saledate_collection_year(record)
- expect(record.errors["saledate"]).not_to include(match "Enter a date within the 2024 to 2025 collection year, which is between 1st April 2024 and 31st March 2025.")
+ expect(record.errors["saledate"]).not_to include(match "Enter a date within the #{current_year} to #{current_year + 1} collection year, which is between 1st April #{current_year} and 31st March #{current_year + 1}.")
end
end
From dab1ee25db75e00ce1002a06e7386c0042c9e082 Mon Sep 17 00:00:00 2001
From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>
Date: Thu, 2 Jan 2025 10:28:11 +0000
Subject: [PATCH 05/17] Fix dates to depend of collections in homepage tests
(#2880)
---
spec/presenters/homepage_presenter_spec.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/spec/presenters/homepage_presenter_spec.rb b/spec/presenters/homepage_presenter_spec.rb
index 857482abd..aa10c8cde 100644
--- a/spec/presenters/homepage_presenter_spec.rb
+++ b/spec/presenters/homepage_presenter_spec.rb
@@ -5,8 +5,8 @@ RSpec.describe HomepagePresenter do
let(:user) { create(:user, organisation:) }
let(:in_crossover_period) { true }
let(:presenter) { described_class.new(user) }
- let(:date_this_year) { Time.zone.today }
- let(:date_last_year) { Time.zone.today - 1.year }
+ let(:date_this_year) { FormHandler.instance.current_collection_start_date }
+ let(:date_last_year) { FormHandler.instance.previous_collection_start_date }
let(:expected_count) { rand 1..10 }
before do
From 8a8903864d0bf38a34a61f524be94b22e241f458 Mon Sep 17 00:00:00 2001
From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com>
Date: Thu, 2 Jan 2025 15:06:20 +0000
Subject: [PATCH 06/17] Fix soft validation unpend logs (#2881)
* Update status
* Add test
* Update test
---------
Co-authored-by: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>
---
app/models/bulk_upload.rb | 1 +
spec/models/bulk_upload_spec.rb | 14 ++++++++++++++
2 files changed, 15 insertions(+)
diff --git a/app/models/bulk_upload.rb b/app/models/bulk_upload.rb
index 2e0232dfe..3a3d41540 100644
--- a/app/models/bulk_upload.rb
+++ b/app/models/bulk_upload.rb
@@ -129,6 +129,7 @@ class BulkUpload < ApplicationRecord
def unpend_and_confirm_soft_validations
logs.find_each do |log|
fields_to_confirm(log).each { |field| log[field] = 0 }
+ log.status = log.status_cache
log.save!
end
end
diff --git a/spec/models/bulk_upload_spec.rb b/spec/models/bulk_upload_spec.rb
index db475709a..b07bef3c6 100644
--- a/spec/models/bulk_upload_spec.rb
+++ b/spec/models/bulk_upload_spec.rb
@@ -257,4 +257,18 @@ RSpec.describe BulkUpload, type: :model do
end
end
end
+
+ describe "#unpend_and_confirm_soft_validations" do
+ let(:bulk_upload) { create(:bulk_upload, :lettings) }
+ let(:log) { create(:lettings_log, :completed, bulk_upload:, status: "pending", status_cache: "in_progress", supcharg: 183.24) }
+
+ it "resets the fields to confirm and updates the status to status_cache" do
+ expect(log.status).to eq("pending")
+
+ bulk_upload.unpend_and_confirm_soft_validations
+
+ log.reload
+ expect(log.status).to eq("completed")
+ end
+ end
end
From 02d1c664ef3554182b7bcd56b5009134746e1449 Mon Sep 17 00:00:00 2001
From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com>
Date: Mon, 6 Jan 2025 17:15:20 +0000
Subject: [PATCH 07/17] Fix view bulk uploads and add another status label
(#2883)
* Add another bulk upload status for invalid uploads
* Add test and update text
* update text missed
---
app/helpers/tag_helper.rb | 2 ++
app/models/bulk_upload.rb | 3 ++-
app/services/bulk_upload/processor.rb | 3 +++
spec/services/bulk_upload/processor_spec.rb | 5 +++++
4 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/app/helpers/tag_helper.rb b/app/helpers/tag_helper.rb
index 398f897cf..3ecea6d25 100644
--- a/app/helpers/tag_helper.rb
+++ b/app/helpers/tag_helper.rb
@@ -21,6 +21,7 @@ module TagHelper
processing: "Processing",
blank_template: "Blank template",
wrong_template: "Wrong template used",
+ 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",
@@ -48,6 +49,7 @@ module TagHelper
processing: "yellow",
blank_template: "red",
wrong_template: "red",
+ processing_error: "red",
important_errors: "red",
critical_errors: "red",
potential_errors: "red",
diff --git a/app/models/bulk_upload.rb b/app/models/bulk_upload.rb
index 3a3d41540..6616285b0 100644
--- a/app/models/bulk_upload.rb
+++ b/app/models/bulk_upload.rb
@@ -1,7 +1,7 @@
class BulkUpload < ApplicationRecord
enum :log_type, { lettings: "lettings", sales: "sales" }
enum :rent_type_fix_status, { not_applied: "not_applied", applied: "applied", not_needed: "not_needed" }
- enum :failure_reason, { blank_template: "blank_template", wrong_template: "wrong_template" }
+ enum :failure_reason, { blank_template: "blank_template", wrong_template: "wrong_template", processing_error: "processing_error" }
belongs_to :user
@@ -43,6 +43,7 @@ class BulkUpload < ApplicationRecord
return :processing if processing
return :blank_template if failure_reason == "blank_template"
return :wrong_template if failure_reason == "wrong_template"
+ return :processing_error if failure_reason == "processing_error"
if logs.visible.exists?
return :errors_fixed_in_service if completed? && bulk_upload_errors.any?
diff --git a/app/services/bulk_upload/processor.rb b/app/services/bulk_upload/processor.rb
index c54032fda..f6ce5eaea 100644
--- a/app/services/bulk_upload/processor.rb
+++ b/app/services/bulk_upload/processor.rb
@@ -61,6 +61,7 @@ class BulkUpload::Processor
end
rescue StandardError => e
Sentry.capture_exception(e)
+ @bulk_upload.update!(failure_reason: "processing_error")
send_failure_mail
ensure
downloader.delete_local_file!
@@ -184,6 +185,8 @@ private
@bulk_upload.update!(failure_reason: "blank_template")
elsif wrong_template_errors.any? { |error| validator.errors.full_messages.include?(error) }
@bulk_upload.update!(failure_reason: "wrong_template")
+ else
+ @bulk_upload.update!(failure_reason: "processing_error")
end
send_failure_mail(errors: validator.errors.full_messages)
diff --git a/spec/services/bulk_upload/processor_spec.rb b/spec/services/bulk_upload/processor_spec.rb
index 468d5fef8..27f1aebed 100644
--- a/spec/services/bulk_upload/processor_spec.rb
+++ b/spec/services/bulk_upload/processor_spec.rb
@@ -101,6 +101,11 @@ RSpec.describe BulkUpload::Processor do
allow(mock_validator).to receive(:call).and_raise(StandardError)
end
+ it "updates the failure_reason to invalid_upload" do
+ processor.call
+ expect(bulk_upload.reload.failure_reason).to eq("processing_error")
+ end
+
it "sends failure email" do
mail_double = instance_double("ActionMailer::MessageDelivery", deliver_later: nil)
From 5d7649a9e46b844a516d4c479f807b7edcce3a74 Mon Sep 17 00:00:00 2001
From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>
Date: Fri, 10 Jan 2025 12:35:04 +0000
Subject: [PATCH 08/17] CLDC-3821 Remove care home questions (#2885)
* Remove carehome questions for 2025
* Update routing to rent pages for 2025
* lint
---
.../form/lettings/pages/rent_4_weekly.rb | 19 +++-
.../form/lettings/pages/rent_bi_weekly.rb | 19 +++-
.../form/lettings/pages/rent_monthly.rb | 19 +++-
app/models/form/lettings/pages/rent_weekly.rb | 19 +++-
.../subsections/income_and_benefits.rb | 22 +++--
.../form/lettings/pages/rent4_weekly_spec.rb | 44 +++++++++
.../lettings/pages/rent_bi_weekly_spec.rb | 44 +++++++++
.../form/lettings/pages/rent_monthly_spec.rb | 44 +++++++++
.../form/lettings/pages/rent_weekly_spec.rb | 44 +++++++++
.../subsections/income_and_benefits_spec.rb | 93 +++++++++++++------
10 files changed, 317 insertions(+), 50 deletions(-)
create mode 100644 spec/models/form/lettings/pages/rent4_weekly_spec.rb
create mode 100644 spec/models/form/lettings/pages/rent_bi_weekly_spec.rb
create mode 100644 spec/models/form/lettings/pages/rent_monthly_spec.rb
create mode 100644 spec/models/form/lettings/pages/rent_weekly_spec.rb
diff --git a/app/models/form/lettings/pages/rent_4_weekly.rb b/app/models/form/lettings/pages/rent_4_weekly.rb
index aa6441f6e..4bfaf28ff 100644
--- a/app/models/form/lettings/pages/rent_4_weekly.rb
+++ b/app/models/form/lettings/pages/rent_4_weekly.rb
@@ -3,10 +3,7 @@ class Form::Lettings::Pages::Rent4Weekly < ::Form::Page
super
@id = "rent_4_weekly"
@copy_key = "lettings.income_and_benefits.rent_and_charges"
- @depends_on = [
- { "household_charge" => 0, "rent_and_charges_paid_every_4_weeks?" => true, "is_carehome?" => false },
- { "household_charge" => nil, "rent_and_charges_paid_every_4_weeks?" => true, "is_carehome?" => false },
- ]
+ @depends_on = depends_on
end
def questions
@@ -18,4 +15,18 @@ class Form::Lettings::Pages::Rent4Weekly < ::Form::Page
Form::Lettings::Questions::Tcharge4Weekly.new(nil, nil, self),
]
end
+
+ def depends_on
+ if form.start_year_2025_or_later?
+ [
+ { "household_charge" => 0, "rent_and_charges_paid_every_4_weeks?" => true },
+ { "household_charge" => nil, "rent_and_charges_paid_every_4_weeks?" => true },
+ ]
+ else
+ [
+ { "household_charge" => 0, "rent_and_charges_paid_every_4_weeks?" => true, "is_carehome?" => false },
+ { "household_charge" => nil, "rent_and_charges_paid_every_4_weeks?" => true, "is_carehome?" => false },
+ ]
+ end
+ end
end
diff --git a/app/models/form/lettings/pages/rent_bi_weekly.rb b/app/models/form/lettings/pages/rent_bi_weekly.rb
index 7eab8daf4..aad9e9312 100644
--- a/app/models/form/lettings/pages/rent_bi_weekly.rb
+++ b/app/models/form/lettings/pages/rent_bi_weekly.rb
@@ -3,10 +3,7 @@ class Form::Lettings::Pages::RentBiWeekly < ::Form::Page
super
@id = "rent_bi_weekly"
@copy_key = "lettings.income_and_benefits.rent_and_charges"
- @depends_on = [
- { "household_charge" => nil, "rent_and_charges_paid_every_2_weeks?" => true, "is_carehome?" => false },
- { "household_charge" => 0, "rent_and_charges_paid_every_2_weeks?" => true, "is_carehome?" => false },
- ]
+ @depends_on = depends_on
end
def questions
@@ -18,4 +15,18 @@ class Form::Lettings::Pages::RentBiWeekly < ::Form::Page
Form::Lettings::Questions::TchargeBiWeekly.new(nil, nil, self),
]
end
+
+ def depends_on
+ if form.start_year_2025_or_later?
+ [
+ { "household_charge" => nil, "rent_and_charges_paid_every_2_weeks?" => true },
+ { "household_charge" => 0, "rent_and_charges_paid_every_2_weeks?" => true },
+ ]
+ else
+ [
+ { "household_charge" => nil, "rent_and_charges_paid_every_2_weeks?" => true, "is_carehome?" => false },
+ { "household_charge" => 0, "rent_and_charges_paid_every_2_weeks?" => true, "is_carehome?" => false },
+ ]
+ end
+ end
end
diff --git a/app/models/form/lettings/pages/rent_monthly.rb b/app/models/form/lettings/pages/rent_monthly.rb
index 9a3cd6a7e..1fcc21b17 100644
--- a/app/models/form/lettings/pages/rent_monthly.rb
+++ b/app/models/form/lettings/pages/rent_monthly.rb
@@ -3,10 +3,7 @@ class Form::Lettings::Pages::RentMonthly < ::Form::Page
super
@id = "rent_monthly"
@copy_key = "lettings.income_and_benefits.rent_and_charges"
- @depends_on = [
- { "household_charge" => nil, "rent_and_charges_paid_monthly?" => true, "is_carehome?" => false },
- { "household_charge" => 0, "rent_and_charges_paid_monthly?" => true, "is_carehome?" => false },
- ]
+ @depends_on = depends_on
end
def questions
@@ -18,4 +15,18 @@ class Form::Lettings::Pages::RentMonthly < ::Form::Page
Form::Lettings::Questions::TchargeMonthly.new(nil, nil, self),
]
end
+
+ def depends_on
+ if form.start_year_2025_or_later?
+ [
+ { "household_charge" => nil, "rent_and_charges_paid_monthly?" => true },
+ { "household_charge" => 0, "rent_and_charges_paid_monthly?" => true },
+ ]
+ else
+ [
+ { "household_charge" => nil, "rent_and_charges_paid_monthly?" => true, "is_carehome?" => false },
+ { "household_charge" => 0, "rent_and_charges_paid_monthly?" => true, "is_carehome?" => false },
+ ]
+ end
+ end
end
diff --git a/app/models/form/lettings/pages/rent_weekly.rb b/app/models/form/lettings/pages/rent_weekly.rb
index 86106cfe3..b40641ebe 100644
--- a/app/models/form/lettings/pages/rent_weekly.rb
+++ b/app/models/form/lettings/pages/rent_weekly.rb
@@ -3,10 +3,7 @@ class Form::Lettings::Pages::RentWeekly < ::Form::Page
super
@id = "rent_weekly"
@copy_key = "lettings.income_and_benefits.rent_and_charges"
- @depends_on = [
- { "rent_and_charges_paid_weekly?" => true, "household_charge" => 0, "is_carehome?" => false },
- { "rent_and_charges_paid_weekly?" => true, "household_charge" => nil, "is_carehome?" => false },
- ]
+ @depends_on = depends_on
end
def questions
@@ -18,4 +15,18 @@ class Form::Lettings::Pages::RentWeekly < ::Form::Page
Form::Lettings::Questions::TchargeWeekly.new(nil, nil, self),
]
end
+
+ def depends_on
+ if form.start_year_2025_or_later?
+ [
+ { "rent_and_charges_paid_weekly?" => true, "household_charge" => 0 },
+ { "rent_and_charges_paid_weekly?" => true, "household_charge" => nil },
+ ]
+ else
+ [
+ { "rent_and_charges_paid_weekly?" => true, "household_charge" => 0, "is_carehome?" => false },
+ { "rent_and_charges_paid_weekly?" => true, "household_charge" => nil, "is_carehome?" => false },
+ ]
+ end
+ end
end
diff --git a/app/models/form/lettings/subsections/income_and_benefits.rb b/app/models/form/lettings/subsections/income_and_benefits.rb
index 2be2fb9a5..4ad3003cb 100644
--- a/app/models/form/lettings/subsections/income_and_benefits.rb
+++ b/app/models/form/lettings/subsections/income_and_benefits.rb
@@ -15,11 +15,7 @@ class Form::Lettings::Subsections::IncomeAndBenefits < ::Form::Subsection
Form::Lettings::Pages::BenefitsProportion.new("benefits_proportion", nil, self),
Form::Lettings::Pages::RentOrOtherCharges.new(nil, nil, self),
Form::Lettings::Pages::RentPeriod.new(nil, nil, self),
- Form::Lettings::Pages::CareHomeWeekly.new(nil, nil, self),
- Form::Lettings::Pages::CareHomeBiWeekly.new(nil, nil, self),
- Form::Lettings::Pages::CareHome4Weekly.new(nil, nil, self),
- Form::Lettings::Pages::CareHomeMonthly.new(nil, nil, self),
- Form::Lettings::Pages::CareHomeChargesValueCheck.new(nil, nil, self),
+ carehome_questions,
Form::Lettings::Pages::RentWeekly.new(nil, nil, self),
Form::Lettings::Pages::RentBiWeekly.new(nil, nil, self),
Form::Lettings::Pages::Rent4Weekly.new(nil, nil, self),
@@ -30,6 +26,20 @@ class Form::Lettings::Subsections::IncomeAndBenefits < ::Form::Subsection
Form::Lettings::Pages::SupchargValueCheck.new(nil, nil, self),
Form::Lettings::Pages::Outstanding.new(nil, nil, self),
Form::Lettings::Pages::OutstandingAmount.new(nil, nil, self),
- ].compact
+ ].flatten.compact
+ end
+
+private
+
+ def carehome_questions
+ return [] if form.start_year_2025_or_later?
+
+ [
+ Form::Lettings::Pages::CareHomeWeekly.new(nil, nil, self),
+ Form::Lettings::Pages::CareHomeBiWeekly.new(nil, nil, self),
+ Form::Lettings::Pages::CareHome4Weekly.new(nil, nil, self),
+ Form::Lettings::Pages::CareHomeMonthly.new(nil, nil, self),
+ Form::Lettings::Pages::CareHomeChargesValueCheck.new(nil, nil, self),
+ ]
end
end
diff --git a/spec/models/form/lettings/pages/rent4_weekly_spec.rb b/spec/models/form/lettings/pages/rent4_weekly_spec.rb
new file mode 100644
index 000000000..8a8527d6a
--- /dev/null
+++ b/spec/models/form/lettings/pages/rent4_weekly_spec.rb
@@ -0,0 +1,44 @@
+require "rails_helper"
+
+RSpec.describe Form::Lettings::Pages::Rent4Weekly, type: :model do
+ subject(:page) { described_class.new(nil, page_definition, subsection) }
+
+ let(:page_definition) { nil }
+ let(:start_date) { Time.zone.local(2024, 4, 1) }
+ let(:start_year_2025_or_later) { false }
+ let(:form) { instance_double(Form, start_date:) }
+ let(:subsection) { instance_double(Form::Subsection, form:) }
+ let(:person_index) { 2 }
+
+ before do
+ allow(form).to receive(:start_year_2025_or_later?).and_return(start_year_2025_or_later)
+ end
+
+ context "with form before 2025" do
+ let(:start_date) { Time.zone.local(2024, 4, 1) }
+ let(:start_year_2025_or_later) { false }
+
+ it "has correct depends_on" do
+ expect(page.depends_on).to eq(
+ [
+ { "rent_and_charges_paid_every_4_weeks?" => true, "household_charge" => 0, "is_carehome?" => false },
+ { "rent_and_charges_paid_every_4_weeks?" => true, "household_charge" => nil, "is_carehome?" => false },
+ ],
+ )
+ end
+ end
+
+ context "with form on or after 2025" do
+ let(:start_date) { Time.zone.local(2025, 4, 1) }
+ let(:start_year_2025_or_later) { true }
+
+ it "has correct depends_on" do
+ expect(page.depends_on).to eq(
+ [
+ { "rent_and_charges_paid_every_4_weeks?" => true, "household_charge" => 0 },
+ { "rent_and_charges_paid_every_4_weeks?" => true, "household_charge" => nil },
+ ],
+ )
+ end
+ end
+end
diff --git a/spec/models/form/lettings/pages/rent_bi_weekly_spec.rb b/spec/models/form/lettings/pages/rent_bi_weekly_spec.rb
new file mode 100644
index 000000000..a1975f766
--- /dev/null
+++ b/spec/models/form/lettings/pages/rent_bi_weekly_spec.rb
@@ -0,0 +1,44 @@
+require "rails_helper"
+
+RSpec.describe Form::Lettings::Pages::RentBiWeekly, type: :model do
+ subject(:page) { described_class.new(nil, page_definition, subsection) }
+
+ let(:page_definition) { nil }
+ let(:start_date) { Time.zone.local(2024, 4, 1) }
+ let(:start_year_2025_or_later) { false }
+ let(:form) { instance_double(Form, start_date:) }
+ let(:subsection) { instance_double(Form::Subsection, form:) }
+ let(:person_index) { 2 }
+
+ before do
+ allow(form).to receive(:start_year_2025_or_later?).and_return(start_year_2025_or_later)
+ end
+
+ context "with form before 2025" do
+ let(:start_date) { Time.zone.local(2024, 4, 1) }
+ let(:start_year_2025_or_later) { false }
+
+ it "has correct depends_on" do
+ expect(page.depends_on).to eq(
+ [
+ { "rent_and_charges_paid_every_2_weeks?" => true, "household_charge" => nil, "is_carehome?" => false },
+ { "rent_and_charges_paid_every_2_weeks?" => true, "household_charge" => 0, "is_carehome?" => false },
+ ],
+ )
+ end
+ end
+
+ context "with form on or after 2025" do
+ let(:start_date) { Time.zone.local(2025, 4, 1) }
+ let(:start_year_2025_or_later) { true }
+
+ it "has correct depends_on" do
+ expect(page.depends_on).to eq(
+ [
+ { "rent_and_charges_paid_every_2_weeks?" => true, "household_charge" => nil },
+ { "rent_and_charges_paid_every_2_weeks?" => true, "household_charge" => 0 },
+ ],
+ )
+ end
+ end
+end
diff --git a/spec/models/form/lettings/pages/rent_monthly_spec.rb b/spec/models/form/lettings/pages/rent_monthly_spec.rb
new file mode 100644
index 000000000..619fc254e
--- /dev/null
+++ b/spec/models/form/lettings/pages/rent_monthly_spec.rb
@@ -0,0 +1,44 @@
+require "rails_helper"
+
+RSpec.describe Form::Lettings::Pages::RentMonthly, type: :model do
+ subject(:page) { described_class.new(nil, page_definition, subsection) }
+
+ let(:page_definition) { nil }
+ let(:start_date) { Time.zone.local(2024, 4, 1) }
+ let(:start_year_2025_or_later) { false }
+ let(:form) { instance_double(Form, start_date:) }
+ let(:subsection) { instance_double(Form::Subsection, form:) }
+ let(:person_index) { 2 }
+
+ before do
+ allow(form).to receive(:start_year_2025_or_later?).and_return(start_year_2025_or_later)
+ end
+
+ context "with form before 2025" do
+ let(:start_date) { Time.zone.local(2024, 4, 1) }
+ let(:start_year_2025_or_later) { false }
+
+ it "has correct depends_on" do
+ expect(page.depends_on).to eq(
+ [
+ { "rent_and_charges_paid_monthly?" => true, "household_charge" => nil, "is_carehome?" => false },
+ { "rent_and_charges_paid_monthly?" => true, "household_charge" => 0, "is_carehome?" => false },
+ ],
+ )
+ end
+ end
+
+ context "with form on or after 2025" do
+ let(:start_date) { Time.zone.local(2025, 4, 1) }
+ let(:start_year_2025_or_later) { true }
+
+ it "has correct depends_on" do
+ expect(page.depends_on).to eq(
+ [
+ { "rent_and_charges_paid_monthly?" => true, "household_charge" => nil },
+ { "rent_and_charges_paid_monthly?" => true, "household_charge" => 0 },
+ ],
+ )
+ end
+ end
+end
diff --git a/spec/models/form/lettings/pages/rent_weekly_spec.rb b/spec/models/form/lettings/pages/rent_weekly_spec.rb
new file mode 100644
index 000000000..89bbae37a
--- /dev/null
+++ b/spec/models/form/lettings/pages/rent_weekly_spec.rb
@@ -0,0 +1,44 @@
+require "rails_helper"
+
+RSpec.describe Form::Lettings::Pages::RentWeekly, type: :model do
+ subject(:page) { described_class.new(nil, page_definition, subsection) }
+
+ let(:page_definition) { nil }
+ let(:start_date) { Time.zone.local(2024, 4, 1) }
+ let(:start_year_2025_or_later) { false }
+ let(:form) { instance_double(Form, start_date:) }
+ let(:subsection) { instance_double(Form::Subsection, form:) }
+ let(:person_index) { 2 }
+
+ before do
+ allow(form).to receive(:start_year_2025_or_later?).and_return(start_year_2025_or_later)
+ end
+
+ context "with form before 2025" do
+ let(:start_date) { Time.zone.local(2024, 4, 1) }
+ let(:start_year_2025_or_later) { false }
+
+ it "has correct depends_on" do
+ expect(page.depends_on).to eq(
+ [
+ { "rent_and_charges_paid_weekly?" => true, "household_charge" => 0, "is_carehome?" => false },
+ { "rent_and_charges_paid_weekly?" => true, "household_charge" => nil, "is_carehome?" => false },
+ ],
+ )
+ end
+ end
+
+ context "with form on or after 2025" do
+ let(:start_date) { Time.zone.local(2025, 4, 1) }
+ let(:start_year_2025_or_later) { true }
+
+ it "has correct depends_on" do
+ expect(page.depends_on).to eq(
+ [
+ { "rent_and_charges_paid_weekly?" => true, "household_charge" => 0 },
+ { "rent_and_charges_paid_weekly?" => true, "household_charge" => nil },
+ ],
+ )
+ end
+ end
+end
diff --git a/spec/models/form/lettings/subsections/income_and_benefits_spec.rb b/spec/models/form/lettings/subsections/income_and_benefits_spec.rb
index 7bdc26bfa..9d78b3216 100644
--- a/spec/models/form/lettings/subsections/income_and_benefits_spec.rb
+++ b/spec/models/form/lettings/subsections/income_and_benefits_spec.rb
@@ -5,40 +5,77 @@ RSpec.describe Form::Lettings::Subsections::IncomeAndBenefits, type: :model do
let(:subsection_id) { nil }
let(:subsection_definition) { nil }
- let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) }
+ let(:start_date) { Time.zone.local(2024, 4, 1) }
+ let(:start_year_2025_or_later) { false }
+ let(:form) { instance_double(Form, start_date:) }
let(:section) { instance_double(Form::Lettings::Sections::RentAndCharges, form:) }
+ before do
+ allow(form).to receive(:start_year_2025_or_later?).and_return(start_year_2025_or_later)
+ end
+
it "has correct section" do
expect(income_and_benefits.section).to eq(section)
end
- it "has correct pages" do
- expect(income_and_benefits.pages.map(&:id)).to eq(
- %w[
- income_known
- income_amount
- net_income_value_check
- housing_benefit
- benefits_proportion
- rent_or_other_charges
- rent_period
- care_home_weekly
- care_home_bi_weekly
- care_home_4_weekly
- care_home_monthly
- care_home_charges_value_check
- rent_weekly
- rent_bi_weekly
- rent_4_weekly
- rent_monthly
- brent_rent_value_check
- scharge_value_check
- pscharge_value_check
- supcharg_value_check
- outstanding
- outstanding_amount
- ],
- )
+ context "with 2024 form" do
+ it "has correct pages" do
+ expect(income_and_benefits.pages.map(&:id)).to eq(
+ %w[
+ income_known
+ income_amount
+ net_income_value_check
+ housing_benefit
+ benefits_proportion
+ rent_or_other_charges
+ rent_period
+ care_home_weekly
+ care_home_bi_weekly
+ care_home_4_weekly
+ care_home_monthly
+ care_home_charges_value_check
+ rent_weekly
+ rent_bi_weekly
+ rent_4_weekly
+ rent_monthly
+ brent_rent_value_check
+ scharge_value_check
+ pscharge_value_check
+ supcharg_value_check
+ outstanding
+ outstanding_amount
+ ],
+ )
+ end
+ end
+
+ context "with 2025 form" do
+ let(:start_date) { Time.zone.local(2025, 4, 1) }
+ let(:start_year_2025_or_later) { true }
+
+ it "has correct pages" do
+ expect(income_and_benefits.pages.map(&:id)).to eq(
+ %w[
+ income_known
+ income_amount
+ net_income_value_check
+ housing_benefit
+ benefits_proportion
+ rent_or_other_charges
+ rent_period
+ rent_weekly
+ rent_bi_weekly
+ rent_4_weekly
+ rent_monthly
+ brent_rent_value_check
+ scharge_value_check
+ pscharge_value_check
+ supcharg_value_check
+ outstanding
+ outstanding_amount
+ ],
+ )
+ end
end
it "has the correct id" do
From cabd650dd668c7c55d637b7ffadce9209ce466aa Mon Sep 17 00:00:00 2001
From: Rachael Booth
Date: Fri, 10 Jan 2025 14:59:59 +0000
Subject: [PATCH 09/17] CLDC-3833: Update validation on total discount for
percentage discounts to include an extra 1000 leeway for rounding errors
(#2889)
---
.../sales/sale_information_validations.rb | 4 +-
.../validations/sales/sale_information.en.yml | 20 +++++-----
.../sale_information_validations_spec.rb | 38 ++++++++++++-------
3 files changed, 36 insertions(+), 26 deletions(-)
diff --git a/app/models/validations/sales/sale_information_validations.rb b/app/models/validations/sales/sale_information_validations.rb
index 4b8948053..f99f6668a 100644
--- a/app/models/validations/sales/sale_information_validations.rb
+++ b/app/models/validations/sales/sale_information_validations.rb
@@ -144,11 +144,11 @@ module Validations::Sales::SaleInformationValidations
return unless record.saledate && record.form.start_year_2024_or_later?
return unless record.discount && record.value && record.la
- if record.london_property? && record.discount_value > 136_400
+ if record.london_property? && record.discount_value > 137_400
%i[discount value la postcode_full uprn].each do |field|
record.errors.add field, I18n.t("validations.sales.sale_information.#{field}.value_over_discounted_london_max", discount_value: record.field_formatted_as_currency("discount_value"))
end
- elsif record.property_not_in_london? && record.discount_value > 102_400
+ elsif record.property_not_in_london? && record.discount_value > 103_400
%i[discount value la postcode_full uprn].each do |field|
record.errors.add field, I18n.t("validations.sales.sale_information.#{field}.value_over_discounted_max", discount_value: record.field_formatted_as_currency("discount_value"))
end
diff --git a/config/locales/validations/sales/sale_information.en.yml b/config/locales/validations/sales/sale_information.en.yml
index ea17953fb..f29856143 100644
--- a/config/locales/validations/sales/sale_information.en.yml
+++ b/config/locales/validations/sales/sale_information.en.yml
@@ -47,8 +47,8 @@ en:
value:
discounted_ownership_value: "The mortgage%{mortgage}%{deposit_and_grant_sentence} added together is %{mortgage_deposit_and_grant_total}.The full purchase price%{discount_sentence} is %{value_with_discount}.These two amounts should be the same."
outright_sale_value: "The mortgage%{mortgage} and cash deposit (%{deposit}) when added together is %{mortgage_and_deposit_total}.The full purchase price is %{value}.These two amounts should be the same."
- value_over_discounted_london_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £136,400 for properties in London."
- value_over_discounted_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £102,400 for properties outside of London."
+ value_over_discounted_london_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £137,400 for properties in London."
+ value_over_discounted_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £103,400 for properties outside of London."
non_staircasing_mortgage:
mortgage_used: "The mortgage (%{mortgage}) and cash deposit (%{deposit}) added together is %{mortgage_and_deposit_total}.The full purchase price (%{value}) multiplied by the percentage equity stake purchased (%{equity}) is %{expected_shared_ownership_deposit_value}.These two amounts should be the same."
mortgage_not_used: "The cash deposit is %{deposit}.The full purchase price (%{value}) multiplied by the percentage bought is %{expected_shared_ownership_deposit_value}.These two amounts should be the same."
@@ -87,8 +87,8 @@ en:
mortgage_not_used_socialhomebuy: "The cash deposit (%{deposit}) and cash discount (%{cashdis}) added together is %{deposit_and_discount_total}.The full purchase price (%{value}) multiplied by the percentage bought (%{equity}) is %{expected_shared_ownership_deposit_value}.These two amounts should be the same."
discount:
discounted_ownership_value: "The mortgage%{mortgage}%{deposit_and_grant_sentence} added together is %{mortgage_deposit_and_grant_total}.The full purchase price%{discount_sentence} is %{value_with_discount}.These two amounts should be the same."
- value_over_discounted_london_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £136,400 for properties in London."
- value_over_discounted_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £102,400 for properties outside of London."
+ value_over_discounted_london_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £137,400 for properties in London."
+ value_over_discounted_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £103,400 for properties outside of London."
grant:
discounted_ownership_value: "The mortgage%{mortgage}%{deposit_and_grant_sentence} added together is %{mortgage_deposit_and_grant_total}.The full purchase price%{discount_sentence} is %{value_with_discount}.These two amounts should be the same."
out_of_range: "Loan, grants or subsidies must be between £9,000 and £16,000."
@@ -119,14 +119,14 @@ en:
staircase:
mortgage_used_value: "You must answer either ‘yes’ or ‘no’ to the question ‘was a mortgage used’ for staircasing transactions."
la:
- value_over_discounted_london_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £136,400 for properties in London."
- value_over_discounted_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £102,400 for properties outside of London."
+ value_over_discounted_london_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £137,400 for properties in London."
+ value_over_discounted_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £103,400 for properties outside of London."
uprn:
- value_over_discounted_london_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £136,400 for properties in London."
- value_over_discounted_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £102,400 for properties outside of London."
+ value_over_discounted_london_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £137,400 for properties in London."
+ value_over_discounted_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £103,400 for properties outside of London."
postcode_full:
- value_over_discounted_london_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £136,400 for properties in London."
- value_over_discounted_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £102,400 for properties outside of London."
+ value_over_discounted_london_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £137,400 for properties in London."
+ value_over_discounted_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £103,400 for properties outside of London."
numstair:
must_be_greater_than_one: "The number of staircasing transactions must be greater than 1 when this is not the first staircasing transaction."
firststair:
diff --git a/spec/models/validations/sales/sale_information_validations_spec.rb b/spec/models/validations/sales/sale_information_validations_spec.rb
index fabe3c8c5..da49d1936 100644
--- a/spec/models/validations/sales/sale_information_validations_spec.rb
+++ b/spec/models/validations/sales/sale_information_validations_spec.rb
@@ -795,17 +795,22 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
record.la = "E09000001"
end
- it "adds an error if value * discount is more than 136,400" do
+ it "adds an error if value * discount is more than 137,400" do
+ record.value = 200_000
record.discount = 80
+ discount_value = "£160,000.00"
sale_information_validator.validate_discount_and_value(record)
- expect(record.errors["value"]).to include("The percentage discount multiplied by the purchase price is £160,000.00. This figure should not be more than £136,400 for properties in London.")
- expect(record.errors["discount"]).to include("The percentage discount multiplied by the purchase price is £160,000.00. This figure should not be more than £136,400 for properties in London.")
- expect(record.errors["la"]).to include("The percentage discount multiplied by the purchase price is £160,000.00. This figure should not be more than £136,400 for properties in London.")
- expect(record.errors["postcode_full"]).to include("The percentage discount multiplied by the purchase price is £160,000.00. This figure should not be more than £136,400 for properties in London.")
- expect(record.errors["uprn"]).to include("The percentage discount multiplied by the purchase price is £160,000.00. This figure should not be more than £136,400 for properties in London.")
+ expect(record.errors["value"]).to include(I18n.t("validations.sales.sale_information.value.value_over_discounted_london_max", discount_value:))
+ expect(record.errors["discount"]).to include(I18n.t("validations.sales.sale_information.discount.value_over_discounted_london_max", discount_value:))
+ expect(record.errors["la"]).to include(I18n.t("validations.sales.sale_information.la.value_over_discounted_london_max", discount_value:))
+ expect(record.errors["postcode_full"]).to include(I18n.t("validations.sales.sale_information.postcode_full.value_over_discounted_london_max", discount_value:))
+ expect(record.errors["uprn"]).to include(I18n.t("validations.sales.sale_information.uprn.value_over_discounted_london_max", discount_value:))
end
- it "does not add an error value * discount is less than 136,400" do
+ it "does not add an error value * discount is less than 137,400" do
+ record.value = 200_000
+ record.discount = 50
+ # Discount value: 100,000
sale_information_validator.validate_discount_and_value(record)
expect(record.errors["value"]).to be_empty
expect(record.errors["discount"]).to be_empty
@@ -820,17 +825,22 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
record.la = "E06000015"
end
- it "adds an error if value * discount is more than 136,400" do
+ it "adds an error if value * discount is more than 103,400" do
+ record.value = 200_000
record.discount = 52
+ discount_value = "£104,000.00"
sale_information_validator.validate_discount_and_value(record)
- expect(record.errors["value"]).to include("The percentage discount multiplied by the purchase price is £104,000.00. This figure should not be more than £102,400 for properties outside of London.")
- expect(record.errors["discount"]).to include("The percentage discount multiplied by the purchase price is £104,000.00. This figure should not be more than £102,400 for properties outside of London.")
- expect(record.errors["la"]).to include("The percentage discount multiplied by the purchase price is £104,000.00. This figure should not be more than £102,400 for properties outside of London.")
- expect(record.errors["postcode_full"]).to include("The percentage discount multiplied by the purchase price is £104,000.00. This figure should not be more than £102,400 for properties outside of London.")
- expect(record.errors["uprn"]).to include("The percentage discount multiplied by the purchase price is £104,000.00. This figure should not be more than £102,400 for properties outside of London.")
+ expect(record.errors["value"]).to include(I18n.t("validations.sales.sale_information.value.value_over_discounted_max", discount_value:))
+ expect(record.errors["discount"]).to include(I18n.t("validations.sales.sale_information.discount.value_over_discounted_max", discount_value:))
+ expect(record.errors["la"]).to include(I18n.t("validations.sales.sale_information.la.value_over_discounted_max", discount_value:))
+ expect(record.errors["postcode_full"]).to include(I18n.t("validations.sales.sale_information.postcode_full.value_over_discounted_max", discount_value:))
+ expect(record.errors["uprn"]).to include(I18n.t("validations.sales.sale_information.uprn.value_over_discounted_max", discount_value:))
end
- it "does not add an error value * discount is less than 136,400" do
+ it "does not add an error value * discount is less than 103,400" do
+ record.value = 200_000
+ record.discount = 50
+ # Discount value: 100,000
sale_information_validator.validate_discount_and_value(record)
expect(record.errors["value"]).to be_empty
expect(record.errors["discount"]).to be_empty
From 80f126c49ba1526a7e1045de75e9d91df4f93dd0 Mon Sep 17 00:00:00 2001
From: Rachael Booth
Date: Mon, 13 Jan 2025 11:24:07 +0000
Subject: [PATCH 10/17] CLDC-3837: Fix bug with step validation for numeric
fields with step 0.1 (#2893)
* CLDC-3837: Fix bug with step validation for numeric fields with step 0.1
* Refactor tests
* Fix test
---
app/models/validations/shared_validations.rb | 17 +--
config/locales/validations/shared.en.yml | 2 +
.../validations/shared_validations_spec.rb | 122 +++++++++++-------
3 files changed, 85 insertions(+), 56 deletions(-)
diff --git a/app/models/validations/shared_validations.rb b/app/models/validations/shared_validations.rb
index da79599ee..7b0ecc420 100644
--- a/app/models/validations/shared_validations.rb
+++ b/app/models/validations/shared_validations.rb
@@ -54,14 +54,15 @@ module Validations::SharedValidations
field = question.check_answer_label || question.id
incorrect_accuracy = (value.to_d * 100) % (question.step * 100) != 0
- if question.step < 1 && incorrect_accuracy
- record.errors.add question.id.to_sym, I18n.t("validations.shared.numeric.nearest_hundredth", field:)
- elsif incorrect_accuracy || value.to_d != value.to_i # if the user enters a value in exponent notation (eg '4e1') the to_i method does not convert this to the correct value
- field = question.check_answer_label || question.id
- case question.step
- when 1 then record.errors.add question.id.to_sym, :not_integer, message: I18n.t("validations.shared.numeric.whole_number", field:)
- when 10 then record.errors.add question.id.to_sym, I18n.t("validations.shared.numeric.nearest_ten", field:)
- end
+ next unless incorrect_accuracy
+
+ case question.step
+ when 0.01 then record.errors.add question.id.to_sym, I18n.t("validations.shared.numeric.nearest_hundredth", field:)
+ when 0.1 then record.errors.add question.id.to_sym, I18n.t("validations.shared.numeric.nearest_tenth", field:)
+ when 1 then record.errors.add question.id.to_sym, :not_integer, message: I18n.t("validations.shared.numeric.whole_number", field:)
+ when 10 then record.errors.add question.id.to_sym, I18n.t("validations.shared.numeric.nearest_ten", field:)
+ else
+ record.errors.add question.id.to_sym, I18n.t("validations.shared.numeric.nearest_step", field:, step: question.step)
end
end
end
diff --git a/config/locales/validations/shared.en.yml b/config/locales/validations/shared.en.yml
index a29d2bd74..ea06636dc 100644
--- a/config/locales/validations/shared.en.yml
+++ b/config/locales/validations/shared.en.yml
@@ -9,7 +9,9 @@ en:
above_min: "%{field} must be at least %{min}."
whole_number: "%{field} must be a whole number."
nearest_ten: "%{field} must be given to the nearest ten."
+ nearest_tenth: "%{field} must be given to the nearest tenth."
nearest_hundredth: "%{field} must be given to the nearest hundredth."
+ nearest_step: "${field} must be given to the nearest %{step}."
normal_format: "Enter a number."
format: "%{field} must be a number."
diff --git a/spec/models/validations/shared_validations_spec.rb b/spec/models/validations/shared_validations_spec.rb
index 53efc6675..2d9ec4ef3 100644
--- a/spec/models/validations/shared_validations_spec.rb
+++ b/spec/models/validations/shared_validations_spec.rb
@@ -116,19 +116,23 @@ RSpec.describe Validations::SharedValidations do
end
describe "validating level of accuracy or rounding for numeric questions" do
+ let(:sales_log) { build(:sales_log, :completed) }
+
+ before do
+ income_question = instance_double(Form::Question, step:, type: "numeric", id: "income1", check_answer_label: "Buyer 1’s gross annual income", page: instance_double(Form::Page, routed_to?: true))
+ form = instance_double(Form, numeric_questions: [income_question])
+ allow(FormHandler.instance).to receive(:get_form).and_return(form)
+ end
+
context "when validating a question with a step of 1" do
+ let(:step) { 1 }
+
it "adds an error if input is a decimal" do
sales_log.income1 = 30_000.5
shared_validator.validate_numeric_step(sales_log)
expect(sales_log.errors[:income1]).to include I18n.t("validations.shared.numeric.whole_number", field: "Buyer 1’s gross annual income")
end
- it "adds an error if the user attempts to input a number in exponent format" do
- sales_log.income1 = "3e5"
- shared_validator.validate_numeric_step(sales_log)
- expect(sales_log.errors[:income1]).to include I18n.t("validations.shared.numeric.whole_number", field: "Buyer 1’s gross annual income")
- end
-
it "does not add an error if input is an integer" do
sales_log.income1 = 30_000
shared_validator.validate_numeric_step(sales_log)
@@ -137,80 +141,96 @@ RSpec.describe Validations::SharedValidations do
end
context "when validating a question with a step of 10" do
- it "adds an error if input is not a multiple of ten" do
- sales_log.savings = 30_005
- sales_log.jointpur = 1
- shared_validator.validate_numeric_step(sales_log)
- expect(sales_log.errors[:savings]).to include I18n.t("validations.shared.numeric.nearest_ten", field: "Buyers’ total savings before any deposit paid")
- end
+ let(:step) { 10 }
- it "adds an error if the user attempts to input a number in exponent format" do
- sales_log.savings = "3e5"
- sales_log.jointpur = 1
+ it "adds an error if input is not a multiple of ten" do
+ sales_log.income1 = 30_005
shared_validator.validate_numeric_step(sales_log)
- expect(sales_log.errors[:savings]).to include I18n.t("validations.shared.numeric.nearest_ten", field: "Buyers’ total savings before any deposit paid")
+ expect(sales_log.errors[:income1]).to include I18n.t("validations.shared.numeric.nearest_ten", field: "Buyer 1’s gross annual income")
end
it "does not add an error if input is a multiple of ten" do
- sales_log.savings = 30_000
+ sales_log.income1 = 30_000
shared_validator.validate_numeric_step(sales_log)
expect(sales_log.errors).to be_empty
end
end
context "when validating a question with a step of 0.01" do
+ let(:step) { 0.01 }
+
it "adds an error if input has more than 2 decimal places" do
- sales_log.mscharge = 30.7418
+ sales_log.income1 = 30_123.7418
shared_validator.validate_numeric_step(sales_log)
- expect(sales_log.errors[:mscharge]).to include I18n.t("validations.shared.numeric.nearest_hundredth", field: "Monthly leasehold charges")
+ expect(sales_log.errors[:income1]).to include I18n.t("validations.shared.numeric.nearest_hundredth", field: "Buyer 1’s gross annual income")
end
- it "does not add an error if the user attempts to input a number in exponent format" do
- sales_log.mscharge = "3e1"
+ it "does not add an error if input has 2 or fewer decimal places" do
+ sales_log.income1 = 30_123.74
shared_validator.validate_numeric_step(sales_log)
expect(sales_log.errors).to be_empty
end
+ end
- it "does not add an error if input has 2 or fewer decimal places" do
- sales_log.mscharge = 30.74
+ context "when validating a question with a step of 0.1" do
+ let(:step) { 0.1 }
+
+ it "adds an error if input has more than 1 decimal place" do
+ sales_log.income1 = 30_123.74
+ shared_validator.validate_numeric_step(sales_log)
+ expect(sales_log.errors[:income1]).to include I18n.t("validations.shared.numeric.nearest_tenth", field: "Buyer 1’s gross annual income")
+ end
+
+ it "does not add an error if input has 1 or fewer decimal places" do
+ sales_log.income1 = 30_123.8
shared_validator.validate_numeric_step(sales_log)
expect(sales_log.errors).to be_empty
end
end
- %i[sales_log lettings_log].each do |log_type|
- describe "validate_owning_organisation_data_sharing_agremeent_signed" do
- it "is valid if the Data Protection Confirmation is signed" do
- log = build(log_type, :in_progress, owning_organisation: create(:organisation))
+ context "when validating a question with an unusual step" do
+ let(:step) { 0.001 }
- expect(log).to be_valid
- end
+ it "adds an appropriate error if input does not match" do
+ sales_log.income1 = 30_123.7419
+ shared_validator.validate_numeric_step(sales_log)
+ expect(sales_log.errors[:income1]).to include I18n.t("validations.shared.numeric.nearest_step", field: "Buyer 1’s gross annual income", step: 0.001)
+ end
+ end
+ end
- it "is valid when owning_organisation nil" do
- log = build(log_type, owning_organisation: nil)
+ %i[sales_log lettings_log].each do |log_type|
+ describe "validate_owning_organisation_data_sharing_agremeent_signed" do
+ it "is valid if the Data Protection Confirmation is signed" do
+ log = build(log_type, :in_progress, owning_organisation: create(:organisation))
- expect(log).to be_valid
- end
+ expect(log).to be_valid
+ end
- it "is not valid if the Data Protection Confirmation is not signed" do
- log = build(log_type, owning_organisation: create(:organisation, :without_dpc))
+ it "is valid when owning_organisation nil" do
+ log = build(log_type, owning_organisation: nil)
- expect(log).not_to be_valid
- expect(log.errors[:owning_organisation_id]).to eq(["The organisation must accept the Data Sharing Agreement before it can be selected as the owning organisation."])
- end
+ expect(log).to be_valid
+ end
+
+ it "is not valid if the Data Protection Confirmation is not signed" do
+ log = build(log_type, owning_organisation: create(:organisation, :without_dpc))
- context "when updating" do
- let(:log) { create(log_type, :in_progress) }
- let(:org_with_dpc) { create(:organisation) }
- let(:org_without_dpc) { create(:organisation, :without_dpc) }
+ expect(log).not_to be_valid
+ expect(log.errors[:owning_organisation_id]).to eq(["The organisation must accept the Data Sharing Agreement before it can be selected as the owning organisation."])
+ end
- it "is valid when changing to another org with a signed Data Protection Confirmation" do
- expect { log.owning_organisation = org_with_dpc }.not_to change(log, :valid?)
- end
+ context "when updating" do
+ let(:log) { create(log_type, :in_progress) }
+ let(:org_with_dpc) { create(:organisation) }
+ let(:org_without_dpc) { create(:organisation, :without_dpc) }
+
+ it "is valid when changing to another org with a signed Data Protection Confirmation" do
+ expect { log.owning_organisation = org_with_dpc }.not_to change(log, :valid?)
+ end
- it "invalid when changing to another org without a signed Data Protection Confirmation" do
- expect { log.owning_organisation = org_without_dpc }.to change(log, :valid?).from(true).to(false).and(change { log.errors[:owning_organisation_id] }.to(["The organisation must accept the Data Sharing Agreement before it can be selected as the owning organisation."]))
- end
+ it "invalid when changing to another org without a signed Data Protection Confirmation" do
+ expect { log.owning_organisation = org_without_dpc }.to change(log, :valid?).from(true).to(false).and(change { log.errors[:owning_organisation_id] }.to(["The organisation must accept the Data Sharing Agreement before it can be selected as the owning organisation."]))
end
end
end
@@ -229,6 +249,12 @@ RSpec.describe Validations::SharedValidations do
expect(sales_log.errors[:income1]).to include I18n.t("validations.shared.numeric.format", field: "Buyer 1’s gross annual income")
end
+ it "does not allow exponent format" do
+ sales_log.income1 = "1e4"
+ shared_validator.validate_numeric_input(sales_log)
+ expect(sales_log.errors[:income1]).to include I18n.t("validations.shared.numeric.format", field: "Buyer 1’s gross annual income")
+ end
+
it "allows a digit" do
sales_log.income1 = "300"
shared_validator.validate_numeric_input(sales_log)
From 7455440e0154f0d383679a44f5058d3feea251c4 Mon Sep 17 00:00:00 2001
From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>
Date: Mon, 13 Jan 2025 14:41:05 +0000
Subject: [PATCH 11/17] CLDC-3822 Update date validations for 2025 (#2886)
* Update date validations for 2025
* Refactor date validations, account for leap years
---
app/models/validations/date_validations.rb | 55 ++++----
.../locales/validations/lettings/date.en.yml | 4 +
.../validations/date_validations_spec.rb | 123 +++++++++++-------
3 files changed, 110 insertions(+), 72 deletions(-)
diff --git a/app/models/validations/date_validations.rb b/app/models/validations/date_validations.rb
index 7462290b6..f69f41cdd 100644
--- a/app/models/validations/date_validations.rb
+++ b/app/models/validations/date_validations.rb
@@ -2,53 +2,56 @@ module Validations::DateValidations
include Validations::SharedValidations
def validate_property_major_repairs(record)
- date_valid?("mrcdate", record)
- if record["startdate"].present? && record["mrcdate"].present? && record["startdate"] < record["mrcdate"]
- record.errors.add :mrcdate, I18n.t("validations.lettings.date.mrcdate.before_tenancy_start")
- end
+ return unless record["mrcdate"].present? && date_valid?("mrcdate", record)
if is_rsnvac_first_let?(record) && record["mrcdate"].present?
record.errors.add :mrcdate, I18n.t("validations.lettings.date.mrcdate.not_first_let")
end
+ return unless record["startdate"].present? && date_valid?("startdate", record)
- if record["mrcdate"].present? && record["startdate"].present? && record["startdate"].to_date - record["mrcdate"].to_date > 3650
+ if record["startdate"].present? && record["mrcdate"].present? && record["startdate"] < record["mrcdate"]
+ record.errors.add :mrcdate, I18n.t("validations.lettings.date.mrcdate.before_tenancy_start")
+ record.errors.add :startdate, I18n.t("validations.lettings.date.startdate.after_major_repair_date")
+ end
+
+ if record.form.start_year_2025_or_later?
+ if record["startdate"].to_date - 20.years > record["mrcdate"].to_date
+ record.errors.add :mrcdate, I18n.t("validations.lettings.date.mrcdate.twenty_years_before_tenancy_start")
+ record.errors.add :startdate, I18n.t("validations.lettings.date.startdate.twenty_years_after_mrc_date")
+ end
+ elsif record["startdate"].to_date - 10.years > record["mrcdate"].to_date
record.errors.add :mrcdate, I18n.t("validations.lettings.date.mrcdate.ten_years_before_tenancy_start")
+ record.errors.add :startdate, I18n.t("validations.lettings.date.startdate.ten_years_after_mrc_date")
end
end
def validate_property_void_date(record)
- if record["voiddate"].present? && record["startdate"].present? && record["startdate"].to_date - record["voiddate"].to_date > 3650
- record.errors.add :voiddate, I18n.t("validations.lettings.date.void_date.ten_years_before_tenancy_start")
- end
-
- if record["voiddate"].present? && record["startdate"].present? && record["startdate"].to_date < record["voiddate"].to_date
- record.errors.add :voiddate, I18n.t("validations.lettings.date.void_date.before_tenancy_start")
- end
+ return unless record["voiddate"].present? && date_valid?("voiddate", record)
- if record["voiddate"].present? && record["mrcdate"].present? && record["mrcdate"].to_date < record["voiddate"].to_date
+ if record["mrcdate"].present? && record["mrcdate"].to_date < record["voiddate"].to_date
record.errors.add :voiddate, :after_mrcdate, message: I18n.t("validations.lettings.date.void_date.after_mrcdate")
record.errors.add :mrcdate, I18n.t("validations.lettings.date.mrcdate.before_void_date")
end
- end
-
- def validate_startdate(record)
- return unless record.startdate && date_valid?("startdate", record)
+ return unless record["startdate"].present? && date_valid?("startdate", record)
- if record["voiddate"].present? && record.startdate < record["voiddate"]
+ if record["startdate"].to_date < record["voiddate"].to_date
+ record.errors.add :voiddate, I18n.t("validations.lettings.date.void_date.before_tenancy_start")
record.errors.add :startdate, I18n.t("validations.lettings.date.startdate.after_void_date")
end
- if record["mrcdate"].present? && record.startdate < record["mrcdate"]
- record.errors.add :startdate, I18n.t("validations.lettings.date.startdate.after_major_repair_date")
- end
-
- if record["voiddate"].present? && record["startdate"].to_date - record["voiddate"].to_date > 3650
+ if record.form.start_year_2025_or_later?
+ if record["startdate"].to_date - 20.years > record["voiddate"].to_date
+ record.errors.add :voiddate, I18n.t("validations.lettings.date.void_date.twenty_years_before_tenancy_start")
+ record.errors.add :startdate, I18n.t("validations.lettings.date.startdate.twenty_years_after_void_date")
+ end
+ elsif record["startdate"].to_date - 10.years > record["voiddate"].to_date
+ record.errors.add :voiddate, I18n.t("validations.lettings.date.void_date.ten_years_before_tenancy_start")
record.errors.add :startdate, I18n.t("validations.lettings.date.startdate.ten_years_after_void_date")
end
+ end
- if record["mrcdate"].present? && record["startdate"].to_date - record["mrcdate"].to_date > 3650
- record.errors.add :startdate, I18n.t("validations.lettings.date.startdate.ten_years_after_mrc_date")
- end
+ def validate_startdate(record)
+ date_valid?("startdate", record)
end
private
diff --git a/config/locales/validations/lettings/date.en.yml b/config/locales/validations/lettings/date.en.yml
index 54c53996f..1e46dba7b 100644
--- a/config/locales/validations/lettings/date.en.yml
+++ b/config/locales/validations/lettings/date.en.yml
@@ -7,14 +7,18 @@ en:
after_major_repair_date: "Enter a tenancy start date that is after the major repair date."
ten_years_after_void_date: "Enter a tenancy start date that is no more than 10 years after the void date."
ten_years_after_mrc_date: "Enter a tenancy start date that is no more than 10 years after the major repairs completion date."
+ twenty_years_after_void_date: "Enter a tenancy start date that is no more than 20 years after the void date."
+ twenty_years_after_mrc_date: "Enter a tenancy start date that is no more than 20 years after the major repairs completion date."
mrcdate:
before_tenancy_start: "Enter a major repairs date that is before the tenancy start date."
not_first_let: "Major repairs date must not be completed if the tenancy is a first let."
ten_years_before_tenancy_start: "Enter a major repairs completion date that is no more than 10 years before the tenancy start date."
+ twenty_years_before_tenancy_start: "Enter a major repairs completion date that is no more than 20 years before the tenancy start date."
before_void_date: "Major repairs date must be after the void date if provided."
void_date:
ten_years_before_tenancy_start: "Enter a void date no more than 10 years before the tenancy start date."
+ twenty_years_before_tenancy_start: "Enter a void date no more than 20 years before the tenancy start date."
before_tenancy_start: "Enter a void date that is before the tenancy start date."
after_mrcdate: "Void date must be before the major repairs date if provided."
diff --git a/spec/models/validations/date_validations_spec.rb b/spec/models/validations/date_validations_spec.rb
index 3ca259b16..b88a75eb2 100644
--- a/spec/models/validations/date_validations_spec.rb
+++ b/spec/models/validations/date_validations_spec.rb
@@ -21,22 +21,6 @@ RSpec.describe Validations::DateValidations do
expect(record.errors["startdate"]).to be_empty
end
- it "validates that the tenancy start date is after the void date if it has a void date" do
- record.startdate = Time.zone.local(2022, 1, 1)
- record.voiddate = Time.zone.local(2022, 2, 1)
- date_validator.validate_startdate(record)
- expect(record.errors["startdate"])
- .to include(match I18n.t("validations.lettings.date.startdate.after_void_date"))
- end
-
- it "validates that the tenancy start date is after the major repair date if it has a major repair date" do
- record.startdate = Time.zone.local(2022, 1, 1)
- record.mrcdate = Time.zone.local(2022, 2, 1)
- date_validator.validate_startdate(record)
- expect(record.errors["startdate"])
- .to include(match I18n.t("validations.lettings.date.startdate.after_major_repair_date"))
- end
-
it "produces no error when the tenancy start date is before the end date of the chosen scheme if it has an end date" do
record.startdate = Time.zone.today - 30.days
record.scheme = scheme
@@ -59,6 +43,8 @@ RSpec.describe Validations::DateValidations do
date_validator.validate_property_major_repairs(record)
expect(record.errors["mrcdate"])
.to include(match I18n.t("validations.lettings.date.mrcdate.before_tenancy_start"))
+ expect(record.errors["startdate"])
+ .to include(match I18n.t("validations.lettings.date.startdate.after_major_repair_date"))
end
it "must be before the tenancy start date" do
@@ -68,23 +54,44 @@ RSpec.describe Validations::DateValidations do
expect(record.errors["mrcdate"]).to be_empty
end
- it "cannot be more than 10 years before the tenancy start date" do
- record.startdate = Time.zone.local(2022, 2, 1)
- record.mrcdate = Time.zone.local(2012, 1, 1)
- date_validator.validate_property_major_repairs(record)
- date_validator.validate_startdate(record)
- expect(record.errors["mrcdate"])
- .to include(match I18n.t("validations.lettings.date.mrcdate.ten_years_before_tenancy_start"))
- expect(record.errors["startdate"])
- .to include(match I18n.t("validations.lettings.date.startdate.ten_years_after_mrc_date"))
+ context "with 2024 logs or earlier" do
+ it "cannot be more than 10 years before the tenancy start date" do
+ record.startdate = Time.zone.local(2024, 2, 1)
+ record.mrcdate = Time.zone.local(2014, 1, 31)
+ date_validator.validate_property_major_repairs(record)
+ expect(record.errors["mrcdate"])
+ .to include(match I18n.t("validations.lettings.date.mrcdate.ten_years_before_tenancy_start"))
+ expect(record.errors["startdate"])
+ .to include(match I18n.t("validations.lettings.date.startdate.ten_years_after_mrc_date"))
+ end
+
+ it "must be within 10 years of the tenancy start date" do
+ record.startdate = Time.zone.local(2024, 2, 1)
+ record.mrcdate = Time.zone.local(2014, 2, 1)
+ date_validator.validate_property_major_repairs(record)
+ expect(record.errors["mrcdate"]).to be_empty
+ expect(record.errors["startdate"]).to be_empty
+ end
end
- it "must be within 10 years of the tenancy start date" do
- record.startdate = Time.zone.local(2022, 2, 1)
- record.mrcdate = Time.zone.local(2012, 3, 1)
- date_validator.validate_property_major_repairs(record)
- expect(record.errors["mrcdate"]).to be_empty
- expect(record.errors["startdate"]).to be_empty
+ context "with 2025 logs or later" do
+ it "cannot be more than 20 years before the tenancy start date" do
+ record.startdate = Time.zone.local(2026, 2, 1)
+ record.mrcdate = Time.zone.local(2006, 1, 31)
+ date_validator.validate_property_major_repairs(record)
+ expect(record.errors["mrcdate"])
+ .to include(match I18n.t("validations.lettings.date.mrcdate.twenty_years_before_tenancy_start"))
+ expect(record.errors["startdate"])
+ .to include(match I18n.t("validations.lettings.date.startdate.twenty_years_after_mrc_date"))
+ end
+
+ it "must be within 20 years of the tenancy start date" do
+ record.startdate = Time.zone.local(2026, 2, 1)
+ record.mrcdate = Time.zone.local(2006, 2, 1)
+ date_validator.validate_property_major_repairs(record)
+ expect(record.errors["mrcdate"]).to be_empty
+ expect(record.errors["startdate"]).to be_empty
+ end
end
context "when reason for vacancy is first let of property" do
@@ -130,6 +137,8 @@ RSpec.describe Validations::DateValidations do
date_validator.validate_property_void_date(record)
expect(record.errors["voiddate"])
.to include(match I18n.t("validations.lettings.date.void_date.before_tenancy_start"))
+ expect(record.errors["startdate"])
+ .to include(match I18n.t("validations.lettings.date.startdate.after_void_date"))
end
it "must be before the tenancy start date" do
@@ -139,23 +148,45 @@ RSpec.describe Validations::DateValidations do
expect(record.errors["voiddate"]).to be_empty
end
- it "cannot be more than 10 years before the tenancy start date" do
- record.startdate = Time.zone.local(2022, 2, 1)
- record.voiddate = Time.zone.local(2012, 1, 1)
- date_validator.validate_property_void_date(record)
- date_validator.validate_startdate(record)
- expect(record.errors["voiddate"])
- .to include(match I18n.t("validations.lettings.date.void_date.ten_years_before_tenancy_start"))
- expect(record.errors["startdate"])
- .to include(match I18n.t("validations.lettings.date.startdate.ten_years_after_void_date"))
+ context "with 2024 logs or earlier" do
+ it "cannot be more than 10 years before the tenancy start date" do
+ record.startdate = Time.zone.local(2024, 2, 1)
+ record.voiddate = Time.zone.local(2014, 1, 31)
+ date_validator.validate_property_void_date(record)
+ expect(record.errors["voiddate"])
+ .to include(match I18n.t("validations.lettings.date.void_date.ten_years_before_tenancy_start"))
+ expect(record.errors["startdate"])
+ .to include(match I18n.t("validations.lettings.date.startdate.ten_years_after_void_date"))
+ end
+
+ it "must be within 10 years of the tenancy start date" do
+ record.startdate = Time.zone.local(2024, 2, 1)
+ record.voiddate = Time.zone.local(2014, 2, 1)
+ date_validator.validate_property_void_date(record)
+ expect(record.errors["voiddate"]).to be_empty
+ expect(record.errors["startdate"]).to be_empty
+ end
end
- it "must be within 10 years of the tenancy start date" do
- record.startdate = Time.zone.local(2022, 2, 1)
- record.voiddate = Time.zone.local(2012, 3, 1)
- date_validator.validate_property_void_date(record)
- expect(record.errors["voiddate"]).to be_empty
- expect(record.errors["startdate"]).to be_empty
+ context "with 2025 logs or later" do
+ it "cannot be more than 20 years before the tenancy start date" do
+ record.startdate = Time.zone.local(2026, 2, 1)
+ record.voiddate = Time.zone.local(2006, 1, 31)
+ date_validator.validate_property_void_date(record)
+ date_validator.validate_startdate(record)
+ expect(record.errors["voiddate"])
+ .to include(match I18n.t("validations.lettings.date.void_date.twenty_years_before_tenancy_start"))
+ expect(record.errors["startdate"])
+ .to include(match I18n.t("validations.lettings.date.startdate.twenty_years_after_void_date"))
+ end
+
+ it "must be within 20 years of the tenancy start date" do
+ record.startdate = Time.zone.local(2026, 2, 1)
+ record.voiddate = Time.zone.local(2006, 2, 1)
+ date_validator.validate_property_void_date(record)
+ expect(record.errors["voiddate"]).to be_empty
+ expect(record.errors["startdate"]).to be_empty
+ end
end
context "when major repairs have been carried out" do
From b1a384e454ef266c41a7220c9514c2cd44eb1f5c Mon Sep 17 00:00:00 2001
From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>
Date: Mon, 13 Jan 2025 14:41:40 +0000
Subject: [PATCH 12/17] Update person relationship questions (#2892)
---
.../lettings/pages/person_lead_partner.rb | 12 ++
.../form/lettings/questions/person_partner.rb | 30 ++++
.../subsections/household_characteristics.rb | 22 ++-
.../lettings/household_characteristics.en.yml | 28 ++--
.../pages/person_lead_partner_spec.rb | 51 ++++++
.../lettings/questions/person_partner_spec.rb | 57 +++++++
.../household_characteristics_spec.rb | 156 ++++++++++++++++++
7 files changed, 335 insertions(+), 21 deletions(-)
create mode 100644 app/models/form/lettings/pages/person_lead_partner.rb
create mode 100644 app/models/form/lettings/questions/person_partner.rb
create mode 100644 spec/models/form/lettings/pages/person_lead_partner_spec.rb
create mode 100644 spec/models/form/lettings/questions/person_partner_spec.rb
diff --git a/app/models/form/lettings/pages/person_lead_partner.rb b/app/models/form/lettings/pages/person_lead_partner.rb
new file mode 100644
index 000000000..30613d976
--- /dev/null
+++ b/app/models/form/lettings/pages/person_lead_partner.rb
@@ -0,0 +1,12 @@
+class Form::Lettings::Pages::PersonLeadPartner < ::Form::Page
+ def initialize(id, hsh, subsection, person_index:)
+ super(id, hsh, subsection)
+ @id = "person_#{person_index}_lead_partner"
+ @depends_on = [{ "details_known_#{person_index}" => 0 }]
+ @person_index = person_index
+ end
+
+ def questions
+ @questions ||= [Form::Lettings::Questions::PersonPartner.new(nil, nil, self, person_index: @person_index)]
+ end
+end
diff --git a/app/models/form/lettings/questions/person_partner.rb b/app/models/form/lettings/questions/person_partner.rb
new file mode 100644
index 000000000..25c2d72c1
--- /dev/null
+++ b/app/models/form/lettings/questions/person_partner.rb
@@ -0,0 +1,30 @@
+class Form::Lettings::Questions::PersonPartner < ::Form::Question
+ def initialize(id, hsh, page, person_index:)
+ super(id, hsh, page)
+ @id = "relat#{person_index}"
+ @type = "radio"
+ @check_answers_card_number = person_index
+ @answer_options = answer_options
+ @person_index = person_index
+ @question_number = question_number
+ end
+
+ def answer_options
+ {
+ "P" => { "value" => "Yes" },
+ "X" => { "value" => "No" },
+ "R" => { "value" => "Tenant prefers not to say" },
+ }
+ end
+
+ def question_number
+ base_question_number = case form.start_date.year
+ when 2023
+ 30
+ else
+ 29
+ end
+
+ base_question_number + (4 * @person_index)
+ end
+end
diff --git a/app/models/form/lettings/subsections/household_characteristics.rb b/app/models/form/lettings/subsections/household_characteristics.rb
index 61334d84c..a454ffed5 100644
--- a/app/models/form/lettings/subsections/household_characteristics.rb
+++ b/app/models/form/lettings/subsections/household_characteristics.rb
@@ -32,7 +32,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::LeadTenantUnderRetirementValueCheck.new("working_situation_lead_tenant_under_retirement_value_check", nil, self),
Form::Lettings::Pages::LeadTenantOverRetirementValueCheck.new("working_situation_lead_tenant_over_retirement_value_check", nil, self),
Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 2),
- Form::Lettings::Pages::PersonRelationshipToLead.new(nil, nil, self, person_index: 2),
+ relationship_question(person_index: 2),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_2_partner_under_16_value_check", nil, self, person_index: 2) if form.start_year_2024_or_later?),
(Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_2_multiple_partners_value_check", nil, self, person_index: 2) if form.start_year_2024_or_later?),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 2),
@@ -52,7 +52,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("working_situation_2_under_retirement_value_check", nil, self, person_index: 2),
Form::Lettings::Pages::PersonOverRetirementValueCheck.new("working_situation_2_over_retirement_value_check", nil, self, person_index: 2),
Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 3),
- Form::Lettings::Pages::PersonRelationshipToLead.new(nil, nil, self, person_index: 3),
+ relationship_question(person_index: 3),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_3_partner_under_16_value_check", nil, self, person_index: 3) if form.start_year_2024_or_later?),
(Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_3_multiple_partners_value_check", nil, self, person_index: 3) if form.start_year_2024_or_later?),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 3),
@@ -72,7 +72,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("working_situation_3_under_retirement_value_check", nil, self, person_index: 3),
Form::Lettings::Pages::PersonOverRetirementValueCheck.new("working_situation_3_over_retirement_value_check", nil, self, person_index: 3),
Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 4),
- Form::Lettings::Pages::PersonRelationshipToLead.new(nil, nil, self, person_index: 4),
+ relationship_question(person_index: 4),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_4_partner_under_16_value_check", nil, self, person_index: 4) if form.start_year_2024_or_later?),
(Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_4_multiple_partners_value_check", nil, self, person_index: 4) if form.start_year_2024_or_later?),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 4),
@@ -92,7 +92,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("working_situation_4_under_retirement_value_check", nil, self, person_index: 4),
Form::Lettings::Pages::PersonOverRetirementValueCheck.new("working_situation_4_over_retirement_value_check", nil, self, person_index: 4),
Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 5),
- Form::Lettings::Pages::PersonRelationshipToLead.new(nil, nil, self, person_index: 5),
+ relationship_question(person_index: 5),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_5_partner_under_16_value_check", nil, self, person_index: 5) if form.start_year_2024_or_later?),
(Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_5_multiple_partners_value_check", nil, self, person_index: 5) if form.start_year_2024_or_later?),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 5),
@@ -112,7 +112,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("working_situation_5_under_retirement_value_check", nil, self, person_index: 5),
Form::Lettings::Pages::PersonOverRetirementValueCheck.new("working_situation_5_over_retirement_value_check", nil, self, person_index: 5),
Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 6),
- Form::Lettings::Pages::PersonRelationshipToLead.new(nil, nil, self, person_index: 6),
+ relationship_question(person_index: 6),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_6_partner_under_16_value_check", nil, self, person_index: 6) if form.start_year_2024_or_later?),
(Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_6_multiple_partners_value_check", nil, self, person_index: 6) if form.start_year_2024_or_later?),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 6),
@@ -132,7 +132,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("working_situation_6_under_retirement_value_check", nil, self, person_index: 6),
Form::Lettings::Pages::PersonOverRetirementValueCheck.new("working_situation_6_over_retirement_value_check", nil, self, person_index: 6),
Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 7),
- Form::Lettings::Pages::PersonRelationshipToLead.new(nil, nil, self, person_index: 7),
+ relationship_question(person_index: 7),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_7_partner_under_16_value_check", nil, self, person_index: 7) if form.start_year_2024_or_later?),
(Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_7_multiple_partners_value_check", nil, self, person_index: 7) if form.start_year_2024_or_later?),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 7),
@@ -152,7 +152,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("working_situation_7_under_retirement_value_check", nil, self, person_index: 7),
Form::Lettings::Pages::PersonOverRetirementValueCheck.new("working_situation_7_over_retirement_value_check", nil, self, person_index: 7),
Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 8),
- Form::Lettings::Pages::PersonRelationshipToLead.new(nil, nil, self, person_index: 8),
+ relationship_question(person_index: 8),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_8_partner_under_16_value_check", nil, self, person_index: 8) if form.start_year_2024_or_later?),
(Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_8_multiple_partners_value_check", nil, self, person_index: 8) if form.start_year_2024_or_later?),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 8),
@@ -173,4 +173,12 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::PersonOverRetirementValueCheck.new("working_situation_8_over_retirement_value_check", nil, self, person_index: 8),
].compact
end
+
+ def relationship_question(person_index:)
+ if form.start_year_2025_or_later?
+ Form::Lettings::Pages::PersonLeadPartner.new(nil, nil, self, person_index:)
+ else
+ Form::Lettings::Pages::PersonRelationshipToLead.new(nil, nil, self, person_index:)
+ end
+ end
end
diff --git a/config/locales/forms/2025/lettings/household_characteristics.en.yml b/config/locales/forms/2025/lettings/household_characteristics.en.yml
index b6d7ad7e9..79646b32b 100644
--- a/config/locales/forms/2025/lettings/household_characteristics.en.yml
+++ b/config/locales/forms/2025/lettings/household_characteristics.en.yml
@@ -84,9 +84,9 @@ en:
relat2:
page_header: ""
- check_answer_label: "Person 2’s relationship to the lead tenant"
+ check_answer_label: "Person 2 lead tenant’s partner"
hint_text: ""
- question_text: "What is person 2’s relationship to the lead tenant?"
+ question_text: "Is tenant 2 the partner of tenant 1?"
age2:
page_header: ""
@@ -119,9 +119,9 @@ en:
relat3:
page_header: ""
- check_answer_label: "Person 3’s relationship to the lead tenant"
+ check_answer_label: "Person 3 lead tenant’s partner"
hint_text: ""
- question_text: "What is person 3’s relationship to the lead tenant?"
+ question_text: "Is tenant 3 the partner of tenant 1?"
age3:
page_header: ""
@@ -154,9 +154,9 @@ en:
relat4:
page_header: ""
- check_answer_label: "Person 4’s relationship to the lead tenant"
+ check_answer_label: "Person 4 lead tenant’s partner"
hint_text: ""
- question_text: "What is person 4’s relationship to the lead tenant?"
+ question_text: "Is tenant 4 the partner of tenant 1?"
age4:
page_header: ""
@@ -189,9 +189,9 @@ en:
relat5:
page_header: ""
- check_answer_label: "Person 5’s relationship to the lead tenant"
+ check_answer_label: "Person 5 lead tenant’s partner"
hint_text: ""
- question_text: "What is person 5’s relationship to the lead tenant?"
+ question_text: "Is tenant 5 the partner of tenant 1?"
age5:
page_header: ""
@@ -224,9 +224,9 @@ en:
relat6:
page_header: ""
- check_answer_label: "Person 6’s relationship to the lead tenant"
+ check_answer_label: "Person 6 lead tenant’s partner"
hint_text: ""
- question_text: "What is person 6’s relationship to the lead tenant?"
+ question_text: "Is tenant 6 the partner of tenant 1?"
age6:
page_header: ""
@@ -259,9 +259,9 @@ en:
relat7:
page_header: ""
- check_answer_label: "Person 7’s relationship to the lead tenant"
+ check_answer_label: "Person 7 lead tenant’s partner"
hint_text: ""
- question_text: "What is person 7’s relationship to the lead tenant?"
+ question_text: "Is tenant 7 the partner of tenant 1?"
age7:
page_header: ""
@@ -294,9 +294,9 @@ en:
relat8:
page_header: ""
- check_answer_label: "Person 8’s relationship to the lead tenant"
+ check_answer_label: "Person 8 lead tenant’s partner"
hint_text: ""
- question_text: "What is person 8’s relationship to the lead tenant?"
+ question_text: "Is tenant 8 the partner of tenant 1?"
age8:
page_header: ""
diff --git a/spec/models/form/lettings/pages/person_lead_partner_spec.rb b/spec/models/form/lettings/pages/person_lead_partner_spec.rb
new file mode 100644
index 000000000..88aa3095d
--- /dev/null
+++ b/spec/models/form/lettings/pages/person_lead_partner_spec.rb
@@ -0,0 +1,51 @@
+require "rails_helper"
+
+RSpec.describe Form::Lettings::Pages::PersonLeadPartner, type: :model do
+ subject(:page) { described_class.new(nil, page_definition, subsection, person_index:) }
+
+ let(:page_definition) { nil }
+ let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2024, 4, 1), start_year_2025_or_later?: true)) }
+ let(:person_index) { 2 }
+
+ it "has correct subsection" do
+ expect(page.subsection).to eq(subsection)
+ end
+
+ it "has the correct description" do
+ expect(page.description).to be nil
+ end
+
+ context "with person 2" do
+ it "has correct questions" do
+ expect(page.questions.map(&:id)).to eq(%w[relat2])
+ end
+
+ it "has the correct id" do
+ expect(page.id).to eq("person_2_lead_partner")
+ end
+
+ it "has correct depends_on" do
+ expect(page.depends_on).to eq(
+ [{ "details_known_2" => 0 }],
+ )
+ end
+ end
+
+ context "with person 3" do
+ let(:person_index) { 3 }
+
+ it "has correct questions" do
+ expect(page.questions.map(&:id)).to eq(%w[relat3])
+ end
+
+ it "has the correct id" do
+ expect(page.id).to eq("person_3_lead_partner")
+ end
+
+ it "has correct depends_on" do
+ expect(page.depends_on).to eq(
+ [{ "details_known_3" => 0 }],
+ )
+ end
+ end
+end
diff --git a/spec/models/form/lettings/questions/person_partner_spec.rb b/spec/models/form/lettings/questions/person_partner_spec.rb
new file mode 100644
index 000000000..7e2d177bd
--- /dev/null
+++ b/spec/models/form/lettings/questions/person_partner_spec.rb
@@ -0,0 +1,57 @@
+require "rails_helper"
+
+RSpec.describe Form::Lettings::Questions::PersonPartner, type: :model do
+ subject(:question) { described_class.new(nil, question_definition, page, person_index:) }
+
+ let(:question_definition) { nil }
+ let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2025, 4, 4), start_year_2025_or_later?: true))) }
+ let(:person_index) { 2 }
+
+ it "has correct page" do
+ expect(question.page).to eq(page)
+ end
+
+ it "has the correct type" do
+ expect(question.type).to eq("radio")
+ end
+
+ it "is not marked as derived" do
+ expect(question.derived?(nil)).to be false
+ end
+
+ it "has the correct answer_options" do
+ expect(question.answer_options).to eq("P" => { "value" => "Yes" },
+ "X" => { "value" => "No" },
+ "R" => { "value" => "Tenant prefers not to say" })
+ end
+
+ it "has correct conditional for" do
+ expect(question.conditional_for).to be nil
+ end
+
+ it "has the correct hidden_in_check_answers" do
+ expect(question.hidden_in_check_answers).to be nil
+ end
+
+ context "with person 2" do
+ it "has the correct id" do
+ expect(question.id).to eq("relat2")
+ end
+
+ it "has the correct check_answers_card_number" do
+ expect(question.check_answers_card_number).to eq(2)
+ end
+ end
+
+ context "with person 3" do
+ let(:person_index) { 3 }
+
+ it "has the correct id" do
+ expect(question.id).to eq("relat3")
+ end
+
+ it "has the correct check_answers_card_number" do
+ expect(question.check_answers_card_number).to eq(3)
+ end
+ end
+end
diff --git a/spec/models/form/lettings/subsections/household_characteristics_spec.rb b/spec/models/form/lettings/subsections/household_characteristics_spec.rb
index b45f86fce..5aab3514c 100644
--- a/spec/models/form/lettings/subsections/household_characteristics_spec.rb
+++ b/spec/models/form/lettings/subsections/household_characteristics_spec.rb
@@ -10,6 +10,7 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
before do
allow(section).to receive(:form).and_return(form)
+ allow(form).to receive(:start_year_2025_or_later?).and_return(false)
end
it "has correct section" do
@@ -304,6 +305,161 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
end
end
+ context "with start year >= 2025" do
+ before do
+ allow(form).to receive(:start_year_2024_or_later?).and_return(true)
+ allow(form).to receive(:start_year_2025_or_later?).and_return(true)
+ end
+
+ it "has correct pages" do
+ expect(household_characteristics.pages.map(&:id)).to eq(
+ %w[
+ household_members
+ no_females_pregnant_household_lead_hhmemb_value_check
+ females_in_soft_age_range_in_pregnant_household_lead_hhmemb_value_check
+ lead_tenant_age
+ no_females_pregnant_household_lead_age_value_check
+ females_in_soft_age_range_in_pregnant_household_lead_age_value_check
+ age_lead_tenant_under_retirement_value_check
+ age_lead_tenant_over_retirement_value_check
+ lead_tenant_gender_identity
+ no_females_pregnant_household_lead_value_check
+ females_in_soft_age_range_in_pregnant_household_lead_value_check
+ gender_lead_tenant_over_retirement_value_check
+ lead_tenant_ethnic_group
+ lead_tenant_ethnic_background_arab
+ lead_tenant_ethnic_background_asian
+ lead_tenant_ethnic_background_black
+ lead_tenant_ethnic_background_mixed
+ lead_tenant_ethnic_background_white
+ lead_tenant_nationality
+ lead_tenant_working_situation
+ working_situation_lead_tenant_under_retirement_value_check
+ working_situation_lead_tenant_over_retirement_value_check
+ person_2_known
+ person_2_lead_partner
+ relationship_2_partner_under_16_value_check
+ relationship_2_multiple_partners_value_check
+ person_2_age
+ no_females_pregnant_household_person_2_age_value_check
+ females_in_soft_age_range_in_pregnant_household_person_2_age_value_check
+ age_2_under_retirement_value_check
+ age_2_over_retirement_value_check
+ age_2_partner_under_16_value_check
+ person_2_gender_identity
+ no_females_pregnant_household_person_2_value_check
+ females_in_soft_age_range_in_pregnant_household_person_2_value_check
+ gender_2_over_retirement_value_check
+ person_2_working_situation
+ working_situation_2_under_retirement_value_check
+ working_situation_2_over_retirement_value_check
+ person_3_known
+ person_3_lead_partner
+ relationship_3_partner_under_16_value_check
+ relationship_3_multiple_partners_value_check
+ person_3_age
+ no_females_pregnant_household_person_3_age_value_check
+ females_in_soft_age_range_in_pregnant_household_person_3_age_value_check
+ age_3_under_retirement_value_check
+ age_3_over_retirement_value_check
+ age_3_partner_under_16_value_check
+ person_3_gender_identity
+ no_females_pregnant_household_person_3_value_check
+ females_in_soft_age_range_in_pregnant_household_person_3_value_check
+ gender_3_over_retirement_value_check
+ person_3_working_situation
+ working_situation_3_under_retirement_value_check
+ working_situation_3_over_retirement_value_check
+ person_4_known
+ person_4_lead_partner
+ relationship_4_partner_under_16_value_check
+ relationship_4_multiple_partners_value_check
+ person_4_age
+ no_females_pregnant_household_person_4_age_value_check
+ females_in_soft_age_range_in_pregnant_household_person_4_age_value_check
+ age_4_under_retirement_value_check
+ age_4_over_retirement_value_check
+ age_4_partner_under_16_value_check
+ person_4_gender_identity
+ no_females_pregnant_household_person_4_value_check
+ females_in_soft_age_range_in_pregnant_household_person_4_value_check
+ gender_4_over_retirement_value_check
+ person_4_working_situation
+ working_situation_4_under_retirement_value_check
+ working_situation_4_over_retirement_value_check
+ person_5_known
+ person_5_lead_partner
+ relationship_5_partner_under_16_value_check
+ relationship_5_multiple_partners_value_check
+ person_5_age
+ no_females_pregnant_household_person_5_age_value_check
+ females_in_soft_age_range_in_pregnant_household_person_5_age_value_check
+ age_5_under_retirement_value_check
+ age_5_over_retirement_value_check
+ age_5_partner_under_16_value_check
+ person_5_gender_identity
+ no_females_pregnant_household_person_5_value_check
+ females_in_soft_age_range_in_pregnant_household_person_5_value_check
+ gender_5_over_retirement_value_check
+ person_5_working_situation
+ working_situation_5_under_retirement_value_check
+ working_situation_5_over_retirement_value_check
+ person_6_known
+ person_6_lead_partner
+ relationship_6_partner_under_16_value_check
+ relationship_6_multiple_partners_value_check
+ person_6_age
+ no_females_pregnant_household_person_6_age_value_check
+ females_in_soft_age_range_in_pregnant_household_person_6_age_value_check
+ age_6_under_retirement_value_check
+ age_6_over_retirement_value_check
+ age_6_partner_under_16_value_check
+ person_6_gender_identity
+ no_females_pregnant_household_person_6_value_check
+ females_in_soft_age_range_in_pregnant_household_person_6_value_check
+ gender_6_over_retirement_value_check
+ person_6_working_situation
+ working_situation_6_under_retirement_value_check
+ working_situation_6_over_retirement_value_check
+ person_7_known
+ person_7_lead_partner
+ relationship_7_partner_under_16_value_check
+ relationship_7_multiple_partners_value_check
+ person_7_age
+ no_females_pregnant_household_person_7_age_value_check
+ females_in_soft_age_range_in_pregnant_household_person_7_age_value_check
+ age_7_under_retirement_value_check
+ age_7_over_retirement_value_check
+ age_7_partner_under_16_value_check
+ person_7_gender_identity
+ no_females_pregnant_household_person_7_value_check
+ females_in_soft_age_range_in_pregnant_household_person_7_value_check
+ gender_7_over_retirement_value_check
+ person_7_working_situation
+ working_situation_7_under_retirement_value_check
+ working_situation_7_over_retirement_value_check
+ person_8_known
+ person_8_lead_partner
+ relationship_8_partner_under_16_value_check
+ relationship_8_multiple_partners_value_check
+ person_8_age
+ no_females_pregnant_household_person_8_age_value_check
+ females_in_soft_age_range_in_pregnant_household_person_8_age_value_check
+ age_8_under_retirement_value_check
+ age_8_over_retirement_value_check
+ age_8_partner_under_16_value_check
+ person_8_gender_identity
+ no_females_pregnant_household_person_8_value_check
+ females_in_soft_age_range_in_pregnant_household_person_8_value_check
+ gender_8_over_retirement_value_check
+ person_8_working_situation
+ working_situation_8_under_retirement_value_check
+ working_situation_8_over_retirement_value_check
+ ],
+ )
+ end
+ end
+
it "has the correct id" do
expect(household_characteristics.id).to eq("household_characteristics")
end
From ddebebee30ee1b786783fd560e29522ec05dd565 Mon Sep 17 00:00:00 2001
From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>
Date: Tue, 14 Jan 2025 09:02:16 +0000
Subject: [PATCH 13/17] Remove irrelevant 2023 checks (#2895)
* Remove irrelevant 2023 checks
* Update/remove tests
---
.../lettings_log_variables.rb | 2 +-
.../derived_variables/sales_log_variables.rb | 2 +-
app/models/form/question.rb | 2 +-
.../bulk_upload_form/prepare_your_file.rb | 2 -
app/models/lettings_log.rb | 4 +-
app/models/sales_log.rb | 25 +---------
.../validations/financial_validations.rb | 2 +-
.../validations/household_validations.rb | 2 +-
.../sales/financial_validations.rb | 2 +-
.../sales/household_validations.rb | 2 -
.../forms/prepare_your_file_2023.html.erb | 46 -------------------
.../forms/prepare_your_file_2023.html.erb | 40 ----------------
.../bulk_upload_shared/guidance.html.erb | 21 ++-------
spec/features/bulk_upload_sales_logs_spec.rb | 14 +++---
spec/models/sales_log_spec.rb | 8 ----
.../validations/financial_validations_spec.rb | 14 ------
...lk_upload_lettings_logs_controller_spec.rb | 1 +
.../bulk_upload_sales_logs_controller_spec.rb | 1 +
18 files changed, 20 insertions(+), 170 deletions(-)
delete mode 100644 app/views/bulk_upload_lettings_logs/forms/prepare_your_file_2023.html.erb
delete mode 100644 app/views/bulk_upload_sales_logs/forms/prepare_your_file_2023.html.erb
diff --git a/app/models/derived_variables/lettings_log_variables.rb b/app/models/derived_variables/lettings_log_variables.rb
index ced530b17..6d50bb5ff 100644
--- a/app/models/derived_variables/lettings_log_variables.rb
+++ b/app/models/derived_variables/lettings_log_variables.rb
@@ -346,7 +346,7 @@ private
end
def address_answered_without_uprn?
- [address_line1, town_or_city].all?(&:present?) && uprn.nil? && form.start_date.year >= 2023
+ [address_line1, town_or_city].all?(&:present?) && uprn.nil?
end
def get_lar
diff --git a/app/models/derived_variables/sales_log_variables.rb b/app/models/derived_variables/sales_log_variables.rb
index 6e12ec488..ef4997283 100644
--- a/app/models/derived_variables/sales_log_variables.rb
+++ b/app/models/derived_variables/sales_log_variables.rb
@@ -226,7 +226,7 @@ private
end
def address_answered_without_uprn?
- [address_line1, town_or_city].all?(&:present?) && uprn.nil? && form.start_date.year >= 2023
+ [address_line1, town_or_city].all?(&:present?) && uprn.nil?
end
def soctenant_from_prevten_values
diff --git a/app/models/form/question.rb b/app/models/form/question.rb
index 05eec89dd..a91187003 100644
--- a/app/models/form/question.rb
+++ b/app/models/form/question.rb
@@ -276,7 +276,7 @@ class Form::Question
end
def question_number_string(hidden: false)
- if @question_number && !hidden && form.start_date.year >= 2023
+ if @question_number && !hidden
"Q#{@question_number}"
end
end
diff --git a/app/models/forms/bulk_upload_form/prepare_your_file.rb b/app/models/forms/bulk_upload_form/prepare_your_file.rb
index b89367d9f..911daa4fe 100644
--- a/app/models/forms/bulk_upload_form/prepare_your_file.rb
+++ b/app/models/forms/bulk_upload_form/prepare_your_file.rb
@@ -11,8 +11,6 @@ module Forms
def view_path
case year
- when 2023
- "bulk_upload_#{log_type}_logs/forms/prepare_your_file_2023"
when 2024
"bulk_upload_#{log_type}_logs/forms/prepare_your_file_2024"
end
diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb
index 67cafb75b..3ec0d6bf7 100644
--- a/app/models/lettings_log.rb
+++ b/app/models/lettings_log.rb
@@ -670,8 +670,7 @@ class LettingsLog < Log
["owning_organisation_id",
"startdate",
"tenancycode",
- form.start_date.year < 2023 || uprn.blank? ? "postcode_full" : nil,
- form.start_date.year >= 2023 && uprn.present? ? "uprn" : nil,
+ uprn.blank? ? "postcode_full" : "uprn",
"scheme_id",
"location_id",
"age1",
@@ -884,7 +883,6 @@ private
def should_process_uprn_change?
return unless uprn
return unless startdate
- return unless collection_start_year_for_date(startdate) >= 2023
uprn_changed? || startdate_changed?
end
diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb
index d03425ee4..f7604b11e 100644
--- a/app/models/sales_log.rb
+++ b/app/models/sales_log.rb
@@ -129,33 +129,12 @@ class SalesLog < Log
def dynamically_not_required
not_required = []
- not_required << "proplen" if proplen_optional?
- 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]
not_required
end
- def proplen_optional?
- return false unless collection_start_year
-
- collection_start_year < 2023
- end
-
- def mortlen_optional?
- return false unless collection_start_year
-
- collection_start_year < 2023
- end
-
- def frombeds_optional?
- return false unless collection_start_year
-
- collection_start_year < 2023
- end
-
def unresolved
false
end
@@ -449,7 +428,6 @@ class SalesLog < Log
def should_process_uprn_change?
return unless uprn
return unless saledate
- return unless collection_start_year_for_date(saledate) >= 2023
uprn_changed? || saledate_changed?
end
@@ -514,8 +492,7 @@ class SalesLog < Log
"age1",
"sex1",
"ecstat1",
- form.start_date.year < 2023 || uprn.blank? ? "postcode_full" : nil,
- form.start_date.year >= 2023 && uprn.present? ? "uprn" : nil].compact
+ uprn.blank? ? "postcode_full" : "uprn"].compact
end
def soctenant_is_inferred?
diff --git a/app/models/validations/financial_validations.rb b/app/models/validations/financial_validations.rb
index 73b389f4c..82b3fae01 100644
--- a/app/models/validations/financial_validations.rb
+++ b/app/models/validations/financial_validations.rb
@@ -25,7 +25,7 @@ module Validations::FinancialValidations
end
def validate_net_income(record)
- if record.ecstat1 && record.hhmemb && record.weekly_net_income && record.startdate && record.form.start_date.year >= 2023
+ if record.ecstat1 && record.hhmemb && record.weekly_net_income && record.startdate
if record.weekly_net_income > record.applicable_income_range.hard_max
frequency = record.form.get_question("incfreq", record).label_from_value(record.incfreq).downcase
hard_max = format_as_currency(record.applicable_income_range.hard_max)
diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb
index cf0ae009e..b4fa934dc 100644
--- a/app/models/validations/household_validations.rb
+++ b/app/models/validations/household_validations.rb
@@ -201,7 +201,7 @@ module Validations::HouseholdValidations
def validate_layear_and_prevloc(record)
return unless record.layear && record.la && record.prevloc && record.collection_start_year
- if record.la == record.prevloc && record.layear == 1 && record.collection_start_year >= 2023
+ if record.la == record.prevloc && record.layear == 1
record.errors.add :layear, :renewal_just_moved, message: I18n.t("validations.lettings.household.layear.same_la_just_moved_to_area")
record.errors.add :la, :renewal_just_moved, message: I18n.t("validations.lettings.household.la.same_la_just_moved_to_area")
record.errors.add :postcode_full, :renewal_just_moved, message: I18n.t("validations.lettings.household.postcode_full.same_la_just_moved_to_area")
diff --git a/app/models/validations/sales/financial_validations.rb b/app/models/validations/sales/financial_validations.rb
index 91d4c31b7..e5d8232f0 100644
--- a/app/models/validations/sales/financial_validations.rb
+++ b/app/models/validations/sales/financial_validations.rb
@@ -82,7 +82,7 @@ module Validations::Sales::FinancialValidations
def validate_child_income(record)
return unless record.income2 && record.ecstat2
- if record.income2.positive? && is_economic_status_child?(record.ecstat2) && record.form.start_date.year >= 2023
+ if record.income2.positive? && is_economic_status_child?(record.ecstat2)
record.errors.add :ecstat2, I18n.t("validations.sales.financial.ecstat2.child_has_income")
record.errors.add :income2, I18n.t("validations.sales.financial.income2.child_has_income")
end
diff --git a/app/models/validations/sales/household_validations.rb b/app/models/validations/sales/household_validations.rb
index 175474098..e5a66f935 100644
--- a/app/models/validations/sales/household_validations.rb
+++ b/app/models/validations/sales/household_validations.rb
@@ -13,8 +13,6 @@ module Validations::Sales::HouseholdValidations
end
def validate_buyers_living_in_property(record)
- return unless record.form.start_date.year >= 2023
-
if record.buyers_will_live_in? && record.buyer_one_will_not_live_in_property? && record.buyer_two_will_not_live_in_property?
record.errors.add :buylivein, I18n.t("validations.sales.household.buylivein.buyers_will_live_in_property_values_inconsistent")
record.errors.add :buy1livein, I18n.t("validations.sales.household.buy1livein.buyers_will_live_in_property_values_inconsistent")
diff --git a/app/views/bulk_upload_lettings_logs/forms/prepare_your_file_2023.html.erb b/app/views/bulk_upload_lettings_logs/forms/prepare_your_file_2023.html.erb
deleted file mode 100644
index f8549807b..000000000
--- a/app/views/bulk_upload_lettings_logs/forms/prepare_your_file_2023.html.erb
+++ /dev/null
@@ -1,46 +0,0 @@
-<% content_for :before_content do %>
- <%= govuk_back_link href: @form.back_path %>
-<% end %>
-
-
-
- <%= form_with model: @form, scope: :form, url: bulk_upload_lettings_log_path(id: "prepare-your-file"), method: :patch do |f| %>
- <%= f.hidden_field :year %>
-
-
Upload lettings logs in bulk (<%= @form.year_combo %>)
-
Prepare your file
-
<%= govuk_link_to "Read the full guidance", bulk_upload_lettings_log_path(id: "guidance", form: { year: @form.year }, referrer: "prepare-your-file") %> before you start if you have not used bulk upload before.
-
-
Download template
-
-
Use one of these templates to upload logs for 2023/24:
-
- -
- <%= govuk_link_to "Download the new template", @form.template_path %>: In this template, the questions are in the same order as the 2023/24 paper form and web form.
-
-
-
There are 7 or 8 rows of content in the templates. These rows are called the ‘headers’. They contain the CORE form questions and guidance about which questions are required and how to format your answers.
-
-
Create your file
-
-
- - Fill in the template with data from your housing management system. Your data should go below the headers, with one row per log. Leave column A blank - the bulk upload fields start in column B.
- - Make sure each column of your data aligns with the matching headers above. You may need to reorder your data.
- - Use the <%= govuk_link_to "Lettings #{@form.year_combo} Bulk Upload Specification", @form.specification_path %> to check your data is in the correct format.
- - Username field: To assign a log to someone else, enter the email address they use to log into CORE.
- - If you are using the new template, keep the headers. If you are using the legacy template, you can either keep or remove the headers. If you remove the headers, you should also remove the blank column A.
-
-
- <%= govuk_inset_text(text: "You can upload both general needs and supported housing logs in the same file for 2023 to 2024 data.") %>
-
-
Save your file
-
-
- - Save your file as a CSV.
- - Your file should now be ready to upload.
-
-
- <%= f.govuk_submit class: "govuk-!-margin-top-7" %>
- <% end %>
-
-
diff --git a/app/views/bulk_upload_sales_logs/forms/prepare_your_file_2023.html.erb b/app/views/bulk_upload_sales_logs/forms/prepare_your_file_2023.html.erb
deleted file mode 100644
index 427a835e8..000000000
--- a/app/views/bulk_upload_sales_logs/forms/prepare_your_file_2023.html.erb
+++ /dev/null
@@ -1,40 +0,0 @@
-<% content_for :before_content do %>
- <%= govuk_back_link href: @form.back_path %>
-<% end %>
-
-
-
- <%= form_with model: @form, scope: :form, url: bulk_upload_sales_log_path(id: "prepare-your-file"), method: :patch do |f| %>
- <%= f.hidden_field :year %>
-
-
Upload sales logs in bulk (<%= @form.year_combo %>)
-
Prepare your file
-
<%= govuk_link_to "Read the full guidance", bulk_upload_sales_log_path(id: "guidance", form: { year: @form.year }, referrer: "prepare-your-file") %> before you start if you have not used bulk upload before.
-
-
Download template
-
-
Use one of these templates to upload logs for 2023/24:
-
- - <%= govuk_link_to "Download the new template", @form.template_path %>: In this template, the questions are in the same order as the 2023/24 paper form and web form.
-
-
There are 7 or 8 rows of content in the templates. These rows are called the ‘headers’. They contain the CORE form questions and guidance about which questions are required and how to format your answers.
-
-
Create your file
-
- - Fill in the template with data from your housing management system. Your data should go below the headers, with one row per log. The bulk upload fields start at column B. Leave column A blank.
- - Make sure each column of your data aligns with the matching headers above. You may need to reorder your data.
- - Use the <%= govuk_link_to "Sales #{@form.year_combo} Bulk Upload Specification", @form.specification_path %> to check your data is in the correct format.
- - Username field: To assign a log to someone else, enter the email address they use to log into CORE.
- - If you are using the new template, keep the headers. If you are using the legacy template, you can either keep or remove the headers. If you remove the headers, you should also remove the blank column A.
-
-
-
Save your file
-
- - Save your file as a CSV.
- - Your file should now be ready to upload.
-
-
- <%= f.govuk_submit %>
- <% end %>
-
-
diff --git a/app/views/bulk_upload_shared/guidance.html.erb b/app/views/bulk_upload_shared/guidance.html.erb
index 54e8063f0..1463f63b9 100644
--- a/app/views/bulk_upload_shared/guidance.html.erb
+++ b/app/views/bulk_upload_shared/guidance.html.erb
@@ -28,29 +28,14 @@
<%= accordion.with_section(heading_text: "Using the bulk upload template") do %>
For each collection year, we publish a bulk upload template and specification.
- <% if @form.year == 2023 %>
- The bulk upload templates contain 7 or 8 rows of ‘headers’ with information about how to fill in the template, including:
- <% else %>
- The bulk upload templates contain 8 rows of ‘headers’ with information about how to fill in the template, including:
- <% end %>
+ The bulk upload templates contain 8 rows of ‘headers’ with information about how to fill in the template, including:
<%= govuk_list ["the CORE form questions and their field numbers", "each field’s valid responses", "if/when certain fields can be left blank", "which fields are used to check for duplicate logs"], type: :bullet %>
You can paste your data below the headers or copy the headers and insert them above the data in your file. The bulk upload fields start at column B. Leave column A blank.
Make sure that each column of data aligns with the corresponding question in the headers. We recommend ordering your data to match the headers, but you can also reorder the headers to match your data. When processing the file, we check what each column of data represents based on the headers above.
- <% if @form.year == 2023 %>
- For 2023/24 uploads, there are 2 templates to choose from, a new template and a legacy template. They outline suggested ways of ordering your data.
- You must include the headers in your file when you upload, unless your data matches the exact order of the legacy template. If you choose to remove the headers, you must also remove the blank column A.
-
- New template: In this template, the questions are in the same order as the 2023/24 paper form and web form. Use this template if your organisation is new to bulk upload or if your housing management system matches the new column ordering.
- <%= govuk_link_to "Download the lettings bulk upload template (2023 to 2024) – New question ordering", @form.lettings_template_path %>
- <%= govuk_link_to "Download the sales bulk upload template (2023 to 2024) – New question ordering", @form.sales_template_path %>
-
- Legacy template: In this template, the questions are in the same order as the 2022/23 template, with new questions added on to the end. Use this template if you have not updated your system to match the new template yet.
- <% else %>
- <%= govuk_link_to "Download the lettings bulk upload template (2024 to 2025)", @form.lettings_template_path %>
- <%= govuk_link_to "Download the sales bulk upload template (2024 to 2025)", @form.sales_template_path %>
- <% end %>
+ <%= govuk_link_to "Download the lettings bulk upload template (2024 to 2025)", @form.lettings_template_path %>
+ <%= govuk_link_to "Download the sales bulk upload template (2024 to 2025)", @form.sales_template_path %>
<% end %>
<%= accordion.with_section(heading_text: "Using the bulk upload specification") do %>
diff --git a/spec/features/bulk_upload_sales_logs_spec.rb b/spec/features/bulk_upload_sales_logs_spec.rb
index 1ff0d9fb0..1816b6720 100644
--- a/spec/features/bulk_upload_sales_logs_spec.rb
+++ b/spec/features/bulk_upload_sales_logs_spec.rb
@@ -22,7 +22,7 @@ RSpec.describe "Bulk upload sales log" do
# rubocop:disable RSpec/AnyInstance
context "when during crossover period" do
before do
- Timecop.freeze(2023, 5, 1)
+ Timecop.freeze(2024, 5, 1)
end
after do
@@ -38,15 +38,15 @@ RSpec.describe "Bulk upload sales log" do
click_button("Continue")
expect(page).to have_content("You must select a collection period to upload for")
- choose("2023 to 2024")
+ choose("2024 to 2025")
click_button("Continue")
click_link("Back")
- expect(page.find_field("form-year-2023-field")).to be_checked
+ expect(page.find_field("form-year-2024-field")).to be_checked
click_button("Continue")
- expect(page).to have_content("Upload sales logs in bulk (2023 to 2024)")
+ expect(page).to have_content("Upload sales logs in bulk (2024 to 2025)")
click_button("Continue")
expect(page).to have_content("Upload your file")
@@ -80,7 +80,7 @@ RSpec.describe "Bulk upload sales log" do
expect(page).to have_content("Which year")
click_button("Continue")
click_button("Continue")
- choose("2023 to 2024")
+ choose("2024 to 2025")
click_button("Continue")
click_button("Continue")
@@ -96,7 +96,7 @@ RSpec.describe "Bulk upload sales log" do
context "when not in crossover period" do
before do
- Timecop.freeze(2024, 2, 1)
+ Timecop.freeze(2025, 2, 1)
end
after do
@@ -108,7 +108,7 @@ RSpec.describe "Bulk upload sales log" do
expect(page).to have_link("Upload sales logs in bulk")
click_link("Upload sales logs in bulk")
- expect(page).to have_content("Upload sales logs in bulk (2023 to 2024)")
+ expect(page).to have_content("Upload sales logs in bulk (2024 to 2025)")
click_button("Continue")
expect(page).to have_content("Upload your file")
diff --git a/spec/models/sales_log_spec.rb b/spec/models/sales_log_spec.rb
index 20eb0b2a6..3e6d6405d 100644
--- a/spec/models/sales_log_spec.rb
+++ b/spec/models/sales_log_spec.rb
@@ -120,14 +120,6 @@ RSpec.describe SalesLog, type: :model do
allow(Time).to receive(:now).and_return(Time.zone.local(2023, 5, 1))
end
- it "is set to completed for a log with a saledate before 23/24" do
- completed_sales_log.update!(proplen: nil, proplen_asked: 0, saledate: Time.zone.local(2022, 5, 1))
- expect(completed_sales_log.in_progress?).to be(false)
- expect(completed_sales_log.not_started?).to be(false)
- expect(completed_sales_log.completed?).to be(true)
- expect(completed_sales_log.deleted?).to be(false)
- end
-
it "is set to in_progress for a log with a saledate after 23/24" do
completed_sales_log.update!(proplen: nil, proplen_asked: 0, saledate: Time.zone.local(2023, 5, 1))
expect(completed_sales_log.in_progress?).to be(true)
diff --git a/spec/models/validations/financial_validations_spec.rb b/spec/models/validations/financial_validations_spec.rb
index 282e050a2..7151c4c9d 100644
--- a/spec/models/validations/financial_validations_spec.rb
+++ b/spec/models/validations/financial_validations_spec.rb
@@ -338,20 +338,6 @@ RSpec.describe Validations::FinancialValidations do
expect(record.errors["ecstat#{n}"]).to be_empty
end
end
-
- context "when the net income is lower than the hard min for their employment status for 22/23 collection" do
- it "does not add an error" do
- record.startdate = Time.zone.local(2022, 5, 1)
- record.earnings = 50
- record.incfreq = 1
- record.hhmemb = 1
- record.ecstat1 = 1
- financial_validator.validate_net_income(record)
- expect(record.errors["earnings"]).to be_empty
- expect(record.errors["ecstat1"]).to be_empty
- expect(record.errors["hhmemb"]).to be_empty
- end
- end
end
end
diff --git a/spec/requests/bulk_upload_lettings_logs_controller_spec.rb b/spec/requests/bulk_upload_lettings_logs_controller_spec.rb
index c9a22768d..abdea7079 100644
--- a/spec/requests/bulk_upload_lettings_logs_controller_spec.rb
+++ b/spec/requests/bulk_upload_lettings_logs_controller_spec.rb
@@ -112,6 +112,7 @@ RSpec.describe BulkUploadLettingsLogsController, type: :request do
context "when requesting the previous year in a crossover period" do
before do
+ allow(Time.zone).to receive(:now).and_return(Time.zone.now + 1.year)
allow(FormHandler.instance).to receive(:lettings_in_crossover_period?).and_return(true)
end
diff --git a/spec/requests/bulk_upload_sales_logs_controller_spec.rb b/spec/requests/bulk_upload_sales_logs_controller_spec.rb
index 4c20482be..a2d6e7ef4 100644
--- a/spec/requests/bulk_upload_sales_logs_controller_spec.rb
+++ b/spec/requests/bulk_upload_sales_logs_controller_spec.rb
@@ -112,6 +112,7 @@ RSpec.describe BulkUploadSalesLogsController, type: :request do
context "when requesting the previous year in a crossover period" do
before do
+ allow(Time.zone).to receive(:now).and_return(Time.zone.now + 1.year)
allow(FormHandler.instance).to receive(:sales_in_crossover_period?).and_return(true)
end
From 19c5deb1d31ebef0f6394667d530113ae95e939c Mon Sep 17 00:00:00 2001
From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>
Date: Tue, 14 Jan 2025 09:02:57 +0000
Subject: [PATCH 14/17] CLDC-3817 Only run net income validations when
applicable_income_range exists (#2882)
* Only run net income validations when applicable_income_range exists
* Check that income ranges exist
---
app/models/lettings_log.rb | 2 +-
app/models/sales_log.rb | 4 ++--
app/models/validations/soft_validations.rb | 4 ++--
.../bulk_upload/lettings/year2024/row_parser_spec.rb | 9 +++++++++
4 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb
index 3ec0d6bf7..c8505b310 100644
--- a/app/models/lettings_log.rb
+++ b/app/models/lettings_log.rb
@@ -240,7 +240,7 @@ class LettingsLog < Log
end
def applicable_income_range
- return unless ecstat1 && hhmemb
+ return unless ecstat1 && hhmemb && ALLOWED_INCOME_RANGES[ecstat1]
range = ALLOWED_INCOME_RANGES[ecstat1].clone
diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb
index f7604b11e..49ba9f81c 100644
--- a/app/models/sales_log.rb
+++ b/app/models/sales_log.rb
@@ -419,9 +419,9 @@ class SalesLog < Log
def income_soft_min_for_ecstat(ecstat_field)
economic_status_code = public_send(ecstat_field)
- return unless ALLOWED_INCOME_RANGES_SALES
+ return unless ALLOWED_INCOME_RANGES_SALES && ALLOWED_INCOME_RANGES_SALES[economic_status_code]
- soft_min = ALLOWED_INCOME_RANGES_SALES[economic_status_code]&.soft_min
+ soft_min = ALLOWED_INCOME_RANGES_SALES[economic_status_code].soft_min
format_as_currency(soft_min)
end
diff --git a/app/models/validations/soft_validations.rb b/app/models/validations/soft_validations.rb
index 1a2c61138..9dc8828e8 100644
--- a/app/models/validations/soft_validations.rb
+++ b/app/models/validations/soft_validations.rb
@@ -16,13 +16,13 @@ module Validations::SoftValidations
}.freeze
def net_income_in_soft_max_range?
- return unless weekly_net_income && ecstat1 && hhmemb
+ return unless weekly_net_income && ecstat1 && hhmemb && applicable_income_range
weekly_net_income.between?(applicable_income_range.soft_max, applicable_income_range.hard_max)
end
def net_income_in_soft_min_range?
- return unless weekly_net_income && ecstat1 && hhmemb
+ return unless weekly_net_income && ecstat1 && hhmemb && applicable_income_range
weekly_net_income.between?(applicable_income_range.hard_min, applicable_income_range.soft_min)
end
diff --git a/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb
index 357d661b7..01529a80b 100644
--- a/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb
+++ b/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb
@@ -1915,6 +1915,15 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
expect(parser.errors.where(:field_125, category: :soft_validation).first.message).to eql("You told us the rent is £120.00 every week. This is higher than we would expect.")
end
end
+
+ context "when an invalid ecstat1 is given" do
+ let(:attributes) { setup_section_params.merge({ field_46: 11, field_119: 123, field_118: 1 }) }
+
+ it "does not run net income soft validations validation" do
+ parser.valid?
+ expect(parser.errors.where(:field_46).count).to be(1)
+ end
+ end
end
describe "log_already_exists?" do
From 02a77e0889511790a21d73e8d0ac698f2336b697 Mon Sep 17 00:00:00 2001
From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com>
Date: Tue, 14 Jan 2025 15:04:41 +0000
Subject: [PATCH 15/17] CLDC-3835: Export merged organisations as inactive
(#2896)
* Export active to CDS as false for merged orgs
* Export status to CDS for orgs
---
.../exports/organisation_export_constants.rb | 3 ++-
.../exports/organisation_export_service.rb | 2 ++
spec/fixtures/exports/organisation.xml | 1 +
.../organisation_export_service_spec.rb | 21 +++++++++++++++++++
4 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/app/services/exports/organisation_export_constants.rb b/app/services/exports/organisation_export_constants.rb
index 3a1c5fb48..6c78a55db 100644
--- a/app/services/exports/organisation_export_constants.rb
+++ b/app/services/exports/organisation_export_constants.rb
@@ -22,6 +22,7 @@ module Exports::OrganisationExportConstants
"dsa_signed_at",
"dpo_email",
"profit_status",
- "group"
+ "group",
+ "status"
]
end
diff --git a/app/services/exports/organisation_export_service.rb b/app/services/exports/organisation_export_service.rb
index afcf16cb0..8ceba93a9 100644
--- a/app/services/exports/organisation_export_service.rb
+++ b/app/services/exports/organisation_export_service.rb
@@ -65,6 +65,8 @@ module Exports
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
+ attribute_hash["status"] = organisation.status
+ attribute_hash["active"] = attribute_hash["status"] == :active
attribute_hash
end
diff --git a/spec/fixtures/exports/organisation.xml b/spec/fixtures/exports/organisation.xml
index 70c699915..f70ac2b7d 100644
--- a/spec/fixtures/exports/organisation.xml
+++ b/spec/fixtures/exports/organisation.xml
@@ -22,5 +22,6 @@
{dpo_email}
+ active
diff --git a/spec/services/exports/organisation_export_service_spec.rb b/spec/services/exports/organisation_export_service_spec.rb
index 199ee239e..6ef66161a 100644
--- a/spec/services/exports/organisation_export_service_spec.rb
+++ b/spec/services/exports/organisation_export_service_spec.rb
@@ -84,6 +84,27 @@ RSpec.describe Exports::OrganisationExportService do
it "returns the list with correct archive" do
expect(export_service.export_xml_organisations).to eq({ expected_zip_filename.gsub(".zip", "") => start_time })
end
+
+ context "and the organisation is merged" do
+ let(:expected_content) { replace_entity_ids(organisation, xml_export_file.read) }
+
+ before do
+ organisation.update!(merge_date: Time.zone.yesterday)
+ expected_content.sub!("true", "false")
+ expected_content.sub!("", "#{organisation.merge_date.iso8601}")
+ expected_content.sub!("active", "merged")
+ end
+
+ it "generates an XML export file with the expected content within the ZIP file" do
+ expect(storage_service).to receive(:write_file).with(expected_zip_filename, any_args) do |_, content|
+ entry = Zip::File.open_buffer(content).find_entry(expected_data_filename)
+ expect(entry).not_to be_nil
+ expect(entry.get_input_stream.read).to eq(expected_content)
+ end
+
+ export_service.export_xml_organisations
+ end
+ end
end
context "and multiple organisations are available for export" do
From d8fa3cf7fe65d552fe57ccccdd5fbae55dd6996f Mon Sep 17 00:00:00 2001
From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>
Date: Wed, 15 Jan 2025 13:06:46 +0000
Subject: [PATCH 16/17] CLDC-3816 Update rails admin styling (#2879)
* Update rails admin console layout
* Update dashboard and view tables
* lint
* More lint
* Inline actions
* Re-add filters
* Update buttons
* Update validation documentation generating (#2894)
* Update documentation generator to use relevant translation files
* Add and use collection_year instead of from/to in log validations
---
app/frontend/styles/_custom-rails-admin.scss | 34 ++++
app/frontend/styles/application.scss | 1 +
app/services/documentation_generator.rb | 58 +++---
.../layouts/rails_admin/_navigation.html.erb | 9 +
.../layouts/rails_admin/application.html.erb | 70 +++++++
.../rails_admin/main/_submit_buttons.html.erb | 25 +++
app/views/rails_admin/main/dashboard.html.erb | 68 +++++++
app/views/rails_admin/main/delete.html.erb | 21 ++
app/views/rails_admin/main/index.html.erb | 187 ++++++++++++++++++
config/initializers/assets.rb | 2 +
.../{financial.yml => financial.en.yml} | 0
.../20250110150609_add_collection_year.rb | 5 +
db/schema.rb | 3 +-
.../generate_lettings_documentation.rake | 1 +
.../set_log_validation_collection_year.rake | 6 +
...set_log_validation_collection_year_spec.rb | 29 +++
spec/services/documentation_generator_spec.rb | 12 +-
17 files changed, 498 insertions(+), 33 deletions(-)
create mode 100644 app/frontend/styles/_custom-rails-admin.scss
create mode 100644 app/views/layouts/rails_admin/_navigation.html.erb
create mode 100644 app/views/layouts/rails_admin/application.html.erb
create mode 100644 app/views/rails_admin/main/_submit_buttons.html.erb
create mode 100644 app/views/rails_admin/main/dashboard.html.erb
create mode 100644 app/views/rails_admin/main/delete.html.erb
create mode 100644 app/views/rails_admin/main/index.html.erb
rename config/locales/validations/lettings/{financial.yml => financial.en.yml} (100%)
create mode 100644 db/migrate/20250110150609_add_collection_year.rb
create mode 100644 lib/tasks/set_log_validation_collection_year.rake
create mode 100644 spec/lib/tasks/set_log_validation_collection_year_spec.rb
diff --git a/app/frontend/styles/_custom-rails-admin.scss b/app/frontend/styles/_custom-rails-admin.scss
new file mode 100644
index 000000000..2652b8480
--- /dev/null
+++ b/app/frontend/styles/_custom-rails-admin.scss
@@ -0,0 +1,34 @@
+.rails-admin-sidescroll {
+ overflow-x: scroll;
+}
+
+.rails-admin-description_field {
+ min-width: 500px;
+}
+
+.rails-admin-case_field {
+ min-width: 500px;
+}
+
+.rails-admin-error_message_field {
+ min-width: 500px;
+}
+
+.rails-admin-actions {
+ min-width: 160px;
+
+ ul {
+ float: right;
+ }
+}
+
+.rails-admin-filters-box {
+ .filter {
+ // stylelint-disable-next-line declaration-no-important
+ display: flex !important;
+ }
+
+ button {
+ min-width: 20%;
+ }
+}
diff --git a/app/frontend/styles/application.scss b/app/frontend/styles/application.scss
index 3e75107bd..94135074e 100644
--- a/app/frontend/styles/application.scss
+++ b/app/frontend/styles/application.scss
@@ -48,6 +48,7 @@ $govuk-breakpoints: (
@import "search";
@import "sub-navigation";
@import "unread-notification";
+@import "custom-rails-admin";
// App utilities
.app-\!-colour-muted {
diff --git a/app/services/documentation_generator.rb b/app/services/documentation_generator.rb
index d77a4e093..43426d8d4 100644
--- a/app/services/documentation_generator.rb
+++ b/app/services/documentation_generator.rb
@@ -18,14 +18,16 @@ class DocumentationGenerator
next
end
- validation_source = method(meth).source
+ validation = method(meth)
+ validation_source = validation.source
+ file_path = validation.source_location[0]
helper_methods_source = all_helper_methods.map { |helper_method|
if validation_source.include?(helper_method.to_s)
method(helper_method).source
end
}.compact.join("\n")
- response = describe_hard_validation(client, meth, validation_source, helper_methods_source, form)
+ response = describe_hard_validation(client, meth, validation_source, helper_methods_source, form, file_path)
next unless response
begin
@@ -41,19 +43,19 @@ class DocumentationGenerator
def describe_bu_validations(client, form, row_parser_class, all_validation_methods, all_helper_methods, field_mapping_for_errors, log_type)
all_validation_methods.each do |meth|
- if LogValidation.where(validation_name: meth.to_s, bulk_upload_specific: true, from: form.start_date, log_type:).exists?
+ if LogValidation.where(validation_name: meth.to_s, bulk_upload_specific: true, collection_year: "#{form.start_date.year}/#{form.start_date.year + 1}", log_type:).exists?
Rails.logger.info("Validation #{meth} already exists for #{form.start_date.year}")
next
end
-
- validation_source = row_parser_class.instance_method(meth).source
+ validation = row_parser_class.instance_method(meth)
+ validation_source = validation.source
helper_methods_source = all_helper_methods.map { |helper_method|
if validation_source.include?(helper_method.to_s)
row_parser_class.instance_method(helper_method).source
end
}.compact.join("\n")
- response = describe_hard_validation(client, meth, validation_source, helper_methods_source, form)
+ response = describe_hard_validation(client, meth, validation_source, helper_methods_source, form, validation.source_location[0])
next unless response
begin
@@ -69,7 +71,7 @@ class DocumentationGenerator
def describe_soft_validations(client, all_validation_methods, all_helper_methods, log_type)
validation_descriptions = {}
- all_validation_methods.each do |meth|
+ all_validation_methods[0..5].each do |meth|
validation_source = method(meth).source
helper_methods_source = all_helper_methods.map { |helper_method|
if validation_source.include?(helper_method.to_s)
@@ -101,8 +103,8 @@ class DocumentationGenerator
private
- def describe_hard_validation(client, meth, validation_source, helper_methods_source, form)
- en_yml = File.read("./config/locales/en.yml")
+ def describe_hard_validation(client, meth, validation_source, helper_methods_source, form, file_path)
+ en_yml = File.read(translation_file_path(form, file_path))
begin
client.chat(
@@ -166,14 +168,6 @@ private
required: %w[error_message field],
},
},
- from: {
- type: :number,
- description: "the year from which the validation starts. If this validation runs for logs with a startdate after a certain year, specify that year here, only if it is not specified in the validation method, leave this field blank",
- },
- to: {
- type: :number,
- description: "the year in which the validation ends. If this validation runs for logs with a startdate before a certain year, specify that year here, only if it is not specified in the validation method, leave this field blank",
- },
validation_type: {
type: :string,
enum: %w[presence format minimum maximum range inclusion length other],
@@ -271,8 +265,7 @@ Look at these helper methods where needed to understand what is being checked in
error_message: error["error_message"],
case: case_info["case_description"],
section: form.get_question(error["field"], nil)&.subsection&.id,
- from: case_info["from"] || "",
- to: case_info["to"] || "",
+ collection_year: "#{form.start_date.year}/#{form.start_date.year + 1}",
validation_type: case_info["validation_type"],
hard_soft: "hard",
other_validated_models: case_info["other_validated_models"])
@@ -295,8 +288,7 @@ Look at these helper methods where needed to understand what is being checked in
error_message: error["error_message"],
case: case_info["case_description"],
section: form.get_question(error_field, nil)&.subsection&.id,
- from: form.start_date,
- to: form.start_date + 1.year,
+ collection_year: "#{form.start_date.year}/#{form.start_date.year + 1}",
validation_type: case_info["validation_type"],
hard_soft: "hard",
other_validated_models: case_info["other_validated_models"],
@@ -333,7 +325,7 @@ Look at these helper methods where needed to understand what is being checked in
return
end
- if LogValidation.where(validation_name: validation_depends_on_hash.keys.first, field: page_the_validation_applied_to.questions.first.id, from: form.start_date, log_type:).exists?
+ if LogValidation.where(validation_name: validation_depends_on_hash.keys.first, field: page_the_validation_applied_to.questions.first.id, collection_year: "#{form.start_date.year}/#{form.start_date.year + 1}", log_type:).exists?
Rails.logger.info("Validation #{validation_depends_on_hash.keys.first} already exists for #{page_the_validation_applied_to.questions.first.id} for start year #{form.start_date.year}")
return
end
@@ -360,12 +352,30 @@ Look at these helper methods where needed to understand what is being checked in
error_message:,
case: case_info,
section: form.get_question(page_the_validation_applied_to.questions.first.id, nil)&.subsection&.id,
- from: form.start_date,
- to: form.start_date + 1.year,
+ collection_year: "#{form.start_date.year}/#{form.start_date.year + 1}",
validation_type: result["validation_type"],
hard_soft: "soft",
other_validated_models: result["other_validated_models"])
Rails.logger.info("******** described #{validation_depends_on_hash.keys.first} for #{page_the_validation_applied_to.questions.first.id} ********")
end
+
+ TRANSLATION_FILE_MAPPINGS = {
+ "property" => "property_information",
+ }.freeze
+
+ def translation_file_path(form, file_path)
+ return "./config/locales/validations/#{form.type}/#{form.start_date.year}/bulk_upload.en.yml" if file_path.include?("bulk_upload")
+
+ file_name = file_path.split("/").last.gsub("_validations.rb", "")
+ translation_file_name = TRANSLATION_FILE_MAPPINGS[file_name] || file_name
+
+ file_path = "./config/locales/validations/#{form.type}/#{translation_file_name}.en.yml"
+ return file_path if File.exist?(file_path)
+
+ shared_file_path = "./config/locales/validations/#{translation_file_name}.en.yml"
+ return shared_file_path if File.exist?(shared_file_path)
+
+ "./config/locales/en.yml"
+ end
end
diff --git a/app/views/layouts/rails_admin/_navigation.html.erb b/app/views/layouts/rails_admin/_navigation.html.erb
new file mode 100644
index 000000000..6c5f77aa3
--- /dev/null
+++ b/app/views/layouts/rails_admin/_navigation.html.erb
@@ -0,0 +1,9 @@
+<%= govuk_header(
+ classes: "app-header app-header--orange",
+ homepage_url: Rails.application.routes.url_helpers.root_path,
+ navigation_classes: "govuk-header__navigation--end",
+ ) do |component|
+ component.with_product_name(name: t("service_name"))
+ component.with_navigation_item(text: "Your account", href: Rails.application.routes.url_helpers.account_path)
+ component.with_navigation_item(text: "Sign out", href: Rails.application.routes.url_helpers.destroy_user_session_path)
+ end %>
diff --git a/app/views/layouts/rails_admin/application.html.erb b/app/views/layouts/rails_admin/application.html.erb
new file mode 100644
index 000000000..27dc747fd
--- /dev/null
+++ b/app/views/layouts/rails_admin/application.html.erb
@@ -0,0 +1,70 @@
+