Browse Source
* Sends a correct email if there are only soft validations * Add soft errors valid page * Add soft errors confirm page * Confirm the soft validations * Reuse the how to fix template for check soft validations email * Update email link * Move soft validation confirmation to processor * Correctly set the log status, remove redundant confirm_soft_validations * Redirect successful upload to logs index and display a success banner * Implement the soft validations only journey for sales logs * Display the soft validation errors on the soft-errors-valid page * Fix page alignment * Fix tests by mapping housingneeds in csv hepler * Add the sales soft validations to unpend_and_confirm_soft_validations * Change naming * Update method names * refactor * undo typo * Only set the existing soft validations for correct types * Fix path name * Add missing error mappings for location fields * Add missing tests and cancel button * Change some wording * Typospull/1626/head
kosiakkatrina
2 years ago
committed by
GitHub
31 changed files with 973 additions and 22 deletions
@ -0,0 +1,43 @@ |
|||||||
|
class BulkUploadLettingsSoftValidationsCheckController < ApplicationController |
||||||
|
include ActionView::Helpers::TextHelper |
||||||
|
|
||||||
|
before_action :authenticate_user! |
||||||
|
|
||||||
|
def show |
||||||
|
@bulk_upload = current_user.bulk_uploads.find(params[:id]) |
||||||
|
|
||||||
|
render form.view_path |
||||||
|
end |
||||||
|
|
||||||
|
def update |
||||||
|
@bulk_upload = current_user.bulk_uploads.find(params[:id]) |
||||||
|
|
||||||
|
if form.valid? && form.save! |
||||||
|
if params[:page] == "confirm" |
||||||
|
n_logs = pluralize(@bulk_upload.logs.count, "log") |
||||||
|
flash[:notice] = "You’ve successfully uploaded #{n_logs}" |
||||||
|
end |
||||||
|
|
||||||
|
redirect_to form.next_path |
||||||
|
else |
||||||
|
render form.view_path |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
private |
||||||
|
|
||||||
|
def form |
||||||
|
@form ||= case params[:page] |
||||||
|
when "confirm-soft-errors" |
||||||
|
Forms::BulkUploadLettingsSoftValidationsCheck::ConfirmSoftErrors.new(form_params.merge(bulk_upload: @bulk_upload)) |
||||||
|
when "confirm" |
||||||
|
Forms::BulkUploadLettingsSoftValidationsCheck::Confirm.new(form_params.merge(bulk_upload: @bulk_upload)) |
||||||
|
else |
||||||
|
raise "invalid form" |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def form_params |
||||||
|
params.fetch(:form, {}).permit(:confirm_soft_errors) |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,43 @@ |
|||||||
|
class BulkUploadSalesSoftValidationsCheckController < ApplicationController |
||||||
|
include ActionView::Helpers::TextHelper |
||||||
|
|
||||||
|
before_action :authenticate_user! |
||||||
|
|
||||||
|
def show |
||||||
|
@bulk_upload = current_user.bulk_uploads.find(params[:id]) |
||||||
|
|
||||||
|
render form.view_path |
||||||
|
end |
||||||
|
|
||||||
|
def update |
||||||
|
@bulk_upload = current_user.bulk_uploads.find(params[:id]) |
||||||
|
|
||||||
|
if form.valid? && form.save! |
||||||
|
if params[:page] == "confirm" |
||||||
|
n_logs = pluralize(@bulk_upload.logs.count, "log") |
||||||
|
flash[:notice] = "You’ve successfully uploaded #{n_logs}" |
||||||
|
end |
||||||
|
|
||||||
|
redirect_to form.next_path |
||||||
|
else |
||||||
|
render form.view_path |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
private |
||||||
|
|
||||||
|
def form |
||||||
|
@form ||= case params[:page] |
||||||
|
when "confirm-soft-errors" |
||||||
|
Forms::BulkUploadSalesSoftValidationsCheck::ConfirmSoftErrors.new(form_params.merge(bulk_upload: @bulk_upload)) |
||||||
|
when "confirm" |
||||||
|
Forms::BulkUploadSalesSoftValidationsCheck::Confirm.new(form_params.merge(bulk_upload: @bulk_upload)) |
||||||
|
else |
||||||
|
raise "invalid form" |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def form_params |
||||||
|
params.fetch(:form, {}).permit(:confirm_soft_errors) |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,30 @@ |
|||||||
|
module Forms |
||||||
|
module BulkUploadLettingsSoftValidationsCheck |
||||||
|
class Confirm |
||||||
|
include ActiveModel::Model |
||||||
|
include ActiveModel::Attributes |
||||||
|
include Rails.application.routes.url_helpers |
||||||
|
|
||||||
|
attribute :bulk_upload |
||||||
|
|
||||||
|
def view_path |
||||||
|
"bulk_upload_lettings_soft_validations_check/confirm" |
||||||
|
end |
||||||
|
|
||||||
|
def back_path |
||||||
|
page_bulk_upload_lettings_soft_validations_check_path(bulk_upload, page: "confirm-soft-errors") |
||||||
|
end |
||||||
|
|
||||||
|
def next_path |
||||||
|
lettings_logs_path |
||||||
|
end |
||||||
|
|
||||||
|
def save! |
||||||
|
processor = BulkUpload::Processor.new(bulk_upload:) |
||||||
|
processor.approve_and_confirm_soft_validations |
||||||
|
|
||||||
|
true |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,40 @@ |
|||||||
|
module Forms |
||||||
|
module BulkUploadLettingsSoftValidationsCheck |
||||||
|
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_lettings_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) |
||||||
|
when "yes" |
||||||
|
page_bulk_upload_lettings_soft_validations_check_path(bulk_upload, page: "confirm") |
||||||
|
else |
||||||
|
raise "invalid choice" |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def save! |
||||||
|
true |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,30 @@ |
|||||||
|
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! |
||||||
|
processor = BulkUpload::Processor.new(bulk_upload:) |
||||||
|
processor.approve_and_confirm_soft_validations |
||||||
|
|
||||||
|
true |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,40 @@ |
|||||||
|
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 |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,22 @@ |
|||||||
|
<% 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">Are you sure you want to upload all logs from this bulk upload?</h1> |
||||||
|
|
||||||
|
<p class="govuk-body">There are <%= pluralize(@bulk_upload.logs.count, "log") %> in this bulk upload, and <%= pluralize(@bulk_upload.bulk_upload_errors.count, "unexpected answer") %> will be marked as correct.</p> |
||||||
|
|
||||||
|
<%= govuk_warning_text(icon_fallback_text: "Danger") do %> |
||||||
|
You can not delete logs once you create them |
||||||
|
<% end %> |
||||||
|
|
||||||
|
<%= form_with model: @form, scope: :form, url: page_bulk_upload_lettings_soft_validations_check_path(@bulk_upload, page: "confirm"), method: :patch do |f| %> |
||||||
|
<%= f.govuk_submit %> |
||||||
|
|
||||||
|
<%= govuk_button_link_to "Cancel", @form.back_path, secondary: true %> |
||||||
|
<% end %> |
||||||
|
</div> |
||||||
|
</div> |
@ -0,0 +1,32 @@ |
|||||||
|
<%= form_with model: @form, scope: :form, url: page_bulk_upload_lettings_soft_validations_check_path(@bulk_upload, page: "confirm-soft-errors"), method: :patch do |f| %> |
||||||
|
<div class="govuk-grid-row"> |
||||||
|
<div class="govuk-grid-column-two-thirds"> |
||||||
|
<%= f.govuk_error_summary %> |
||||||
|
|
||||||
|
<span class="govuk-caption-l">Bulk upload for lettings (<%= @bulk_upload.year_combo %>)</span> |
||||||
|
<h1 class="govuk-heading-l">Check these <%= pluralize(@bulk_upload.bulk_upload_errors.count, "answer") %> </h1> |
||||||
|
|
||||||
|
<p class="govuk-body-l">Some data from your bulk upload might not be right. Check your file for any errors in the fields below.</p> |
||||||
|
|
||||||
|
<p class="govuk-body"> |
||||||
|
<%= @bulk_upload.filename %> |
||||||
|
</p> |
||||||
|
</div> |
||||||
|
|
||||||
|
<div class="govuk-grid-column-full"> |
||||||
|
<% @bulk_upload.bulk_upload_errors.order_by_cell.group_by(&:row).each do |_row, errors_for_row| %> |
||||||
|
<%= render BulkUploadErrorRowComponent.new(bulk_upload_errors: errors_for_row) %> |
||||||
|
<% end %> |
||||||
|
</div> |
||||||
|
|
||||||
|
<div class="govuk-grid-column-full"> |
||||||
|
<%= f.govuk_collection_radio_buttons :confirm_soft_errors, |
||||||
|
@form.options, |
||||||
|
:id, |
||||||
|
:name, |
||||||
|
legend: { text: "Are these fields correct?", size: "l" } %> |
||||||
|
|
||||||
|
<%= f.govuk_submit %> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
<% end %> |
@ -0,0 +1,22 @@ |
|||||||
|
<% 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">Are you sure you want to upload all logs from this bulk upload?</h1> |
||||||
|
|
||||||
|
<p class="govuk-body">There are <%= pluralize(@bulk_upload.logs.count, "log") %> in this bulk upload, and <%= pluralize(@bulk_upload.bulk_upload_errors.count, "unexpected answer") %> will be marked as correct.</p> |
||||||
|
|
||||||
|
<%= govuk_warning_text(icon_fallback_text: "Danger") do %> |
||||||
|
You can not delete logs once you create them |
||||||
|
<% end %> |
||||||
|
|
||||||
|
<%= form_with model: @form, scope: :form, url: page_bulk_upload_sales_soft_validations_check_path(@bulk_upload, page: "confirm"), method: :patch do |f| %> |
||||||
|
<%= f.govuk_submit %> |
||||||
|
|
||||||
|
<%= govuk_button_link_to "Cancel", @form.back_path, secondary: true %> |
||||||
|
<% end %> |
||||||
|
</div> |
||||||
|
</div> |
@ -0,0 +1,32 @@ |
|||||||
|
<%= form_with model: @form, scope: :form, url: page_bulk_upload_sales_soft_validations_check_path(@bulk_upload, page: "confirm-soft-errors"), method: :patch do |f| %> |
||||||
|
<div class="govuk-grid-row"> |
||||||
|
<div class="govuk-grid-column-two-thirds"> |
||||||
|
<%= f.govuk_error_summary %> |
||||||
|
|
||||||
|
<span class="govuk-caption-l">Bulk upload for sales (<%= @bulk_upload.year_combo %>)</span> |
||||||
|
<h1 class="govuk-heading-l">Check these <%= pluralize(@bulk_upload.bulk_upload_errors.count, "answer") %> </h1> |
||||||
|
|
||||||
|
<p class="govuk-body-l">Some data from your bulk upload might not be right. Check your file for any errors in the fields below.</p> |
||||||
|
|
||||||
|
<p class="govuk-body"> |
||||||
|
<%= @bulk_upload.filename %> |
||||||
|
</p> |
||||||
|
</div> |
||||||
|
|
||||||
|
<div class="govuk-grid-column-full"> |
||||||
|
<% @bulk_upload.bulk_upload_errors.order_by_cell.group_by(&:row).each do |_row, errors_for_row| %> |
||||||
|
<%= render BulkUploadErrorRowComponent.new(bulk_upload_errors: errors_for_row) %> |
||||||
|
<% end %> |
||||||
|
</div> |
||||||
|
|
||||||
|
<div class="govuk-grid-column-full"> |
||||||
|
<%= f.govuk_collection_radio_buttons :confirm_soft_errors, |
||||||
|
@form.options, |
||||||
|
:id, |
||||||
|
:name, |
||||||
|
legend: { text: "Are these fields correct?", size: "l" } %> |
||||||
|
|
||||||
|
<%= f.govuk_submit %> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
<% end %> |
@ -0,0 +1,90 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
RSpec.describe BulkUploadLettingsSoftValidationsCheckController, type: :request do |
||||||
|
let(:user) { create(:user) } |
||||||
|
let(:bulk_upload) { create(:bulk_upload, :lettings, user:, bulk_upload_errors:) } |
||||||
|
let(:bulk_upload_errors) { create_list(:bulk_upload_error, 2) } |
||||||
|
|
||||||
|
before do |
||||||
|
create_list(:lettings_log, 2, bulk_upload:) |
||||||
|
sign_in user |
||||||
|
end |
||||||
|
|
||||||
|
describe "GET /lettings-logs/bulk-upload-soft-validations-check/:ID/confirm-soft-errors" do |
||||||
|
it "shows the soft validation errors with confirmation question" do |
||||||
|
get "/lettings-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/confirm-soft-errors" |
||||||
|
|
||||||
|
expect(response.body).to include("Bulk upload for lettings") |
||||||
|
expect(response.body).to include("2022/23") |
||||||
|
expect(response.body).to include("Check these 2 answers") |
||||||
|
expect(response.body).to include(bulk_upload.filename) |
||||||
|
expect(response.body).to include("Are these fields correct?") |
||||||
|
end |
||||||
|
|
||||||
|
it "shows the soft validation and lists the errors" do |
||||||
|
get "/lettings-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/confirm-soft-errors" |
||||||
|
|
||||||
|
expect(response.body).to include("Row #{bulk_upload_errors.first.row}") |
||||||
|
expect(response.body).to include("Tenant code") |
||||||
|
expect(response.body).to include("some error") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "PATCH /lettings-logs/bulk-upload-soft-validations-check/:ID/confirm-soft-errors" do |
||||||
|
context "when no option selected" do |
||||||
|
it "renders error message" do |
||||||
|
patch "/lettings-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/confirm-soft-errors" |
||||||
|
|
||||||
|
expect(response).to be_successful |
||||||
|
|
||||||
|
expect(response.body).to include("You must select if there are errors in these fields") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when no is selected" do |
||||||
|
it "sends them to the fix choice page" do |
||||||
|
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") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when yes is selected" do |
||||||
|
it "sends them to confirm choice" do |
||||||
|
patch "/lettings-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/confirm-soft-errors", params: { form: { confirm_soft_errors: "yes" } } |
||||||
|
|
||||||
|
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") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "GET /lettings-logs/bulk-upload-soft-validations-check/:ID/confirm" do |
||||||
|
it "renders page" do |
||||||
|
get "/lettings-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/confirm" |
||||||
|
|
||||||
|
expect(response).to be_successful |
||||||
|
|
||||||
|
expect(response.body).to include("Are you sure you want to upload all logs from this bulk upload?") |
||||||
|
expect(response.body).to include("There are 2 logs in this bulk upload, and 2 unexpected answers will be marked as correct.") |
||||||
|
expect(response.body).not_to include("You’ve successfully uploaded") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "PATCH /lettings-logs/bulk-upload-soft-validations-check/:ID/confirm" do |
||||||
|
let(:mock_processor) { instance_double(BulkUpload::Processor, approve_and_confirm_soft_validations: nil) } |
||||||
|
|
||||||
|
it "approves logs for creation" do |
||||||
|
allow(BulkUpload::Processor).to receive(:new).with(bulk_upload:).and_return(mock_processor) |
||||||
|
|
||||||
|
patch "/lettings-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/confirm" |
||||||
|
|
||||||
|
expect(mock_processor).to have_received(:approve_and_confirm_soft_validations) |
||||||
|
|
||||||
|
expect(response).to redirect_to("/lettings-logs") |
||||||
|
follow_redirect! |
||||||
|
expect(response.body).to include("You’ve successfully uploaded 2 logs") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,96 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
RSpec.describe BulkUploadSalesResumeController, type: :request do |
||||||
|
let(:user) { create(:user) } |
||||||
|
let(:bulk_upload) { create(:bulk_upload, :sales, user:, bulk_upload_errors:) } |
||||||
|
let(:bulk_upload_errors) { create_list(:bulk_upload_error, 2) } |
||||||
|
|
||||||
|
before do |
||||||
|
sign_in user |
||||||
|
end |
||||||
|
|
||||||
|
describe "GET /sales-logs/bulk-upload-resume/:ID/start" 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 |
||||||
|
|
||||||
|
describe "GET /sales-logs/bulk-upload-resume/:ID/fix-choice" do |
||||||
|
it "renders the page correctly" do |
||||||
|
get "/sales-logs/bulk-upload-resume/#{bulk_upload.id}/fix-choice" |
||||||
|
|
||||||
|
expect(response).to be_successful |
||||||
|
|
||||||
|
expect(response.body).to include("Bulk upload for sales") |
||||||
|
expect(response.body).to include("2022/23") |
||||||
|
expect(response.body).to include("How would you like to fix 2 errors?") |
||||||
|
expect(response.body).to include(bulk_upload.filename) |
||||||
|
expect(response.body).not_to include("Cancel") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "GET /sales-logs/bulk-upload-resume/:ID/fix-choice?soft_errors_only=true" do |
||||||
|
it "displays a cancel button" do |
||||||
|
get "/sales-logs/bulk-upload-resume/#{bulk_upload.id}/fix-choice?soft_errors_only=true" |
||||||
|
|
||||||
|
expect(response).to be_successful |
||||||
|
|
||||||
|
expect(response.body).to include("Bulk upload for sales") |
||||||
|
expect(response.body).to include("Cancel") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "PATCH /sales-logs/bulk-upload-resume/:ID/fix-choice" do |
||||||
|
context "when no option selected" do |
||||||
|
it "renders error message" do |
||||||
|
patch "/sales-logs/bulk-upload-resume/#{bulk_upload.id}/fix-choice" |
||||||
|
|
||||||
|
expect(response).to be_successful |
||||||
|
|
||||||
|
expect(response.body).to include("Select how you would like to fix these errors") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when upload again selected" do |
||||||
|
it "sends them to relevant report" 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}") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when fix inline selected" do |
||||||
|
it "sends them to confirm choice" 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") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "GET /sales-logs/bulk-upload-resume/:ID/confirm" do |
||||||
|
it "renders page" do |
||||||
|
get "/sales-logs/bulk-upload-resume/#{bulk_upload.id}/confirm" |
||||||
|
|
||||||
|
expect(response).to be_successful |
||||||
|
|
||||||
|
expect(response.body).to include("Are you sure") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "PATCH /sales-logs/bulk-upload-resume/:ID/confirm" do |
||||||
|
let(:mock_processor) { instance_double(BulkUpload::Processor, approve: nil) } |
||||||
|
|
||||||
|
it "approves logs for creation" do |
||||||
|
allow(BulkUpload::Processor).to receive(:new).with(bulk_upload:).and_return(mock_processor) |
||||||
|
|
||||||
|
patch "/sales-logs/bulk-upload-resume/#{bulk_upload.id}/confirm" |
||||||
|
|
||||||
|
expect(mock_processor).to have_received(:approve) |
||||||
|
|
||||||
|
expect(response).to redirect_to("/sales-logs/bulk-upload-results/#{bulk_upload.id}/resume") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,90 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
RSpec.describe BulkUploadSalesSoftValidationsCheckController, type: :request do |
||||||
|
let(:user) { create(:user) } |
||||||
|
let(:bulk_upload) { create(:bulk_upload, :sales, user:, bulk_upload_errors:) } |
||||||
|
let(:bulk_upload_errors) { create_list(:bulk_upload_error, 2) } |
||||||
|
|
||||||
|
before do |
||||||
|
create_list(:sales_log, 2, bulk_upload:) |
||||||
|
sign_in user |
||||||
|
end |
||||||
|
|
||||||
|
describe "GET /sales-logs/bulk-upload-soft-validations-check/:ID/confirm-soft-errors" do |
||||||
|
it "shows the soft validation errors with confirmation question" do |
||||||
|
get "/sales-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/confirm-soft-errors" |
||||||
|
|
||||||
|
expect(response.body).to include("Bulk upload for sales") |
||||||
|
expect(response.body).to include("2022/23") |
||||||
|
expect(response.body).to include("Check these 2 answers") |
||||||
|
expect(response.body).to include(bulk_upload.filename) |
||||||
|
expect(response.body).to include("Are these fields correct?") |
||||||
|
end |
||||||
|
|
||||||
|
it "shows the soft validation and lists the errors" do |
||||||
|
get "/sales-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/confirm-soft-errors" |
||||||
|
|
||||||
|
expect(response.body).to include("Row #{bulk_upload_errors.first.row}") |
||||||
|
expect(response.body).to include("Purchaser code") |
||||||
|
expect(response.body).to include("some error") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "PATCH /sales-logs/bulk-upload-soft-validations-check/:ID/confirm-soft-errors" do |
||||||
|
context "when no option selected" do |
||||||
|
it "renders error message" do |
||||||
|
patch "/sales-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/confirm-soft-errors" |
||||||
|
|
||||||
|
expect(response).to be_successful |
||||||
|
|
||||||
|
expect(response.body).to include("You must select if there are errors in these fields") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when no is selected" do |
||||||
|
it "sends them to the fix choice page" 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") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when yes is selected" do |
||||||
|
it "sends them to confirm choice" do |
||||||
|
patch "/sales-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/confirm-soft-errors", params: { form: { confirm_soft_errors: "yes" } } |
||||||
|
|
||||||
|
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") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "GET /sales-logs/bulk-upload-soft-validations-check/:ID/confirm" do |
||||||
|
it "renders page" do |
||||||
|
get "/sales-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/confirm" |
||||||
|
|
||||||
|
expect(response).to be_successful |
||||||
|
|
||||||
|
expect(response.body).to include("Are you sure you want to upload all logs from this bulk upload?") |
||||||
|
expect(response.body).to include("There are 2 logs in this bulk upload, and 2 unexpected answers will be marked as correct.") |
||||||
|
expect(response.body).not_to include("You’ve successfully uploaded") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "PATCH /sales-logs/bulk-upload-soft-validations-check/:ID/confirm" do |
||||||
|
let(:mock_processor) { instance_double(BulkUpload::Processor, approve_and_confirm_soft_validations: nil) } |
||||||
|
|
||||||
|
it "approves logs for creation" do |
||||||
|
allow(BulkUpload::Processor).to receive(:new).with(bulk_upload:).and_return(mock_processor) |
||||||
|
|
||||||
|
patch "/sales-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/confirm" |
||||||
|
|
||||||
|
expect(mock_processor).to have_received(:approve_and_confirm_soft_validations) |
||||||
|
|
||||||
|
expect(response).to redirect_to("/sales-logs") |
||||||
|
follow_redirect! |
||||||
|
expect(response.body).to include("You’ve successfully uploaded 2 logs") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue