Browse Source

CLDC-2330 Fix again (#1670)

* persist how to fix choice

* fix choice decision persisted

* set no cache headers

* add chosen to sales journey

* set no cache headers for sales

* fix linting

* Add chosen journey for sales soft validations

* Add chosen journey for lettings soft validations

* Update copy

* Also redirect fix inline and confirm if soft validations are chosen to be bulk fixed

---------

Co-authored-by: Kat <katrina@kosiak.co.uk>
pull/1687/head
Phil Lee 2 years ago committed by GitHub
parent
commit
0834897308
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      app/controllers/bulk_upload_lettings_resume_controller.rb
  2. 9
      app/controllers/bulk_upload_lettings_soft_validations_check_controller.rb
  3. 9
      app/controllers/bulk_upload_sales_resume_controller.rb
  4. 9
      app/controllers/bulk_upload_sales_soft_validations_check_controller.rb
  5. 31
      app/models/forms/bulk_upload_lettings_resume/chosen.rb
  6. 21
      app/models/forms/bulk_upload_lettings_resume/confirm.rb
  7. 15
      app/models/forms/bulk_upload_lettings_resume/fix_choice.rb
  8. 31
      app/models/forms/bulk_upload_lettings_soft_validations_check/chosen.rb
  9. 21
      app/models/forms/bulk_upload_lettings_soft_validations_check/confirm.rb
  10. 13
      app/models/forms/bulk_upload_lettings_soft_validations_check/confirm_soft_errors.rb
  11. 31
      app/models/forms/bulk_upload_sales_resume/chosen.rb
  12. 21
      app/models/forms/bulk_upload_sales_resume/confirm.rb
  13. 15
      app/models/forms/bulk_upload_sales_resume/fix_choice.rb
  14. 31
      app/models/forms/bulk_upload_sales_soft_validations_check/chosen.rb
  15. 21
      app/models/forms/bulk_upload_sales_soft_validations_check/confirm.rb
  16. 13
      app/models/forms/bulk_upload_sales_soft_validations_check/confirm_soft_errors.rb
  17. 14
      app/views/bulk_upload_lettings_resume/chosen.html.erb
  18. 14
      app/views/bulk_upload_lettings_soft_validations_check/chosen.html.erb
  19. 14
      app/views/bulk_upload_sales_resume/chosen.html.erb
  20. 14
      app/views/bulk_upload_sales_soft_validations_check/chosen.html.erb
  21. 5
      db/migrate/20230525090508_add_choice_to_bulk_upload.rb
  22. 1
      db/schema.rb
  23. 58
      spec/requests/bulk_upload_lettings_resume_controller_spec.rb
  24. 34
      spec/requests/bulk_upload_lettings_soft_validations_check_controller_spec.rb
  25. 56
      spec/requests/bulk_upload_sales_resume_controller_spec.rb
  26. 34
      spec/requests/bulk_upload_sales_soft_validations_check_controller_spec.rb

9
app/controllers/bulk_upload_lettings_resume_controller.rb

@ -1,5 +1,10 @@
class BulkUploadLettingsResumeController < ApplicationController class BulkUploadLettingsResumeController < ApplicationController
before_action :authenticate_user! 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 def start
@bulk_upload = current_user.bulk_uploads.find(params[:id]) @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]) @bulk_upload = current_user.bulk_uploads.find(params[:id])
@soft_errors_only = params[:soft_errors_only] == "true" @soft_errors_only = params[:soft_errors_only] == "true"
return redirect_to form.preflight_redirect unless form.preflight_valid?
render form.view_path render form.view_path
end end
@ -30,6 +37,8 @@ private
@form ||= case params[:page] @form ||= case params[:page]
when "fix-choice" when "fix-choice"
Forms::BulkUploadLettingsResume::FixChoice.new(form_params.merge(bulk_upload: @bulk_upload)) 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" when "confirm"
Forms::BulkUploadLettingsResume::Confirm.new(form_params.merge(bulk_upload: @bulk_upload)) Forms::BulkUploadLettingsResume::Confirm.new(form_params.merge(bulk_upload: @bulk_upload))
else else

