-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathimageViewAnalysis_test.go
394 lines (352 loc) · 12.5 KB
/
imageViewAnalysis_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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
// 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"
)
// mockImageViewAnalysis crates an imageViewAnalysis
func mockImageViewAnalysis() ImageViewAnalysis {
ivAnalysis := NewImageViewAnalysis()
ivAnalysis.GlobalImageQuality = 2
ivAnalysis.GlobalImageUsability = 2
ivAnalysis.ImagingBankSpecificTest = 0
ivAnalysis.PartialImage = 2
ivAnalysis.ExcessiveImageSkew = 2
ivAnalysis.PiggybackImage = 2
ivAnalysis.TooLightOrTooDark = 2
ivAnalysis.StreaksAndOrBands = 2
ivAnalysis.BelowMinimumImageSize = 2
ivAnalysis.ExceedsMaximumImageSize = 2
ivAnalysis.ImageEnabledPOD = 1
ivAnalysis.SourceDocumentBad = 0
ivAnalysis.DateUsability = 2
ivAnalysis.PayeeUsability = 2
ivAnalysis.ConvenienceAmountUsability = 2
ivAnalysis.AmountInWordsUsability = 2
ivAnalysis.SignatureUsability = 2
ivAnalysis.PayorNameAddressUsability = 2
ivAnalysis.MICRLineUsability = 2
ivAnalysis.MemoLineUsability = 2
ivAnalysis.PayorBankNameAddressUsability = 2
ivAnalysis.PayeeEndorsementUsability = 2
ivAnalysis.BOFDEndorsementUsability = 2
ivAnalysis.TransitEndorsementUsability = 2
return ivAnalysis
}
// TestMockImageViewAnalysis creates an ImageViewAnalysis
func TestMockImageViewAnalysis(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
require.NoError(t, ivAnalysis.Validate())
require.Equal(t, 2, ivAnalysis.GlobalImageQuality)
require.Equal(t, 2, ivAnalysis.GlobalImageUsability)
require.Equal(t, 0, ivAnalysis.ImagingBankSpecificTest)
require.Equal(t, 2, ivAnalysis.PartialImage)
require.Equal(t, 2, ivAnalysis.ExcessiveImageSkew)
require.Equal(t, 2, ivAnalysis.PiggybackImage)
require.Equal(t, 2, ivAnalysis.TooLightOrTooDark)
require.Equal(t, 2, ivAnalysis.StreaksAndOrBands)
require.Equal(t, 2, ivAnalysis.BelowMinimumImageSize)
require.Equal(t, 2, ivAnalysis.ExceedsMaximumImageSize)
_ = additionalIVAnalysisFields(ivAnalysis, t)
}
func additionalIVAnalysisFields(ivAnalysis ImageViewAnalysis, t *testing.T) string {
require.Equal(t, 1, ivAnalysis.ImageEnabledPOD)
require.Equal(t, 0, ivAnalysis.SourceDocumentBad)
require.Equal(t, 2, ivAnalysis.DateUsability)
require.Equal(t, 2, ivAnalysis.PayeeUsability)
require.Equal(t, 2, ivAnalysis.ConvenienceAmountUsability)
require.Equal(t, 2, ivAnalysis.AmountInWordsUsability)
require.Equal(t, 2, ivAnalysis.SignatureUsability)
require.Equal(t, 2, ivAnalysis.PayorNameAddressUsability)
require.Equal(t, 2, ivAnalysis.MICRLineUsability)
require.Equal(t, 2, ivAnalysis.MemoLineUsability)
require.Equal(t, 2, ivAnalysis.PayorBankNameAddressUsability)
require.Equal(t, 2, ivAnalysis.PayeeEndorsementUsability)
require.Equal(t, 2, ivAnalysis.BOFDEndorsementUsability)
require.Equal(t, 2, ivAnalysis.TransitEndorsementUsability)
return ""
}
// testIVAnalysisString validates that a known parsed ImageViewAnalysis can return to a string of the same value
func testIVAnalysisString(t testing.TB) {
var line = "542202222222 10222222222222 "
r := NewReader(strings.NewReader(line))
r.line = line
clh := mockCashLetterHeader()
r.addCurrentCashLetter(NewCashLetter(clh))
bh := mockBundleHeader()
b := NewBundle(bh)
r.currentCashLetter.AddBundle(b)
r.addCurrentBundle(b)
cd := mockCheckDetail()
r.currentCashLetter.currentBundle.AddCheckDetail(cd)
require.NoError(t, r.parseImageViewAnalysis())
record := r.currentCashLetter.currentBundle.GetChecks()[0].ImageViewAnalysis[0]
require.Equal(t, line, record.String())
}
// TestIVAnalysisString tests validating that a known parsed ImageViewAnalysis an return to a string of the
// same value
func TestIVAnalysisString(t *testing.T) {
testIVAnalysisString(t)
}
// BenchmarkIVAnalysisString benchmarks validating that a known parsed ImageViewAnalysis
// can return to a string of the same value
func BenchmarkIVAnalysisString(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testIVAnalysisString(b)
}
}
// TestIVAnalysisRecordType validation
func TestIVAnalysisRecordType(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
ivAnalysis.recordType = "00"
err := ivAnalysis.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "recordType", e.FieldName)
}
// TestIVAnalysisGlobalImageQuality validation
func TestIVAnalysisGlobalImageQuality(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
ivAnalysis.GlobalImageQuality = 5
err := ivAnalysis.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "GlobalImageQuality", e.FieldName)
}
// TestIVAnalysisGlobalImageUsability validation
func TestIVAnalysisGlobalImageUsability(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
ivAnalysis.GlobalImageUsability = 5
err := ivAnalysis.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "GlobalImageUsability", e.FieldName)
}
// TestIVAnalysisImagingBankSpecificTest validation
func TestIVAnalysisImagingBankSpecificTest(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
ivAnalysis.ImagingBankSpecificTest = 5
err := ivAnalysis.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "ImagingBankSpecificTest", e.FieldName)
}
// TestIVAnalysisPartialImage validation
func TestIVAnalysisPartialImage(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
ivAnalysis.PartialImage = 5
err := ivAnalysis.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "PartialImage", e.FieldName)
}
// TestIVAnalysisExcessiveImageSkew validation
func TestIVAnalysisExcessiveImageSkew(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
ivAnalysis.ExcessiveImageSkew = 5
err := ivAnalysis.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "ExcessiveImageSkew", e.FieldName)
}
// TestIVAnalysisPiggybackImage validation
func TestIVAnalysisPiggybackImage(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
ivAnalysis.PiggybackImage = 5
err := ivAnalysis.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "PiggybackImage", e.FieldName)
}
// TestIVAnalysisTooLightOrTooDark validation
func TestIVAnalysisTooLightOrTooDarke(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
ivAnalysis.TooLightOrTooDark = 5
err := ivAnalysis.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "TooLightOrTooDark", e.FieldName)
}
// TestIVAnalysisStreaksAndOrBands validation
func TestIVAnalysisStreaksAndOrBands(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
ivAnalysis.StreaksAndOrBands = 5
err := ivAnalysis.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "StreaksAndOrBands", e.FieldName)
}
// TestIVAnalysisBelowMinimumImageSize validation
func TestIVAnalysisBelowMinimumImageSize(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
ivAnalysis.BelowMinimumImageSize = 5
err := ivAnalysis.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "BelowMinimumImageSize", e.FieldName)
}
// TestIVAnalysisExceedsMaximumImageSize validation
func TestIVAnalysisExceedsMaximumImageSize(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
ivAnalysis.ExceedsMaximumImageSize = 5
err := ivAnalysis.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "ExceedsMaximumImageSize", e.FieldName)
}
// TestIVAnalysisImageEnabledPOD validation
func TestIVAnalysisImageEnabledPOD(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
ivAnalysis.ImageEnabledPOD = 5
err := ivAnalysis.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "ImageEnabledPOD", e.FieldName)
}
// TestIVAnalysisSourceDocumentBad validation
func TestIVAnalysisSourceDocumentBad(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
ivAnalysis.SourceDocumentBad = 5
err := ivAnalysis.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "SourceDocumentBad", e.FieldName)
}
// TestIVAnalysisDateUsability validation
func TestIVAnalysisDateUsability(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
ivAnalysis.DateUsability = 5
err := ivAnalysis.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "DateUsability", e.FieldName)
}
// TestIVAnalysisPayeeUsability validation
func TestIVAnalysisPayeeUsability(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
ivAnalysis.PayeeUsability = 5
err := ivAnalysis.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "PayeeUsability", e.FieldName)
}
// TestIVAnalysisConvenienceAmountUsability validation
func TestIVAnalysisConvenienceAmountUsability(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
ivAnalysis.ConvenienceAmountUsability = 5
err := ivAnalysis.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "ConvenienceAmountUsability", e.FieldName)
}
// TestIVAnalysisAmountInWordsUsability validation
func TestIVAnalysisAmountInWordsUsability(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
ivAnalysis.AmountInWordsUsability = 57
err := ivAnalysis.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "AmountInWordsUsability", e.FieldName)
}
// TestIVAnalysisSignatureUsability validation
func TestIVAnalysisSignatureUsability(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
ivAnalysis.SignatureUsability = 5
err := ivAnalysis.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "SignatureUsability", e.FieldName)
}
// TestIVAnalysisPayorNameAddressUsability validation
func TestIVAnalysisPayorNameAddressUsability(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
ivAnalysis.PayorNameAddressUsability = 5
err := ivAnalysis.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "PayorNameAddressUsability", e.FieldName)
}
// TestIVAnalysisMICRLineUsability validation
func TestIVAnalysisMICRLineUsability(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
ivAnalysis.MICRLineUsability = 5
err := ivAnalysis.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "MICRLineUsability", e.FieldName)
}
// TestIVAnalysisMemoLineUsability validation
func TestIVAnalysisMemoLineUsability(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
ivAnalysis.MemoLineUsability = 5
err := ivAnalysis.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "MemoLineUsability", e.FieldName)
}
// TestIVAnalysisPayorBankNameAddressUsability validation
func TestIVAnalysisPayorBankNameAddressUsability(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
ivAnalysis.PayorBankNameAddressUsability = 5
err := ivAnalysis.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "PayorBankNameAddressUsability", e.FieldName)
}
// TestIVAnalysisPayeeEndorsementUsability validation
func TestIVAnalysisPayeeEndorsementUsability(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
ivAnalysis.PayeeEndorsementUsability = 5
err := ivAnalysis.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "PayeeEndorsementUsability", e.FieldName)
}
// TestIVAnalysisBOFDEndorsementUsability validation
func TestIVAnalysisBOFDEndorsementUsability(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
ivAnalysis.BOFDEndorsementUsability = 5
err := ivAnalysis.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "BOFDEndorsementUsability", e.FieldName)
}
// TestIVAnalysisTransitEndorsementUsability validation
func TestIVAnalysisTransitEndorsementUsability(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
ivAnalysis.TransitEndorsementUsability = 5
err := ivAnalysis.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "TransitEndorsementUsability", e.FieldName)
}
// TestIVAnalysisUserField validation
func TestIVAnalysisUserField(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
ivAnalysis.UserField = "®©"
err := ivAnalysis.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "UserField", e.FieldName)
}
// Field Inclusion
// TestIVAnalysisFIRecordType validation
func TestIVAnalysisFIRecordType(t *testing.T) {
ivAnalysis := mockImageViewAnalysis()
ivAnalysis.recordType = ""
err := ivAnalysis.Validate()
var e *FieldError
require.ErrorAs(t, err, &e)
require.Equal(t, "recordType", e.FieldName)
}
// TestIVAnalysisRuneCountInString validates RuneCountInString
func TestIVAnalysisRuneCountInString(t *testing.T) {
ivAnalysis := NewImageViewAnalysis()
var line = "54"
ivAnalysis.Parse(line)
require.Equal(t, 0, ivAnalysis.AmountInWordsUsability)
}