Browse Source

Add soft errors valid page

pull/1615/head
Kat 3 years ago
parent
commit
328bcbcf6e
  1. 36
      app/controllers/bulk_upload_lettings_data_check_controller.rb
  2. 2
      app/mailers/bulk_upload_mailer.rb
  3. 23
      app/models/forms/bulk_upload_lettings_data_check/confirm.rb
  4. 40
      app/models/forms/bulk_upload_lettings_data_check/soft_errors_valid.rb
  5. 24
      app/views/bulk_upload_lettings_data_check/soft_errors_valid.html.erb
  6. 4
      config/locales/en.yml
  7. 7
      config/routes.rb
  8. 51
      spec/requests/bulk_upload_lettings_data_check_controller_spec.rb

36
app/controllers/bulk_upload_lettings_data_check_controller.rb

@ -0,0 +1,36 @@
class BulkUploadLettingsDataCheckController < ApplicationController
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!
redirect_to form.next_path
else
render form.view_path
end
end
private
def form
@form ||= case params[:page]
when "soft-errors-valid"
Forms::BulkUploadLettingsDataCheck::SoftErrorsValid.new(form_params.merge(bulk_upload: @bulk_upload))
when "confirm"
Forms::BulkUploadLettingsDataCheck::Confirm.new(form_params.merge(bulk_upload: @bulk_upload))
else
raise "invalid form"
end
end
def form_params
params.fetch(:form, {}).permit(:soft_errors_valid)
end
end

2
app/mailers/bulk_upload_mailer.rb

@ -29,7 +29,7 @@ class BulkUploadMailer < NotifyMailer
def send_check_soft_validations_mail(bulk_upload:) def send_check_soft_validations_mail(bulk_upload:)
title = "Check your file data" title = "Check your file data"
description = "Some of your #{bulk_upload.year_combo} #{bulk_upload.log_type} data might not be right. Click the link below to review the potential errors, and check your file to see if the data is correct." description = "Some of your #{bulk_upload.year_combo} #{bulk_upload.log_type} data might not be right. Click the link below to review the potential errors, and check your file to see if the data is correct."
cta_link = bulk_upload.sales? ? bulk_upload_sales_check_data_url(bulk_upload) : bulk_upload_lettings_check_data_url(bulk_upload) cta_link = bulk_upload.sales? ? bulk_upload_sales_data_check_url(bulk_upload) : bulk_upload_lettings_data_check_url(bulk_upload)
send_email( send_email(
bulk_upload.user.email, bulk_upload.user.email,

23
app/models/forms/bulk_upload_lettings_data_check/confirm.rb

@ -0,0 +1,23 @@
module Forms
module BulkUploadLettingsDataCheck
class Confirm
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
attribute :bulk_upload
def view_path
"bulk_upload_lettings_data_check/confirm"
end
def back_path
page_bulk_upload_lettings_data_check_path(bulk_upload, page: "soft-errors-valid")
end
def next_path
page_bulk_upload_lettings_resume_path(bulk_upload, page: "fix-choice")
end
end
end
end

40
app/models/forms/bulk_upload_lettings_data_check/soft_errors_valid.rb

@ -0,0 +1,40 @@
module Forms
module BulkUploadLettingsDataCheck
class SoftErrorsValid
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
attribute :bulk_upload
attribute :soft_errors_valid, :string
validates :soft_errors_valid, presence: true
def options
[
OpenStruct.new(id: "yes", name: "Yes, some of these are errors"),
OpenStruct.new(id: "no", name: "No, all the data is correct"),
]
end
def view_path
"bulk_upload_lettings_data_check/soft_errors_valid"
end
def next_path
case soft_errors_valid
when "yes"
page_bulk_upload_lettings_resume_path(bulk_upload, page: "fix-choice")
when "no"
page_bulk_upload_lettings_data_check_path(bulk_upload, page: "confirm")
else
raise "invalid choice"
end
end
def save!
true
end
end
end
end

24
app/views/bulk_upload_lettings_data_check/soft_errors_valid.html.erb

@ -0,0 +1,24 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= form_with model: @form, scope: :form, url: page_bulk_upload_lettings_data_check_path(@bulk_upload, page: "soft-errors-valid"), method: :patch do |f| %>
<%= 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">Some data from your bulk upload might not be right. Check your file for any errors in the fields below.</p>
<div class="govuk-body-l">
<%= @bulk_upload.filename %>
</div>
<%= f.govuk_collection_radio_buttons :soft_errors_valid,
@form.options,
:id,
:name,
legend: { text: "Are there any errors in these fields?", size: "l" } %>
<%= f.govuk_submit %>
<% end %>
</div>
</div>

4
config/locales/en.yml

@ -73,6 +73,10 @@ en:
choice: choice:
blank: You must select how would you like to fix errors blank: You must select how would you like to fix errors
inclusion: You must select one of the following options for how would like to fix errors inclusion: You must select one of the following options for how would like to fix errors
forms/bulk_upload_lettings_data_check/soft_errors_valid:
attributes:
soft_errors_valid:
blank: You must select if there are errors in these fields
activerecord: activerecord:
errors: errors:

7
config/routes.rb

@ -180,6 +180,13 @@ Rails.application.routes.draw do
end end
end end
resources :bulk_upload_lettings_data_check, path: "bulk-upload-data-check", only: %i[show update] do
member do
get "*page", to: "bulk_upload_lettings_data_check#show", as: "page"
patch "*page", to: "bulk_upload_lettings_data_check#update"
end
end
get "update-logs", to: "lettings_logs#update_logs" get "update-logs", to: "lettings_logs#update_logs"
end end

51
spec/requests/bulk_upload_lettings_data_check_controller_spec.rb

@ -0,0 +1,51 @@
require "rails_helper"
RSpec.describe BulkUploadLettingsDataCheckController, 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
sign_in user
end
describe "GET /lettings-logs/bulk-upload-data-check/:ID/soft-errors-valid" do
it "shows the soft validation errors with confirmation question" do
get "/lettings-logs/bulk-upload-data-check/#{bulk_upload.id}/soft-errors-valid"
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 there any errors in these fields?")
end
end
describe "PATCH /lettings-logs/bulk-upload-data-check/:ID/soft-errors-valid" do
context "when no option selected" do
it "renders error message" do
patch "/lettings-logs/bulk-upload-data-check/#{bulk_upload.id}/soft-errors-valid"
expect(response).to be_successful
expect(response.body).to include("You must select if there are errors in these fields")
end
end
context "when yes is selected" do
it "sends them to the fix choice page" do
patch "/lettings-logs/bulk-upload-data-check/#{bulk_upload.id}/soft-errors-valid", params: { form: { soft_errors_valid: "yes" } }
expect(response).to redirect_to("/lettings-logs/bulk-upload-resume/#{bulk_upload.id}/fix-choice")
end
end
context "when no is selected" do
it "sends them to confirm choice" do
patch "/lettings-logs/bulk-upload-data-check/#{bulk_upload.id}/soft-errors-valid", params: { form: { soft_errors_valid: "no" } }
expect(response).to redirect_to("/lettings-logs/bulk-upload-data-check/#{bulk_upload.id}/confirm")
end
end
end
end
Loading…
Cancel
Save