-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathfiBeneficiary_test.go
171 lines (127 loc) · 5.79 KB
/
fiBeneficiary_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
package wire
import (
"errors"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// mockFIBeneficiary creates a FIBeneficiary
func mockFIBeneficiary() *FIBeneficiary {
fib := NewFIBeneficiary()
fib.FIToFI.LineOne = "Line One"
fib.FIToFI.LineTwo = "Line Two"
fib.FIToFI.LineThree = "Line Three"
fib.FIToFI.LineFour = "Line Four"
fib.FIToFI.LineFive = "Line Five"
fib.FIToFI.LineSix = "Line Six"
return fib
}
// TestMockFIBeneficiary validates mockFIBeneficiary
func TestMockFIBeneficiary(t *testing.T) {
fib := mockFIBeneficiary()
require.NoError(t, fib.Validate(), "mockFIBeneficiary does not validate and will break other tests")
}
// TestFIBeneficiaryLineOneAlphaNumeric validates FIBeneficiary LineOne is alphanumeric
func TestFIBeneficiaryLineOneAlphaNumeric(t *testing.T) {
fib := mockFIBeneficiary()
fib.FIToFI.LineOne = "®"
err := fib.Validate()
require.EqualError(t, err, fieldError("LineOne", ErrNonAlphanumeric, fib.FIToFI.LineOne).Error())
}
// TestFIBeneficiaryLineTwoAlphaNumeric validates FIBeneficiary LineTwo is alphanumeric
func TestFIBeneficiaryLineTwoAlphaNumeric(t *testing.T) {
fib := mockFIBeneficiary()
fib.FIToFI.LineTwo = "®"
err := fib.Validate()
require.EqualError(t, err, fieldError("LineTwo", ErrNonAlphanumeric, fib.FIToFI.LineTwo).Error())
}
// TestFIBeneficiaryLineThreeAlphaNumeric validates FIBeneficiary LineThree is alphanumeric
func TestFIBeneficiaryLineThreeAlphaNumeric(t *testing.T) {
fib := mockFIBeneficiary()
fib.FIToFI.LineThree = "®"
err := fib.Validate()
require.EqualError(t, err, fieldError("LineThree", ErrNonAlphanumeric, fib.FIToFI.LineThree).Error())
}
// TestFIBeneficiaryLineFourAlphaNumeric validates FIBeneficiary LineFour is alphanumeric
func TestFIBeneficiaryLineFourAlphaNumeric(t *testing.T) {
fib := mockFIBeneficiary()
fib.FIToFI.LineFour = "®"
err := fib.Validate()
require.EqualError(t, err, fieldError("LineFour", ErrNonAlphanumeric, fib.FIToFI.LineFour).Error())
}
// TestFIBeneficiaryLineFiveAlphaNumeric validates FIBeneficiary LineFive is alphanumeric
func TestFIBeneficiaryLineFiveAlphaNumeric(t *testing.T) {
fib := mockFIBeneficiary()
fib.FIToFI.LineFive = "®"
err := fib.Validate()
require.EqualError(t, err, fieldError("LineFive", ErrNonAlphanumeric, fib.FIToFI.LineFive).Error())
}
// TestFIBeneficiaryLineSixAlphaNumeric validates FIBeneficiary LineSix is alphanumeric
func TestFIBeneficiaryLineSixAlphaNumeric(t *testing.T) {
fib := mockFIBeneficiary()
fib.FIToFI.LineSix = "®"
err := fib.Validate()
require.EqualError(t, err, fieldError("LineSix", ErrNonAlphanumeric, fib.FIToFI.LineSix).Error())
}
// TestParseFIBeneficiaryWrongLength parses a wrong FIBeneficiary record length
func TestParseFIBeneficiaryWrongLength(t *testing.T) {
var line = "{6400}Line Six "
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIBeneficiary()
require.EqualError(t, err, r.parseError(fieldError("LineOne", ErrRequireDelimiter)).Error())
}
// TestParseFIBeneficiaryReaderParseError parses a wrong FIBeneficiary reader parse error
func TestParseFIBeneficiaryReaderParseError(t *testing.T) {
var line = "{6400}Line Si® *"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIBeneficiary()
expected := r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "Line Si®")).Error()
require.EqualError(t, err, expected)
_, err = r.Read()
expected = r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "Line Si®")).Error()
require.EqualError(t, err, expected)
}
// TestFIBeneficiaryTagError validates a FIBeneficiary tag
func TestFIBeneficiaryTagError(t *testing.T) {
fib := mockFIBeneficiary()
fib.tag = "{9999}"
err := fib.Validate()
require.EqualError(t, err, fieldError("tag", ErrValidTagForType, fib.tag).Error())
}
// TestStringFIBeneficiaryVariableLength parses using variable length
func TestStringFIBeneficiaryVariableLength(t *testing.T) {
var line = "{6400}"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIBeneficiary()
require.Nil(t, err)
line = "{6400} NNN"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseFIBeneficiary()
require.ErrorContains(t, err, ErrRequireDelimiter.Error())
line = "{6400}********"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseFIBeneficiary()
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
line = "{6400}*"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseFIBeneficiary()
require.Equal(t, err, nil)
}
// TestStringFIBeneficiaryOptions validates Format() formatted according to the FormatOptions
func TestStringFIBeneficiaryOptions(t *testing.T) {
var line = "{6400}*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIBeneficiary()
require.Equal(t, err, nil)
record := r.currentFEDWireMessage.FIBeneficiary
require.Equal(t, record.String(), "{6400} * * * * * *")
require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6400}*")
require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false}))
}