Browse Source

Update wrong template errors

pull/2719/head
Kat 8 months ago
parent
commit
55f1eae088
  1. 27
      app/services/bulk_upload/processor.rb
  2. 8
      app/services/bulk_upload/sales/validator.rb
  3. 11
      config/locales/validations/sales/2023/bulk_upload.en.yml
  4. 11
      config/locales/validations/sales/2024/bulk_upload.en.yml
  5. 2
      spec/services/bulk_upload/sales/validator_spec.rb

27
app/services/bulk_upload/processor.rb

@ -1,15 +1,22 @@
class BulkUpload::Processor class BulkUpload::Processor
include CollectionTimeHelper
attr_reader :bulk_upload attr_reader :bulk_upload
BLANK_TEMPLATE_ERRORS = [ def blank_template_errors
I18n.t("activemodel.errors.models.bulk_upload/lettings/validator.attributes.base.blank_file"), [
I18n.t("validations.sales.2024.bulk_upload.blank_file"), I18n.t("activemodel.errors.models.bulk_upload/lettings/validator.attributes.base.blank_file"),
].freeze I18n.t("validations.sales.#{current_collection_start_year}.bulk_upload.blank_file"),
I18n.t("validations.sales.#{previous_collection_start_year}.bulk_upload.blank_file"),
].freeze
end
WRONG_TEMPLATE_ERRORS = [ def wrong_template_errors
*I18n.t("activemodel.errors.models.bulk_upload/lettings/validator.attributes.base", default: {}).values, [
*I18n.t("validations.sales.2024", default: {}).values, *I18n.t("activemodel.errors.models.bulk_upload/lettings/validator.attributes.base", default: {}).values,
].freeze *I18n.t("validations.sales.#{current_collection_start_year}.bulk_upload.wrong_template", default: {}).values,
*I18n.t("validations.sales.#{previous_collection_start_year}.bulk_upload.wrong_template", default: {}).values,
].freeze
end
def initialize(bulk_upload:) def initialize(bulk_upload:)
@bulk_upload = bulk_upload @bulk_upload = bulk_upload
@ -157,9 +164,9 @@ private
end end
def handle_invalid_validator def handle_invalid_validator
if BLANK_TEMPLATE_ERRORS.any? { |error| validator.errors.full_messages.include?(error) } if blank_template_errors.any? { |error| validator.errors.full_messages.include?(error) }
@bulk_upload.update!(failure_reason: "blank_template") @bulk_upload.update!(failure_reason: "blank_template")
elsif WRONG_TEMPLATE_ERRORS.any? { |error| validator.errors.full_messages.include?(error) } elsif wrong_template_errors.any? { |error| validator.errors.full_messages.include?(error) }
@bulk_upload.update!(failure_reason: "wrong_template") @bulk_upload.update!(failure_reason: "wrong_template")
end end

8
app/services/bulk_upload/sales/validator.rb

@ -164,20 +164,20 @@ private
column_count = rows.map(&:size).max column_count = rows.map(&:size).max
errors.add(:base, I18n.t("validations.sales.#{@bulk_upload.year}.bulk_upload.over_max_column_count")) if column_count > csv_parser.class::MAX_COLUMNS errors.add(:base, I18n.t("validations.sales.#{@bulk_upload.year}.bulk_upload.wrong_template.over_max_column_count")) if column_count > csv_parser.class::MAX_COLUMNS
end end
def validate_correct_template def validate_correct_template
return if halt_validations? return if halt_validations?
errors.add(:base, I18n.t("validations.sales.#{@bulk_upload.year}.bulk_upload.wrong_template")) if csv_parser.wrong_template_for_year? errors.add(:base, I18n.t("validations.sales.#{@bulk_upload.year}.bulk_upload.wrong_template.wrong_template")) if csv_parser.wrong_template_for_year?
end end
def validate_missing_required_headers def validate_missing_required_headers
return if halt_validations? return if halt_validations?
if csv_parser.missing_required_headers? if csv_parser.missing_required_headers?
errors.add :base, I18n.t("validations.sales.#{@bulk_upload.year}.bulk_upload.no_headers", guidance_link: bulk_upload_sales_log_url(id: "guidance", form: { year: bulk_upload.year }, host: ENV["APP_HOST"], anchor: "using-the-bulk-upload-template")) errors.add :base, I18n.t("validations.sales.#{@bulk_upload.year}.bulk_upload.wrong_template.no_headers", guidance_link: bulk_upload_sales_log_url(id: "guidance", form: { year: bulk_upload.year }, host: ENV["APP_HOST"], anchor: "using-the-bulk-upload-template"))
end end
end end
@ -185,7 +185,7 @@ private
return if halt_validations? return if halt_validations?
unless csv_parser.correct_field_count? unless csv_parser.correct_field_count?
errors.add(:base, I18n.t("validations.sales.#{@bulk_upload.year}.bulk_upload.wrong_field_numbers_count")) errors.add(:base, I18n.t("validations.sales.#{@bulk_upload.year}.bulk_upload.wrong_template.wrong_field_numbers_count"))
halt_validations! halt_validations!
end end
end end

