-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathfiDrawdownDebitAccountAdvice_test.go
183 lines (135 loc) · 7.46 KB
/
fiDrawdownDebitAccountAdvice_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"
)
// mockFIDrawdownDebitAccountAdvice creates a FIDrawdownDebitAccountAdvice
func mockFIDrawdownDebitAccountAdvice() *FIDrawdownDebitAccountAdvice {
debitDDAdvice := NewFIDrawdownDebitAccountAdvice()
debitDDAdvice.Advice.AdviceCode = AdviceCodeLetter
debitDDAdvice.Advice.LineOne = "Line One"
debitDDAdvice.Advice.LineTwo = "Line Two"
debitDDAdvice.Advice.LineThree = "Line Three"
debitDDAdvice.Advice.LineFour = "Line Four"
debitDDAdvice.Advice.LineFive = "Line Five"
debitDDAdvice.Advice.LineSix = "Line Six"
return debitDDAdvice
}
// TestMockFIDrawdownDebitAccountAdvice validates mockFIDrawdownDebitAccountAdvice
func TestMockFIDrawdownDebitAccountAdvice(t *testing.T) {
debitDDAdvice := mockFIDrawdownDebitAccountAdvice()
require.NoError(t, debitDDAdvice.Validate(), "mockFIDrawdownDebitAccountAdvice does not validate and will break other tests")
}
// TestFIDrawdownDebitAccountAdviceAdviceCodeValid validates FIDrawdownDebitAccountAdvice AdviceCode is alphanumeric
func TestFIDrawdownDebitAccountAdviceCodeValid(t *testing.T) {
debitDDAdvice := mockFIDrawdownDebitAccountAdvice()
debitDDAdvice.Advice.AdviceCode = "Z"
err := debitDDAdvice.Validate()
require.EqualError(t, err, fieldError("AdviceCode", ErrAdviceCode, debitDDAdvice.Advice.AdviceCode).Error())
}
// TestFIDrawdownDebitAccountAdviceLineOneAlphaNumeric validates FIDrawdownDebitAccountAdvice LineOne is alphanumeric
func TestFIDrawdownDebitAccountAdviceLineOneAlphaNumeric(t *testing.T) {
debitDDAdvice := mockFIDrawdownDebitAccountAdvice()
debitDDAdvice.Advice.LineOne = "®"
err := debitDDAdvice.Validate()
require.EqualError(t, err, fieldError("LineOne", ErrNonAlphanumeric, debitDDAdvice.Advice.LineOne).Error())
}
// TestFIDrawdownDebitAccountAdviceLineTwoAlphaNumeric validates FIDrawdownDebitAccountAdvice LineTwo is alphanumeric
func TestFIDrawdownDebitAccountAdviceLineTwoAlphaNumeric(t *testing.T) {
debitDDAdvice := mockFIDrawdownDebitAccountAdvice()
debitDDAdvice.Advice.LineTwo = "®"
err := debitDDAdvice.Validate()
require.EqualError(t, err, fieldError("LineTwo", ErrNonAlphanumeric, debitDDAdvice.Advice.LineTwo).Error())
}
// TestFIDrawdownDebitAccountAdviceLineThreeAlphaNumeric validates FIDrawdownDebitAccountAdvice LineThree is alphanumeric
func TestFIDrawdownDebitAccountAdviceLineThreeAlphaNumeric(t *testing.T) {
debitDDAdvice := mockFIDrawdownDebitAccountAdvice()
debitDDAdvice.Advice.LineThree = "®"
err := debitDDAdvice.Validate()
require.EqualError(t, err, fieldError("LineThree", ErrNonAlphanumeric, debitDDAdvice.Advice.LineThree).Error())
}
// TestFIDrawdownDebitAccountAdviceLineFourAlphaNumeric validates FIDrawdownDebitAccountAdvice LineFour is alphanumeric
func TestFIDrawdownDebitAccountAdviceLineFourAlphaNumeric(t *testing.T) {
debitDDAdvice := mockFIDrawdownDebitAccountAdvice()
debitDDAdvice.Advice.LineFour = "®"
err := debitDDAdvice.Validate()
require.EqualError(t, err, fieldError("LineFour", ErrNonAlphanumeric, debitDDAdvice.Advice.LineFour).Error())
}
// TestFIDrawdownDebitAccountAdviceLineFiveAlphaNumeric validates FIDrawdownDebitAccountAdvice LineFive is alphanumeric
func TestFIDrawdownDebitAccountAdviceLineFiveAlphaNumeric(t *testing.T) {
debitDDAdvice := mockFIDrawdownDebitAccountAdvice()
debitDDAdvice.Advice.LineFive = "®"
err := debitDDAdvice.Validate()
require.EqualError(t, err, fieldError("LineFive", ErrNonAlphanumeric, debitDDAdvice.Advice.LineFive).Error())
}
// TestFIDrawdownDebitAccountAdviceLineSixAlphaNumeric validates FIDrawdownDebitAccountAdvice LineSix is alphanumeric
func TestFIDrawdownDebitAccountAdviceLineSixAlphaNumeric(t *testing.T) {
debitDDAdvice := mockFIDrawdownDebitAccountAdvice()
debitDDAdvice.Advice.LineSix = "®"
err := debitDDAdvice.Validate()
require.EqualError(t, err, fieldError("LineSix", ErrNonAlphanumeric, debitDDAdvice.Advice.LineSix).Error())
}
// TestParseFIDrawdownDebitAccountAdviceWrongLength parses a wrong FIDrawdownDebitAccountAdvice record length
func TestParseFIDrawdownDebitAccountAdviceWrongLength(t *testing.T) {
var line = "{6110}LTRLine One Line Two Line Three Line Four Line Five Line Six "
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIDrawdownDebitAccountAdvice()
require.EqualError(t, err, r.parseError(fieldError("LineOne", ErrRequireDelimiter)).Error())
}
// TestParseFIDrawdownDebitAccountAdviceReaderParseError parses a wrong FIDrawdownDebitAccountAdvice reader parse error
func TestParseFIDrawdownDebitAccountAdviceReaderParseError(t *testing.T) {
var line = "{6110}LTR®ine One *Line Two *Line Three *Line Four *Line Five *Line Six *"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIDrawdownDebitAccountAdvice()
expected := r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "®ine One")).Error()
require.EqualError(t, err, expected)
_, err = r.Read()
expected = r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "®ine One")).Error()
require.EqualError(t, err, expected)
}
// TestFIDrawdownDebitAccountAdviceTagError validates a FIDrawdownDebitAccountAdvice tag
func TestFIDrawdownDebitAccountAdviceTagError(t *testing.T) {
debitDDAdvice := mockFIDrawdownDebitAccountAdvice()
debitDDAdvice.tag = "{9999}"
err := debitDDAdvice.Validate()
require.EqualError(t, err, fieldError("tag", ErrValidTagForType, debitDDAdvice.tag).Error())
}
// TestStringFIDrawdownDebitAccountAdviceVariableLength parses using variable length
func TestStringFIDrawdownDebitAccountAdviceVariableLength(t *testing.T) {
var line = "{6110}HLD"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIDrawdownDebitAccountAdvice()
require.Nil(t, err)
line = "{6110}HLD NNN"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseFIDrawdownDebitAccountAdvice()
require.ErrorContains(t, err, ErrRequireDelimiter.Error())
line = "{6110}HLD********"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseFIDrawdownDebitAccountAdvice()
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
line = "{6110}HLD*"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseFIDrawdownDebitAccountAdvice()
require.Equal(t, err, nil)
}
// TestStringFIDrawdownDebitAccountAdviceOptions validates Format() formatted according to the FormatOptions
func TestStringFIDrawdownDebitAccountAdviceOptions(t *testing.T) {
var line = "{6110}HLD*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIDrawdownDebitAccountAdvice()
require.Equal(t, err, nil)
record := r.currentFEDWireMessage.FIDrawdownDebitAccountAdvice
require.Equal(t, record.String(), "{6110}HLD * * * * * *")
require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6110}HLD*")
require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false}))
}