-
Notifications
You must be signed in to change notification settings - Fork 39
/
beneficiaryCustomer_test.go
182 lines (134 loc) · 6.76 KB
/
beneficiaryCustomer_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
package wire
import (
"errors"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// mockBeneficiaryCustomer creates a BeneficiaryCustomer
func mockBeneficiaryCustomer() *BeneficiaryCustomer {
bc := NewBeneficiaryCustomer()
bc.CoverPayment.SwiftFieldTag = "Swift Field Tag"
bc.CoverPayment.SwiftLineOne = "Swift Line One"
bc.CoverPayment.SwiftLineTwo = "Swift Line Two"
bc.CoverPayment.SwiftLineThree = "Swift Line Three"
bc.CoverPayment.SwiftLineFour = "Swift Line Four"
bc.CoverPayment.SwiftLineFive = "Swift Line Five"
return bc
}
// TestMockBeneficiaryCustomer validates mockBeneficiaryCustomer
func TestMockBeneficiaryCustomer(t *testing.T) {
bc := mockBeneficiaryCustomer()
require.NoError(t, bc.Validate(), "mockBeneficiaryCustomer does not validate and will break other tests")
}
// TestBeneficiaryCustomerSwiftFieldTagAlphaNumeric validates BeneficiaryCustomer SwiftFieldTag is alphanumeric
func TestBeneficiaryCustomerSwiftFieldTagAlphaNumeric(t *testing.T) {
bc := mockBeneficiaryCustomer()
bc.CoverPayment.SwiftFieldTag = "®"
err := bc.Validate()
require.EqualError(t, err, fieldError("SwiftFieldTag", ErrNonAlphanumeric, bc.CoverPayment.SwiftFieldTag).Error())
}
// TestBeneficiaryCustomerSwiftLineOneAlphaNumeric validates BeneficiaryCustomer SwiftLineOne is alphanumeric
func TestBeneficiaryCustomerSwiftLineOneAlphaNumeric(t *testing.T) {
bc := mockBeneficiaryCustomer()
bc.CoverPayment.SwiftLineOne = "®"
err := bc.Validate()
require.EqualError(t, err, fieldError("SwiftLineOne", ErrNonAlphanumeric, bc.CoverPayment.SwiftLineOne).Error())
}
// TestBeneficiaryCustomerSwiftLineTwoAlphaNumeric validates BeneficiaryCustomer SwiftLineTwo is alphanumeric
func TestBeneficiaryCustomerSwiftLineTwoAlphaNumeric(t *testing.T) {
bc := mockBeneficiaryCustomer()
bc.CoverPayment.SwiftLineTwo = "®"
err := bc.Validate()
require.EqualError(t, err, fieldError("SwiftLineTwo", ErrNonAlphanumeric, bc.CoverPayment.SwiftLineTwo).Error())
}
// TestBeneficiaryCustomerSwiftLineThreeAlphaNumeric validates BeneficiaryCustomer SwiftLineThree is alphanumeric
func TestBeneficiaryCustomerSwiftLineThreeAlphaNumeric(t *testing.T) {
bc := mockBeneficiaryCustomer()
bc.CoverPayment.SwiftLineThree = "®"
err := bc.Validate()
require.EqualError(t, err, fieldError("SwiftLineThree", ErrNonAlphanumeric, bc.CoverPayment.SwiftLineThree).Error())
}
// TestBeneficiaryCustomerSwiftLineFourAlphaNumeric validates BeneficiaryCustomer SwiftLineFour is alphanumeric
func TestBeneficiaryCustomerSwiftLineFourAlphaNumeric(t *testing.T) {
bc := mockBeneficiaryCustomer()
bc.CoverPayment.SwiftLineFour = "®"
err := bc.Validate()
require.EqualError(t, err, fieldError("SwiftLineFour", ErrNonAlphanumeric, bc.CoverPayment.SwiftLineFour).Error())
}
// TestBeneficiaryCustomerSwiftLineFiveAlphaNumeric validates BeneficiaryCustomer SwiftLineFive is alphanumeric
func TestBeneficiaryCustomerSwiftLineFiveAlphaNumeric(t *testing.T) {
bc := mockBeneficiaryCustomer()
bc.CoverPayment.SwiftLineFive = "®"
err := bc.Validate()
require.EqualError(t, err, fieldError("SwiftLineFive", ErrNonAlphanumeric, bc.CoverPayment.SwiftLineFive).Error())
}
// TestBeneficiaryCustomerSwiftLineSixAlphaNumeric validates BeneficiaryCustomer SwiftLineSix is alphanumeric
func TestBeneficiaryCustomerSwiftLineSixAlphaNumeric(t *testing.T) {
sr := mockBeneficiaryCustomer()
sr.CoverPayment.SwiftLineSix = "Test"
err := sr.Validate()
require.EqualError(t, err, fieldError("SwiftLineSix", ErrInvalidProperty, sr.CoverPayment.SwiftLineSix).Error())
}
// TestParseBeneficiaryCustomerWrongLength parses a wrong BeneficiaryCustomer record length
func TestParseBeneficiaryCustomerWrongLength(t *testing.T) {
var line = "{7059}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.parseBeneficiaryCustomer()
require.EqualError(t, err, r.parseError(fieldError("SwiftFieldTag", ErrRequireDelimiter)).Error())
}
// TestParseBeneficiaryCustomerReaderParseError parses a wrong BeneficiaryCustomer reader parse error
func TestParseBeneficiaryCustomerReaderParseError(t *testing.T) {
var line = "{7059}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.parseBeneficiaryCustomer()
expected := r.parseError(fieldError("SwiftLineOne", ErrNonAlphanumeric, "Swift ®ine One")).Error()
require.EqualError(t, err, expected)
_, err = r.Read()
expected = r.parseError(fieldError("SwiftLineOne", ErrNonAlphanumeric, "Swift ®ine One")).Error()
require.EqualError(t, err, expected)
}
// TestBeneficiaryCustomerTagError validates a BeneficiaryCustomer tag
func TestBeneficiaryCustomerTagError(t *testing.T) {
bc := mockBeneficiaryCustomer()
bc.tag = "{9999}"
err := bc.Validate()
require.EqualError(t, err, fieldError("tag", ErrValidTagForType, bc.tag).Error())
}
// TestStringBeneficiaryCustomerVariableLength parses using variable length
func TestStringBeneficiaryCustomerVariableLength(t *testing.T) {
var line = "{7059}"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseBeneficiaryCustomer()
require.Nil(t, err)
line = "{7059}SwiftSwift ®ine One *Swift Line Two *Swift Line Three *Swift Line Four *Swift Line Five NN"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseBeneficiaryCustomer()
require.ErrorContains(t, err, ErrRequireDelimiter.Error())
line = "{7059}********"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseBeneficiaryCustomer()
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
line = "{7059}******"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseBeneficiaryCustomer()
require.Equal(t, err, nil)
}
// TestStringBeneficiaryCustomerOptions validates Format() formatted according to the FormatOptions
func TestStringBeneficiaryCustomerOptions(t *testing.T) {
var line = "{7059}*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseBeneficiaryCustomer()
require.Equal(t, err, nil)
bc := r.currentFEDWireMessage.BeneficiaryCustomer
require.Equal(t, bc.String(), "{7059} * * * * * *")
require.Equal(t, bc.Format(FormatOptions{VariableLengthFields: true}), "{7059}*")
require.Equal(t, bc.String(), bc.Format(FormatOptions{VariableLengthFields: false}))
}