-
Notifications
You must be signed in to change notification settings - Fork 40
/
fiIntermediaryFIAdvice_test.go
182 lines (135 loc) · 6.81 KB
/
fiIntermediaryFIAdvice_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"
)
// mockFIIntermediaryFIAdvice creates a FIIntermediaryFIAdvice
func mockFIIntermediaryFIAdvice() *FIIntermediaryFIAdvice {
fiifia := NewFIIntermediaryFIAdvice()
fiifia.Advice.AdviceCode = AdviceCodeLetter
fiifia.Advice.LineOne = "Line One"
fiifia.Advice.LineTwo = "Line Two"
fiifia.Advice.LineThree = "Line Three"
fiifia.Advice.LineFour = "Line Four"
fiifia.Advice.LineFive = "Line Five"
fiifia.Advice.LineSix = "Line Six"
return fiifia
}
// TestMockFIIntermediaryFIAdvice validates mockFIIntermediaryFIAdvice
func TestMockFIIntermediaryFIAdvice(t *testing.T) {
fiifia := mockFIIntermediaryFIAdvice()
require.NoError(t, fiifia.Validate(), "mockFIIntermediaryFIAdvice does not validate and will break other tests")
}
// TestFIIntermediaryFIAdviceAdviceCodeValid validates FIIntermediaryFIAdvice AdviceCode is alphanumeric
func TestFIIntermediaryFIAdviceAdviceCodeValid(t *testing.T) {
fiifia := mockFIIntermediaryFIAdvice()
fiifia.Advice.AdviceCode = "Z"
err := fiifia.Validate()
require.EqualError(t, err, fieldError("AdviceCode", ErrAdviceCode, fiifia.Advice.AdviceCode).Error())
}
// TestFIIntermediaryFIAdviceLineOneAlphaNumeric validates FIIntermediaryFIAdvice LineOne is alphanumeric
func TestFIIntermediaryFIAdviceLineOneAlphaNumeric(t *testing.T) {
fiifia := mockFIIntermediaryFIAdvice()
fiifia.Advice.LineOne = "®"
err := fiifia.Validate()
require.EqualError(t, err, fieldError("LineOne", ErrNonAlphanumeric, fiifia.Advice.LineOne).Error())
}
// TestFIIntermediaryFIAdviceLineTwoAlphaNumeric validates FIIntermediaryFIAdvice LineTwo is alphanumeric
func TestFIIntermediaryFIAdviceLineTwoAlphaNumeric(t *testing.T) {
fiifia := mockFIIntermediaryFIAdvice()
fiifia.Advice.LineTwo = "®"
err := fiifia.Validate()
require.EqualError(t, err, fieldError("LineTwo", ErrNonAlphanumeric, fiifia.Advice.LineTwo).Error())
}
// TestFIIntermediaryFIAdviceLineThreeAlphaNumeric validates FIIntermediaryFIAdvice LineThree is alphanumeric
func TestFIIntermediaryFIAdviceLineThreeAlphaNumeric(t *testing.T) {
fiifia := mockFIIntermediaryFIAdvice()
fiifia.Advice.LineThree = "®"
err := fiifia.Validate()
require.EqualError(t, err, fieldError("LineThree", ErrNonAlphanumeric, fiifia.Advice.LineThree).Error())
}
// TestFIIntermediaryFIAdviceLineFourAlphaNumeric validates FIIntermediaryFIAdvice LineFour is alphanumeric
func TestFIIntermediaryFIAdviceLineFourAlphaNumeric(t *testing.T) {
fiifia := mockFIIntermediaryFIAdvice()
fiifia.Advice.LineFour = "®"
err := fiifia.Validate()
require.EqualError(t, err, fieldError("LineFour", ErrNonAlphanumeric, fiifia.Advice.LineFour).Error())
}
// TestFIIntermediaryFIAdviceLineFiveAlphaNumeric validates FIIntermediaryFIAdvice LineFive is alphanumeric
func TestFIIntermediaryFIAdviceLineFiveAlphaNumeric(t *testing.T) {
fiifia := mockFIIntermediaryFIAdvice()
fiifia.Advice.LineFive = "®"
err := fiifia.Validate()
require.EqualError(t, err, fieldError("LineFive", ErrNonAlphanumeric, fiifia.Advice.LineFive).Error())
}
// TestFIIntermediaryFIAdviceLineSixAlphaNumeric validates FIIntermediaryFIAdvice LineSix is alphanumeric
func TestFIIntermediaryFIAdviceLineSixAlphaNumeric(t *testing.T) {
fiifia := mockFIIntermediaryFIAdvice()
fiifia.Advice.LineSix = "®"
err := fiifia.Validate()
require.EqualError(t, err, fieldError("LineSix", ErrNonAlphanumeric, fiifia.Advice.LineSix).Error())
}
// TestParseFIIntermediaryFIAdviceWrongLength parses a wrong FIIntermediaryFIAdvice record length
func TestParseFIIntermediaryFIAdviceWrongLength(t *testing.T) {
var line = "{6210}LTRLine One Line Two Line Three Line Four Line Five Line Six "
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIIntermediaryFIAdvice()
require.EqualError(t, err, r.parseError(fieldError("LineOne", ErrRequireDelimiter)).Error())
}
// TestParseFIIntermediaryFIAdviceReaderParseError parses a wrong FIIntermediaryFIAdvice reader parse error
func TestParseFIIntermediaryFIAdviceReaderParseError(t *testing.T) {
var line = "{6210}LTRLine ®ne *Line Two *Line Three *Line Four *Line Five *Line Six *"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIIntermediaryFIAdvice()
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)
}
// TestFIIntermediaryFIAdviceTagError validates a FIIntermediaryFIAdvice tag
func TestFIIntermediaryFIAdviceTagError(t *testing.T) {
fiifia := mockFIIntermediaryFI()
fiifia.tag = "{9999}"
err := fiifia.Validate()
require.EqualError(t, err, fieldError("tag", ErrValidTagForType, fiifia.tag).Error())
}
// TestStringFIIntermediaryFIAdviceVariableLength parses using variable length
func TestStringFIIntermediaryFIAdviceVariableLength(t *testing.T) {
var line = "{6210}HLD"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIIntermediaryFIAdvice()
require.Nil(t, err)
line = "{6210}HLD NNN"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseFIIntermediaryFIAdvice()
require.ErrorContains(t, err, ErrRequireDelimiter.Error())
line = "{6210}HLD********"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseFIIntermediaryFIAdvice()
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
line = "{6210}HLD*"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseFIIntermediaryFIAdvice()
require.Equal(t, err, nil)
}
// TestStringFIIntermediaryFIAdviceOptions validates Format() formatted according to the FormatOptions
func TestStringFIIntermediaryFIAdviceOptions(t *testing.T) {
var line = "{6210}HLD*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIIntermediaryFIAdvice()
require.Equal(t, err, nil)
record := r.currentFEDWireMessage.FIIntermediaryFIAdvice
require.Equal(t, record.String(), "{6210}HLD * * * * * *")
require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6210}HLD*")
require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false}))
}