-
Notifications
You must be signed in to change notification settings - Fork 39
/
bundle_test.go
272 lines (238 loc) · 9.33 KB
/
bundle_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
// 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 (
"testing"
"github.com/stretchr/testify/require"
)
// mockBundleChecks
func mockBundleChecks(t *testing.T) *Bundle {
t.Helper()
bundle := &Bundle{}
bundle.SetHeader(mockBundleHeader())
bundle.AddCheckDetail(mockCheckDetail())
bundle.Checks[0].AddCheckDetailAddendumA(mockCheckDetailAddendumA())
bundle.Checks[0].AddCheckDetailAddendumB(mockCheckDetailAddendumB())
bundle.Checks[0].AddCheckDetailAddendumC(mockCheckDetailAddendumC())
bundle.Checks[0].AddImageViewDetail(mockImageViewDetail())
bundle.Checks[0].AddImageViewData(mockImageViewData())
bundle.Checks[0].AddImageViewAnalysis(mockImageViewAnalysis())
require.NoError(t, bundle.build())
return bundle
}
// mockBundleReturns
func mockBundleReturns(t *testing.T) *Bundle {
t.Helper()
bundle := &Bundle{}
bundle.SetHeader(mockBundleHeader())
bundle.AddReturnDetail(mockReturnDetail())
bundle.Returns[0].AddReturnDetailAddendumA(mockReturnDetailAddendumA())
bundle.Returns[0].AddReturnDetailAddendumB(mockReturnDetailAddendumB())
bundle.Returns[0].AddReturnDetailAddendumC(mockReturnDetailAddendumC())
bundle.Returns[0].AddReturnDetailAddendumD(mockReturnDetailAddendumD())
bundle.Returns[0].AddImageViewDetail(mockImageViewDetail())
bundle.Returns[0].AddImageViewData(mockImageViewData())
bundle.Returns[0].AddImageViewAnalysis(mockImageViewAnalysis())
require.NoError(t, bundle.build())
return bundle
}
// TestMockBundleChecks creates a Bundle of checks
func TestMockBundleChecks(t *testing.T) {
bundle := mockBundleChecks(t)
require.NoError(t, bundle.Validate())
bundle = nil // ensure we don't panic
require.NotPanics(t, func() {
checks := bundle.GetChecks()
require.Nil(t, checks)
})
}
// TestMockBundleReturns creates a Bundle of returns
func TestMockBundleReturns(t *testing.T) {
bundle := mockBundleReturns(t)
require.NoError(t, bundle.Validate())
bundle = nil // ensure we don't panic
require.NotPanics(t, func() {
returns := bundle.GetReturns()
require.Nil(t, returns)
})
}
func TestBundleValidate(t *testing.T) {
header := mockBundleHeader()
bundle := NewBundle(header)
require.Error(t, bundle.Validate())
}
// TestCheckDetailAddendumCount validates CheckDetail AddendumCount
func TestCheckDetailAddendumCount(t *testing.T) {
cd := mockCheckDetail()
cd.AddendumCount = 2 // incorrect count should cause error
cd.AddCheckDetailAddendumA(mockCheckDetailAddendumA())
cd.AddCheckDetailAddendumB(mockCheckDetailAddendumB())
cd.AddCheckDetailAddendumC(mockCheckDetailAddendumC())
cd.AddImageViewDetail(mockImageViewDetail())
cd.AddImageViewData(mockImageViewData())
cd.AddImageViewAnalysis(mockImageViewAnalysis())
bundle := NewBundle(mockBundleHeader())
bundle.AddCheckDetail(cd)
err := bundle.Validate()
var bundleErr *BundleError
require.ErrorAs(t, err, &bundleErr)
require.Equal(t, "AddendumCount", bundleErr.FieldName)
}
// TestCheckDetailAddendumACount validates CheckDetailAddendumA AddendaCount
func TestCheckDetailAddendumACount(t *testing.T) {
cd := mockCheckDetail()
cd.AddendumCount = 12 // incorrect count should cause error
for i := 0; i < 10; i++ {
cd.AddCheckDetailAddendumA(mockCheckDetailAddendumA())
}
cd.AddCheckDetailAddendumB(mockCheckDetailAddendumB())
cd.AddCheckDetailAddendumC(mockCheckDetailAddendumC())
cd.AddImageViewDetail(mockImageViewDetail())
cd.AddImageViewData(mockImageViewData())
cd.AddImageViewAnalysis(mockImageViewAnalysis())
bundle := NewBundle(mockBundleHeader())
bundle.AddCheckDetail(cd)
err := bundle.Validate()
var bundleErr *BundleError
require.ErrorAs(t, err, &bundleErr)
require.Equal(t, "CheckDetailAddendumA", bundleErr.FieldName)
}
// TestCheckDetailAddendumBCount validates CheckDetailAddendumB AddendaCount
func TestCheckDetailAddendumBCount(t *testing.T) {
cd := mockCheckDetail()
cd.AddendumCount = 4
cd.AddCheckDetailAddendumA(mockCheckDetailAddendumA())
cd.AddCheckDetailAddendumB(mockCheckDetailAddendumB())
cd.AddCheckDetailAddendumB(mockCheckDetailAddendumB())
cd.AddCheckDetailAddendumC(mockCheckDetailAddendumC())
cd.AddImageViewDetail(mockImageViewDetail())
cd.AddImageViewData(mockImageViewData())
cd.AddImageViewAnalysis(mockImageViewAnalysis())
bundle := NewBundle(mockBundleHeader())
bundle.AddCheckDetail(cd)
err := bundle.Validate()
var bundleErr *BundleError
require.ErrorAs(t, err, &bundleErr)
require.Equal(t, "CheckDetailAddendumB", bundleErr.FieldName)
}
// TestCheckDetailAddendumCCount validates CheckDetailAddendumC AddendaCount
func TestCheckDetailAddendumCCount(t *testing.T) {
cd := mockCheckDetail()
cd.AddendumCount = 102
cd.AddCheckDetailAddendumA(mockCheckDetailAddendumA())
cd.AddCheckDetailAddendumB(mockCheckDetailAddendumB())
for i := 0; i < 100; i++ {
cd.AddCheckDetailAddendumC(mockCheckDetailAddendumC())
}
cd.AddImageViewDetail(mockImageViewDetail())
cd.AddImageViewData(mockImageViewData())
cd.AddImageViewAnalysis(mockImageViewAnalysis())
bundle := NewBundle(mockBundleHeader())
bundle.AddCheckDetail(cd)
err := bundle.Validate()
var bundleErr *BundleError
require.ErrorAs(t, err, &bundleErr)
require.Equal(t, "CheckDetailAddendumC", bundleErr.FieldName)
}
// TestReturnDetailAddendumCount validates ReturnDetail AddendumCount
func TestReturnDetailAddendumCount(t *testing.T) {
// Create ReturnDetail
rd := mockReturnDetail()
rd.AddendumCount = 3
rd.AddReturnDetailAddendumA(mockReturnDetailAddendumA())
rd.AddReturnDetailAddendumB(mockReturnDetailAddendumB())
rd.AddReturnDetailAddendumC(mockReturnDetailAddendumC())
rd.AddReturnDetailAddendumD(mockReturnDetailAddendumD())
rd.AddImageViewDetail(mockImageViewDetail())
rd.AddImageViewData(mockImageViewData())
rd.AddImageViewAnalysis(mockImageViewAnalysis())
returnBundle := NewBundle(mockBundleHeader())
returnBundle.AddReturnDetail(rd)
err := returnBundle.Validate()
var bundleErr *BundleError
require.ErrorAs(t, err, &bundleErr)
require.Equal(t, "AddendumCount", bundleErr.FieldName)
}
// TestReturnDetailAddendumACount validates ReturnDetailAddendumA Count
func TestReturnDetailAddendumACount(t *testing.T) {
// Create ReturnDetail
rd := mockReturnDetail()
rd.AddendumCount = 13
for i := 0; i < 10; i++ {
rd.AddReturnDetailAddendumA(mockReturnDetailAddendumA())
}
rd.AddReturnDetailAddendumB(mockReturnDetailAddendumB())
rd.AddReturnDetailAddendumC(mockReturnDetailAddendumC())
rd.AddReturnDetailAddendumD(mockReturnDetailAddendumD())
rd.AddImageViewDetail(mockImageViewDetail())
rd.AddImageViewData(mockImageViewData())
rd.AddImageViewAnalysis(mockImageViewAnalysis())
returnBundle := NewBundle(mockBundleHeader())
returnBundle.AddReturnDetail(rd)
err := returnBundle.Validate()
var bundleErr *BundleError
require.ErrorAs(t, err, &bundleErr)
require.Equal(t, "ReturnDetailAddendumA", bundleErr.FieldName)
}
// TestReturnDetailAddendumBCount validates ReturnDetailAddendumB Count
func TestReturnDetailAddendumBCount(t *testing.T) {
// Create ReturnDetail
rd := mockReturnDetail()
rd.AddendumCount = 5
rd.AddReturnDetailAddendumA(mockReturnDetailAddendumA())
rd.AddReturnDetailAddendumB(mockReturnDetailAddendumB())
rd.AddReturnDetailAddendumB(mockReturnDetailAddendumB())
rd.AddReturnDetailAddendumC(mockReturnDetailAddendumC())
rd.AddReturnDetailAddendumD(mockReturnDetailAddendumD())
rd.AddImageViewDetail(mockImageViewDetail())
rd.AddImageViewData(mockImageViewData())
rd.AddImageViewAnalysis(mockImageViewAnalysis())
returnBundle := NewBundle(mockBundleHeader())
returnBundle.AddReturnDetail(rd)
err := returnBundle.Validate()
var bundleErr *BundleError
require.ErrorAs(t, err, &bundleErr)
require.Equal(t, "ReturnDetailAddendumB", bundleErr.FieldName)
}
// TestReturnDetailAddendumCCount validates ReturnDetailAddendumC Count
func TestReturnDetailAddendumCCount(t *testing.T) {
// Create ReturnDetail
rd := mockReturnDetail()
rd.AddendumCount = 5
rd.AddReturnDetailAddendumA(mockReturnDetailAddendumA())
rd.AddReturnDetailAddendumB(mockReturnDetailAddendumB())
rd.AddReturnDetailAddendumC(mockReturnDetailAddendumC())
rd.AddReturnDetailAddendumC(mockReturnDetailAddendumC())
rd.AddReturnDetailAddendumD(mockReturnDetailAddendumD())
rd.AddImageViewDetail(mockImageViewDetail())
rd.AddImageViewData(mockImageViewData())
rd.AddImageViewAnalysis(mockImageViewAnalysis())
returnBundle := NewBundle(mockBundleHeader())
returnBundle.AddReturnDetail(rd)
err := returnBundle.Validate()
var bundleErr *BundleError
require.ErrorAs(t, err, &bundleErr)
require.Equal(t, "ReturnDetailAddendumC", bundleErr.FieldName)
}
// TestReturnDetailAddendumDCount validates ReturnDetailAddendumD Count
func TestReturnDetailAddendumDCount(t *testing.T) {
// Create ReturnDetail
rd := mockReturnDetail()
rd.AddendumCount = 103
rd.AddReturnDetailAddendumA(mockReturnDetailAddendumA())
rd.AddReturnDetailAddendumB(mockReturnDetailAddendumB())
rd.AddReturnDetailAddendumC(mockReturnDetailAddendumC())
for i := 0; i < 100; i++ {
rd.AddReturnDetailAddendumD(mockReturnDetailAddendumD())
}
rd.AddImageViewDetail(mockImageViewDetail())
rd.AddImageViewData(mockImageViewData())
rd.AddImageViewAnalysis(mockImageViewAnalysis())
returnBundle := NewBundle(mockBundleHeader())
returnBundle.AddReturnDetail(rd)
err := returnBundle.Validate()
var bundleErr *BundleError
require.ErrorAs(t, err, &bundleErr)
require.Equal(t, "ReturnDetailAddendumD", bundleErr.FieldName)
}