Skip to content

Commit

Permalink
build: add basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Feb 21, 2024
1 parent c240614 commit c0867fa
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 11 deletions.
10 changes: 8 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
13 changes: 7 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"flag"
"fmt"
"io"
"os"
"strings"
"text/tabwriter"
Expand All @@ -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
}
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down
82 changes: 82 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -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()))
})
}
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c0867fa

Please sign in to comment.