|
18 | 18 | package ach |
19 | 19 |
|
20 | 20 | import ( |
| 21 | + "fmt" |
21 | 22 | "strings" |
22 | 23 | "testing" |
23 | 24 |
|
@@ -358,55 +359,152 @@ func TestCorrectedData__first(t *testing.T) { |
358 | 359 | } |
359 | 360 |
|
360 | 361 | func TestCorrectedData__ParseCorrectedData(t *testing.T) { |
361 | | - run := func(code, data string) *CorrectedData { |
| 362 | + run := func(code, data string, options ...correctedDataOption) *CorrectedData { |
362 | 363 | add := NewAddenda98() |
363 | 364 | add.ChangeCode = code |
364 | 365 | add.CorrectedData = data |
365 | | - return add.ParseCorrectedData() |
| 366 | + return add.ParseCorrectedData(options...) |
| 367 | + } |
| 368 | + |
| 369 | + cases := []struct { |
| 370 | + changeCode string |
| 371 | + correctedData string |
| 372 | + options []correctedDataOption |
| 373 | + |
| 374 | + expected *CorrectedData |
| 375 | + }{ |
| 376 | + { |
| 377 | + changeCode: "C01", |
| 378 | + correctedData: "123456789 ", |
| 379 | + expected: &CorrectedData{AccountNumber: "123456789"}, |
| 380 | + }, |
| 381 | + { |
| 382 | + changeCode: "C02", |
| 383 | + correctedData: "987654320 ", |
| 384 | + expected: &CorrectedData{RoutingNumber: "987654320"}, |
| 385 | + }, |
| 386 | + { |
| 387 | + changeCode: "C03", |
| 388 | + correctedData: "987654320 123456", |
| 389 | + expected: &CorrectedData{ |
| 390 | + AccountNumber: "123456", |
| 391 | + RoutingNumber: "987654320", |
| 392 | + }, |
| 393 | + }, |
| 394 | + { |
| 395 | + changeCode: "C03", |
| 396 | + correctedData: "987654320 123456", |
| 397 | + expected: &CorrectedData{ |
| 398 | + AccountNumber: "123456", |
| 399 | + RoutingNumber: "987654320", |
| 400 | + }, |
| 401 | + }, |
| 402 | + { |
| 403 | + changeCode: "C04", |
| 404 | + correctedData: "Jane Doe", |
| 405 | + expected: &CorrectedData{ |
| 406 | + Name: "Jane Doe", |
| 407 | + }, |
| 408 | + }, |
| 409 | + { |
| 410 | + changeCode: "C05", |
| 411 | + correctedData: "22 other", |
| 412 | + expected: &CorrectedData{ |
| 413 | + TransactionCode: 22, |
| 414 | + }, |
| 415 | + }, |
| 416 | + { |
| 417 | + changeCode: "C06", |
| 418 | + correctedData: "123456789 22", |
| 419 | + expected: &CorrectedData{ |
| 420 | + AccountNumber: "123456789", |
| 421 | + TransactionCode: 22, |
| 422 | + }, |
| 423 | + }, |
| 424 | + { |
| 425 | + changeCode: "C07", |
| 426 | + correctedData: "987654320 12345 22", |
| 427 | + expected: &CorrectedData{ |
| 428 | + RoutingNumber: "987654320", |
| 429 | + AccountNumber: "12345", |
| 430 | + TransactionCode: 22, |
| 431 | + }, |
| 432 | + }, |
| 433 | + { |
| 434 | + changeCode: "C07", |
| 435 | + correctedData: "9876543201242415 22", |
| 436 | + expected: &CorrectedData{ |
| 437 | + RoutingNumber: "987654320", |
| 438 | + AccountNumber: "1242415", |
| 439 | + TransactionCode: 22, |
| 440 | + }, |
| 441 | + }, |
| 442 | + { |
| 443 | + changeCode: "C07", |
| 444 | + correctedData: "9876543201242415 22", |
| 445 | + expected: &CorrectedData{ |
| 446 | + RoutingNumber: "987654320", |
| 447 | + AccountNumber: "1242415", |
| 448 | + TransactionCode: 22, |
| 449 | + }, |
| 450 | + }, |
| 451 | + { |
| 452 | + changeCode: "C07", |
| 453 | + correctedData: "1234", |
| 454 | + expected: nil, |
| 455 | + }, |
| 456 | + { |
| 457 | + changeCode: "C07", |
| 458 | + correctedData: "1234", |
| 459 | + options: []correctedDataOption{PartialCorrectedData()}, |
| 460 | + expected: &CorrectedData{ |
| 461 | + RoutingNumber: "1234 ", |
| 462 | + }, |
| 463 | + }, |
| 464 | + { |
| 465 | + changeCode: "C07", |
| 466 | + correctedData: "987654320 1234 1234 1234", |
| 467 | + expected: nil, |
| 468 | + }, |
| 469 | + { |
| 470 | + changeCode: "C07", |
| 471 | + correctedData: "987654320 1234 1234 1234", |
| 472 | + options: []correctedDataOption{PartialCorrectedData()}, |
| 473 | + expected: &CorrectedData{ |
| 474 | + AccountNumber: "1234", |
| 475 | + RoutingNumber: "987654320", |
| 476 | + TransactionCode: 1234, |
| 477 | + }, |
| 478 | + }, |
| 479 | + { |
| 480 | + changeCode: "C09", |
| 481 | + correctedData: "21345678 ", |
| 482 | + expected: &CorrectedData{ |
| 483 | + Identification: "21345678", |
| 484 | + }, |
| 485 | + }, |
| 486 | + { |
| 487 | + changeCode: "C99", |
| 488 | + correctedData: " ", |
| 489 | + expected: nil, |
| 490 | + }, |
| 491 | + { |
| 492 | + changeCode: "C99", |
| 493 | + correctedData: " ", |
| 494 | + options: []correctedDataOption{PartialCorrectedData()}, |
| 495 | + expected: nil, |
| 496 | + }, |
| 497 | + } |
| 498 | + |
| 499 | + for _, tc := range cases { |
| 500 | + name := fmt.Sprintf("%s/%s", tc.changeCode, strings.TrimSpace(tc.correctedData)) |
| 501 | + |
| 502 | + t.Run(name, func(t *testing.T) { |
| 503 | + got := run(tc.changeCode, tc.correctedData, tc.options...) |
| 504 | + require.Equal(t, tc.expected, got) |
| 505 | + }) |
366 | 506 | } |
367 | 507 |
|
368 | | - if v := run("C01", "123456789 "); v.AccountNumber != "123456789" { |
369 | | - t.Errorf("%#v", v) |
370 | | - } |
371 | | - if v := run("C02", "987654320 "); v.RoutingNumber != "987654320" { |
372 | | - t.Errorf("%#v", v) |
373 | | - } |
374 | | - if v := run("C03", "987654320 123456"); v.AccountNumber != "123456" || v.RoutingNumber != "987654320" { |
375 | | - t.Errorf("%#v", v) |
376 | | - } |
377 | | - if v := run("C03", "987654320 123456"); v.AccountNumber != "123456" || v.RoutingNumber != "987654320" { |
378 | | - t.Errorf("%#v", v) |
379 | | - } |
380 | | - if v := run("C04", "Jane Doe"); v.Name != "Jane Doe" { |
381 | | - t.Errorf("%#v", v) |
382 | | - } |
383 | | - if v := run("C05", "22 other"); v.TransactionCode != 22 { |
384 | | - t.Errorf("%#v", v) |
385 | | - } |
386 | | - if v := run("C06", "123456789 22"); v.AccountNumber != "123456789" || v.TransactionCode != 22 { |
387 | | - t.Errorf("%#v", v) |
388 | | - } |
389 | | - if v := run("C07", "987654320 12345 22"); v.RoutingNumber != "987654320" || v.AccountNumber != "12345" || v.TransactionCode != 22 { |
390 | | - t.Errorf("%#v", v) |
391 | | - } |
392 | | - if v := run("C07", "9876543201242415 22"); v.RoutingNumber != "987654320" || v.AccountNumber != "1242415" || v.TransactionCode != 22 { |
393 | | - t.Errorf("%#v", v) |
394 | | - } |
395 | | - if v := run("C07", "9876543201242415 22"); v.RoutingNumber != "987654320" || v.AccountNumber != "1242415" || v.TransactionCode != 22 { |
396 | | - t.Errorf("%#v", v) |
397 | | - } |
398 | | - if v := run("C07", "1234"); v != nil { |
399 | | - t.Errorf("expected nil: %v", v) |
400 | | - } |
401 | | - if v := run("C07", "987654320 1234 1234 1234"); v != nil { |
402 | | - t.Errorf("expected nil: %v", v) |
403 | | - } |
404 | | - if v := run("C09", "21345678 "); v.Identification != "21345678" { |
405 | | - t.Errorf("%#v", v) |
406 | | - } |
407 | | - if v := run("C99", " "); v != nil { |
408 | | - t.Error("expected nil CorrectedData") |
409 | | - } |
410 | 508 | } |
411 | 509 |
|
412 | 510 | func TestCorrectedData__WriteCorrectionData(t *testing.T) { |
|
0 commit comments