Browse Source

feat: make unique count track repeated errors across rows

pull/2142/head
natdeanlewissoftwire 2 years ago
parent
commit
e5b8151fb7
  1. 2
      app/helpers/logs_helper.rb
  2. 81
      spec/helpers/logs_helper_spec.rb

2
app/helpers/logs_helper.rb

@ -78,7 +78,7 @@ module LogsHelper
end end
def unique_answers_to_be_cleared(bulk_upload) def unique_answers_to_be_cleared(bulk_upload)
all_answers_to_be_cleared(bulk_upload.bulk_upload_errors).uniq(&:field) all_answers_to_be_cleared(bulk_upload.bulk_upload_errors).uniq { |error| [error.field, error.row] }
end end
def answers_to_be_deleted_title_text(bulk_upload) def answers_to_be_deleted_title_text(bulk_upload)

81
spec/helpers/logs_helper_spec.rb

@ -7,12 +7,14 @@ RSpec.describe LogsHelper, type: :helper do
context "with a lettings bulk upload with various errors" do context "with a lettings bulk upload with various errors" do
let(:bulk_upload) { create(:bulk_upload, :lettings) } let(:bulk_upload) { create(:bulk_upload, :lettings) }
context "with one row" do
before do before do
errors = [OpenStruct.new(attribute: "field_50", message: "you must answer field 50", category: :not_answered), errors = [OpenStruct.new(attribute: "field_50", message: "you must answer field 50", category: :not_answered),
OpenStruct.new(attribute: "field_60", message: "some compound error", category: :other_category), OpenStruct.new(attribute: "field_60", message: "some compound error", category: :other_category),
OpenStruct.new(attribute: "field_61", message: "some compound error", category: :other_category), OpenStruct.new(attribute: "field_61", message: "some compound error", category: :other_category),
OpenStruct.new(attribute: "field_61", message: "some other compound error that overlaps with a previous error field", category: :another_category), OpenStruct.new(attribute: "field_61", message: "some other compound error that overlaps with a previous error field", category: :another_category),
OpenStruct.new(attribute: "field_62", message: "some other compound error that overlaps with a previous error field", category: :another_category)] OpenStruct.new(attribute: "field_62", message: "some other compound error that overlaps with a previous error field", category: :another_category),
OpenStruct.new(attribute: "field_63", message: "some soft validation error", category: :soft_validation)]
errors.each do |error| errors.each do |error|
bulk_upload.bulk_upload_errors.create!( bulk_upload.bulk_upload_errors.create!(
field: error.attribute, field: error.attribute,
@ -33,20 +35,58 @@ RSpec.describe LogsHelper, type: :helper do
end end
end end
context "with multiple rows" do
before do
errors = [OpenStruct.new(attribute: "field_50", message: "you must answer field 50", category: :not_answered, row: 1),
OpenStruct.new(attribute: "field_60", message: "some compound error", category: :other_category, row: 1),
OpenStruct.new(attribute: "field_61", message: "some compound error", category: :other_category, row: 1),
OpenStruct.new(attribute: "field_61", message: "some other compound error that overlaps with a previous error field", category: :another_category, row: 1),
OpenStruct.new(attribute: "field_62", message: "some other compound error that overlaps with a previous error field", category: :another_category, row: 1),
OpenStruct.new(attribute: "field_63", message: "some soft validation error", category: :soft_validation, row: 1),
OpenStruct.new(attribute: "field_50", message: "you must answer field 50", category: :not_answered, row: 2),
OpenStruct.new(attribute: "field_60", message: "some compound error", category: :other_category, row: 2),
OpenStruct.new(attribute: "field_61", message: "some compound error", category: :other_category, row: 2),
OpenStruct.new(attribute: "field_61", message: "some other compound error that overlaps with a previous error field", category: :another_category, row: 2),
OpenStruct.new(attribute: "field_62", message: "some other compound error that overlaps with a previous error field", category: :another_category, row: 2),
OpenStruct.new(attribute: "field_63", message: "some soft validation error", category: :soft_validation, row: 2)]
errors.each do |error|
bulk_upload.bulk_upload_errors.create!(
field: error.attribute,
error: error.message,
tenant_code: "test",
property_ref: "test",
row: error.row,
cell: "test",
col: "test",
category: error.category,
)
end
end
it "returns the correct unique answers to be cleared" do
expect(result.count).to eq(6)
expect(result.map(&:field)).to match_array(%w[field_60 field_61 field_62 field_60 field_61 field_62])
end
end
end
context "with a sales bulk upload with various errors" do context "with a sales bulk upload with various errors" do
let(:bulk_upload) { create(:bulk_upload, :sales) } let(:bulk_upload) { create(:bulk_upload, :sales) }
context "with one row" do
before do before do
errors = [OpenStruct.new(attribute: "field_50", message: "you must answer field 50", category: :not_answered), errors = [OpenStruct.new(attribute: "field_50", message: "you must answer field 50", category: :not_answered),
OpenStruct.new(attribute: "field_60", message: "some compound error", category: :other_category), OpenStruct.new(attribute: "field_60", message: "some compound error", category: :other_category),
OpenStruct.new(attribute: "field_61", message: "some compound error", category: :other_category), OpenStruct.new(attribute: "field_61", message: "some compound error", category: :other_category),
OpenStruct.new(attribute: "field_61", message: "some other compound error that overlaps with a previous error field", category: :another_category), OpenStruct.new(attribute: "field_61", message: "some other compound error that overlaps with a previous error field", category: :another_category),
OpenStruct.new(attribute: "field_62", message: "some other compound error that overlaps with a previous error field", category: :another_category)] OpenStruct.new(attribute: "field_62", message: "some other compound error that overlaps with a previous error field", category: :another_category),
OpenStruct.new(attribute: "field_63", message: "some soft validation error", category: :soft_validation)]
errors.each do |error| errors.each do |error|
bulk_upload.bulk_upload_errors.create!( bulk_upload.bulk_upload_errors.create!(
field: error.attribute, field: error.attribute,
error: error.message, error: error.message,
purchaser_code: "test", tenant_code: "test",
property_ref: "test",
row: "test", row: "test",
cell: "test", cell: "test",
col: "test", col: "test",
@ -60,5 +100,40 @@ RSpec.describe LogsHelper, type: :helper do
expect(result.map(&:field)).to match_array(%w[field_60 field_61 field_62]) expect(result.map(&:field)).to match_array(%w[field_60 field_61 field_62])
end end
end end
context "with multiple rows" do
before do
errors = [OpenStruct.new(attribute: "field_50", message: "you must answer field 50", category: :not_answered, row: 1),
OpenStruct.new(attribute: "field_60", message: "some compound error", category: :other_category, row: 1),
OpenStruct.new(attribute: "field_61", message: "some compound error", category: :other_category, row: 1),
OpenStruct.new(attribute: "field_61", message: "some other compound error that overlaps with a previous error field", category: :another_category, row: 1),
OpenStruct.new(attribute: "field_62", message: "some other compound error that overlaps with a previous error field", category: :another_category, row: 1),
OpenStruct.new(attribute: "field_63", message: "some soft validation error", category: :soft_validation, row: 1),
OpenStruct.new(attribute: "field_50", message: "you must answer field 50", category: :not_answered, row: 2),
OpenStruct.new(attribute: "field_60", message: "some compound error", category: :other_category, row: 2),
OpenStruct.new(attribute: "field_61", message: "some compound error", category: :other_category, row: 2),
OpenStruct.new(attribute: "field_61", message: "some other compound error that overlaps with a previous error field", category: :another_category, row: 2),
OpenStruct.new(attribute: "field_62", message: "some other compound error that overlaps with a previous error field", category: :another_category, row: 2),
OpenStruct.new(attribute: "field_63", message: "some soft validation error", category: :soft_validation, row: 2)]
errors.each do |error|
bulk_upload.bulk_upload_errors.create!(
field: error.attribute,
error: error.message,
tenant_code: "test",
property_ref: "test",
row: error.row,
cell: "test",
col: "test",
category: error.category,
)
end
end
it "returns the correct unique answers to be cleared" do
expect(result.count).to eq(6)
expect(result.map(&:field)).to match_array(%w[field_60 field_61 field_62 field_60 field_61 field_62])
end
end
end
end end
end end

Loading…
Cancel
Save