Browse Source

feat: copy changes to sales as well

pull/2142/head
natdeanlewissoftwire 2 years ago
parent
commit
e14c324d20
  1. 6
      app/controllers/bulk_upload_sales_results_controller.rb
  2. 8
      app/services/bulk_upload/sales/year2023/row_parser.rb
  3. 31
      app/views/bulk_upload_sales_results/deletion_report.html.erb
  4. 17
      app/views/bulk_upload_sales_resume/confirm.html.erb
  5. 4
      app/views/bulk_upload_sales_resume/fix_choice.html.erb
  6. 1
      config/routes.rb
  7. 52
      spec/requests/bulk_upload_sales_results_controller_spec.rb
  8. 6
      spec/requests/bulk_upload_sales_resume_controller_spec.rb

6
app/controllers/bulk_upload_sales_results_controller.rb

@ -27,6 +27,12 @@ class BulkUploadSalesResultsController < ApplicationController
authorize @bulk_upload
end
def deletion_report
@bulk_upload = BulkUpload.lettings.find(params[:id])
authorize @bulk_upload
end
private
def reset_logs_filters

8
app/services/bulk_upload/sales/year2023/row_parser.rb

@ -608,18 +608,18 @@ private
def validate_uprn_exists_if_any_key_address_fields_are_blank
if field_19.blank? && (field_20.blank? || field_22.blank?)
errors.add(:field_19, I18n.t("validations.not_answered", question: "UPRN"))
errors.add(:field_19, I18n.t("validations.not_answered", question: "UPRN"), category: :not_answered)
end
end
def validate_address_fields
if field_19.blank? || log.errors.attribute_names.include?(:uprn)
if field_20.blank?
errors.add(:field_20, I18n.t("validations.not_answered", question: "address line 1"))
errors.add(:field_20, I18n.t("validations.not_answered", question: "address line 1"), category: :not_answered)
end
if field_22.blank?
errors.add(:field_22, I18n.t("validations.not_answered", question: "town or city"))
errors.add(:field_22, I18n.t("validations.not_answered", question: "town or city"), category: :not_answered)
end
end
end
@ -1245,7 +1245,7 @@ private
else
fields.each do |field|
unless errors.any? { |e| fields.include?(e.attribute) }
errors.add(field, I18n.t("validations.not_answered", question: question.error_display_label&.downcase))
errors.add(field, I18n.t("validations.not_answered", question: question.error_display_label&.downcase), category: :not_answered)
end
end
end

31
app/views/bulk_upload_sales_results/deletion_report.html.erb

@ -0,0 +1,31 @@
<% content_for :before_content do %>
<%= govuk_back_link(href: :back) %>
<% 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"><%= pluralize(unique_answers_to_be_cleared(@bulk_upload).count, "answer") %> will be deleted if you upload the <%= "log".pluralize(@bulk_upload.logs.count) %></h1>
<p>The following cells contain data this is incorrect.</p>
<p>If you upload the logs, these answers will be deleted. You will have to re-enter the data on the site and resolve these errors.</p>
<p>If you do not want these answers to be deleted, correct the data in the CSV and upload the file again.</p>
<h2 class="govuk-heading-m">File: <%= @bulk_upload.filename %></h2>
</div>
</div>
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<% @bulk_upload.bulk_upload_errors.order_by_row.order_by_cell.group_by(&:row).each do |_row, errors_for_row| %>
<%= render BulkUploadErrorRowComponent.new(bulk_upload_errors: errors_for_row.reject { |e| e.category == :not_answered }) %>
<% end %>
</div>
</div>
<div class="govuk-button-group">
<%= form_with model: @form, scope: :form, url: page_bulk_upload_sales_resume_path(@bulk_upload, page: "confirm"), method: :patch do |f| %>
<%= f.govuk_submit "Clear this data and upload the logs" %>
<%= govuk_button_link_to "I have fixed these errors and I want to reupload the file", start_bulk_upload_sales_logs_path, secondary: true %>
<% end %>
</div>

17
app/views/bulk_upload_sales_resume/confirm.html.erb

@ -5,14 +5,23 @@
<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 have chosen to upload all logs from this bulk upload.</h1>
<h1 class="govuk-heading-l">Are you sure you want to upload all logs from this bulk upload?</h1>
<p class="govuk-body"><%= logs_and_errors_warning(@bulk_upload) %></p>
<p class="govuk-body">
<%= logs_and_errors_warning(@bulk_upload) %>
<%= govuk_link_to "View the error report", deletion_report_bulk_upload_sales_result_path %>
</p>
<%= form_with model: @form, scope: :form, url: page_bulk_upload_sales_resume_path(@bulk_upload, page: "confirm"), method: :patch do |f| %>
<%= f.govuk_submit %>
<%= govuk_warning_text do %>
<%= deleted_errors_warning_text(@bulk_upload) %>
<%= govuk_link_to "See which answers will be deleted", deletion_report_bulk_upload_sales_result_path %>
<% end %>
<div class="govuk-button-group">
<%= form_with model: @form, scope: :form, url: page_bulk_upload_sales_resume_path(@bulk_upload, page: "confirm"), method: :patch do |f| %>
<%= f.govuk_submit "Confirm" %>
<%= govuk_button_link_to "Cancel", @form.back_path, secondary: true %>
<% end %>
</div>
</div>
</div>

4
app/views/bulk_upload_sales_resume/fix_choice.html.erb

@ -18,6 +18,10 @@
<%= @form.recommendation %>
</div>
<div class="govuk-body">
<%= govuk_link_to "View the error report", deletion_report_bulk_upload_sales_result_path %>
</div>
<%= govuk_details(summary_text: "How to choose between fixing errors on the CORE site or in the CSV") do %>
<p class="govuk-body govuk-!-margin-bottom-2">You may find it easier to fix the errors in the CSV file if:</p>
<ul class="govuk-list govuk-list--bullet">

1
config/routes.rb

@ -284,6 +284,7 @@ Rails.application.routes.draw do
member do
get :resume
get :summary
get "deletion-report"
end
end

52
spec/requests/bulk_upload_sales_results_controller_spec.rb

@ -9,6 +9,58 @@ RSpec.describe BulkUploadSalesResultsController, type: :request do
sign_in user
end
describe "GET /sales-logs/bulk-upload-results/:ID/deletion-report" do
it "renders year combo" do
get "/sales-logs/bulk-upload-results/#{bulk_upload.id}/deletion-report"
expect(response).to be_successful
expect(response.body).to include("Bulk upload for sales (2022/23)")
end
it "renders the bulk upload filename" do
get "/sales-logs/bulk-upload-results/#{bulk_upload.id}/deletion-report"
expect(response.body).to include(bulk_upload.filename)
end
context "when viewed by support user" do
before do
allow(support_user).to receive(:need_two_factor_authentication?).and_return(false)
end
let(:viewing_user) { support_user }
it "is accessible" do
get "/sales-logs/bulk-upload-results/#{bulk_upload.id}/deletion-report"
expect(response).to be_successful
expect(response.body).to include(bulk_upload.filename)
end
end
context "when viewed by some other random user" do
let(:other_user) { create(:user) }
let(:viewing_user) { other_user }
it "is not accessible" do
get "/sales-logs/bulk-upload-results/#{bulk_upload.id}/deletion-report"
expect(response).to be_unauthorized
end
end
context "when viewed by another user in the same org" do
let(:other_user) { create(:user, organisation: user.organisation) }
let(:viewing_user) { other_user }
it "is accessible" do
get "/sales-logs/bulk-upload-results/#{bulk_upload.id}/deletion-report"
expect(response).to be_successful
expect(response.body).to include(bulk_upload.filename)
end
end
end
describe "GET /sales-logs/bulk-upload-results/:ID" do
it "renders correct year" do
get "/sales-logs/bulk-upload-results/#{bulk_upload.id}"

6
spec/requests/bulk_upload_sales_resume_controller_spec.rb

@ -17,6 +17,7 @@ RSpec.describe BulkUploadSalesResumeController, type: :request do
expect(response.body).to include("Bulk upload for sales")
expect(response.body).to include("2022/23")
expect(response.body).to include("View the error report")
expect(response.body).to include("How would you like to fix the errors?")
expect(response.body).to include(bulk_upload.filename)
expect(response.body).not_to include("Cancel")
@ -98,7 +99,10 @@ RSpec.describe BulkUploadSalesResumeController, type: :request do
expect(response).to be_successful
expect(response.body).to include("You have chosen to upload all logs from this bulk upload.")
expect(response.body).to include("Are you sure you want to upload all logs from this bulk upload?")
expect(response.body).to include("View the error report")
expect(response.body).to include("2 answers will be deleted because they are invalid.")
expect(response.body).to include("See which answers will be deleted")
end
it "sets no cache headers" do

Loading…
Cancel
Save