-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathbeneficiaryFI_test.go
203 lines (149 loc) · 7.4 KB
/
beneficiaryFI_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
package wire
import (
"errors"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// mockBeneficiaryFI creates a BeneficiaryFI
func mockBeneficiaryFI() *BeneficiaryFI {
bfi := NewBeneficiaryFI()
bfi.FinancialInstitution.IdentificationCode = DemandDepositAccountNumber
bfi.FinancialInstitution.Identifier = "123456789"
bfi.FinancialInstitution.Name = "FI Name"
bfi.FinancialInstitution.Address.AddressLineOne = "Address One"
bfi.FinancialInstitution.Address.AddressLineTwo = "Address Two"
bfi.FinancialInstitution.Address.AddressLineThree = "Address Three"
return bfi
}
// TestMockBeneficiaryFI validates mockBeneficiaryFI
func TestMockBeneficiaryFI(t *testing.T) {
bfi := mockBeneficiaryFI()
require.NoError(t, bfi.Validate(), "mockBeneficiaryFI does not validate and will break other tests")
}
// TestBeneficiaryFIIdentificationCodeValid validates BeneficiaryFI IdentificationCode
func TestBeneficiaryFIIdentificationCodeValid(t *testing.T) {
bfi := mockBeneficiaryFI()
bfi.FinancialInstitution.IdentificationCode = "Football Card ID"
err := bfi.Validate()
require.EqualError(t, err, fieldError("IdentificationCode", ErrIdentificationCode, bfi.FinancialInstitution.IdentificationCode).Error())
}
// TestBeneficiaryFIIdentificationCodeFI validates BeneficiaryFI IdentificationCode is an FI code
func TestBeneficiaryFIIdentificationCodeFI(t *testing.T) {
bfi := mockBeneficiaryFI()
bfi.FinancialInstitution.IdentificationCode = "1"
err := bfi.Validate()
require.EqualError(t, err, fieldError("IdentificationCode", ErrIdentificationCode, bfi.FinancialInstitution.IdentificationCode).Error())
}
// TestBeneficiaryFIIdentifierAlphaNumeric validates BeneficiaryFI Identifier is alphanumeric
func TestBeneficiaryFIIdentifierAlphaNumeric(t *testing.T) {
bfi := mockBeneficiaryFI()
bfi.FinancialInstitution.Identifier = "®"
err := bfi.Validate()
require.EqualError(t, err, fieldError("Identifier", ErrNonAlphanumeric, bfi.FinancialInstitution.Identifier).Error())
}
// TestBeneficiaryFINameAlphaNumeric validates BeneficiaryFI Name is alphanumeric
func TestBeneficiaryFINameAlphaNumeric(t *testing.T) {
bfi := mockBeneficiaryFI()
bfi.FinancialInstitution.Name = "®"
err := bfi.Validate()
require.EqualError(t, err, fieldError("Name", ErrNonAlphanumeric, bfi.FinancialInstitution.Name).Error())
}
// TestBeneficiaryFIAddressLineOneAlphaNumeric validates BeneficiaryFI AddressLineOne is alphanumeric
func TestBeneficiaryFIAddressLineOneAlphaNumeric(t *testing.T) {
bfi := mockBeneficiaryFI()
bfi.FinancialInstitution.Address.AddressLineOne = "®"
err := bfi.Validate()
require.EqualError(t, err, fieldError("AddressLineOne", ErrNonAlphanumeric, bfi.FinancialInstitution.Address.AddressLineOne).Error())
}
// TestBeneficiaryFIAddressLineTwoAlphaNumeric validates BeneficiaryFI AddressLineTwo is alphanumeric
func TestBeneficiaryFIAddressLineTwoAlphaNumeric(t *testing.T) {
bfi := mockBeneficiaryFI()
bfi.FinancialInstitution.Address.AddressLineTwo = "®"
err := bfi.Validate()
require.EqualError(t, err, fieldError("AddressLineTwo", ErrNonAlphanumeric, bfi.FinancialInstitution.Address.AddressLineTwo).Error())
}
// TestBeneficiaryFIAddressLineThreeAlphaNumeric validates BeneficiaryFI AddressLineThree is alphanumeric
func TestBeneficiaryFIAddressLineThreeAlphaNumeric(t *testing.T) {
bfi := mockBeneficiaryFI()
bfi.FinancialInstitution.Address.AddressLineThree = "®"
err := bfi.Validate()
require.EqualError(t, err, fieldError("AddressLineThree", ErrNonAlphanumeric, bfi.FinancialInstitution.Address.AddressLineThree).Error())
}
// TestBeneficiaryFIIdentificationCodeRequired validates BeneficiaryFI IdentificationCode is required
func TestBeneficiaryFIIdentificationCodeRequired(t *testing.T) {
bfi := mockBeneficiaryFI()
bfi.FinancialInstitution.IdentificationCode = ""
err := bfi.Validate()
require.EqualError(t, err, fieldError("IdentificationCode", ErrFieldRequired).Error())
}
// TestBeneficiaryFIIdentifierRequired validates BeneficiaryFI Identifier is required
func TestBeneficiaryFIIdentifierRequired(t *testing.T) {
bfi := mockBeneficiaryFI()
bfi.FinancialInstitution.Identifier = ""
err := bfi.Validate()
require.EqualError(t, err, fieldError("Identifier", ErrFieldRequired).Error())
}
// TestParseBeneficiaryFIWrongLength parses a wrong BeneficiaryFI record length
func TestParseBeneficiaryFIWrongLength(t *testing.T) {
var line = "{4100}D123456789 FI Name Address One Address Two Address Three "
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseBeneficiaryFI()
require.EqualError(t, err, r.parseError(fieldError("Identifier", ErrRequireDelimiter)).Error())
}
// TestParseBeneficiaryFIReaderParseError parses a wrong BeneficiaryFI reader parse error
func TestParseBeneficiaryFIReaderParseError(t *testing.T) {
var line = "{4100}D123456789 *F® Name *Address One *Address Two *Address Three *"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseBeneficiaryFI()
expected := r.parseError(fieldError("Name", ErrNonAlphanumeric, "F® Name")).Error()
require.EqualError(t, err, expected)
_, err = r.Read()
expected = r.parseError(fieldError("Name", ErrNonAlphanumeric, "F® Name")).Error()
require.EqualError(t, err, expected)
}
// TestBeneficiaryFITagError validates a BeneficiaryFI tag
func TestBeneficiaryFITagError(t *testing.T) {
bfi := mockBeneficiaryFI()
bfi.tag = "{9999}"
err := bfi.Validate()
require.EqualError(t, err, fieldError("tag", ErrValidTagForType, bfi.tag).Error())
}
// TestStringBeneficiaryFIVariableLength parses using variable length
func TestStringBeneficiaryFIVariableLength(t *testing.T) {
var line = "{4100}"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseBeneficiaryFI()
expected := r.parseError(NewTagMinLengthErr(7, len(r.line))).Error()
require.EqualError(t, err, expected)
line = "{4100}D123456789 *FI Name *Address One *Address Two *Address Three NNN"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseBeneficiaryFI()
require.ErrorContains(t, err, ErrRequireDelimiter.Error())
line = "{4100}D123456789*******"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseBeneficiaryFI()
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
line = "{4100}D123456789****"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseBeneficiaryFI()
require.Equal(t, err, nil)
}
// TestStringBeneficiaryFIOptions validates Format() formatted according to the FormatOptions
func TestStringBeneficiaryFIOptions(t *testing.T) {
var line = "{4100}D123456789*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseBeneficiaryFI()
require.Equal(t, err, nil)
bfi := r.currentFEDWireMessage.BeneficiaryFI
require.Equal(t, bfi.String(), "{4100}D123456789 * * * * *")
require.Equal(t, bfi.Format(FormatOptions{VariableLengthFields: true}), "{4100}D123456789*")
require.Equal(t, bfi.String(), bfi.Format(FormatOptions{VariableLengthFields: false}))
}