Browse Source

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
main
kosiakkatrina 4 days ago committed by GitHub
parent
commit
a437670874
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 10
      app/controllers/bulk_upload_lettings_logs_controller.rb
  2. 8
      app/controllers/bulk_upload_lettings_resume_controller.rb
  3. 6
      app/controllers/bulk_upload_lettings_soft_validations_check_controller.rb
  4. 10
      app/controllers/bulk_upload_sales_logs_controller.rb
  5. 8
      app/controllers/bulk_upload_sales_resume_controller.rb
  6. 6
      app/controllers/bulk_upload_sales_soft_validations_check_controller.rb
  7. 9
      app/models/forms/bulk_upload_form/checking_file.rb
  8. 13
      app/models/forms/bulk_upload_form/guidance.rb
  9. 21
      app/models/forms/bulk_upload_form/prepare_your_file.rb
  10. 13
      app/models/forms/bulk_upload_form/upload_your_file.rb
  11. 17
      app/models/forms/bulk_upload_form/year.rb
  12. 60
      app/models/forms/bulk_upload_lettings/prepare_your_file.rb
  13. 55
      app/models/forms/bulk_upload_lettings_resume/confirm.rb
  14. 28
      app/models/forms/bulk_upload_lettings_resume/deletion_report.rb
  15. 74
      app/models/forms/bulk_upload_lettings_resume/fix_choice.rb
  16. 31
      app/models/forms/bulk_upload_lettings_soft_validations_check/chosen.rb
  17. 9
      app/models/forms/bulk_upload_resume/chosen.rb
  18. 17
      app/models/forms/bulk_upload_resume/confirm.rb
  19. 9
      app/models/forms/bulk_upload_resume/deletion_report.rb
  20. 17
      app/models/forms/bulk_upload_resume/fix_choice.rb
  21. 32
      app/models/forms/bulk_upload_sales/checking_file.rb
  22. 51
      app/models/forms/bulk_upload_sales/guidance.rb
  23. 83
      app/models/forms/bulk_upload_sales/upload_your_file.rb
  24. 50
      app/models/forms/bulk_upload_sales/year.rb
  25. 31
      app/models/forms/bulk_upload_sales_soft_validations_check/chosen.rb
  26. 47
      app/models/forms/bulk_upload_sales_soft_validations_check/confirm.rb
  27. 53
      app/models/forms/bulk_upload_sales_soft_validations_check/confirm_soft_errors.rb
  28. 9
      app/models/forms/bulk_upload_soft_validations_check/chosen.rb
  29. 13
      app/models/forms/bulk_upload_soft_validations_check/confirm.rb
  30. 13
      app/models/forms/bulk_upload_soft_validations_check/confirm_soft_errors.rb
  31. 2
      app/views/bulk_upload_lettings_results/show.html.erb
  32. 2
      app/views/bulk_upload_lettings_results/summary.html.erb
  33. 2
      app/views/bulk_upload_sales_results/show.html.erb
  34. 2
      app/views/bulk_upload_sales_results/summary.html.erb
  35. 29
      config/locales/en.yml
  36. 8
      spec/features/bulk_upload_lettings_logs_spec.rb
  37. 8
      spec/features/bulk_upload_sales_logs_spec.rb
  38. 117
      spec/models/forms/bulk_upload_form/guidance_spec.rb
  39. 100
      spec/models/forms/bulk_upload_form/upload_your_file_spec.rb
  40. 101
      spec/models/forms/bulk_upload_form/year_spec.rb
  41. 60
      spec/models/forms/bulk_upload_lettings/guidance_spec.rb
  42. 61
      spec/models/forms/bulk_upload_lettings/upload_your_file_spec.rb
  43. 47
      spec/models/forms/bulk_upload_lettings/year_spec.rb
  44. 60
      spec/models/forms/bulk_upload_sales/guidance_spec.rb
  45. 59
      spec/models/forms/bulk_upload_sales/upload_your_file_spec.rb
  46. 51
      spec/models/forms/bulk_upload_sales/year_spec.rb

10
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

8
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

6
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

10
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

8
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

6
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

9
app/models/forms/bulk_upload_lettings/checking_file.rb → 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

13
app/models/forms/bulk_upload_lettings/guidance.rb → 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

21
app/models/forms/bulk_upload_sales/prepare_your_file.rb → 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