11
config/locales/validations/sales/2023/bulk_upload.en.yml

@ -3,15 +3,16 @@ en:
sales: sales:
2023: 2023:
bulk_upload: bulk_upload:
blank_file: "Template is blank - The template must be filled in for us to create the logs and check if data is correct."
over_max_column_count: "Too many columns, please ensure you have used the correct template."
no_headers: "Your file does not contain the required header rows. Add or check the header rows and upload your file again. [Read more about using the template headers](%{guidance_link})."
wrong_field_numbers_count: "Incorrect number of fields, please ensure you have used the correct template."
wrong_template: "Incorrect sale dates, please ensure you have used the correct template."
not_answered: "You must answer %{question}" not_answered: "You must answer %{question}"
invalid_option: "Enter a valid value for %{question}" invalid_option: "Enter a valid value for %{question}"
spreadsheet_dupe: "This is a duplicate of a log in your file." spreadsheet_dupe: "This is a duplicate of a log in your file."
duplicate: "This is a duplicate log." duplicate: "This is a duplicate log."
blank_file: "Template is blank - The template must be filled in for us to create the logs and check if data is correct."
wrong_template:
wrong_template: "Incorrect sale dates, please ensure you have used the correct template."
no_headers: "Your file does not contain the required header rows. Add or check the header rows and upload your file again. [Read more about using the template headers](%{guidance_link})."
wrong_field_numbers_count: "Incorrect number of fields, please ensure you have used the correct template."
over_max_column_count: "Too many columns, please ensure you have used the correct template."
owning_organisation: owning_organisation:
not_answered: "The owning organisation code is incorrect." not_answered: "The owning organisation code is incorrect."
not_found: "The owning organisation code is incorrect." not_found: "The owning organisation code is incorrect."

11
config/locales/validations/sales/2024/bulk_upload.en.yml

@ -3,15 +3,16 @@ en:
sales: sales:
2024: 2024:
bulk_upload: bulk_upload:
blank_file: "Template is blank - The template must be filled in for us to create the logs and check if data is correct."
over_max_column_count: "Too many columns, please ensure you have used the correct template."
no_headers: "Your file does not contain the required header rows. Add or check the header rows and upload your file again. [Read more about using the template headers](%{guidance_link})."
wrong_field_numbers_count: "Incorrect number of fields, please ensure you have used the correct template."
wrong_template: "Incorrect sale dates, please ensure you have used the correct template."
not_answered: "You must answer %{question}" not_answered: "You must answer %{question}"
invalid_option: "Enter a valid value for %{question}" invalid_option: "Enter a valid value for %{question}"
spreadsheet_dupe: "This is a duplicate of a log in your file." spreadsheet_dupe: "This is a duplicate of a log in your file."
duplicate: "This is a duplicate log." duplicate: "This is a duplicate log."
blank_file: "Template is blank - The template must be filled in for us to create the logs and check if data is correct."
wrong_template:
over_max_column_count: "Too many columns, please ensure you have used the correct template."
no_headers: "Your file does not contain the required header rows. Add or check the header rows and upload your file again. [Read more about using the template headers](%{guidance_link})."
wrong_field_numbers_count: "Incorrect number of fields, please ensure you have used the correct template."
wrong_template: "Incorrect sale dates, please ensure you have used the correct template."
numeric: numeric:
within_range: "%{field} must be between %{min} and %{max}." within_range: "%{field} must be between %{min} and %{max}."
owning_organisation: owning_organisation:

2
spec/services/bulk_upload/sales/validator_spec.rb

@ -54,7 +54,7 @@ RSpec.describe BulkUpload::Sales::Validator do
it "is not valid" do it "is not valid" do
expect(validator).not_to be_valid expect(validator).not_to be_valid
expect(validator.errors["base"]).to eql([I18n.t("validations.sales.2024.bulk_upload.wrong_template")]) expect(validator.errors["base"]).to eql([I18n.t("validations.sales.2024.bulk_upload.wrong_template.wrong_template")])
end end
end end

Loading…
Cancel
Save