diff --git a/app/controllers/bulk_upload_lettings_resume_controller.rb b/app/controllers/bulk_upload_lettings_resume_controller.rb index 7041051ba..132ca095b 100644 --- a/app/controllers/bulk_upload_lettings_resume_controller.rb +++ b/app/controllers/bulk_upload_lettings_resume_controller.rb @@ -1,5 +1,10 @@ class BulkUploadLettingsResumeController < ApplicationController before_action :authenticate_user! + before_action :set_no_cache_headers + + def set_no_cache_headers + response.set_header("Cache-Control", "no-store") + end def start @bulk_upload = current_user.bulk_uploads.find(params[:id]) @@ -11,6 +16,8 @@ class BulkUploadLettingsResumeController < ApplicationController @bulk_upload = current_user.bulk_uploads.find(params[:id]) @soft_errors_only = params[:soft_errors_only] == "true" + return redirect_to form.preflight_redirect unless form.preflight_valid? + render form.view_path end @@ -30,6 +37,8 @@ private @form ||= case params[:page] when "fix-choice" Forms::BulkUploadLettingsResume::FixChoice.new(form_params.merge(bulk_upload: @bulk_upload)) + when "chosen" + Forms::BulkUploadLettingsResume::Chosen.new(form_params.merge(bulk_upload: @bulk_upload)) when "confirm" Forms::BulkUploadLettingsResume::Confirm.new(form_params.merge(bulk_upload: @bulk_upload)) else 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 5f9140452..a70af3c4b 100644 --- a/app/controllers/bulk_upload_lettings_soft_validations_check_controller.rb +++ b/app/controllers/bulk_upload_lettings_soft_validations_check_controller.rb @@ -2,10 +2,17 @@ class BulkUploadLettingsSoftValidationsCheckController < ApplicationController include ActionView::Helpers::TextHelper before_action :authenticate_user! + before_action :set_no_cache_headers + + def set_no_cache_headers + response.set_header("Cache-Control", "no-store") + end def show @bulk_upload = current_user.bulk_uploads.find(params[:id]) + return redirect_to form.preflight_redirect unless form.preflight_valid? + render form.view_path end @@ -30,6 +37,8 @@ private @form ||= case params[:page] when "confirm-soft-errors" Forms::BulkUploadLettingsSoftValidationsCheck::ConfirmSoftErrors.new(form_params.merge(bulk_upload: @bulk_upload)) + when "chosen" + Forms::BulkUploadLettingsSoftValidationsCheck::Chosen.new(form_params.merge(bulk_upload: @bulk_upload)) when "confirm" Forms::BulkUploadLettingsSoftValidationsCheck::Confirm.new(form_params.merge(bulk_upload: @bulk_upload)) else diff --git a/app/controllers/bulk_upload_sales_resume_controller.rb b/app/controllers/bulk_upload_sales_resume_controller.rb index e120620a2..9f937630d 100644 --- a/app/controllers/bulk_upload_sales_resume_controller.rb +++ b/app/controllers/bulk_upload_sales_resume_controller.rb @@ -1,5 +1,10 @@ class BulkUploadSalesResumeController < ApplicationController before_action :authenticate_user! + before_action :set_no_cache_headers + + def set_no_cache_headers + response.set_header("Cache-Control", "no-store") + end def start @bulk_upload = current_user.bulk_uploads.find(params[:id]) @@ -11,6 +16,8 @@ class BulkUploadSalesResumeController < ApplicationController @bulk_upload = current_user.bulk_uploads.find(params[:id]) @soft_errors_only = params[:soft_errors_only] == "true" + return redirect_to form.preflight_redirect unless form.preflight_valid? + render form.view_path end @@ -30,6 +37,8 @@ private @form ||= case params[:page] when "fix-choice" Forms::BulkUploadSalesResume::FixChoice.new(form_params.merge(bulk_upload: @bulk_upload)) + when "chosen" + Forms::BulkUploadSalesResume::Chosen.new(form_params.merge(bulk_upload: @bulk_upload)) when "confirm" Forms::BulkUploadSalesResume::Confirm.new(form_params.merge(bulk_upload: @bulk_upload)) else 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 6daf167f8..5b71b2c40 100644 --- a/app/controllers/bulk_upload_sales_soft_validations_check_controller.rb +++ b/app/controllers/bulk_upload_sales_soft_validations_check_controller.rb @@ -2,10 +2,17 @@ class BulkUploadSalesSoftValidationsCheckController < ApplicationController include ActionView::Helpers::TextHelper before_action :authenticate_user! + before_action :set_no_cache_headers + + def set_no_cache_headers + response.set_header("Cache-Control", "no-store") + end def show @bulk_upload = current_user.bulk_uploads.find(params[:id]) + return redirect_to form.preflight_redirect unless form.preflight_valid? + render form.view_path end @@ -30,6 +37,8 @@ private @form ||= case params[:page] when "confirm-soft-errors" Forms::BulkUploadSalesSoftValidationsCheck::ConfirmSoftErrors.new(form_params.merge(bulk_upload: @bulk_upload)) + when "chosen" + Forms::BulkUploadSalesSoftValidationsCheck::Chosen.new(form_params.merge(bulk_upload: @bulk_upload)) when "confirm" Forms::BulkUploadSalesSoftValidationsCheck::Confirm.new(form_params.merge(bulk_upload: @bulk_upload)) else diff --git a/app/models/forms/bulk_upload_lettings_resume/chosen.rb b/app/models/forms/bulk_upload_lettings_resume/chosen.rb new file mode 100644 index 000000000..6a6f670c4 --- /dev/null +++ b/app/models/forms/bulk_upload_lettings_resume/chosen.rb @@ -0,0 +1,31 @@ +module Forms + module BulkUploadLettingsResume + class Chosen + include ActiveModel::Model + include ActiveModel::Attributes + include Rails.application.routes.url_helpers + + attribute :bulk_upload + + def view_path + "bulk_upload_lettings_resume/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/confirm.rb b/app/models/forms/bulk_upload_lettings_resume/confirm.rb index 7760ab2e8..c109cd1b1 100644 --- a/app/models/forms/bulk_upload_lettings_resume/confirm.rb +++ b/app/models/forms/bulk_upload_lettings_resume/confirm.rb @@ -20,11 +20,28 @@ module Forms end def save! - processor = BulkUpload::Processor.new(bulk_upload:) - processor.approve + 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/fix_choice.rb b/app/models/forms/bulk_upload_lettings_resume/fix_choice.rb index 5513434de..76ee10d17 100644 --- a/app/models/forms/bulk_upload_lettings_resume/fix_choice.rb +++ b/app/models/forms/bulk_upload_lettings_resume/fix_choice.rb @@ -46,8 +46,23 @@ module Forms end def save! + bulk_upload.update!(choice:) if choice == "upload-again" + 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_soft_validations_check/chosen.rb b/app/models/forms/bulk_upload_lettings_soft_validations_check/chosen.rb new file mode 100644 index 000000000..b3091bc51 --- /dev/null +++ b/app/models/forms/bulk_upload_lettings_soft_validations_check/chosen.rb @@ -0,0 +1,31 @@ +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_soft_validations_check/confirm.rb b/app/models/forms/bulk_upload_lettings_soft_validations_check/confirm.rb index b804d7767..aba75791e 100644 --- a/app/models/forms/bulk_upload_lettings_soft_validations_check/confirm.rb +++ b/app/models/forms/bulk_upload_lettings_soft_validations_check/confirm.rb @@ -20,11 +20,28 @@ module Forms end def save! - processor = BulkUpload::Processor.new(bulk_upload:) - processor.approve_and_confirm_soft_validations + 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_lettings_soft_validations_check_path(bulk_upload, :chosen) + when "create-fix-inline" + page_bulk_upload_lettings_resume_path(bulk_upload, :chosen) + end + end 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_lettings_soft_validations_check/confirm_soft_errors.rb index cbf486a4d..34b4b97f3 100644 --- a/app/models/forms/bulk_upload_lettings_soft_validations_check/confirm_soft_errors.rb +++ b/app/models/forms/bulk_upload_lettings_soft_validations_check/confirm_soft_errors.rb @@ -35,6 +35,19 @@ module Forms 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_lettings_soft_validations_check_path(bulk_upload, :chosen) + when "create-fix-inline" + page_bulk_upload_lettings_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_sales_resume/chosen.rb new file mode 100644 index 000000000..2fa85c6c9 --- /dev/null +++ b/app/models/forms/bulk_upload_sales_resume/chosen.rb @@ -0,0 +1,31 @@ +module Forms + module BulkUploadSalesResume + class Chosen + include ActiveModel::Model + include ActiveModel::Attributes + include Rails.application.routes.url_helpers + + attribute :bulk_upload + + def view_path + "bulk_upload_sales_resume/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_resume/confirm.rb b/app/models/forms/bulk_upload_sales_resume/confirm.rb index 4ce50fb55..1211ef3f0 100644 --- a/app/models/forms/bulk_upload_sales_resume/confirm.rb +++ b/app/models/forms/bulk_upload_sales_resume/confirm.rb @@ -20,11 +20,28 @@ module Forms end def save! - processor = BulkUpload::Processor.new(bulk_upload:) - processor.approve + 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_sales_resume_path(bulk_upload, :chosen) + when "bulk-confirm-soft-validations" + page_bulk_upload_sales_soft_validations_check_path(bulk_upload, :chosen) + end + end end end end diff --git a/app/models/forms/bulk_upload_sales_resume/fix_choice.rb b/app/models/forms/bulk_upload_sales_resume/fix_choice.rb index 671891429..fc565e2f6 100644 --- a/app/models/forms/bulk_upload_sales_resume/fix_choice.rb +++ b/app/models/forms/bulk_upload_sales_resume/fix_choice.rb @@ -46,8 +46,23 @@ module Forms end def save! + bulk_upload.update!(choice:) if choice == "upload-again" + 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_sales_resume_path(bulk_upload, :chosen) + when "bulk-confirm-soft-validations" + page_bulk_upload_sales_soft_validations_check_path(bulk_upload, :chosen) + end + 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 new file mode 100644 index 000000000..2286d3b39 --- /dev/null +++ b/app/models/forms/bulk_upload_sales_soft_validations_check/chosen.rb @@ -0,0 +1,31 @@ +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 index 579af7e84..894f55123 100644 --- a/app/models/forms/bulk_upload_sales_soft_validations_check/confirm.rb +++ b/app/models/forms/bulk_upload_sales_soft_validations_check/confirm.rb @@ -20,11 +20,28 @@ module Forms end def save! - processor = BulkUpload::Processor.new(bulk_upload:) - processor.approve_and_confirm_soft_validations + 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 index e6fe00495..041647cf0 100644 --- 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 @@ -35,6 +35,19 @@ module Forms 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/views/bulk_upload_lettings_resume/chosen.html.erb b/app/views/bulk_upload_lettings_resume/chosen.html.erb new file mode 100644 index 000000000..47ed9bbfd --- /dev/null +++ b/app/views/bulk_upload_lettings_resume/chosen.html.erb @@ -0,0 +1,14 @@ +<% content_for :before_content do %> + <%= govuk_back_link href: @form.back_path %> +<% end %> + +
+
+ Bulk upload for lettings (<%= @bulk_upload.year_combo %>) +

