-
Notifications
You must be signed in to change notification settings - Fork 40
/
accountDebitedDrawdown_test.go
213 lines (156 loc) · 7.44 KB
/
accountDebitedDrawdown_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
package wire
import (
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// mockAccountDebitedDrawdown creates a AccountDebitedDrawdown
func mockAccountDebitedDrawdown() *AccountDebitedDrawdown {
debitDD := NewAccountDebitedDrawdown()
debitDD.IdentificationCode = DemandDepositAccountNumber
debitDD.Identifier = "123456789"
debitDD.Name = "debitDD Name"
debitDD.Address.AddressLineOne = "Address One"
debitDD.Address.AddressLineTwo = "Address Two"
debitDD.Address.AddressLineThree = "Address Three"
return debitDD
}
// TestMockAccountDebitedDrawdown validates mockAccountDebitedDrawdown
func TestMockAccountDebitedDrawdown(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
require.NoError(t, debitDD.Validate(), "mockAccountDebitedDrawdown does not validate and will break other tests")
}
// TestADDIdentifierAlphaNumeric validates Identifier is alphanumeric
func TestADDIdentifierAlphaNumeric(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.Identifier = "®"
err := debitDD.Validate()
require.EqualError(t, err, fieldError("Identifier", ErrNonAlphanumeric, debitDD.Identifier).Error())
}
// TestADDNameAlphaNumeric validates Name is alphanumeric
func TestADDNameAlphaNumeric(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.Name = "®"
err := debitDD.Validate()
require.EqualError(t, err, fieldError("Name", ErrNonAlphanumeric, debitDD.Name).Error())
}
// TestADDAddressLineOneAlphaNumeric validates AddressLineOne is alphanumeric
func TestADDAddressLineOneAlphaNumeric(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.Address.AddressLineOne = "®"
err := debitDD.Validate()
require.EqualError(t, err, fieldError("AddressLineOne", ErrNonAlphanumeric, debitDD.Address.AddressLineOne).Error())
}
// TestADDAddressLineTwoAlphaNumeric validates AddressLineTwo is alphanumeric
func TestADDAddressLineTwoAlphaNumeric(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.Address.AddressLineTwo = "®"
err := debitDD.Validate()
require.EqualError(t, err, fieldError("AddressLineTwo", ErrNonAlphanumeric, debitDD.Address.AddressLineTwo).Error())
}
// TestADDAddressLineThreeAlphaNumeric validates AddressLineThree is alphanumeric
func TestADDAddressLineThreeAlphaNumeric(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.Address.AddressLineThree = "®"
err := debitDD.Validate()
require.EqualError(t, err, fieldError("AddressLineThree", ErrNonAlphanumeric, debitDD.Address.AddressLineThree).Error())
}
// TestADDIdentifierRequired validates Identifier is required
func TestADDIdentifierRequired(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.Identifier = ""
err := debitDD.Validate()
require.EqualError(t, err, fieldError("Identifier", ErrFieldRequired).Error())
}
// TestADDNameRequired validates Name is required
func TestADDNameRequired(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.Name = ""
err := debitDD.Validate()
require.EqualError(t, err, fieldError("Name", ErrFieldRequired).Error())
}
// TestADDIdentificationRequired validates IdentificationCode is required
func TestADDIdentificationCodeRequired(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.IdentificationCode = ""
err := debitDD.Validate()
require.EqualError(t, err, fieldError("IdentificationCode", ErrFieldRequired).Error())
}
// TestADDIdentificationCodeValid validates IdentificationCode
func TestADDIdentificationCodeValid(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.IdentificationCode = TaxIdentificationNumber
err := debitDD.Validate()
require.EqualError(t, err, fieldError("IdentificationCode", ErrIdentificationCode, debitDD.IdentificationCode).Error())
}
// TestADDIdentificationCodeBogus validates IdentificationCode if the IdentificationCode is bogus
func TestIdentificationCodeBogus(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.IdentificationCode = "Card ID"
err := debitDD.Validate()
require.EqualError(t, err, fieldError("IdentificationCode", ErrIdentificationCode, debitDD.IdentificationCode).Error())
}
// TestParseAccountDebitedDrawdownWrongLength parses a wrong AccountDebitedDrawdown record length
func TestParseAccountDebitedDrawdownWrongLength(t *testing.T) {
var line = "{4400}D123456789 *debitDD Name *Address One *Address Two *Address Three "
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseAccountDebitedDrawdown()
require.EqualError(t, err, r.parseError(fieldError("AddressLineThree", ErrRequireDelimiter)).Error())
}
// TestParseAccountDebitedDrawdownReaderParseError parses a wrong AccountDebitedDrawdown reader parse error
func TestParseAccountDebitedDrawdownReaderParseError(t *testing.T) {
var line = "{4400}D123456789 *debitDD ®ame *Address One *Address Two *Address Three *"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseAccountDebitedDrawdown()
expected := r.parseError(fieldError("Name", ErrNonAlphanumeric, "debitDD ®ame")).Error()
require.EqualError(t, err, expected)
_, err = r.Read()
expected = r.parseError(fieldError("Name", ErrNonAlphanumeric, "debitDD ®ame")).Error()
require.EqualError(t, err, expected)
}
// TestAccountDebitedDrawdownTagError validates AccountDebitedDrawdown tag
func TestAccountDebitedDrawdownTagError(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.tag = "{9999}"
err := debitDD.Validate()
require.EqualError(t, err, fieldError("tag", ErrValidTagForType, debitDD.tag).Error())
}
// TestStringDebitedDrawdownVariableLength parses using variable length
func TestStringAccountDebitedDrawdownVariableLength(t *testing.T) {
var line = "{4400}"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseAccountDebitedDrawdown()
expected := r.parseError(NewTagMinLengthErr(9, len(r.line))).Error()
require.EqualError(t, err, expected)
line = "{4400}D123456789 *debitDD Name *Address One *Address Two *Address Three NNNNNNNN*"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseAccountDebitedDrawdown()
require.NoError(t, err)
line = "{4400}***"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseAccountDebitedDrawdown()
expected = r.parseError(fieldError("Identifier", ErrFieldRequired)).Error()
require.EqualError(t, err, expected)
line = "{4400}D2*3*"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseAccountDebitedDrawdown()
require.Equal(t, err, nil)
}
// TestStringDebitedDrawdownOptions validates Format() formatted according to the FormatOptions
func TestStringAccountDebitedDrawdownOptions(t *testing.T) {
var line = "{4400}D2*3*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseAccountDebitedDrawdown()
require.Equal(t, err, nil)
add := r.currentFEDWireMessage.AccountDebitedDrawdown
require.Equal(t, add.String(), "{4400}D2 *3 * * * *")
require.Equal(t, add.Format(FormatOptions{VariableLengthFields: true}), "{4400}D2*3*")
require.Equal(t, add.String(), add.Format(FormatOptions{VariableLengthFields: false}))
}