-
Notifications
You must be signed in to change notification settings - Fork 39
/
beneficiaryReference_test.go
117 lines (87 loc) · 3.54 KB
/
beneficiaryReference_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
package wire
import (
"errors"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// mockBeneficiaryReference creates a BeneficiaryReference
func mockBeneficiaryReference() *BeneficiaryReference {
br := NewBeneficiaryReference()
br.BeneficiaryReference = "Reference"
return br
}
// TestMockBeneficiary validates mockBeneficiaryReference
func TestMockBeneficiaryReference(t *testing.T) {
br := mockBeneficiaryReference()
require.NoError(t, br.Validate(), "mockBeneficiaryReference does not validate and will break other tests")
}
// TestBeneficiaryReferenceAlphaNumeric validates BeneficiaryReference is alphanumeric
func TestBeneficiaryReferenceAlphaNumeric(t *testing.T) {
br := mockBeneficiaryReference()
br.BeneficiaryReference = "®"
err := br.Validate()
require.EqualError(t, err, fieldError("BeneficiaryReference", ErrNonAlphanumeric, br.BeneficiaryReference).Error())
}
// TestParseBeneficiaryReferenceWrongLength parses a wrong BeneficiaryReference record length
func TestParseBeneficiaryReferenceWrongLength(t *testing.T) {
var line = "{4320}Reference "
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseBeneficiaryReference()
require.EqualError(t, err, r.parseError(fieldError("BeneficiaryReference", ErrRequireDelimiter)).Error())
}
// TestParseBeneficiaryReferenceReaderParseError parses a wrong BeneficiaryReference reader parse error
func TestParseBeneficiaryReferenceReaderParseError(t *testing.T) {
var line = "{4320}Reference® *"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseBeneficiaryReference()
expected := r.parseError(fieldError("BeneficiaryReference", ErrNonAlphanumeric, "Reference®")).Error()
require.EqualError(t, err, expected)
_, err = r.Read()
expected = r.parseError(fieldError("BeneficiaryReference", ErrNonAlphanumeric, "Reference®")).Error()
require.EqualError(t, err, expected)
}
// TestBeneficiaryReferenceTagError validates a BeneficiaryReference tag
func TestBeneficiaryReferenceTagError(t *testing.T) {
br := mockBeneficiaryReference()
br.tag = "{9999}"
err := br.Validate()
require.EqualError(t, err, fieldError("tag", ErrValidTagForType, br.tag).Error())
}
// TestStringBeneficiaryReferenceVariableLength parses using variable length
func TestStringBeneficiaryReferenceVariableLength(t *testing.T) {
var line = "{4320}"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseBeneficiaryReference()
require.Nil(t, err)
line = "{4320}Reference NN"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseBeneficiaryReference()
require.ErrorContains(t, err, ErrRequireDelimiter.Error())
line = "{4320}***"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseBeneficiaryReference()
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
line = "{4320}*"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseBeneficiaryReference()
require.Equal(t, err, nil)
}
// TestStringBeneficiaryReferenceOptions validates Format() formatted according to the FormatOptions
func TestStringBeneficiaryReferenceOptions(t *testing.T) {
var line = "{4320}Reference*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseBeneficiaryReference()
require.Equal(t, err, nil)
br := r.currentFEDWireMessage.BeneficiaryReference
require.Equal(t, br.String(), "{4320}Reference *")
require.Equal(t, br.Format(FormatOptions{VariableLengthFields: true}), "{4320}Reference*")
require.Equal(t, br.String(), br.Format(FormatOptions{VariableLengthFields: false}))
}