-
Notifications
You must be signed in to change notification settings - Fork 39
/
institutionAccount_test.go
178 lines (131 loc) · 6.92 KB
/
institutionAccount_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
package wire
import (
"errors"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// InstitutionAccount creates a InstitutionAccount
func mockInstitutionAccount() *InstitutionAccount {
iAccount := NewInstitutionAccount()
iAccount.CoverPayment.SwiftFieldTag = "Swift Field Tag"
iAccount.CoverPayment.SwiftLineOne = "Swift Line One"
iAccount.CoverPayment.SwiftLineTwo = "Swift Line Two"
iAccount.CoverPayment.SwiftLineThree = "Swift Line Three"
iAccount.CoverPayment.SwiftLineFour = "Swift Line Four"
iAccount.CoverPayment.SwiftLineFive = "Swift Line Five"
return iAccount
}
// TestMockInstitutionAccount validates mockInstitutionAccount
func TestMockInstitutionAccount(t *testing.T) {
iAccount := mockInstitutionAccount()
require.NoError(t, iAccount.Validate(), "mockInstitutionAccount does not validate and will break other tests")
}
// TestInstitutionAccountSwiftFieldTagAlphaNumeric validates InstitutionAccount SwiftFieldTag is alphanumeric
func TestInstitutionAccountSwiftFieldTagAlphaNumeric(t *testing.T) {
iAccount := mockInstitutionAccount()
iAccount.CoverPayment.SwiftFieldTag = "®"
err := iAccount.Validate()
require.EqualError(t, err, fieldError("SwiftFieldTag", ErrNonAlphanumeric, iAccount.CoverPayment.SwiftFieldTag).Error())
}
// TestInstitutionAccountSwiftLineOneAlphaNumeric validates InstitutionAccount SwiftLineOne is alphanumeric
func TestInstitutionAccountSwiftLineOneAlphaNumeric(t *testing.T) {
iAccount := mockInstitutionAccount()
iAccount.CoverPayment.SwiftLineOne = "®"
err := iAccount.Validate()
require.EqualError(t, err, fieldError("SwiftLineOne", ErrNonAlphanumeric, iAccount.CoverPayment.SwiftLineOne).Error())
}
// TestInstitutionAccountSwiftLineTwoAlphaNumeric validates InstitutionAccount SwiftLineTwo is alphanumeric
func TestInstitutionAccountSwiftLineTwoAlphaNumeric(t *testing.T) {
iAccount := mockInstitutionAccount()
iAccount.CoverPayment.SwiftLineTwo = "®"
err := iAccount.Validate()
require.EqualError(t, err, fieldError("SwiftLineTwo", ErrNonAlphanumeric, iAccount.CoverPayment.SwiftLineTwo).Error())
}
// TestInstitutionAccountSwiftLineThreeAlphaNumeric validates InstitutionAccount SwiftLineThree is alphanumeric
func TestInstitutionAccountSwiftLineThreeAlphaNumeric(t *testing.T) {
iAccount := mockInstitutionAccount()
iAccount.CoverPayment.SwiftLineThree = "®"
err := iAccount.Validate()
require.EqualError(t, err, fieldError("SwiftLineThree", ErrNonAlphanumeric, iAccount.CoverPayment.SwiftLineThree).Error())
}
// TestInstitutionAccountSwiftLineFourAlphaNumeric validates InstitutionAccount SwiftLineFour is alphanumeric
func TestInstitutionAccountSwiftLineFourAlphaNumeric(t *testing.T) {
iAccount := mockInstitutionAccount()
iAccount.CoverPayment.SwiftLineFour = "®"
err := iAccount.Validate()
require.EqualError(t, err, fieldError("SwiftLineFour", ErrNonAlphanumeric, iAccount.CoverPayment.SwiftLineFour).Error())
}
// TestInstitutionAccountSwiftLineFiveAlphaNumeric validates InstitutionAccount SwiftLineFive is alphanumeric
func TestInstitutionAccountSwiftLineFiveAlphaNumeric(t *testing.T) {
iAccount := mockInstitutionAccount()
iAccount.CoverPayment.SwiftLineFive = "®"
err := iAccount.Validate()
require.EqualError(t, err, fieldError("SwiftLineFive", ErrNonAlphanumeric, iAccount.CoverPayment.SwiftLineFive).Error())
}
// TestInstitutionAccountSwiftLineSixAlphaNumeric validates InstitutionAccount SwiftLineSix is an invalid property
func TestInstitutionAccountSwiftLineSixAlphaNumeric(t *testing.T) {
iAccount := mockInstitutionAccount()
iAccount.CoverPayment.SwiftLineSix = "Test"
err := iAccount.Validate()
require.EqualError(t, err, fieldError("SwiftLineSix", ErrInvalidProperty, iAccount.CoverPayment.SwiftLineSix).Error())
}
// TestParseInstitutionAccountWrongLength parses a wrong InstitutionAccount record length
func TestParseInstitutionAccountWrongLength(t *testing.T) {
var line = "{7057}SwiftSwift Line One Swift Line Two Swift Line Three Swift Line Four Swift Line Five "
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseInstitutionAccount()
require.EqualError(t, err, r.parseError(fieldError("SwiftFieldTag", ErrRequireDelimiter)).Error())
}
// TestParseInstitutionAccountReaderParseError parses a wrong InstitutionAccount reader parse error
func TestParseInstitutionAccountReaderParseError(t *testing.T) {
var line = "{7057}Swift*Swift ®ine One *Swift Line Two *Swift Line Three *Swift Line Four *Swift Line Five *"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseInstitutionAccount()
require.EqualError(t, err, r.parseError(fieldError("SwiftLineOne", ErrNonAlphanumeric, "Swift ®ine One")).Error())
_, err = r.Read()
require.EqualError(t, err, r.parseError(fieldError("SwiftLineOne", ErrNonAlphanumeric, "Swift ®ine One")).Error())
}
// TestInstitutionAccountTagError validates a InstitutionAccount tag
func TestInstitutionAccountTagError(t *testing.T) {
iAccount := mockInstitutionAccount()
iAccount.tag = "{9999}"
require.EqualError(t, iAccount.Validate(), fieldError("tag", ErrValidTagForType, iAccount.tag).Error())
}
// TestStringInstitutionAccountVariableLength parses using variable length
func TestStringInstitutionAccountVariableLength(t *testing.T) {
var line = "{7057}"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseInstitutionAccount()
require.Nil(t, err)
line = "{7057}Swift NNN"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseInstitutionAccount()
require.ErrorContains(t, err, ErrRequireDelimiter.Error())
line = "{7057}********"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseInstitutionAccount()
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
line = "{7057}*"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseInstitutionAccount()
require.Equal(t, err, nil)
}
// TestStringInstitutionAccountOptions validates Format() formatted according to the FormatOptions
func TestStringInstitutionAccountOptions(t *testing.T) {
var line = "{7057}Swift*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseInstitutionAccount()
require.Equal(t, err, nil)
record := r.currentFEDWireMessage.InstitutionAccount
require.Equal(t, record.String(), "{7057}Swift* * * * * *")
require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{7057}Swift*")
require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false}))
}