diff --git a/app/controllers/bulk_upload_lettings_resume_controller.rb b/app/controllers/bulk_upload_lettings_resume_controller.rb index 9ddffa27f..a4bd291a9 100644 --- a/app/controllers/bulk_upload_lettings_resume_controller.rb +++ b/app/controllers/bulk_upload_lettings_resume_controller.rb @@ -26,7 +26,7 @@ class BulkUploadLettingsResumeController < ApplicationController private def form - @form ||= Forms::BulkUploadLettingsResume::FixChoice.new(form_params) + @form ||= Forms::BulkUploadLettingsResume::FixChoice.new(form_params.merge(bulk_upload: @bulk_upload)) end def form_params diff --git a/app/models/forms/bulk_upload_lettings_resume/fix_choice.rb b/app/models/forms/bulk_upload_lettings_resume/fix_choice.rb index 4362327d9..df6d1d44e 100644 --- a/app/models/forms/bulk_upload_lettings_resume/fix_choice.rb +++ b/app/models/forms/bulk_upload_lettings_resume/fix_choice.rb @@ -5,6 +5,7 @@ module Forms include ActiveModel::Attributes include Rails.application.routes.url_helpers + attribute :bulk_upload attribute :choice, :string validates :choice, presence: true, @@ -20,6 +21,19 @@ module Forms def view_path "bulk_upload_lettings_resume/fix_choice" end + + def next_path + case choice + when "upload-again" + if BulkUploadErrorSummaryTableComponent.new(bulk_upload:).errors? + summary_bulk_upload_lettings_result_path(bulk_upload) + else + bulk_upload_lettings_result_path(bulk_upload) + end + else + raise "invalid choice" + end + end end end end diff --git a/spec/requests/bulk_upload_lettings_resume_controller_spec.rb b/spec/requests/bulk_upload_lettings_resume_controller_spec.rb index d5109dccf..be808fab5 100644 --- a/spec/requests/bulk_upload_lettings_resume_controller_spec.rb +++ b/spec/requests/bulk_upload_lettings_resume_controller_spec.rb @@ -40,5 +40,13 @@ RSpec.describe BulkUploadLettingsResumeController, type: :request do expect(response.body).to include("You must select") end end + + context "when upload again selected" do + it "sends them to relevant report" do + patch "/lettings-logs/bulk-upload-resume/#{bulk_upload.id}/fix-choice", params: { form: { choice: "upload-again" } } + + expect(response).to redirect_to("/lettings-logs/bulk-upload-results/#{bulk_upload.id}") + end + end end end