9
app/controllers/bulk_upload_lettings_soft_validations_check_controller.rb

@ -2,10 +2,17 @@ class BulkUploadLettingsSoftValidationsCheckController < ApplicationController
include ActionView::Helpers::TextHelper include ActionView::Helpers::TextHelper
before_action :authenticate_user! 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 def show
@bulk_upload = current_user.bulk_uploads.find(params[:id]) @bulk_upload = current_user.bulk_uploads.find(params[:id])
return redirect_to form.preflight_redirect unless form.preflight_valid?
render form.view_path render form.view_path
end end
@ -30,6 +37,8 @@ private
@form ||= case params[:page] @form ||= case params[:page]
when "confirm-soft-errors" when "confirm-soft-errors"
Forms::BulkUploadLettingsSoftValidationsCheck::ConfirmSoftErrors.new(form_params.merge(bulk_upload: @bulk_upload)) 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" when "confirm"
Forms::BulkUploadLettingsSoftValidationsCheck::Confirm.new(form_params.merge(bulk_upload: @bulk_upload)) Forms::BulkUploadLettingsSoftValidationsCheck::Confirm.new(form_params.merge(bulk_upload: @bulk_upload))
else else

9
app/controllers/bulk_upload_sales_resume_controller.rb

@ -1,5 +1,10 @@
class BulkUploadSalesResumeController < ApplicationController class BulkUploadSalesResumeController < ApplicationController
before_action :authenticate_user! 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 def start
@bulk_upload = current_user.bulk_uploads.find(params[:id]) @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]) @bulk_upload = current_user.bulk_uploads.find(params[:id])
@soft_errors_only = params[:soft_errors_only] == "true" @soft_errors_only = params[:soft_errors_only] == "true"
return redirect_to form.preflight_redirect unless form.preflight_valid?
render form.view_path render form.view_path
end end
@ -30,6 +37,8 @@ private
@form ||= case params[:page] @form ||= case params[:page]
when "fix-choice" when "fix-choice"
Forms::BulkUploadSalesResume::FixChoice.new(form_params.merge(bulk_upload: @bulk_upload)) 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" when "confirm"
Forms::BulkUploadSalesResume::Confirm.new(form_params.merge(bulk_upload: @bulk_upload)) Forms::BulkUploadSalesResume::Confirm.new(form_params.merge(bulk_upload: @bulk_upload))
else else

9
app/controllers/bulk_upload_sales_soft_validations_check_controller.rb

@ -2,10 +2,17 @@ class BulkUploadSalesSoftValidationsCheckController < ApplicationController
include ActionView::Helpers::TextHelper include ActionView::Helpers::TextHelper
before_action :authenticate_user! 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 def show
@bulk_upload = current_user.bulk_uploads.find(params[:id]) @bulk_upload = current_user.bulk_uploads.find(params[:id])
return redirect_to form.preflight_redirect unless form.preflight_valid?
render form.view_path render form.view_path
end end
@ -30,6 +37,8 @@ private
@form ||= case params[:page] @form ||= case params[:page]
when "confirm-soft-errors" when "confirm-soft-errors"
Forms::BulkUploadSalesSoftValidationsCheck::ConfirmSoftErrors.new(form_params.merge(bulk_upload: @bulk_upload)) 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" when "confirm"
Forms::BulkUploadSalesSoftValidationsCheck::Confirm.new(form_params.merge(bulk_upload: @bulk_upload)) Forms::BulkUploadSalesSoftValidationsCheck::Confirm.new(form_params.merge(bulk_upload: @bulk_upload))
else else

31
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

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

@ -20,11 +20,28 @@ module Forms
end end
def save! def save!
processor = BulkUpload::Processor.new(bulk_upload:) ApplicationRecord.transaction do
processor.approve processor = BulkUpload::Processor.new(bulk_upload:)
processor.approve
bulk_upload.update!(choice: "create-fix-inline")
end
true true
end 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 end
end end

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

@ -46,8 +46,23 @@ module Forms
end end
def save! def save!
bulk_upload.update!(choice:) if choice == "upload-again"
true true
end 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 end
end end

31
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

