Skip to content

Commit

Permalink
Increase Test Code Coverage for batches
Browse files Browse the repository at this point in the history
Increase Test Code Coverage for batchCIE and batchCOR
  • Loading branch information
bkmoovio committed Nov 26, 2018
1 parent b85fccd commit aeb0381
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
17 changes: 17 additions & 0 deletions batchCIE_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,3 +489,20 @@ func TestBatchCIEAddenda(t *testing.T) {
}
}
}

// TestBatchCIEAddenda02 validates BatchCIE cannot have Addenda02
func TestBatchCIEAddenda02(t *testing.T) {
mockBatch := mockBatchCIE()
mockBatch.Entries[0].AddendaRecordIndicator = 1
mockBatch.GetEntries()[0].Addenda02 = mockAddenda02()
mockBatch.Create()
if err := mockBatch.Validate(); err != nil {
if e, ok := err.(*BatchError); ok {
if e.FieldName != "Addenda02" {
t.Errorf("%T: %s", err, err)
}
} else {
t.Errorf("%T: %s", err, err)
}
}
}
7 changes: 0 additions & 7 deletions batchCOR.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,6 @@ func (batch *BatchCOR) isAddenda98() error {
if entry.Addenda98 == nil {
return &BatchError{BatchNumber: batch.Header.BatchNumber, FieldName: "Addenda98", Msg: msgBatchCORAddenda}
}
// Addenda98 must be Validated
if err := entry.Addenda98.Validate(); err != nil {
// convert the field error in to a batch error for a consistent api
if e, ok := err.(*FieldError); ok {
return &BatchError{BatchNumber: batch.Header.BatchNumber, FieldName: e.FieldName, Msg: e.Msg}
}
}
}
return nil
}
36 changes: 36 additions & 0 deletions batchCOR_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,39 @@ func TestBatchCORCategoryNOCAddenda98(t *testing.T) {
}
}
}

// TestBatchCORValidTranCodeForServiceClassCode validates a transactionCode based on ServiceClassCode
func TestBatchCORValidTranCodeForServiceClassCode(t *testing.T) {
mockBatch := mockBatchCOR()
mockBatch.GetHeader().ServiceClassCode = 280
if err := mockBatch.Create(); err != nil {
if e, ok := err.(*BatchError); ok {
if e.FieldName != "ServiceClassCode" {
t.Errorf("%T: %s", err, err)
}
} else {
t.Errorf("%T: %s", err, err)
}
}
}

// TestBatchCORInvalidAddenda98 validates that an error is returned if Addenda98 is invalid
func TestBatchCORTestBatchCORInvalidAddenda98(t *testing.T) {
mockBatch := NewBatchCOR(mockBatchCORHeader())
mockBatch.AddEntry(mockCOREntryDetail())
mockBatch.GetEntries()[0].Category = CategoryNOC
addenda98 := mockAddenda98()
addenda98.recordType = "03"
mockBatch.GetEntries()[0].Addenda98 = addenda98

mockBatch.Entries[0].AddendaRecordIndicator = 1
if err := mockBatch.Create(); err != nil {
if e, ok := err.(*BatchError); ok {
if e.FieldName != "recordType" {
t.Errorf("%T: %s", err, err)
}
} else {
t.Errorf("%T: %s", err, err)
}
}
}

0 comments on commit aeb0381

Please sign in to comment.