You need to fix logs from your bulk upload

+ +

You have chosen to create logs from your recent bulk upload. To view and complete these logs, return to the list of lettings logs.

+ + <%= govuk_button_link_to "Return to lettings logs", lettings_logs_path %> +
+
diff --git a/app/views/bulk_upload_lettings_soft_validations_check/chosen.html.erb b/app/views/bulk_upload_lettings_soft_validations_check/chosen.html.erb new file mode 100644 index 000000000..418387fc9 --- /dev/null +++ b/app/views/bulk_upload_lettings_soft_validations_check/chosen.html.erb @@ -0,0 +1,14 @@ +<% content_for :before_content do %> + <%= govuk_back_link href: @form.back_path %> +<% end %> + +
+
+ Bulk upload for lettings (<%= @bulk_upload.year_combo %>) +

These logs have been created

+ +

You have created logs from your bulk upload. Return to lettings logs to view them.

+ + <%= govuk_button_link_to "Return to lettings logs", lettings_logs_path %> +
+
diff --git a/app/views/bulk_upload_sales_resume/chosen.html.erb b/app/views/bulk_upload_sales_resume/chosen.html.erb new file mode 100644 index 000000000..0d381e6a6 --- /dev/null +++ b/app/views/bulk_upload_sales_resume/chosen.html.erb @@ -0,0 +1,14 @@ +<% content_for :before_content do %> + <%= govuk_back_link href: @form.back_path %> +<% end %> + +
+
+ Bulk upload for sales (<%= @bulk_upload.year_combo %>) +

