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