-
Notifications
You must be signed in to change notification settings - Fork 39
/
fiBeneficiaryFI_test.go
172 lines (127 loc) · 5.98 KB
/
fiBeneficiaryFI_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
package wire
import (
"errors"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// mockFIBeneficiaryFI creates a FIBeneficiaryFI
func mockFIBeneficiaryFI() *FIBeneficiaryFI {
fibfi := NewFIBeneficiaryFI()
fibfi.FIToFI.LineOne = "Line One"
fibfi.FIToFI.LineTwo = "Line Two"
fibfi.FIToFI.LineThree = "Line Three"
fibfi.FIToFI.LineFour = "Line Four"
fibfi.FIToFI.LineFive = "Line Five"
fibfi.FIToFI.LineSix = "Line Six"
return fibfi
}
// TestMockFIBeneficiaryFI validates mockFIBeneficiaryFI
func TestMockFIBeneficiaryFI(t *testing.T) {
fibfi := mockFIBeneficiaryFI()
require.NoError(t, fibfi.Validate(), "mockFIBeneficiaryFI does not validate and will break other tests")
}
// TestFIBeneficiaryFILineOneAlphaNumeric validates FIBeneficiaryFI LineOne is alphanumeric
func TestFIBeneficiaryFILineOneAlphaNumeric(t *testing.T) {
fibfi := mockFIBeneficiaryFI()
fibfi.FIToFI.LineOne = "®"
err := fibfi.Validate()
require.EqualError(t, err, fieldError("LineOne", ErrNonAlphanumeric, fibfi.FIToFI.LineOne).Error())
}
// TestFIBeneficiaryFILineTwoAlphaNumeric validates FIBeneficiaryFI LineTwo is alphanumeric
func TestFIBeneficiaryFILineTwoAlphaNumeric(t *testing.T) {
fibfi := mockFIBeneficiaryFI()
fibfi.FIToFI.LineTwo = "®"
err := fibfi.Validate()
require.EqualError(t, err, fieldError("LineTwo", ErrNonAlphanumeric, fibfi.FIToFI.LineTwo).Error())
}
// TestFIBeneficiaryFILineThreeAlphaNumeric validates FIBeneficiaryFI LineThree is alphanumeric
func TestFIBeneficiaryFILineThreeAlphaNumeric(t *testing.T) {
fibfi := mockFIBeneficiaryFI()
fibfi.FIToFI.LineThree = "®"
err := fibfi.Validate()
require.EqualError(t, err, fieldError("LineThree", ErrNonAlphanumeric, fibfi.FIToFI.LineThree).Error())
}
// TestFIBeneficiaryFILineFourAlphaNumeric validates FIBeneficiaryFI LineFour is alphanumeric
func TestFIBeneficiaryFILineFourAlphaNumeric(t *testing.T) {
fibfi := mockFIBeneficiaryFI()
fibfi.FIToFI.LineFour = "®"
err := fibfi.Validate()
require.EqualError(t, err, fieldError("LineFour", ErrNonAlphanumeric, fibfi.FIToFI.LineFour).Error())
}
// TestFIBeneficiaryFILineFiveAlphaNumeric validates FIBeneficiaryFI LineFive is alphanumeric
func TestFIBeneficiaryFILineFiveAlphaNumeric(t *testing.T) {
fibfi := mockFIBeneficiaryFI()
fibfi.FIToFI.LineFive = "®"
err := fibfi.Validate()
require.EqualError(t, err, fieldError("LineFive", ErrNonAlphanumeric, fibfi.FIToFI.LineFive).Error())
}
// TestFIBeneficiaryFILineSixAlphaNumeric validates FIBeneficiaryFI LineSix is alphanumeric
func TestFIBeneficiaryFILineSixAlphaNumeric(t *testing.T) {
fibfi := mockFIBeneficiaryFI()
fibfi.FIToFI.LineSix = "®"
err := fibfi.Validate()
require.EqualError(t, err, fieldError("LineSix", ErrNonAlphanumeric, fibfi.FIToFI.LineSix).Error())
}
// TestParseFIBeneficiaryFIWrongLength parses a wrong FIBeneficiaryFI record length
func TestParseFIBeneficiaryFIWrongLength(t *testing.T) {
var line = "{6300}Line One Line Two Line Three Line Four Line Five Line Six "
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIBeneficiaryFI()
require.EqualError(t, err, r.parseError(fieldError("LineOne", ErrRequireDelimiter)).Error())
}
// TestParseFIBeneficiaryFIReaderParseError parses a wrong FIBeneficiaryFI reader parse error
func TestParseFIBeneficiaryFIReaderParseError(t *testing.T) {
var line = "{6300}Line ®ne *Line Two *Line Three *Line Four *Line Five *Line Six *"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIBeneficiaryFI()
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)
}
// TestFIBeneficiaryFITagError validates a FIBeneficiaryFI tag
func TestFIBeneficiaryFITagError(t *testing.T) {
fibfi := mockFIBeneficiaryFI()
fibfi.tag = "{9999}"
err := fibfi.Validate()
require.EqualError(t, err, fieldError("tag", ErrValidTagForType, fibfi.tag).Error())
}
// TestStringFIBeneficiaryFIVariableLength parses using variable length
func TestStringFIBeneficiaryFIVariableLength(t *testing.T) {
var line = "{6300}"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIBeneficiaryFI()
require.Nil(t, err)
line = "{6300} NNN"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseFIBeneficiaryFI()
require.ErrorContains(t, err, ErrRequireDelimiter.Error())
line = "{6300}********"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseFIBeneficiaryFI()
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
line = "{6300}*"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseFIBeneficiaryFI()
require.Equal(t, err, nil)
}
// TestStringFIBeneficiaryFIToFIOptions validates Format() formatted according to the FormatOptions
func TestStringFIBeneficiaryFIToFIOptions(t *testing.T) {
var line = "{6300}*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIBeneficiaryFI()
require.Equal(t, err, nil)
record := r.currentFEDWireMessage.FIBeneficiaryFI
require.Equal(t, record.String(), "{6300} * * * * * *")
require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6300}*")
require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false}))
}