-
Notifications
You must be signed in to change notification settings - Fork 40
/
instructingFI_test.go
220 lines (163 loc) · 8.03 KB
/
instructingFI_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
package wire
import (
"errors"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// mockInstructingFI creates a InstructingFI
func mockInstructingFI() *InstructingFI {
ifi := NewInstructingFI()
ifi.FinancialInstitution.IdentificationCode = DemandDepositAccountNumber
ifi.FinancialInstitution.Identifier = "123456789"
ifi.FinancialInstitution.Name = "FI Name"
ifi.FinancialInstitution.Address.AddressLineOne = "Address One"
ifi.FinancialInstitution.Address.AddressLineTwo = "Address Two"
ifi.FinancialInstitution.Address.AddressLineThree = "Address Three"
return ifi
}
// TestMockInstructingFI validates mockInstructingFI
func TestMockInstructingFI(t *testing.T) {
bfi := mockInstructingFI()
require.NoError(t, bfi.Validate(), "mockInstructingFI does not validate and will break other tests")
}
// TestInstructingFIIdentificationCodeValid validates InstructingFI IdentificationCode
func TestInstructingFIIdentificationCodeValid(t *testing.T) {
bfi := mockInstructingFI()
bfi.FinancialInstitution.IdentificationCode = "Football Card ID"
err := bfi.Validate()
require.EqualError(t, err, fieldError("IdentificationCode", ErrIdentificationCode, bfi.FinancialInstitution.IdentificationCode).Error())
}
// TestInstructingFIIdentificationCodeFI validates InstructingFI IdentificationCode is an FI code
func TestInstructingFIIdentificationCodeFI(t *testing.T) {
bfi := mockInstructingFI()
bfi.FinancialInstitution.IdentificationCode = "1"
err := bfi.Validate()
require.EqualError(t, err, fieldError("IdentificationCode", ErrIdentificationCode, bfi.FinancialInstitution.IdentificationCode).Error())
}
// TestInstructingFIIdentifierAlphaNumeric validates InstructingFI Identifier is alphanumeric
func TestInstructingFIIdentifierAlphaNumeric(t *testing.T) {
bfi := mockInstructingFI()
bfi.FinancialInstitution.Identifier = "®"
err := bfi.Validate()
require.EqualError(t, err, fieldError("Identifier", ErrNonAlphanumeric, bfi.FinancialInstitution.Identifier).Error())
}
// TestInstructingFINameAlphaNumeric validates InstructingFI Name is alphanumeric
func TestInstructingFINameAlphaNumeric(t *testing.T) {
bfi := mockInstructingFI()
bfi.FinancialInstitution.Name = "®"
err := bfi.Validate()
require.EqualError(t, err, fieldError("Name", ErrNonAlphanumeric, bfi.FinancialInstitution.Name).Error())
}
// TestInstructingFIAddressLineOneAlphaNumeric validates InstructingFI AddressLineOne is alphanumeric
func TestInstructingFIAddressLineOneAlphaNumeric(t *testing.T) {
bfi := mockInstructingFI()
bfi.FinancialInstitution.Address.AddressLineOne = "®"
err := bfi.Validate()
require.EqualError(t, err, fieldError("AddressLineOne", ErrNonAlphanumeric, bfi.FinancialInstitution.Address.AddressLineOne).Error())
}
// TestInstructingFIAddressLineTwoAlphaNumeric validates InstructingFI AddressLineTwo is alphanumeric
func TestInstructingFIAddressLineTwoAlphaNumeric(t *testing.T) {
bfi := mockInstructingFI()
bfi.FinancialInstitution.Address.AddressLineTwo = "®"
err := bfi.Validate()
require.EqualError(t, err, fieldError("AddressLineTwo", ErrNonAlphanumeric, bfi.FinancialInstitution.Address.AddressLineTwo).Error())
}
// TestInstructingFIAddressLineThreeAlphaNumeric validates InstructingFI AddressLineThree is alphanumeric
func TestInstructingFIAddressLineThreeAlphaNumeric(t *testing.T) {
bfi := mockInstructingFI()
bfi.FinancialInstitution.Address.AddressLineThree = "®"
err := bfi.Validate()
require.EqualError(t, err, fieldError("AddressLineThree", ErrNonAlphanumeric, bfi.FinancialInstitution.Address.AddressLineThree).Error())
}
// TestInstructingFIIdentificationCodeRequired validates InstructingFI IdentificationCode is required
func TestInstructingFIIdentificationCodeRequired(t *testing.T) {
bfi := mockInstructingFI()
bfi.FinancialInstitution.IdentificationCode = ""
err := bfi.Validate()
require.EqualError(t, err, fieldError("IdentificationCode", ErrFieldRequired).Error())
}
// TestInstructingFIIdentifierRequired validates InstructingFI Identifier is required
func TestInstructingFIIdentifierRequired(t *testing.T) {
bfi := mockInstructingFI()
bfi.FinancialInstitution.Identifier = ""
err := bfi.Validate()
require.EqualError(t, err, fieldError("Identifier", ErrFieldRequired).Error())
}
func TestInstructingFI_IDCodeAndIDValidation(t *testing.T) {
// ID Code must be empty if no identifier is present
line := "{5200} *FI Name*Address One*Address Two*Address Three*"
ifi := new(InstructingFI)
require.NoError(t, ifi.Parse(line))
require.NoError(t, ifi.Validate())
require.Equal(t, ifi.Format(FormatOptions{VariableLengthFields: true}), line)
}
// TestParseInstructingFIWrongLength parses a wrong InstructingFI record length
func TestParseInstructingFIWrongLength(t *testing.T) {
var line = "{5200}D123456789 FI Name Address One Address Two Address Three "
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseInstructingFI()
require.EqualError(t, err, r.parseError(fieldError("Identifier", ErrRequireDelimiter)).Error())
}
// TestParseInstructingFIReaderParseError parses a wrong InstructingFI reader parse error
func TestParseInstructingFIReaderParseError(t *testing.T) {
var line = "{5200}D123456789 *®I Name *Address One *Address Two *Address Three *"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseInstructingFI()
require.EqualError(t, err, r.parseError(fieldError("Name", ErrNonAlphanumeric, "®I Name")).Error())
_, err = r.Read()
require.EqualError(t, err, r.parseError(fieldError("Name", ErrNonAlphanumeric, "®I Name")).Error())
}
// TestInstructingFITagError validates a InstructingFI tag
func TestInstructingFITagError(t *testing.T) {
ifi := mockInstructingFI()
ifi.tag = "{9999}"
require.EqualError(t, ifi.Validate(), fieldError("tag", ErrValidTagForType, ifi.tag).Error())
}
// TestStringInstructingFIVariableLength parses using variable length
func TestStringInstructingFIVariableLength(t *testing.T) {
var line = "{5200}D12*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseInstructingFI()
require.Nil(t, err)
line = "{5200}D12 NNN"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseInstructingFI()
require.ErrorContains(t, err, ErrRequireDelimiter.Error())
line = "{5200}D12***********"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseInstructingFI()
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
line = "{5200}D12*"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseInstructingFI()
require.Equal(t, err, nil)
}
// TestStringInstructingFIOptions validates Format() formatted according to the FormatOptions
func TestStringInstructingFIOptions(t *testing.T) {
var line = "{5200}D12*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseInstructingFI()
require.Equal(t, err, nil)
record := r.currentFEDWireMessage.InstructingFI
require.Equal(t, record.String(), "{5200}D12 * * * * *")
require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{5200}D12*")
require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false}))
}
// TestInstructingFIVariableLength parses using variable length exceeding max limit
func TestInstructingFIVariableLength(t *testing.T) {
var line = "{5200}BCITIGB2LXXX*CITIBANK LONDONENGLAND*CITIGROUP CENTRELONDONGREATER LONDONENGLAND*NGB*LONDON WC2R 1HB, ENGLAND*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseInstructingFI()
require.Nil(t, err)
err = r.parseInstructingFI()
require.Equal(t, err, nil)
}