-
Notifications
You must be signed in to change notification settings - Fork 40
/
cashLetterHeader_test.go
321 lines (288 loc) · 10.2 KB
/
cashLetterHeader_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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
// 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"
"time"
"github.com/stretchr/testify/require"
)
// mockCashLetterHeader creates a CashLetterHeader
func mockCashLetterHeader() *CashLetterHeader {
clh := NewCashLetterHeader()
clh.CollectionTypeIndicator = "01"
clh.DestinationRoutingNumber = "231380104"
clh.ECEInstitutionRoutingNumber = "121042882"
clh.CashLetterBusinessDate = time.Now()
clh.CashLetterCreationDate = time.Now()
clh.CashLetterCreationTime = time.Now()
clh.RecordTypeIndicator = "I"
clh.DocumentationTypeIndicator = "G"
clh.CashLetterID = "A1"
clh.OriginatorContactName = "Contact Name"
clh.OriginatorContactPhoneNumber = "5558675552"
clh.FedWorkType = ""
clh.ReturnsIndicator = ""
clh.UserField = ""
return clh
}
// TestMockCashLetterHeader creates a CashLetterHeader
func TestMockCashLetterHeader(t *testing.T) {
clh := mockCashLetterHeader()
require.NoError(t, clh.Validate())
require.Equal(t, "10", clh.recordType)
require.Equal(t, "01", clh.CollectionTypeIndicator)
require.Equal(t, "231380104", clh.DestinationRoutingNumber)
require.Equal(t, "121042882", clh.ECEInstitutionRoutingNumber)
require.Equal(t, "I", clh.RecordTypeIndicator)
require.Equal(t, "G", clh.DocumentationTypeIndicator)
require.Equal(t, "A1", clh.CashLetterID)
require.Equal(t, "Contact Name", clh.OriginatorContactName)
require.Equal(t, "5558675552", clh.OriginatorContactPhoneNumber)
require.Equal(t, "", clh.FedWorkType)
require.Equal(t, "", clh.ReturnsIndicator)
require.Equal(t, "", clh.UserField)
require.Equal(t, "", clh.reserved)
}
// TestParseCashLetterHeader validates parsing a CashLetterHeader
func TestParseCashLetterHeader(t *testing.T) {
var line = "100123138010412104288220180905201809051523IGA1 Contact Name 5558675552 "
r := NewReader(strings.NewReader(line))
r.line = line
require.NoError(t, r.parseCashLetterHeader())
record := r.currentCashLetter.CashLetterHeader
require.Equal(t, "10", record.recordType)
require.Equal(t, "01", record.CollectionTypeIndicatorField())
require.Equal(t, "231380104", record.DestinationRoutingNumberField())
require.Equal(t, "121042882", record.ECEInstitutionRoutingNumberField())
require.Equal(t, "20180905", record.CashLetterBusinessDateField())
require.Equal(t, "20180905", record.CashLetterCreationDateField())
require.Equal(t, "1523", record.CashLetterCreationTimeField())
require.Equal(t, "I", record.RecordTypeIndicatorField())
require.Equal(t, "G", record.DocumentationTypeIndicatorField())
require.Equal(t, "A1 ", record.CashLetterIDField())
require.Equal(t, "Contact Name ", record.OriginatorContactNameField())
require.Equal(t, "5558675552", record.OriginatorContactPhoneNumberField())
require.Equal(t, " ", record.FedWorkTypeField())
require.Equal(t, " ", record.ReturnsIndicatorField())
require.Equal(t, " ", record.UserFieldField())
require.Equal(t, " ", record.reservedField())
}
// testCLHString validates that a known parsed CashLetterHeader can return to a string of the same value
func testCLHString(t testing.TB) {
var line = "100123138010412104288220180905201809051523IGA1 Contact Name 5558675552 "
r := NewReader(strings.NewReader(line))
r.line = line
require.NoError(t, r.parseCashLetterHeader())
record := r.currentCashLetter.CashLetterHeader
require.Equal(t, line, record.String())
}
// TestCLHString tests validating that a known parsed CashLetterHeader can return to a string of the same value
func TestCLHString(t *testing.T) {
testCLHString(t)
}
// BenchmarkCLHString benchmarks validating that a known parsed CashLetterHeader
// can return to a string of the same value
func BenchmarkCLHString(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testCLHString(b)
}
}
// TestCLHRecordType validation
func TestCLHRecordType(t *testing.T) {
clh := mockCashLetterHeader()
clh.recordType = "00"
err := clh.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "recordType", e.FieldName)
}
// TestCHCollectionTypeIndicator validation
func TestCHCollectionTypeIndicator(t *testing.T) {
clh := mockCashLetterHeader()
clh.CollectionTypeIndicator = "87"
err := clh.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "CollectionTypeIndicator", e.FieldName)
}
// TestRecordTypeIndicator validation
func TestRecordTypeIndicator(t *testing.T) {
clh := mockCashLetterHeader()
clh.RecordTypeIndicator = "W"
err := clh.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "RecordTypeIndicator", e.FieldName)
}
// TestDocumentationTypeIndicator validation
func TestDocumentationTypeIndicator(t *testing.T) {
clh := mockCashLetterHeader()
clh.DocumentationTypeIndicator = "WAZ"
err := clh.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "DocumentationTypeIndicator", e.FieldName)
}
// TestCashLetterID validation
func TestCashLetterID(t *testing.T) {
clh := mockCashLetterHeader()
clh.CashLetterID = "--"
err := clh.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "CashLetterID", e.FieldName)
}
// TestOriginatorContactName validation
func TestOriginatorContactName(t *testing.T) {
clh := mockCashLetterHeader()
clh.OriginatorContactName = "®©"
err := clh.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "OriginatorContactName", e.FieldName)
}
// TestOriginatorContactPhoneNumber validation
func TestOriginatorContactPhoneNumber(t *testing.T) {
clh := mockCashLetterHeader()
clh.OriginatorContactPhoneNumber = "--"
err := clh.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "OriginatorContactPhoneNumber", e.FieldName)
}
// TestFedWorkType validation
func TestFedWorkType(t *testing.T) {
clh := mockCashLetterHeader()
clh.FedWorkType = "--"
err := clh.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "FedWorkType", e.FieldName)
}
// TestReturnsIndicator validation
func TestReturnsIndicator(t *testing.T) {
clh := mockCashLetterHeader()
clh.ReturnsIndicator = "A"
err := clh.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "ReturnsIndicator", e.FieldName)
}
// TestCLHUserField validation
func TestCLHUserFieldI(t *testing.T) {
clh := mockCashLetterHeader()
clh.UserField = "®©"
err := clh.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "UserField", e.FieldName)
}
// TestCLHFieldInclusionRecordType validates FieldInclusion
func TestCLHFieldInclusionRecordType(t *testing.T) {
clh := mockCashLetterHeader()
clh.recordType = ""
err := clh.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "recordType", e.FieldName)
}
// TestFieldInclusionCollectionTypeIndicator validates FieldInclusion
func TestFieldInclusionCollectionTypeIndicator(t *testing.T) {
clh := mockCashLetterHeader()
clh.CollectionTypeIndicator = ""
err := clh.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "CollectionTypeIndicator", e.FieldName)
}
// TestFieldInclusionRecordTypeIndicator validates FieldInclusion
func TestFieldInclusionRecordTypeIndicator(t *testing.T) {
clh := mockCashLetterHeader()
clh.RecordTypeIndicator = ""
err := clh.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "RecordTypeIndicator", e.FieldName)
}
// TestFieldInclusionDestinationRoutingNumber validates FieldInclusion
func TestFieldInclusionDestinationRoutingNumber(t *testing.T) {
clh := mockCashLetterHeader()
clh.DestinationRoutingNumber = ""
err := clh.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "DestinationRoutingNumber", e.FieldName)
}
// TestFieldInclusionDestinationRoutingZerovalidates FieldInclusion
func TestFieldInclusionDestinationRoutingNumberZero(t *testing.T) {
clh := mockCashLetterHeader()
clh.DestinationRoutingNumber = "000000000"
err := clh.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "DestinationRoutingNumber", e.FieldName)
}
// TestFieldInclusionECEInstitutionRoutingNumber validates FieldInclusion
func TestFieldInclusionECEInstitutionRoutingNumber(t *testing.T) {
clh := mockCashLetterHeader()
clh.ECEInstitutionRoutingNumber = ""
err := clh.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "ECEInstitutionRoutingNumber", e.FieldName)
}
// TestFieldInclusionECEInstitutionRoutingNumberZero validates FieldInclusion
func TestFieldInclusionECEInstitutionRoutingNumberZero(t *testing.T) {
clh := mockCashLetterHeader()
clh.ECEInstitutionRoutingNumber = "000000000"
err := clh.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "ECEInstitutionRoutingNumber", e.FieldName)
}
// TestFieldInclusionCashLetterBusinessDate validates FieldInclusion
func TestFieldInclusionCashLetterBusinessDate(t *testing.T) {
clh := mockCashLetterHeader()
clh.CashLetterBusinessDate = time.Time{}
err := clh.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "CashLetterBusinessDate", e.FieldName)
}
// TestFieldInclusionCashLetterCreationDate validates FieldInclusion
func TestFieldInclusionCashLetterCreationDate(t *testing.T) {
clh := mockCashLetterHeader()
clh.CashLetterCreationDate = time.Time{}
err := clh.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "CashLetterCreationDate", e.FieldName)
}
// TestFieldInclusionCashLetterCreationTime validates FieldInclusion
func TestFieldInclusionCashLetterCreationTime(t *testing.T) {
clh := mockCashLetterHeader()
clh.CashLetterCreationTime = time.Time{}
err := clh.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "CashLetterCreationTime", e.FieldName)
}
// TestFieldInclusionCashLetterID validates FieldInclusion
func TestFieldInclusionCashLetterID(t *testing.T) {
clh := mockCashLetterHeader()
clh.CashLetterID = ""
err := clh.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "CashLetterID", e.FieldName)
}
// TestCashLetterHeaderRuneCountInString validates RuneCountInString
func TestCashLetterHeaderRuneCountInString(t *testing.T) {
clh := NewCashLetterHeader()
var line = "10"
clh.Parse(line)
require.Equal(t, "", clh.CollectionTypeIndicator)
}