From c0867fab90a4320fe9ff672ce4d1322ef12d295c Mon Sep 17 00:00:00 2001 From: Adam Shannon Date: Wed, 21 Feb 2024 16:13:00 -0600 Subject: [PATCH] build: add basic test --- go.mod | 10 +++++-- go.sum | 4 +-- main.go | 13 +++++---- main_test.go | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++ makefile | 2 +- 5 files changed, 100 insertions(+), 11 deletions(-) create mode 100644 main_test.go diff --git a/go.mod b/go.mod index 0679f21..e23c5b7 100644 --- a/go.mod +++ b/go.mod @@ -2,14 +2,20 @@ module github.com/adamdecaf/aba go 1.22.0 -require github.com/moov-io/ach v1.34.2 +require ( + github.com/moov-io/ach v1.34.2 + github.com/moovfinancial/moov-go v0.0.0-20240221184051-2d979fd59695 + github.com/stretchr/testify v1.8.4 +) require ( + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/google/uuid v1.6.0 // indirect github.com/moov-io/base v0.48.5 // indirect github.com/moov-io/iso4217 v0.3.0 // indirect - github.com/moovfinancial/moov-go v0.0.0-20240221184051-2d979fd59695 // indirect + github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/rickar/cal/v2 v2.1.13 // indirect golang.org/x/net v0.20.0 // indirect golang.org/x/text v0.14.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 6509b6c..cb5ddb9 100644 --- a/go.sum +++ b/go.sum @@ -10,8 +10,6 @@ github.com/moov-io/base v0.48.5 h1:QaTyTo6eFFFV35R9l/GdePQN40IJti9knD5hqdWPnnM= github.com/moov-io/base v0.48.5/go.mod h1:D5ZV9COV/qtCjTQuYpq7gGInCk64AhOQI6UY4kt4Rq8= github.com/moov-io/iso4217 v0.3.0 h1:xAxeJEn7QIpEy971eElEGiaLNdj81UwOcCcvE6j2ZAo= github.com/moov-io/iso4217 v0.3.0/go.mod h1:/pF1mBInDSJtwyWkLNr8EMdIn1zIl2cyjaVi4Xhpd44= -github.com/moovfinancial/moov-go v0.0.0-20240221181024-76e3d4f4fb1b h1:9BNj/E8UF1y7ppYrmwpNldaVmNxGaLzizD965ZI0G0k= -github.com/moovfinancial/moov-go v0.0.0-20240221181024-76e3d4f4fb1b/go.mod h1:BuU0unYITq678ASZLxbdWZYdYi9HHjkHSBsbm8gjPDY= github.com/moovfinancial/moov-go v0.0.0-20240221184051-2d979fd59695 h1:NQHom3Az0JXdrZX1/yLpmg3LAIRzlx7KyoA2xTjhL4g= github.com/moovfinancial/moov-go v0.0.0-20240221184051-2d979fd59695/go.mod h1:BuU0unYITq678ASZLxbdWZYdYi9HHjkHSBsbm8gjPDY= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= @@ -24,5 +22,7 @@ golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go index f272082..86cb001 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "errors" "flag" "fmt" + "io" "os" "strings" "text/tabwriter" @@ -32,9 +33,9 @@ func main() { switch { case *flagAch: - printAchParticipants(resp.AchParticipants) + printAchParticipants(os.Stdout, resp.AchParticipants) case *flagWire: - printWireParticipants(resp.WireParticipants) + printWireParticipants(os.Stdout, resp.WireParticipants) default: fmt.Println(routingNumber) //nolint:forbidigo } @@ -77,8 +78,8 @@ func listRoutingNumbers(routingNumber string) (*moov.FinancialInstitutions, erro return resp, nil } -func printAchParticipants(participants []moov.AchParticipant) { - w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0) +func printAchParticipants(buf io.Writer, participants []moov.AchParticipant) { + w := tabwriter.NewWriter(buf, 0, 0, 2, ' ', 0) defer w.Flush() fmt.Fprintln(w, "Routing Number\tCustomer Name\tPhone Number\tAddress") @@ -90,8 +91,8 @@ func printAchParticipants(participants []moov.AchParticipant) { } } -func printWireParticipants(participants []moov.WireParticipant) { - w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0) +func printWireParticipants(buf io.Writer, participants []moov.WireParticipant) { + w := tabwriter.NewWriter(buf, 0, 0, 2, ' ', 0) defer w.Flush() fmt.Fprintln(w, "Routing Number\tTelegraphic Name\tCustomer Name\tFund Transfers\tSettlement Only\tBook Entry Transfers\tAddress") diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..1bd7247 --- /dev/null +++ b/main_test.go @@ -0,0 +1,82 @@ +package main + +import ( + "bytes" + "strings" + "testing" + + "github.com/moovfinancial/moov-go/pkg/moov" + + "github.com/stretchr/testify/require" +) + +func TestNormalizeRoutingNumber(t *testing.T) { + input := "12345678" + require.Equal(t, "123456780", normalizeRoutingNumber(input)) + + input = "123456780" + require.Equal(t, "123456780", normalizeRoutingNumber(input)) +} + +func TestPrint(t *testing.T) { + t.Run("ach", func(t *testing.T) { + var buf bytes.Buffer + + participants := []moov.AchParticipant{ + { + RoutingNumber: "021201383", + OfficeCode: "O", + ServicingFRBNumber: "021001208", + RecordTypeCode: "1", + Revised: "020222", + NewRoutingNumber: "000000000", + CustomerName: "VALLEY NATIONAL BANK", + PhoneNumber: "9733058800", + StatusCode: "1", + ViewCode: "1", + AchLocation: moov.AchLocation{ + Address: "ACH DEPARTMENT 4TH FLOOR", + City: "WAYNE", + State: "NJ", + PostalCode: "07470", + PostalCodeExtension: "0000", + }, + }, + } + printAchParticipants(&buf, participants) + + expected := strings.TrimSpace(` +Routing Number Customer Name Phone Number Address +021201383 VALLEY NATIONAL BANK 9733058800 ACH DEPARTMENT 4TH FLOOR WAYNE NJ 07470 +`) + require.Equal(t, expected, strings.TrimSpace(buf.String())) + + }) + + t.Run("wire", func(t *testing.T) { + var buf bytes.Buffer + + participants := []moov.WireParticipant{ + { + RoutingNumber: "273976369", + TelegraphicName: "VERIDIAN", + CustomerName: "VERIDIAN CREDIT UNION", + Location: moov.WireLocation{ + City: "", + State: "", + }, + FundsTransferStatus: "Y", + FundsSettlementOnlyStatus: " ", + BookEntrySecuritiesTransferStatus: "N", + Date: "20141107", + }, + } + printWireParticipants(&buf, participants) + + expected := strings.TrimSpace(` +Routing Number Telegraphic Name Customer Name Fund Transfers Settlement Only Book Entry Transfers Address +273976369 VERIDIAN VERIDIAN CREDIT UNION Y N N +`) + require.Equal(t, expected, strings.TrimSpace(buf.String())) + }) +} diff --git a/makefile b/makefile index c2bde5a..90ee048 100644 --- a/makefile +++ b/makefile @@ -5,7 +5,7 @@ ifeq ($(OS),Windows_NT) else @wget -O lint-project.sh https://raw.githubusercontent.com/moov-io/infra/master/go/lint-project.sh @chmod +x ./lint-project.sh - COVER_THRESHOLD=50.0 ./lint-project.sh + COVER_THRESHOLD=25.0 ./lint-project.sh endif .PHONY: clean