-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathreturnDetailAddendumC_test.go
188 lines (165 loc) · 6.37 KB
/
returnDetailAddendumC_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// Copyright 2020 The Moov Authors
// Use of this source code is governed by an Apache License
// license that can be found in the LICENSE file.
package imagecashletter
import (
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// mockReturnDetailAddendumC creates a ReturnDetailAddendumC
func mockReturnDetailAddendumC() ReturnDetailAddendumC {
rdAddendumC := NewReturnDetailAddendumC()
rdAddendumC.ImageReferenceKeyIndicator = 1
rdAddendumC.MicrofilmArchiveSequenceNumber = "1A"
rdAddendumC.LengthImageReferenceKey = "0034"
rdAddendumC.ImageReferenceKey = "0"
rdAddendumC.Description = "RD Addendum C"
rdAddendumC.UserField = ""
return rdAddendumC
}
func TestReturnDetailAddendumCParseErr(t *testing.T) {
var r ReturnDetailAddendumC
r.Parse("ASdsadasda")
require.Equal(t, 0, r.ImageReferenceKeyIndicator)
r.Parse("3411A 00340 RD Addendum C")
require.Equal(t, 1, r.ImageReferenceKeyIndicator)
require.Equal(t, "", r.ImageReferenceKey)
}
// TestMockReturnDetailAddendumCcreates a ReturnDetailAddendumC
func TestMockReturnDetailAddendumC(t *testing.T) {
rdAddendumC := mockReturnDetailAddendumC()
require.NoError(t, rdAddendumC.Validate())
require.Equal(t, "34", rdAddendumC.recordType)
require.Equal(t, 1, rdAddendumC.ImageReferenceKeyIndicator)
require.Equal(t, "1A", rdAddendumC.MicrofilmArchiveSequenceNumber)
require.Equal(t, "0034", rdAddendumC.LengthImageReferenceKey)
require.Equal(t, "0", rdAddendumC.ImageReferenceKey)
require.Equal(t, "RD Addendum C", rdAddendumC.Description)
require.Equal(t, "", rdAddendumC.UserField)
}
// TestParseReturnDetailAddendumC validates parsing a ReturnDetailAddendumC
func TestParseReturnDetailAddendumC(t *testing.T) {
var line = "3411A 00340 RD Addendum C "
r := NewReader(strings.NewReader(line))
r.line = line
clh := mockCashLetterHeader()
r.addCurrentCashLetter(NewCashLetter(clh))
bh := mockBundleHeader()
rb := NewBundle(bh)
r.currentCashLetter.AddBundle(rb)
r.addCurrentBundle(rb)
cd := mockReturnDetail()
r.currentCashLetter.currentBundle.AddReturnDetail(cd)
require.NoError(t, r.parseReturnDetailAddendumC())
record := r.currentCashLetter.currentBundle.GetReturns()[0].ReturnDetailAddendumC[0]
require.Equal(t, "34", record.recordType)
require.Equal(t, "1", record.ImageReferenceKeyIndicatorField())
require.Equal(t, "1A ", record.MicrofilmArchiveSequenceNumberField())
require.Equal(t, "0034", record.LengthImageReferenceKeyField())
require.Equal(t, "0 ", record.ImageReferenceKeyField())
require.Equal(t, "RD Addendum C ", record.DescriptionField())
require.Equal(t, " ", record.UserFieldField())
require.Equal(t, " ", record.reservedField())
}
// testRDAddendumCString validates that a known parsed ReturnDetailAddendumC can return to a string of the same value
func testRDAddendumCString(t testing.TB) {
var line = "3411A 00340 RD Addendum C "
r := NewReader(strings.NewReader(line))
r.line = line
clh := mockCashLetterHeader()
r.addCurrentCashLetter(NewCashLetter(clh))
bh := mockBundleHeader()
rb := NewBundle(bh)
r.currentCashLetter.AddBundle(rb)
r.addCurrentBundle(rb)
cd := mockReturnDetail()
r.currentCashLetter.currentBundle.AddReturnDetail(cd)
require.NoError(t, r.parseReturnDetailAddendumC())
record := r.currentCashLetter.currentBundle.GetReturns()[0].ReturnDetailAddendumC[0]
require.Equal(t, line, record.String())
}
// TestRDAddendumCString tests validating that a known parsed ReturnDetailAddendumC can return to a string of the
// same value
func TestRDAddendumCString(t *testing.T) {
testRDAddendumCString(t)
}
// BenchmarkRDAddendumCString benchmarks validating that a known parsed ReturnDetailAddendumC
// can return to a string of the same value
func BenchmarkRDAddendumCString(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testRDAddendumCString(b)
}
}
// TestRDAddendumCRecordType validation
func TestRDAddendumCRecordType(t *testing.T) {
rdAddendumC := mockReturnDetailAddendumC()
rdAddendumC.recordType = "00"
err := rdAddendumC.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "recordType", e.FieldName)
}
// TestRDAddendumCImageReferenceKeyIndicator validation
func TestRDAddendumCImageReferenceKeyIndicator(t *testing.T) {
rdAddendumC := mockReturnDetailAddendumC()
rdAddendumC.ImageReferenceKeyIndicator = 5
err := rdAddendumC.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "ImageReferenceKeyIndicator", e.FieldName)
}
// TestRDAddendumCImageReferenceKey validation
func TestRDAddendumCImageReferenceKey(t *testing.T) {
rdAddendumC := mockReturnDetailAddendumC()
rdAddendumC.ImageReferenceKey = "®©"
err := rdAddendumC.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "ImageReferenceKey", e.FieldName)
}
// TestRDAddendumCDescription validation
func TestRDAddendumCDescription(t *testing.T) {
rdAddendumC := mockReturnDetailAddendumC()
rdAddendumC.Description = "®©"
err := rdAddendumC.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "Description", e.FieldName)
}
// TestRDAddendumCUserField validation
func TestRDAddendumCUserField(t *testing.T) {
rdAddendumC := mockReturnDetailAddendumC()
rdAddendumC.UserField = "®©"
err := rdAddendumC.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "UserField", e.FieldName)
}
// Field Inclusion
// TestRDAddendumCFIRecordType validation
func TestRDAddendumCFIRecordType(t *testing.T) {
rdAddendumC := mockReturnDetailAddendumC()
rdAddendumC.recordType = ""
err := rdAddendumC.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "recordType", e.FieldName)
}
// TestRDAddendumCFIMicrofilmArchiveSequenceNumber validation
func TestRDAddendumCFIMicrofilmArchiveSequenceNumber(t *testing.T) {
rdAddendumC := mockReturnDetailAddendumC()
rdAddendumC.MicrofilmArchiveSequenceNumber = " "
err := rdAddendumC.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "MicrofilmArchiveSequenceNumber", e.FieldName)
}
// TestRDAddendumCRuneCountInString validates RuneCountInString
func TestRDAddendumCRuneCountInString(t *testing.T) {
rdAddendumC := NewReturnDetailAddendumC()
var line = "34"
rdAddendumC.Parse(line)
require.Equal(t, "", rdAddendumC.Description)
}