21
app/models/forms/bulk_upload_lettings_soft_validations_check/confirm.rb

@ -20,11 +20,28 @@ module Forms
end end
def save! def save!
processor = BulkUpload::Processor.new(bulk_upload:) ApplicationRecord.transaction do
processor.approve_and_confirm_soft_validations processor = BulkUpload::Processor.new(bulk_upload:)
processor.approve_and_confirm_soft_validations
bulk_upload.update!(choice: "bulk-confirm-soft-validations")
end
true true
end 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 end
end end

13
app/models/forms/bulk_upload_lettings_soft_validations_check/confirm_soft_errors.rb

@ -35,6 +35,19 @@ module Forms
def save! def save!
true true
end 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 end
end end

31
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

21
app/models/forms/bulk_upload_sales_resume/confirm.rb

@ -20,11 +20,28 @@ module Forms
end end
def save! def save!
processor = BulkUpload::Processor.new(bulk_upload:) ApplicationRecord.transaction do
processor.approve processor = BulkUpload::Processor.new(bulk_upload:)
processor.approve
bulk_upload.update!(choice: "create-fix-inline")
end
true true
end 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 end
end end

15
app/models/forms/bulk_upload_sales_resume/fix_choice.rb

@ -46,8 +46,23 @@ module Forms
end end
def save! def save!
bulk_upload.update!(choice:) if choice == "upload-again"
true true
end 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 end
end end

31
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

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

@ -20,11 +20,28 @@ module Forms
end end
def save! def save!
processor = BulkUpload::Processor.new(bulk_upload:) ApplicationRecord.transaction do
processor.approve_and_confirm_soft_validations processor = BulkUpload::Processor.new(bulk_upload:)
processor.approve_and_confirm_soft_validations
bulk_upload.update!(choice: "bulk-confirm-soft-validations")
end
true true
end 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 end
end end

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

@ -35,6 +35,19 @@ module Forms
def save! def save!
true true
end 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 end
end end

14
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 %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<span class="govuk-caption-l">Bulk upload for lettings (<%= @bulk_upload.year_combo %>)</span>
<h1 class="govuk-heading-l">You need to fix logs from your bulk upload</h1>
<p class="govuk-body">You have chosen to create logs from your recent bulk upload. To view and complete these logs, return to the list of lettings logs.</p>
<%= govuk_button_link_to "Return to lettings logs", lettings_logs_path %>
</div>
</div>

14
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 %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<span class="govuk-caption-l">Bulk upload for lettings (<%= @bulk_upload.year_combo %>)</span>
<h1 class="govuk-heading-l">These logs have been created</h1>
<p class="govuk-body">You have created logs from your bulk upload. Return to lettings logs to view them.</p>
<%= govuk_button_link_to "Return to lettings logs", lettings_logs_path %>
</div>
</div>

14
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 %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<span class="govuk-caption-l">Bulk upload for sales (<%= @bulk_upload.year_combo %>)</span>
<h1 class="govuk-heading-l">You need to fix logs from your bulk upload</h1>
<p class="govuk-body">You have chosen to create logs from your recent bulk upload. To view and complete these logs, return to the list of sales logs.</p>
<%= govuk_button_link_to "Return to sales logs", sales_logs_path %>
</div>
</div>

14
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 %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<span class="govuk-caption-l">Bulk upload for sales (<%= @bulk_upload.year_combo %>)</span>
<h1 class="govuk-heading-l">These logs have been created</h1>
<p class="govuk-body">You have created logs from your bulk upload. Return to sales logs to view them.</p>
<%= govuk_button_link_to "Return to sales logs", sales_logs_path %>
</div>
</div>

5
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

1
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.datetime "updated_at", null: false
t.text "filename" t.text "filename"
t.integer "needstype" t.integer "needstype"
t.text "choice"
t.index ["identifier"], name: "index_bulk_uploads_on_identifier", unique: true t.index ["identifier"], name: "index_bulk_uploads_on_identifier", unique: true
t.index ["user_id"], name: "index_bulk_uploads_on_user_id" t.index ["user_id"], name: "index_bulk_uploads_on_user_id"
end end

