-
Notifications
You must be signed in to change notification settings - Fork 40
/
fIBeneficiaryFIAdvice_test.go
183 lines (135 loc) · 6.76 KB
/
fIBeneficiaryFIAdvice_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
package wire
import (
"errors"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// mockFIBeneficiaryFIAdvice creates a FIBeneficiaryFIAdvice
func mockFIBeneficiaryFIAdvice() *FIBeneficiaryFIAdvice {
fibfia := NewFIBeneficiaryFIAdvice()
fibfia.Advice.AdviceCode = AdviceCodeTelex
fibfia.Advice.LineOne = "Line One"
fibfia.Advice.LineTwo = "Line Two"
fibfia.Advice.LineThree = "Line Three"
fibfia.Advice.LineFour = "Line Four"
fibfia.Advice.LineFive = "Line Five"
fibfia.Advice.LineSix = "Line Six"
return fibfia
}
// TestMockFIBeneficiaryFIAdvice validates mockFIBeneficiaryFIAdvice
func TestMockFIBeneficiaryFIAdvice(t *testing.T) {
fibfia := mockFIBeneficiaryFIAdvice()
require.NoError(t, fibfia.Validate(), "mockFIBeneficiaryFIAdvice does not validate and will break other tests")
}
// TestFIBeneficiaryFIAdviceAdviceCodeValid validates FIBeneficiaryFIAdvice AdviceCode is alphanumeric
func TestFIBeneficiaryFIAdviceAdviceCodeValid(t *testing.T) {
fibfia := mockFIBeneficiaryFIAdvice()
fibfia.Advice.AdviceCode = "Z"
err := fibfia.Validate()
require.EqualError(t, err, fieldError("AdviceCode", ErrAdviceCode, fibfia.Advice.AdviceCode).Error())
}
// TestFIBeneficiaryFIAdviceLineOneAlphaNumeric validates FIBeneficiaryFIAdvice LineOne is alphanumeric
func TestFIBeneficiaryFIAdviceLineOneAlphaNumeric(t *testing.T) {
fibfia := mockFIBeneficiaryFIAdvice()
fibfia.Advice.LineOne = "®"
err := fibfia.Validate()
require.EqualError(t, err, fieldError("LineOne", ErrNonAlphanumeric, fibfia.Advice.LineOne).Error())
}
// TestFIBeneficiaryFIAdviceLineTwoAlphaNumeric validates FIBeneficiaryFIAdvice LineTwo is alphanumeric
func TestFIBeneficiaryFIAdviceLineTwoAlphaNumeric(t *testing.T) {
fibfia := mockFIBeneficiaryFIAdvice()
fibfia.Advice.LineTwo = "®"
err := fibfia.Validate()
require.EqualError(t, err, fieldError("LineTwo", ErrNonAlphanumeric, fibfia.Advice.LineTwo).Error())
}
// TestFIBeneficiaryFIAdviceLineThreeAlphaNumeric validates FIBeneficiaryFIAdvice LineThree is alphanumeric
func TestFIBeneficiaryFIAdviceLineThreeAlphaNumeric(t *testing.T) {
fibfia := mockFIBeneficiaryFIAdvice()
fibfia.Advice.LineThree = "®"
err := fibfia.Validate()
require.EqualError(t, err, fieldError("LineThree", ErrNonAlphanumeric, fibfia.Advice.LineThree).Error())
}
// TestFIBeneficiaryFIAdviceLineFourAlphaNumeric validates FIBeneficiaryFIAdvice LineFour is alphanumeric
func TestFIBeneficiaryFIAdviceLineFourAlphaNumeric(t *testing.T) {
fibfia := mockFIBeneficiaryFIAdvice()
fibfia.Advice.LineFour = "®"
err := fibfia.Validate()
require.EqualError(t, err, fieldError("LineFour", ErrNonAlphanumeric, fibfia.Advice.LineFour).Error())
}
// TestFIBeneficiaryFIAdviceLineFiveAlphaNumeric validates FIBeneficiaryFIAdvice LineFive is alphanumeric
func TestFIBeneficiaryFIAdviceLineFiveAlphaNumeric(t *testing.T) {
fibfia := mockFIBeneficiaryFIAdvice()
fibfia.Advice.LineFive = "®"
err := fibfia.Validate()
require.EqualError(t, err, fieldError("LineFive", ErrNonAlphanumeric, fibfia.Advice.LineFive).Error())
}
// TestFIBeneficiaryFIAdviceLineSixAlphaNumeric validates FIBeneficiaryFIAdvice LineSix is alphanumeric
func TestFIBeneficiaryFIAdviceLineSixAlphaNumeric(t *testing.T) {
fibfia := mockFIBeneficiaryFIAdvice()
fibfia.Advice.LineSix = "®"
err := fibfia.Validate()
require.EqualError(t, err, fieldError("LineSix", ErrNonAlphanumeric, fibfia.Advice.LineSix).Error())
}
// TestParseFIBeneficiaryFIAdviceWrongLength parses a wrong FIBeneficiaryFIAdvice record length
func TestParseFIBeneficiaryFIAdviceWrongLength(t *testing.T) {
var line = "{6310}TLXLine One Line Two Line Three Line Four Line Five Line Six "
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIBeneficiaryFIAdvice()
require.EqualError(t, err, r.parseError(fieldError("LineOne", ErrRequireDelimiter)).Error())
}
// TestParseFIBeneficiaryFIAdviceReaderParseError parses a wrong FIBeneficiaryFIAdvice reader parse error
func TestParseFIBeneficiaryFIAdviceReaderParseError(t *testing.T) {
var line = "{6310}TLXLine ®ne *Line Two *Line Three *Line Four *Line Five *Line Six *"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIBeneficiaryFIAdvice()
expected := r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "Line ®ne")).Error()
require.EqualError(t, err, expected)
_, err = r.Read()
expected = r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "Line ®ne")).Error()
require.EqualError(t, err, expected)
}
// TestFIBeneficiaryFIAdviceTagError validates a FIBeneficiaryFIAdvice tag
func TestFIBeneficiaryFIAdviceTagError(t *testing.T) {
fibfia := mockFIBeneficiaryFIAdvice()
fibfia.tag = "{9999}"
err := fibfia.Validate()
require.EqualError(t, err, fieldError("tag", ErrValidTagForType, fibfia.tag).Error())
}
// TestStringFIBeneficiaryFIAdviceVariableLength parses using variable length
func TestStringFIBeneficiaryFIAdviceVariableLength(t *testing.T) {
var line = "{6310}HLD"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIBeneficiaryFIAdvice()
require.Nil(t, err)
line = "{6310}HLD NNN"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseFIBeneficiaryFIAdvice()
require.ErrorContains(t, err, ErrRequireDelimiter.Error())
line = "{6310}HLD********"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseFIBeneficiaryFIAdvice()
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
line = "{6310}HLD*"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseFIBeneficiaryFIAdvice()
require.Equal(t, err, nil)
}
// TestStringFIBeneficiaryFIAdviceOptions validates Format() formatted according to the FormatOptions
func TestStringFIBeneficiaryFIAdviceOptions(t *testing.T) {
var line = "{6310}HLD*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIBeneficiaryFIAdvice()
require.Equal(t, err, nil)
record := r.currentFEDWireMessage.FIBeneficiaryFIAdvice
require.Equal(t, record.String(), "{6310}HLD * * * * * *")
require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6310}HLD*")
require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false}))
}