Browse Source

Fix deletion report sales routing bug (#2202)

* feat: add sales preflight redirect

* feat: fix tests

* feat: fix tests
pull/2205/head v0.4.13
natdeanlewissoftwire 11 months ago committed by GitHub
parent
commit
e8cea58796
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 28
      app/models/forms/bulk_upload_sales_resume/deletion_report.rb
  2. 2
      config/routes.rb
  3. 64
      spec/requests/bulk_upload_sales_resume_controller_spec.rb

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

@ -0,0 +1,28 @@
module Forms
module BulkUploadSalesResume
class DeletionReport
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
attribute :bulk_upload
def view_path
"bulk_upload_sales_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_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

2
config/routes.rb

@ -287,10 +287,10 @@ Rails.application.routes.draw do
resources :bulk_upload_sales_resume, path: "bulk-upload-resume", only: %i[show update] do resources :bulk_upload_sales_resume, path: "bulk-upload-resume", only: %i[show update] do
member do member do
get :start get :start
get "deletion-report"
get "*page", to: "bulk_upload_sales_resume#show", as: "page" get "*page", to: "bulk_upload_sales_resume#show", as: "page"
patch "*page", to: "bulk_upload_sales_resume#update" patch "*page", to: "bulk_upload_sales_resume#update"
get "deletion-report"
end end
end end

64
spec/requests/bulk_upload_sales_resume_controller_spec.rb

@ -9,6 +9,31 @@ RSpec.describe BulkUploadSalesResumeController, type: :request do
sign_in user sign_in user
end end
describe "GET /sales-logs/bulk-upload-resume/:ID/start" do
context "when a choice has not been made" do
it "redirects to choice page" do
get "/sales-logs/bulk-upload-resume/#{bulk_upload.id}/start"
expect(response).to redirect_to("/sales-logs/bulk-upload-resume/#{bulk_upload.id}/fix-choice")
end
end
context "when a choice has been made and then the logs have been completed" do
let(:sales_log) { create_list(:sales_log, 2, :completed, bulk_upload:) }
it "redirects to the complete page if the bulk uploads are completed" do
bulk_upload.update!(choice: "create-fix-inline")
get "/sales-logs/bulk-upload-resume/#{bulk_upload.id}/start"
follow_redirect!
expect(response).to redirect_to("/sales-logs/bulk-upload-resume/#{bulk_upload.id}/chosen")
follow_redirect!
expect(response.body).to include("You have created logs from your bulk upload, and the logs are complete. Return to sales logs to view them.")
end
end
end
describe "GET /sales-logs/bulk-upload-resume/:ID/fix-choice" do describe "GET /sales-logs/bulk-upload-resume/:ID/fix-choice" do
it "renders the page correctly" do it "renders the page correctly" do
get "/sales-logs/bulk-upload-resume/#{bulk_upload.id}/fix-choice" get "/sales-logs/bulk-upload-resume/#{bulk_upload.id}/fix-choice"
@ -111,6 +136,16 @@ RSpec.describe BulkUploadSalesResumeController, type: :request do
expect(response.headers["Cache-Control"]).to eql("no-store") expect(response.headers["Cache-Control"]).to eql("no-store")
end 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}/confirm"
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 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") } let(:bulk_upload) { create(:bulk_upload, :sales, user:, bulk_upload_errors:, choice: "bulk-confirm-soft-validations") }
@ -138,31 +173,6 @@ RSpec.describe BulkUploadSalesResumeController, type: :request do
end end
end end
describe "GET /sales-logs/bulk-upload-resume/:ID/start" do
context "when a choice has not been made" do
it "redirects to choice page" do
get "/sales-logs/bulk-upload-resume/#{bulk_upload.id}/start"
expect(response).to redirect_to("/sales-logs/bulk-upload-resume/#{bulk_upload.id}/fix-choice")
end
end
context "when a choice has been made and then the logs have been completed" do
let(:sales_log) { create_list(:sales_log, 2, :completed, bulk_upload:) }
it "redirects to the complete page if the bulk uploads are completed" do
bulk_upload.update!(choice: "create-fix-inline")
get "/sales-logs/bulk-upload-resume/#{bulk_upload.id}/start"
follow_redirect!
expect(response).to redirect_to("/sales-logs/bulk-upload-resume/#{bulk_upload.id}/chosen")
follow_redirect!
expect(response.body).to include("You have created logs from your bulk upload, and the logs are complete. Return to sales logs to view them.")
end
end
end
describe "GET /sales-logs/bulk-upload-resume/:ID/deletion-report" do describe "GET /sales-logs/bulk-upload-resume/:ID/deletion-report" do
it "renders the page correctly" do it "renders the page correctly" do
get "/sales-logs/bulk-upload-resume/#{bulk_upload.id}/deletion-report" get "/sales-logs/bulk-upload-resume/#{bulk_upload.id}/deletion-report"
@ -186,7 +196,7 @@ RSpec.describe BulkUploadSalesResumeController, type: :request do
let(:bulk_upload) { create(:bulk_upload, :sales, user:, bulk_upload_errors:, choice: "create-fix-inline") } let(:bulk_upload) { create(:bulk_upload, :sales, user:, bulk_upload_errors:, choice: "create-fix-inline") }
it "redirects to chosen" do it "redirects to chosen" do
get "/sales-logs/bulk-upload-resume/#{bulk_upload.id}/fix-choice" get "/sales-logs/bulk-upload-resume/#{bulk_upload.id}/deletion-report"
expect(response).to redirect_to("/sales-logs/bulk-upload-resume/#{bulk_upload.id}/chosen") expect(response).to redirect_to("/sales-logs/bulk-upload-resume/#{bulk_upload.id}/chosen")
end end
@ -196,7 +206,7 @@ RSpec.describe BulkUploadSalesResumeController, type: :request do
let(:bulk_upload) { create(:bulk_upload, :sales, user:, bulk_upload_errors:, choice: "bulk-confirm-soft-validations") } let(:bulk_upload) { create(:bulk_upload, :sales, user:, bulk_upload_errors:, choice: "bulk-confirm-soft-validations") }
it "redirects to soft validations check chosen" do it "redirects to soft validations check chosen" do
get "/sales-logs/bulk-upload-resume/#{bulk_upload.id}/fix-choice" get "/sales-logs/bulk-upload-resume/#{bulk_upload.id}/deletion-report"
expect(response).to redirect_to("/sales-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/chosen") expect(response).to redirect_to("/sales-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/chosen")
end end

Loading…
Cancel
Save