13
app/models/forms/bulk_upload_lettings/upload_your_file.rb → 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,
)

17
app/models/forms/bulk_upload_lettings/year.rb → 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

60
app/models/forms/bulk_upload_lettings/prepare_your_file.rb

@ -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

55
app/models/forms/bulk_upload_lettings_resume/confirm.rb

@ -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

28
app/models/forms/bulk_upload_lettings_resume/deletion_report.rb

@ -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

74
app/models/forms/bulk_upload_lettings_resume/fix_choice.rb

@ -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

31
app/models/forms/bulk_upload_lettings_soft_validations_check/chosen.rb

@ -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

9
app/models/forms/bulk_upload_lettings_resume/chosen.rb → 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!

17
app/models/forms/bulk_upload_sales_resume/confirm.rb → 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

9
app/models/forms/bulk_upload_sales_resume/deletion_report.rb → 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

17
app/models/forms/bulk_upload_sales_resume/fix_choice.rb → 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

32
app/models/forms/bulk_upload_sales/checking_file.rb

@ -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

51
app/models/forms/bulk_upload_sales/guidance.rb

@ -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

83
app/models/forms/bulk_upload_sales/upload_your_file.rb

@ -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

50
app/models/forms/bulk_upload_sales/year.rb

@ -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

31
app/models/forms/bulk_upload_sales_soft_validations_check/chosen.rb

@ -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

47
app/models/forms/bulk_upload_sales_soft_validations_check/confirm.rb

@ -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

53
app/models/forms/bulk_upload_sales_soft_validations_check/confirm_soft_errors.rb

@ -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

9
app/models/forms/bulk_upload_sales_resume/chosen.rb → 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!

13
app/models/forms/bulk_upload_lettings_soft_validations_check/confirm.rb → 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

13
app/models/forms/bulk_upload_lettings_soft_validations_check/confirm_soft_errors.rb → 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

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

@ -10,7 +10,7 @@
<h1 class="govuk-heading-l">We found <%= pluralize(@bulk_upload.bulk_upload_errors.count, "error") %> in your file</h1>
<div class="govuk-body">
Here’s a list of everything that you need to fix your spreadsheet. You can download the <%= govuk_link_to "specification", Forms::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.
</div>
<p class="govuk-!-font-size-19 govuk-!-margin-bottom-2"><strong>File name: </strong><%= @bulk_upload.filename %></p>

2
app/views/bulk_upload_lettings_results/summary.html.erb

@ -6,7 +6,7 @@
<h1 class="govuk-heading-l">Fix <%= pluralize(@bulk_upload.bulk_upload_errors.count, "error") %> and upload file again</h1>
<p class="govuk-body">
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.
</p>
<p class="govuk-!-font-size-19 govuk-!-margin-bottom-2"><strong>File name: </strong><%= @bulk_upload.filename %></p>

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

@ -10,7 +10,7 @@
<h1 class="govuk-heading-l">We found <%= pluralize(@bulk_upload.bulk_upload_errors.count, "error") %> in your file</h1>
<div class="govuk-body">
Here’s a list of everything that you need to fix your spreadsheet. You can download the <%= govuk_link_to "specification", Forms::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.
</div>
<p class="govuk-!-font-size-19 govuk-!-margin-bottom-2"><strong>File name: </strong><%= @bulk_upload.filename %></p>

2
app/views/bulk_upload_sales_results/summary.html.erb

@ -6,7 +6,7 @@
<h1 class="govuk-heading-l">Fix <%= pluralize(@bulk_upload.bulk_upload_errors.count, "error") %> and upload file again</h1>
<p class="govuk-body">
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.
</p>
<p class="govuk-!-font-size-19 govuk-!-margin-bottom-2"><strong>File name: </strong><%= @bulk_upload.filename %></p>

29
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."

8
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")

8
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")

117
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

100
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

101
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

60
spec/models/forms/bulk_upload_lettings/guidance_spec.rb

@ -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

61
spec/models/forms/bulk_upload_lettings/upload_your_file_spec.rb

@ -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

47
spec/models/forms/bulk_upload_lettings/year_spec.rb

@ -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

60
spec/models/forms/bulk_upload_sales/guidance_spec.rb

@ -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

59
spec/models/forms/bulk_upload_sales/upload_your_file_spec.rb

@ -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

51
spec/models/forms/bulk_upload_sales/year_spec.rb

@ -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
Loading…
Cancel
Save