58
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).to include(bulk_upload.filename)
expect(response.body).not_to include("Cancel") expect(response.body).not_to include("Cancel")
end 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 end
describe "GET /lettings-logs/bulk-upload-resume/:ID/fix-choice?soft_errors_only=true" do 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" } } 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(response).to redirect_to("/lettings-logs/bulk-upload-results/#{bulk_upload.id}")
expect(bulk_upload.reload.choice).to eql("upload-again")
end end
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" } } 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(response).to redirect_to("/lettings-logs/bulk-upload-resume/#{bulk_upload.id}/confirm")
expect(bulk_upload.reload.choice).to be_blank
end end
end end
end end
@ -78,6 +108,32 @@ RSpec.describe BulkUploadLettingsResumeController, type: :request do
expect(response.body).to include("Are you sure") expect(response.body).to include("Are you sure")
end 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 end
describe "PATCH /lettings-logs/bulk-upload-resume/:ID/confirm" do 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(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") expect(response).to redirect_to("/lettings-logs/bulk-upload-results/#{bulk_upload.id}/resume")
end end
end end

34
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("Tenant code")
expect(response.body).to include("some error") expect(response.body).to include("some error")
end 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 end
describe "PATCH /lettings-logs/bulk-upload-soft-validations-check/:ID/confirm-soft-errors" do 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).to be_successful
expect(response.body).to include("You must select if there are errors in these fields") 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
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" } } 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(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
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") expect(response).to redirect_to("/lettings-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/confirm")
follow_redirect! follow_redirect!
expect(response.body).not_to include("You’ve successfully uploaded") expect(response.body).not_to include("You’ve successfully uploaded")
expect(bulk_upload.reload.choice).to be_blank
end end
end end
end end
@ -85,6 +117,8 @@ RSpec.describe BulkUploadLettingsSoftValidationsCheckController, type: :request
expect(response).to redirect_to("/lettings-logs") expect(response).to redirect_to("/lettings-logs")
follow_redirect! follow_redirect!
expect(response.body).to include("You’ve successfully uploaded 2 logs") 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 end
end end

56
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).to include(bulk_upload.filename)
expect(response.body).not_to include("Cancel") expect(response.body).not_to include("Cancel")
end 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 end
describe "GET /sales-logs/bulk-upload-resume/:ID/fix-choice?soft_errors_only=true" do 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" } } 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(response).to redirect_to("/sales-logs/bulk-upload-results/#{bulk_upload.id}")
expect(bulk_upload.reload.choice).to eql("upload-again")
end end
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" } } 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(response).to redirect_to("/sales-logs/bulk-upload-resume/#{bulk_upload.id}/confirm")
expect(bulk_upload.reload.choice).to be_blank
end end
end end
end end
@ -78,6 +108,22 @@ RSpec.describe BulkUploadSalesResumeController, type: :request do
expect(response.body).to include("Are you sure") expect(response.body).to include("Are you sure")
end 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 end
describe "PATCH /sales-logs/bulk-upload-resume/:ID/confirm" do 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(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") expect(response).to redirect_to("/sales-logs/bulk-upload-results/#{bulk_upload.id}/resume")
end end
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 end

34
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("Purchaser code")
expect(response.body).to include("some error") expect(response.body).to include("some error")
end 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 end
describe "PATCH /sales-logs/bulk-upload-soft-validations-check/:ID/confirm-soft-errors" do 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).to be_successful
expect(response.body).to include("You must select if there are errors in these fields") 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
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" } } 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(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
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") expect(response).to redirect_to("/sales-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/confirm")
follow_redirect! follow_redirect!
expect(response.body).not_to include("You’ve successfully uploaded") expect(response.body).not_to include("You’ve successfully uploaded")
expect(bulk_upload.reload.choice).to be_blank
end end
end end
end end
@ -85,6 +117,8 @@ RSpec.describe BulkUploadSalesSoftValidationsCheckController, type: :request do
expect(response).to redirect_to("/sales-logs") expect(response).to redirect_to("/sales-logs")
follow_redirect! follow_redirect!
expect(response.body).to include("You’ve successfully uploaded 2 logs") 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 end
end end

Loading…
Cancel
Save