feat: adds error capping
This commit is contained in:
parent
c31392e4fe
commit
3cbd90ecdd
2 changed files with 161 additions and 2 deletions
|
|
@ -325,6 +325,136 @@ defmodule Mv.Membership.Import.MemberCSVTest do
|
|||
# Check that @doc exists by reading the module
|
||||
assert function_exported?(MemberCSV, :process_chunk, 4)
|
||||
end
|
||||
|
||||
test "error capping collects exactly 50 errors" do
|
||||
# Create 50 rows with invalid emails
|
||||
chunk_rows_with_lines =
|
||||
1..50
|
||||
|> Enum.map(fn i ->
|
||||
{i + 1, %{member: %{email: "invalid-email-#{i}"}, custom: %{}}}
|
||||
end)
|
||||
|
||||
column_map = %{email: 0}
|
||||
custom_field_map = %{}
|
||||
opts = [existing_error_count: 0, max_errors: 50]
|
||||
|
||||
assert {:ok, chunk_result} =
|
||||
MemberCSV.process_chunk(chunk_rows_with_lines, column_map, custom_field_map, opts)
|
||||
|
||||
assert chunk_result.inserted == 0
|
||||
assert chunk_result.failed == 50
|
||||
assert length(chunk_result.errors) == 50
|
||||
end
|
||||
|
||||
test "error capping collects only first 50 errors when more than 50 errors occur" do
|
||||
# Create 60 rows with invalid emails
|
||||
chunk_rows_with_lines =
|
||||
1..60
|
||||
|> Enum.map(fn i ->
|
||||
{i + 1, %{member: %{email: "invalid-email-#{i}"}, custom: %{}}}
|
||||
end)
|
||||
|
||||
column_map = %{email: 0}
|
||||
custom_field_map = %{}
|
||||
opts = [existing_error_count: 0, max_errors: 50]
|
||||
|
||||
assert {:ok, chunk_result} =
|
||||
MemberCSV.process_chunk(chunk_rows_with_lines, column_map, custom_field_map, opts)
|
||||
|
||||
assert chunk_result.inserted == 0
|
||||
assert chunk_result.failed == 60
|
||||
assert length(chunk_result.errors) == 50
|
||||
end
|
||||
|
||||
test "error capping respects existing_error_count" do
|
||||
# Create 30 rows with invalid emails
|
||||
chunk_rows_with_lines =
|
||||
1..30
|
||||
|> Enum.map(fn i ->
|
||||
{i + 1, %{member: %{email: "invalid-email-#{i}"}, custom: %{}}}
|
||||
end)
|
||||
|
||||
column_map = %{email: 0}
|
||||
custom_field_map = %{}
|
||||
opts = [existing_error_count: 25, max_errors: 50]
|
||||
|
||||
assert {:ok, chunk_result} =
|
||||
MemberCSV.process_chunk(chunk_rows_with_lines, column_map, custom_field_map, opts)
|
||||
|
||||
assert chunk_result.inserted == 0
|
||||
assert chunk_result.failed == 30
|
||||
# Should only collect 25 errors (25 existing + 25 new = 50 limit)
|
||||
assert length(chunk_result.errors) == 25
|
||||
end
|
||||
|
||||
test "error capping collects no errors when limit already reached" do
|
||||
# Create 10 rows with invalid emails
|
||||
chunk_rows_with_lines =
|
||||
1..10
|
||||
|> Enum.map(fn i ->
|
||||
{i + 1, %{member: %{email: "invalid-email-#{i}"}, custom: %{}}}
|
||||
end)
|
||||
|
||||
column_map = %{email: 0}
|
||||
custom_field_map = %{}
|
||||
opts = [existing_error_count: 50, max_errors: 50]
|
||||
|
||||
assert {:ok, chunk_result} =
|
||||
MemberCSV.process_chunk(chunk_rows_with_lines, column_map, custom_field_map, opts)
|
||||
|
||||
assert chunk_result.inserted == 0
|
||||
assert chunk_result.failed == 10
|
||||
assert length(chunk_result.errors) == 0
|
||||
end
|
||||
|
||||
test "error capping with mixed success and failure" do
|
||||
# Create 100 rows: 30 valid, 70 invalid
|
||||
valid_rows =
|
||||
1..30
|
||||
|> Enum.map(fn i ->
|
||||
{i + 1, %{member: %{email: "valid#{i}@example.com"}, custom: %{}}}
|
||||
end)
|
||||
|
||||
invalid_rows =
|
||||
31..100
|
||||
|> Enum.map(fn i ->
|
||||
{i + 1, %{member: %{email: "invalid-email-#{i}"}, custom: %{}}}
|
||||
end)
|
||||
|
||||
chunk_rows_with_lines = valid_rows ++ invalid_rows
|
||||
|
||||
column_map = %{email: 0}
|
||||
custom_field_map = %{}
|
||||
opts = [existing_error_count: 0, max_errors: 50]
|
||||
|
||||
assert {:ok, chunk_result} =
|
||||
MemberCSV.process_chunk(chunk_rows_with_lines, column_map, custom_field_map, opts)
|
||||
|
||||
assert chunk_result.inserted == 30
|
||||
assert chunk_result.failed == 70
|
||||
# Should only collect 50 errors (limit reached)
|
||||
assert length(chunk_result.errors) == 50
|
||||
end
|
||||
|
||||
test "error capping with custom max_errors" do
|
||||
# Create 20 rows with invalid emails
|
||||
chunk_rows_with_lines =
|
||||
1..20
|
||||
|> Enum.map(fn i ->
|
||||
{i + 1, %{member: %{email: "invalid-email-#{i}"}, custom: %{}}}
|
||||
end)
|
||||
|
||||
column_map = %{email: 0}
|
||||
custom_field_map = %{}
|
||||
opts = [existing_error_count: 0, max_errors: 10]
|
||||
|
||||
assert {:ok, chunk_result} =
|
||||
MemberCSV.process_chunk(chunk_rows_with_lines, column_map, custom_field_map, opts)
|
||||
|
||||
assert chunk_result.inserted == 0
|
||||
assert chunk_result.failed == 20
|
||||
assert length(chunk_result.errors) == 10
|
||||
end
|
||||
end
|
||||
|
||||
describe "validate_row/3" do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue