Skip to content

Commit

Permalink
Merge pull request #394 from moov-io/Add-const-values-for-BatchHeader…
Browse files Browse the repository at this point in the history
….ServiceClassCode

Add const values for batch header.service class code
  • Loading branch information
bkmoovio authored Dec 6, 2018
2 parents e1246a0 + 04887ba commit e4f7177
Show file tree
Hide file tree
Showing 75 changed files with 438 additions and 429 deletions.
7 changes: 2 additions & 5 deletions advBatchControl.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ type ADVBatchControl struct {
ID string `json:"id"`
// RecordType defines the type of record in the block.
recordType string
// ServiceClassCode ACH Mixed Debits and Credits ‘200’
// ACH Credits Only ‘220’
// ACH Debits Only ‘225'
// Same as 'ServiceClassCode' in BatchHeaderRecord
// This should be the same as BatchHeader ServiceClassCode for ADV: AutomatedAccountingAdvices.
ServiceClassCode int `json:"serviceClassCode"`
// EntryAddendaCount is a tally of each Entry Detail Record and each Addenda
// Record processed, within either the batch or file as appropriate.
Expand Down Expand Up @@ -83,7 +80,7 @@ func (bc *ADVBatchControl) Parse(record string) {
func NewADVBatchControl() *ADVBatchControl {
return &ADVBatchControl{
recordType: "8",
ServiceClassCode: 280,
ServiceClassCode: AutomatedAccountingAdvices,
EntryHash: 1,
BatchNumber: 1,
}
Expand Down
14 changes: 7 additions & 7 deletions advBatchControl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func mockADVBatchControl() *ADVBatchControl {
bc := NewADVBatchControl()
bc.ServiceClassCode = 220
bc.ServiceClassCode = CreditsOnly
bc.ACHOperatorData = "T-BANK"
bc.ODFIIdentification = "12104288"
return bc
Expand All @@ -23,7 +23,7 @@ func testMockADVBatchControl(t testing.TB) {
if err := bc.Validate(); err != nil {
t.Error("mockADVBatchControl does not validate and will break other tests")
}
if bc.ServiceClassCode != 220 {
if bc.ServiceClassCode != CreditsOnly {
t.Error("ServiceClassCode depedendent default value has changed")
}
if bc.ACHOperatorData != "T-BANK" {
Expand All @@ -49,12 +49,12 @@ func BenchmarkMockADVBatchControl(b *testing.B) {

// TestParseADVBatchControl parses a known Batch ControlRecord string.
func testParseADVBatchControl(t testing.TB) {
var line = "822500000100053200010000000000000001050000000000000000000000T-BANK 076401250000001"
var line = "828000000100053200010000000000000001050000000000000000000000T-BANK 076401250000001"
r := NewReader(strings.NewReader(line))
r.line = line
bh := BatchHeader{BatchNumber: 1,
StandardEntryClassCode: "ADV",
ServiceClassCode: 280,
ServiceClassCode: AutomatedAccountingAdvices,
CompanyIdentification: "origid",
ODFIIdentification: "12104288"}
r.addCurrentBatch(NewBatchADV(&bh))
Expand All @@ -68,8 +68,8 @@ func testParseADVBatchControl(t testing.TB) {
if record.recordType != "8" {
t.Errorf("RecordType Expected '8' got: %v", record.recordType)
}
if record.ServiceClassCode != 225 {
t.Errorf("ServiceClassCode Expected '225' got: %v", record.ServiceClassCode)
if record.ServiceClassCode != AutomatedAccountingAdvices {
t.Errorf("ServiceClassCode Expected '280' got: %v", record.ServiceClassCode)
}
if record.EntryAddendaCountField() != "000001" {
t.Errorf("EntryAddendaCount Expected '000001' got: %v", record.EntryAddendaCountField())
Expand Down Expand Up @@ -114,7 +114,7 @@ func testADVBCString(t testing.TB) {
r.line = line
bh := BatchHeader{BatchNumber: 1,
StandardEntryClassCode: "ADV",
ServiceClassCode: 280,
ServiceClassCode: AutomatedAccountingAdvices,
CompanyIdentification: "origid",
ODFIIdentification: "12104288"}
r.addCurrentBatch(NewBatchADV(&bh))
Expand Down
4 changes: 2 additions & 2 deletions advEntryDetail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func testADVEDString(t testing.TB) {
r.line = line
bh := BatchHeader{BatchNumber: 1,
StandardEntryClassCode: "ADV",
ServiceClassCode: 280,
ServiceClassCode: AutomatedAccountingAdvices,
CompanyIdentification: "origid",
ODFIIdentification: "121042882"}
r.addCurrentBatch(NewBatchADV(&bh))
Expand Down Expand Up @@ -363,7 +363,7 @@ func TestInvalidADVEDParse(t *testing.T) {
r.line = line
bh := BatchHeader{BatchNumber: 1,
StandardEntryClassCode: "ADV",
ServiceClassCode: 280,
ServiceClassCode: AutomatedAccountingAdvices,
CompanyIdentification: "origid",
ODFIIdentification: "121042882"}
r.addCurrentBatch(NewBatchADV(&bh))
Expand Down
22 changes: 11 additions & 11 deletions batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ type Batch struct {
converters
}

func (b *Batch) UnmarshalJSON(p []byte) error {
b.Header = NewBatchHeader()
b.Control = NewBatchControl()
b.ADVControl = NewADVBatchControl()
func (batch *Batch) UnmarshalJSON(p []byte) error {
batch.Header = NewBatchHeader()
batch.Control = NewBatchControl()
batch.ADVControl = NewADVBatchControl()

type Alias Batch
aux := struct {
*Alias
}{
(*Alias)(b),
(*Alias)(batch),
}
if err := json.Unmarshal(p, &aux); err != nil {
return err
Expand Down Expand Up @@ -786,17 +786,17 @@ func (batch *Batch) ValidTranCodeForServiceClassCode(entry *EntryDetail) error {
}

switch batch.Header.ServiceClassCode {
case 280:
case AutomatedAccountingAdvices:
msg := fmt.Sprintf(msgBatchServiceClassTranCode, batch.Header.ServiceClassCode, batch.Header.StandardEntryClassCode)
return &BatchError{BatchNumber: batch.Header.BatchNumber, FieldName: "ServiceClassCode", Msg: msg}
case 200:
case 220:
if entry.CreditOrDebit() == "D" {
case MixedDebitsAndCredits:
case CreditsOnly:
if entry.CreditOrDebit() != "C" {
msg := fmt.Sprintf(msgBatchServiceClassTranCode, entry.TransactionCode, batch.Header.ServiceClassCode)
return &BatchError{BatchNumber: batch.Header.BatchNumber, FieldName: "TransactionCode", Msg: msg}
}
case 225:
if entry.CreditOrDebit() == "C" {
case DebitsOnly:
if entry.CreditOrDebit() != "D" {
msg := fmt.Sprintf(msgBatchServiceClassTranCode, entry.TransactionCode, batch.Header.ServiceClassCode)
return &BatchError{BatchNumber: batch.Header.BatchNumber, FieldName: "TransactionCode", Msg: msg}
}
Expand Down
4 changes: 2 additions & 2 deletions batchACK_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// mockBatchACKHeader creates a ACK batch header
func mockBatchACKHeader() *BatchHeader {
bh := NewBatchHeader()
bh.ServiceClassCode = 220
bh.ServiceClassCode = CreditsOnly
bh.StandardEntryClassCode = "ACK"
bh.CompanyName = "Your Company, inc"
bh.CompanyIdentification = "231380104"
Expand Down Expand Up @@ -361,7 +361,7 @@ func TestBatchACKAddendum99Category(t *testing.T) {
// TestBatchACKValidTranCodeForServiceClassCode validates a transactionCode based on ServiceClassCode
func TestBatchACKValidTranCodeForServiceClassCode(t *testing.T) {
mockBatch := mockBatchACK()
mockBatch.GetHeader().ServiceClassCode = 225
mockBatch.GetHeader().ServiceClassCode = DebitsOnly
if err := mockBatch.Create(); err != nil {
if e, ok := err.(*BatchError); ok {
if e.FieldName != "TransactionCode" {
Expand Down
2 changes: 1 addition & 1 deletion batchADV.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (batch *BatchADV) Validate() error {
msg := fmt.Sprintf(msgBatchSECType, batch.Header.StandardEntryClassCode, "ADV")
return &BatchError{BatchNumber: batch.Header.BatchNumber, FieldName: "StandardEntryClassCode", Msg: msg}
}
if batch.Header.ServiceClassCode != 280 {
if batch.Header.ServiceClassCode != AutomatedAccountingAdvices {
msg := fmt.Sprintf(msgBatchSECType, batch.Header.ServiceClassCode, "ADV")
return &BatchError{BatchNumber: batch.Header.BatchNumber, FieldName: "ServiceClassCode", Msg: msg}
}
Expand Down
2 changes: 1 addition & 1 deletion batchADV_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
// mockBatchADVHeader creates a ADV batch header
func mockBatchADVHeader() *BatchHeader {
bh := NewBatchHeader()
bh.ServiceClassCode = 280
bh.ServiceClassCode = AutomatedAccountingAdvices
bh.StandardEntryClassCode = "ADV"
bh.CompanyName = "Your Company, inc"
bh.CompanyIdentification = "121042882"
Expand Down
2 changes: 1 addition & 1 deletion batchARC.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (batch *BatchARC) Validate() error {

// ARC detail entries can only be a debit, ServiceClassCode must allow debits
switch batch.Header.ServiceClassCode {
case 200, 220:
case MixedDebitsAndCredits, CreditsOnly:
msg := fmt.Sprintf(msgBatchServiceClassCode, batch.Header.ServiceClassCode, "ARC")
return &BatchError{BatchNumber: batch.Header.BatchNumber, FieldName: "ServiceClassCode", Msg: msg}
}
Expand Down
60 changes: 30 additions & 30 deletions batchARC_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import "testing"
// mockBatchARCHeader creates a BatchARC BatchHeader
func mockBatchARCHeader() *BatchHeader {
bh := NewBatchHeader()
bh.ServiceClassCode = 225
bh.ServiceClassCode = DebitsOnly
bh.StandardEntryClassCode = "ARC"
bh.CompanyName = "Payee Name"
bh.CompanyIdentification = "121042882"
Expand Down Expand Up @@ -45,7 +45,7 @@ func mockBatchARC() *BatchARC {
// mockBatchARCHeaderCredit creates a BatchARC BatchHeader
func mockBatchARCHeaderCredit() *BatchHeader {
bh := NewBatchHeader()
bh.ServiceClassCode = 225
bh.ServiceClassCode = DebitsOnly
bh.StandardEntryClassCode = "ARC"
bh.CompanyName = "Payee Name"
bh.CompanyIdentification = "121042882"
Expand Down Expand Up @@ -151,7 +151,7 @@ func BenchmarkBatchARCStandardEntryClassCode(b *testing.B) {
// testBatchARCServiceClassCodeEquality validates service class code equality
func testBatchARCServiceClassCodeEquality(t testing.TB) {
mockBatch := mockBatchARC()
mockBatch.GetControl().ServiceClassCode = 200
mockBatch.GetControl().ServiceClassCode = MixedDebitsAndCredits
if err := mockBatch.Validate(); err != nil {
if e, ok := err.(*BatchError); ok {
if e.FieldName != "ServiceClassCode" {
Expand All @@ -176,10 +176,10 @@ func BenchmarkBatchARCServiceClassCodeEquality(b *testing.B) {
}
}

// testBatchARCServiceClass200 validates BatchARC create for an invalid ServiceClassCode 200
func testBatchARCServiceClass200(t testing.TB) {
// testBatchARCMixedCreditsAndDebits validates BatchARC create for an invalid MixedCreditsAndDebits
func testBatchARCMixedCreditsAndDebits(t testing.TB) {
mockBatch := mockBatchARC()
mockBatch.Header.ServiceClassCode = 200
mockBatch.Header.ServiceClassCode = MixedDebitsAndCredits
mockBatch.Create()
if err := mockBatch.Validate(); err != nil {
if e, ok := err.(*BatchError); ok {
Expand All @@ -192,23 +192,23 @@ func testBatchARCServiceClass200(t testing.TB) {
}
}

// TestBatchARCServiceClass200 tests validating BatchARC create for an invalid ServiceClassCode 200
func TestBatchARCServiceClass200(t *testing.T) {
testBatchARCServiceClass200(t)
// TestBatchARCMixedCreditsAndDebits tests validating BatchARC create for an invalid MixedCreditsAndDebits
func TestBatchARCMixedCreditsAndDebits(t *testing.T) {
testBatchARCMixedCreditsAndDebits(t)
}

// BenchmarkBatchARCServiceClass200 benchmarks validating BatchARC create for an invalid ServiceClassCode 200
func BenchmarkBatchARCServiceClass200(b *testing.B) {
// BenchmarkBatchARCMixedCreditsAndDebits benchmarks validating BatchARC create for an invalid MixedCreditsAndDebits
func BenchmarkBatchARCMixedCreditsAndDebits(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testBatchARCServiceClass200(b)
testBatchARCMixedCreditsAndDebits(b)
}
}

// testBatchARCServiceClass220 validates BatchARC create for an invalid ServiceClassCode 220
func testBatchARCServiceClass220(t testing.TB) {
// testBatchARCCreditsOnly validates BatchARC create for an invalid CreditsOnly
func testBatchARCCreditsOnly(t testing.TB) {
mockBatch := mockBatchARC()
mockBatch.Header.ServiceClassCode = 220
mockBatch.Header.ServiceClassCode = CreditsOnly
mockBatch.Create()
if err := mockBatch.Validate(); err != nil {
if e, ok := err.(*BatchError); ok {
Expand All @@ -221,23 +221,23 @@ func testBatchARCServiceClass220(t testing.TB) {
}
}

// TestBatchARCServiceClass220 tests validating BatchARC create for an invalid ServiceClassCode 220
func TestBatchARCServiceClass220(t *testing.T) {
testBatchARCServiceClass220(t)
// TestBatchARCCreditsOnly tests validating BatchARC create for an invalid CreditsOnly
func TestBatchARCCreditsOnly(t *testing.T) {
testBatchARCCreditsOnly(t)
}

// BenchmarkBatchARCServiceClass220 benchmarks validating BatchARC create for an invalid ServiceClassCode 220
func BenchmarkBatchARCServiceClass220(b *testing.B) {
// BenchmarkBatchARCCreditsOnly benchmarks validating BatchARC create for an invalid CreditsOnly
func BenchmarkBatchARCCreditsOnly(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testBatchARCServiceClass220(b)
testBatchARCCreditsOnly(b)
}
}

// testBatchARCServiceClass280 validates BatchARC create for an invalid ServiceClassCode 280
func testBatchARCServiceClass280(t testing.TB) {
// testBatchARCAutomatedAccountingAdvices validates BatchARC create for an invalid AutomatedAccountingAdvices
func testBatchARCAutomatedAccountingAdvices(t testing.TB) {
mockBatch := mockBatchARC()
mockBatch.Header.ServiceClassCode = 280
mockBatch.Header.ServiceClassCode = AutomatedAccountingAdvices
mockBatch.Create()
if err := mockBatch.Validate(); err != nil {
if e, ok := err.(*BatchError); ok {
Expand All @@ -250,16 +250,16 @@ func testBatchARCServiceClass280(t testing.TB) {
}
}

// TestBatchARCServiceClass280 tests validating BatchARC create for an invalid ServiceClassCode 280
func TestBatchARCServiceClass280(t *testing.T) {
testBatchARCServiceClass280(t)
// TestBatchARCAutomatedAccountingAdvices tests validating BatchARC create for an invalid AutomatedAccountingAdvices
func TestBatchARCAutomatedAccountingAdvices(t *testing.T) {
testBatchARCAutomatedAccountingAdvices(t)
}

// BenchmarkBatchARCServiceClass280 benchmarks validating BatchARC create for an invalid ServiceClassCode 280
func BenchmarkBatchARCServiceClass280(b *testing.B) {
// BenchmarkBatchARCAutomatedAccountingAdvices benchmarks validating BatchARC create for an invalid AutomatedAccountingAdvices
func BenchmarkBatchARCAutomatedAccountingAdvices(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testBatchARCServiceClass280(b)
testBatchARCAutomatedAccountingAdvices(b)
}
}

Expand Down
16 changes: 8 additions & 8 deletions batchATX_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// mockBatchATXHeader creates a BatchATX BatchHeader
func mockBatchATXHeader() *BatchHeader {
bh := NewBatchHeader()
bh.ServiceClassCode = 220
bh.ServiceClassCode = CreditsOnly
bh.StandardEntryClassCode = "ATX"
bh.CompanyName = "Payee Name"
bh.CompanyIdentification = "231380104"
Expand Down Expand Up @@ -124,7 +124,7 @@ func BenchmarkBatchATXStandardEntryClassCode(b *testing.B) {
// testBatchATXServiceClassCodeEquality validates service class code equality
func testBatchATXServiceClassCodeEquality(t testing.TB) {
mockBatch := mockBatchATX()
mockBatch.GetControl().ServiceClassCode = 200
mockBatch.GetControl().ServiceClassCode = MixedDebitsAndCredits
if err := mockBatch.Validate(); err != nil {
if e, ok := err.(*BatchError); ok {
if e.FieldName != "ServiceClassCode" {
Expand Down Expand Up @@ -288,7 +288,7 @@ func BenchmarkBatchATXInvalidBuild(b *testing.B) {
func testBatchATXAddenda10000(t testing.TB) {

bh := NewBatchHeader()
bh.ServiceClassCode = 220
bh.ServiceClassCode = CreditsOnly
bh.StandardEntryClassCode = "ATX"
bh.CompanyName = "Payee Name"
bh.CompanyIdentification = "231380104"
Expand Down Expand Up @@ -343,7 +343,7 @@ func BenchmarkBatchATXAddenda10000(b *testing.B) {
// testBatchATXAddendaRecords validates error for AddendaRecords not equal to addendum
func testBatchATXAddendaRecords(t testing.TB) {
bh := NewBatchHeader()
bh.ServiceClassCode = 220
bh.ServiceClassCode = CreditsOnly
bh.StandardEntryClassCode = "ATX"
bh.CompanyName = "Payee Name"
bh.CompanyIdentification = "231380104"
Expand Down Expand Up @@ -442,7 +442,7 @@ func BenchmarkBatchATXReserved(b *testing.B) {
// testBatchATXZeroAddendaRecords validates zero addenda records
func testBatchATXZeroAddendaRecords(t testing.TB) {
bh := NewBatchHeader()
bh.ServiceClassCode = 220
bh.ServiceClassCode = CreditsOnly
bh.StandardEntryClassCode = "ATX"
bh.CompanyName = "Payee Name"
bh.CompanyIdentification = "231380104"
Expand Down Expand Up @@ -493,7 +493,7 @@ func BenchmarkBatchATXZeroAddendaRecords(b *testing.B) {
// testBatchATXTransactionCode validates TransactionCode
func testBatchATXTransactionCode(t testing.TB) {
bh := NewBatchHeader()
bh.ServiceClassCode = 220
bh.ServiceClassCode = CreditsOnly
bh.StandardEntryClassCode = "ATX"
bh.CompanyName = "Payee Name"
bh.CompanyIdentification = "231380104"
Expand Down Expand Up @@ -545,7 +545,7 @@ func BenchmarkBatchATXTransactionCode(b *testing.B) {
// TestBatchATXAmount validates Amount
func TestBatchATXAmount(t *testing.T) {
bh := NewBatchHeader()
bh.ServiceClassCode = 220
bh.ServiceClassCode = CreditsOnly
bh.StandardEntryClassCode = "ATX"
bh.CompanyName = "Payee Name"
bh.CompanyIdentification = "231380104"
Expand Down Expand Up @@ -622,7 +622,7 @@ func TestBatchATXAddendum99(t *testing.T) {
// TestBatchATXValidTranCodeForServiceClassCode validates a transactionCode based on ServiceClassCode
func TestBatchATXValidTranCodeForServiceClassCode(t *testing.T) {
mockBatch := mockBatchATX()
mockBatch.GetHeader().ServiceClassCode = 225
mockBatch.GetHeader().ServiceClassCode = DebitsOnly
if err := mockBatch.Create(); err != nil {
if e, ok := err.(*BatchError); ok {
if e.FieldName != "TransactionCode" {
Expand Down
2 changes: 1 addition & 1 deletion batchBOC.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (batch *BatchBOC) Validate() error {

// BOC detail entries can only be a debit, ServiceClassCode must allow debits
switch batch.Header.ServiceClassCode {
case 200, 220:
case MixedDebitsAndCredits, CreditsOnly:
msg := fmt.Sprintf(msgBatchServiceClassCode, batch.Header.ServiceClassCode, "RCK")
return &BatchError{BatchNumber: batch.Header.BatchNumber, FieldName: "ServiceClassCode", Msg: msg}
}
Expand Down
Loading

0 comments on commit e4f7177

Please sign in to comment.