You need to fix logs from your bulk upload

+ +

You have chosen to create logs from your recent bulk upload. To view and complete these logs, return to the list of sales logs.

+ + <%= govuk_button_link_to "Return to sales logs", sales_logs_path %> +
+
diff --git a/app/views/bulk_upload_sales_soft_validations_check/chosen.html.erb b/app/views/bulk_upload_sales_soft_validations_check/chosen.html.erb new file mode 100644 index 000000000..211f9c03c --- /dev/null +++ b/app/views/bulk_upload_sales_soft_validations_check/chosen.html.erb @@ -0,0 +1,14 @@ +<% content_for :before_content do %> + <%= govuk_back_link href: @form.back_path %> +<% end %> + +
+
+ Bulk upload for sales (<%= @bulk_upload.year_combo %>) +

These logs have been created

+ +

You have created logs from your bulk upload. Return to sales logs to view them.

+ + <%= govuk_button_link_to "Return to sales logs", sales_logs_path %> +
+
diff --git a/db/migrate/20230525090508_add_choice_to_bulk_upload.rb b/db/migrate/20230525090508_add_choice_to_bulk_upload.rb new file mode 100644 index 000000000..e8c299ec6 --- /dev/null +++ b/db/migrate/20230525090508_add_choice_to_bulk_upload.rb @@ -0,0 +1,5 @@ +class AddChoiceToBulkUpload < ActiveRecord::Migration[7.0] + def change + add_column :bulk_uploads, :choice, :text, null: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 8337c5305..1bbbba02a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -39,6 +39,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_06_09_101144) do t.datetime "updated_at", null: false t.text "filename" t.integer "needstype" + t.text "choice" t.index ["identifier"], name: "index_bulk_uploads_on_identifier", unique: true t.index ["user_id"], name: "index_bulk_uploads_on_user_id" end diff --git a/spec/requests/bulk_upload_lettings_resume_controller_spec.rb b/spec/requests/bulk_upload_lettings_resume_controller_spec.rb index 3666bc777..7ba8bbc85 100644 --- a/spec/requests/bulk_upload_lettings_resume_controller_spec.rb +++ b/spec/requests/bulk_upload_lettings_resume_controller_spec.rb @@ -29,6 +29,32 @@ RSpec.describe BulkUploadLettingsResumeController, type: :request do expect(response.body).to include(bulk_upload.filename) expect(response.body).not_to include("Cancel") end + + it "sets no cache headers" do + get "/lettings-logs/bulk-upload-resume/#{bulk_upload.id}/fix-choice" + + expect(response.headers["Cache-Control"]).to eql("no-store") + end + + context "and previously told us to fix inline" do + let(:bulk_upload) { create(:bulk_upload, :lettings, user:, bulk_upload_errors:, choice: "create-fix-inline") } + + it "redirects to chosen" do + get "/lettings-logs/bulk-upload-resume/#{bulk_upload.id}/fix-choice" + + expect(response).to redirect_to("/lettings-logs/bulk-upload-resume/#{bulk_upload.id}/chosen") + end + end + + context "and previously told us to bulk confirm soft validations" do + let(:bulk_upload) { create(:bulk_upload, :lettings, user:, bulk_upload_errors:, choice: "bulk-confirm-soft-validations") } + + it "redirects to soft validations check chosen" do + get "/lettings-logs/bulk-upload-resume/#{bulk_upload.id}/fix-choice" + + expect(response).to redirect_to("/lettings-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/chosen") + end + end end describe "GET /lettings-logs/bulk-upload-resume/:ID/fix-choice?soft_errors_only=true" do @@ -58,6 +84,8 @@ RSpec.describe BulkUploadLettingsResumeController, type: :request 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}") + + expect(bulk_upload.reload.choice).to eql("upload-again") end end @@ -66,6 +94,8 @@ RSpec.describe BulkUploadLettingsResumeController, type: :request do patch "/lettings-logs/bulk-upload-resume/#{bulk_upload.id}/fix-choice", params: { form: { choice: "create-fix-inline" } } expect(response).to redirect_to("/lettings-logs/bulk-upload-resume/#{bulk_upload.id}/confirm") + + expect(bulk_upload.reload.choice).to be_blank end end end @@ -78,6 +108,32 @@ RSpec.describe BulkUploadLettingsResumeController, type: :request do expect(response.body).to include("Are you sure") end + + it "sets no cache headers" do + get "/lettings-logs/bulk-upload-resume/#{bulk_upload.id}/confirm" + + expect(response.headers["Cache-Control"]).to eql("no-store") + end + + context "and previously told us to fix inline" do + let(:bulk_upload) { create(:bulk_upload, :lettings, user:, bulk_upload_errors:, choice: "create-fix-inline") } + + it "redirects to chosen" do + get "/lettings-logs/bulk-upload-resume/#{bulk_upload.id}/confirm" + + expect(response).to redirect_to("/lettings-logs/bulk-upload-resume/#{bulk_upload.id}/chosen") + end + end + + context "and previously told us to bulk confirm soft validations" do + let(:bulk_upload) { create(:bulk_upload, :lettings, user:, bulk_upload_errors:, choice: "bulk-confirm-soft-validations") } + + it "redirects to soft validations check chosen" do + get "/lettings-logs/bulk-upload-resume/#{bulk_upload.id}/confirm" + + expect(response).to redirect_to("/lettings-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/chosen") + end + end end describe "PATCH /lettings-logs/bulk-upload-resume/:ID/confirm" do @@ -90,6 +146,8 @@ RSpec.describe BulkUploadLettingsResumeController, type: :request do expect(mock_processor).to have_received(:approve) + expect(bulk_upload.reload.choice).to eql("create-fix-inline") + expect(response).to redirect_to("/lettings-logs/bulk-upload-results/#{bulk_upload.id}/resume") end end diff --git a/spec/requests/bulk_upload_lettings_soft_validations_check_controller_spec.rb b/spec/requests/bulk_upload_lettings_soft_validations_check_controller_spec.rb index d1252b5e2..0603e3d34 100644 --- a/spec/requests/bulk_upload_lettings_soft_validations_check_controller_spec.rb +++ b/spec/requests/bulk_upload_lettings_soft_validations_check_controller_spec.rb @@ -28,6 +28,32 @@ RSpec.describe BulkUploadLettingsSoftValidationsCheckController, type: :request expect(response.body).to include("Tenant code") expect(response.body).to include("some error") end + + it "sets no cache headers" do + get "/lettings-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/confirm-soft-errors" + + expect(response.headers["Cache-Control"]).to eql("no-store") + end + + context "and previously told us to fix inline" do + let(:bulk_upload) { create(:bulk_upload, :lettings, user:, bulk_upload_errors:, choice: "create-fix-inline") } + + it "redirects to resume chosen" do + get "/lettings-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/confirm-soft-errors" + + expect(response).to redirect_to("/lettings-logs/bulk-upload-resume/#{bulk_upload.id}/chosen") + end + end + + context "and previously told us to bulk confirm soft validations" do + let(:bulk_upload) { create(:bulk_upload, :lettings, user:, bulk_upload_errors:, choice: "bulk-confirm-soft-validations") } + + it "redirects to soft validations check chosen" do + get "/lettings-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/confirm-soft-errors" + + expect(response).to redirect_to("/lettings-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/chosen") + end + end end describe "PATCH /lettings-logs/bulk-upload-soft-validations-check/:ID/confirm-soft-errors" do @@ -38,6 +64,8 @@ RSpec.describe BulkUploadLettingsSoftValidationsCheckController, type: :request expect(response).to be_successful expect(response.body).to include("You must select if there are errors in these fields") + + expect(bulk_upload.reload.choice).to be_blank end end @@ -46,6 +74,8 @@ RSpec.describe BulkUploadLettingsSoftValidationsCheckController, type: :request patch "/lettings-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/confirm-soft-errors", params: { form: { confirm_soft_errors: "no" } } expect(response).to redirect_to("/lettings-logs/bulk-upload-resume/#{bulk_upload.id}/fix-choice?soft_errors_only=true") + + expect(bulk_upload.reload.choice).to be_blank end end @@ -56,6 +86,8 @@ RSpec.describe BulkUploadLettingsSoftValidationsCheckController, type: :request expect(response).to redirect_to("/lettings-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/confirm") follow_redirect! expect(response.body).not_to include("You’ve successfully uploaded") + + expect(bulk_upload.reload.choice).to be_blank end end end @@ -85,6 +117,8 @@ RSpec.describe BulkUploadLettingsSoftValidationsCheckController, type: :request expect(response).to redirect_to("/lettings-logs") follow_redirect! expect(response.body).to include("You’ve successfully uploaded 2 logs") + + expect(bulk_upload.reload.choice).to eql("bulk-confirm-soft-validations") end end end diff --git a/spec/requests/bulk_upload_sales_resume_controller_spec.rb b/spec/requests/bulk_upload_sales_resume_controller_spec.rb index 8dcc0ba00..9c0a7112c 100644 --- a/spec/requests/bulk_upload_sales_resume_controller_spec.rb +++ b/spec/requests/bulk_upload_sales_resume_controller_spec.rb @@ -29,6 +29,32 @@ RSpec.describe BulkUploadSalesResumeController, type: :request do expect(response.body).to include(bulk_upload.filename) expect(response.body).not_to include("Cancel") end + + it "sets no cache headers" do + get "/sales-logs/bulk-upload-resume/#{bulk_upload.id}/fix-choice" + + expect(response.headers["Cache-Control"]).to eql("no-store") + end + + context "and previously told us to fix inline" do + let(:bulk_upload) { create(:bulk_upload, :sales, user:, bulk_upload_errors:, choice: "create-fix-inline") } + + it "redirects to chosen" do + get "/sales-logs/bulk-upload-resume/#{bulk_upload.id}/fix-choice" + + expect(response).to redirect_to("/sales-logs/bulk-upload-resume/#{bulk_upload.id}/chosen") + end + end + + context "and previously told us to bulk confirm soft validations" do + let(:bulk_upload) { create(:bulk_upload, :sales, user:, bulk_upload_errors:, choice: "bulk-confirm-soft-validations") } + + it "redirects to soft validations check chosen" do + get "/sales-logs/bulk-upload-resume/#{bulk_upload.id}/fix-choice" + + expect(response).to redirect_to("/sales-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/chosen") + end + end end describe "GET /sales-logs/bulk-upload-resume/:ID/fix-choice?soft_errors_only=true" do @@ -58,6 +84,8 @@ RSpec.describe BulkUploadSalesResumeController, type: :request do patch "/sales-logs/bulk-upload-resume/#{bulk_upload.id}/fix-choice", params: { form: { choice: "upload-again" } } expect(response).to redirect_to("/sales-logs/bulk-upload-results/#{bulk_upload.id}") + + expect(bulk_upload.reload.choice).to eql("upload-again") end end @@ -66,6 +94,8 @@ RSpec.describe BulkUploadSalesResumeController, type: :request do patch "/sales-logs/bulk-upload-resume/#{bulk_upload.id}/fix-choice", params: { form: { choice: "create-fix-inline" } } expect(response).to redirect_to("/sales-logs/bulk-upload-resume/#{bulk_upload.id}/confirm") + + expect(bulk_upload.reload.choice).to be_blank end end end @@ -78,6 +108,22 @@ RSpec.describe BulkUploadSalesResumeController, type: :request do expect(response.body).to include("Are you sure") end + + it "sets no cache headers" do + get "/sales-logs/bulk-upload-resume/#{bulk_upload.id}/confirm" + + expect(response.headers["Cache-Control"]).to eql("no-store") + end + + context "and previously told us to bulk confirm soft validations" do + let(:bulk_upload) { create(:bulk_upload, :sales, user:, bulk_upload_errors:, choice: "bulk-confirm-soft-validations") } + + it "redirects to soft validations check chosen" do + get "/sales-logs/bulk-upload-resume/#{bulk_upload.id}/confirm" + + expect(response).to redirect_to("/sales-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/chosen") + end + end end describe "PATCH /sales-logs/bulk-upload-resume/:ID/confirm" do @@ -90,7 +136,17 @@ RSpec.describe BulkUploadSalesResumeController, type: :request do expect(mock_processor).to have_received(:approve) + expect(bulk_upload.reload.choice).to eql("create-fix-inline") + expect(response).to redirect_to("/sales-logs/bulk-upload-results/#{bulk_upload.id}/resume") end end + + describe "GET /sales-logs/bulk-upload-resume/:ID/chosen" do + it "displays correct content" do + get "/sales-logs/bulk-upload-resume/#{bulk_upload.id}/chosen" + + expect(response.body).to include("You need to fix logs from your bulk upload") + end + end end diff --git a/spec/requests/bulk_upload_sales_soft_validations_check_controller_spec.rb b/spec/requests/bulk_upload_sales_soft_validations_check_controller_spec.rb index 3aaa433f0..0b496aea4 100644 --- a/spec/requests/bulk_upload_sales_soft_validations_check_controller_spec.rb +++ b/spec/requests/bulk_upload_sales_soft_validations_check_controller_spec.rb @@ -28,6 +28,32 @@ RSpec.describe BulkUploadSalesSoftValidationsCheckController, type: :request do expect(response.body).to include("Purchaser code") expect(response.body).to include("some error") end + + it "sets no cache headers" do + get "/sales-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/confirm-soft-errors" + + expect(response.headers["Cache-Control"]).to eql("no-store") + end + + context "and previously told us to fix inline" do + let(:bulk_upload) { create(:bulk_upload, :sales, user:, bulk_upload_errors:, choice: "create-fix-inline") } + + it "redirects to resume chosen" do + get "/sales-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/confirm-soft-errors" + + expect(response).to redirect_to("/sales-logs/bulk-upload-resume/#{bulk_upload.id}/chosen") + end + end + + context "and previously told us to bulk confirm soft validations" do + let(:bulk_upload) { create(:bulk_upload, :sales, user:, bulk_upload_errors:, choice: "bulk-confirm-soft-validations") } + + it "redirects to soft validations check chosen" do + get "/sales-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/confirm-soft-errors" + + expect(response).to redirect_to("/sales-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/chosen") + end + end end describe "PATCH /sales-logs/bulk-upload-soft-validations-check/:ID/confirm-soft-errors" do @@ -38,6 +64,8 @@ RSpec.describe BulkUploadSalesSoftValidationsCheckController, type: :request do expect(response).to be_successful expect(response.body).to include("You must select if there are errors in these fields") + + expect(bulk_upload.reload.choice).to be_blank end end @@ -46,6 +74,8 @@ RSpec.describe BulkUploadSalesSoftValidationsCheckController, type: :request do patch "/sales-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/confirm-soft-errors", params: { form: { confirm_soft_errors: "no" } } expect(response).to redirect_to("/sales-logs/bulk-upload-resume/#{bulk_upload.id}/fix-choice?soft_errors_only=true") + + expect(bulk_upload.reload.choice).to be_blank end end @@ -56,6 +86,8 @@ RSpec.describe BulkUploadSalesSoftValidationsCheckController, type: :request do expect(response).to redirect_to("/sales-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/confirm") follow_redirect! expect(response.body).not_to include("You’ve successfully uploaded") + + expect(bulk_upload.reload.choice).to be_blank end end end @@ -85,6 +117,8 @@ RSpec.describe BulkUploadSalesSoftValidationsCheckController, type: :request do expect(response).to redirect_to("/sales-logs") follow_redirect! expect(response.body).to include("You’ve successfully uploaded 2 logs") + + expect(bulk_upload.reload.choice).to eql("bulk-confirm-soft-validations") end end end