-
Notifications
You must be signed in to change notification settings - Fork 39
/
fiPaymentMethodToBeneficiary_test.go
127 lines (95 loc) · 4.32 KB
/
fiPaymentMethodToBeneficiary_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
package wire
import (
"errors"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// mockFIPaymentMethodToBeneficiary creates a FIPaymentMethodToBeneficiary
func mockFIPaymentMethodToBeneficiary() *FIPaymentMethodToBeneficiary {
pm := NewFIPaymentMethodToBeneficiary()
pm.PaymentMethod = "CHECK"
pm.AdditionalInformation = "Additional Information"
return pm
}
// TestMockFIPaymentMethodToBeneficiary validates mockFIPaymentMethodToBeneficiary
func TestMockFIPaymentMethodToBeneficiary(t *testing.T) {
pm := mockFIPaymentMethodToBeneficiary()
require.NoError(t, pm.Validate(), "mockFIPaymentMethodToBeneficiary does not validate and will break other tests")
}
// TestPaymentMethodValid validates FIPaymentMethodToBeneficiary PaymentMethod
func TestPaymentMethodValid(t *testing.T) {
pm := NewFIPaymentMethodToBeneficiary()
pm.PaymentMethod = ""
err := pm.Validate()
require.EqualError(t, err, fieldError("PaymentMethod", ErrFieldInclusion, pm.PaymentMethod).Error())
}
// TestAdditionalInformationAlphaNumeric validates FIPaymentMethodToBeneficiary AdditionalInformation is alphanumeric
func TestAdditionalInformationAlphaNumeric(t *testing.T) {
pm := NewFIPaymentMethodToBeneficiary()
pm.AdditionalInformation = "®"
err := pm.Validate()
require.EqualError(t, err, fieldError("AdditionalInformation", ErrNonAlphanumeric, pm.AdditionalInformation).Error())
}
// TestParseFIPaymentMethodToBeneficiaryWrongLength parses a wrong FIPaymentMethodToBeneficiary record length
func TestParseFIPaymentMethodToBeneficiaryWrongLength(t *testing.T) {
var line = "{6420}CHECKAdditional Information "
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIPaymentMethodToBeneficiary()
require.EqualError(t, err, r.parseError(fieldError("AdditionalInformation", ErrRequireDelimiter)).Error())
}
// TestParseFIPaymentMethodToBeneficiaryReaderParseError parses a wrong FIPaymentMethodToBeneficiary reader parse error
func TestParseFIPaymentMethodToBeneficiaryReaderParseError(t *testing.T) {
var line = "{6420}CHECK®dditional Information *"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIPaymentMethodToBeneficiary()
expected := r.parseError(fieldError("AdditionalInformation", ErrNonAlphanumeric, "®dditional Information")).Error()
require.EqualError(t, err, expected)
_, err = r.Read()
expected = r.parseError(fieldError("AdditionalInformation", ErrNonAlphanumeric, "®dditional Information")).Error()
require.EqualError(t, err, expected)
}
// TestFIPaymentMethodToBeneficiaryTagError validates a FIPaymentMethodToBeneficiary tag
func TestFIPaymentMethodToBeneficiaryTagError(t *testing.T) {
pm := mockFIPaymentMethodToBeneficiary()
pm.tag = "{9999}"
err := pm.Validate()
require.EqualError(t, err, fieldError("tag", ErrValidTagForType, pm.tag).Error())
}
// TestStringFIPaymentMethodToBeneficiaryVariableLength parses using variable length
func TestStringFIPaymentMethodToBeneficiaryVariableLength(t *testing.T) {
var line = "{6420}CHECK"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIPaymentMethodToBeneficiary()
require.Nil(t, err)
line = "{6420}CHECK NNN"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseFIPaymentMethodToBeneficiary()
require.ErrorContains(t, err, ErrRequireDelimiter.Error())
line = "{6420}CHECK***"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseFIPaymentMethodToBeneficiary()
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
line = "{6420}CHECK*"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseFIPaymentMethodToBeneficiary()
require.Equal(t, err, nil)
}
// TestStringFIPaymentMethodToBeneficiaryOptions validates Format() formatted according to the FormatOptions
func TestStringFIPaymentMethodToBeneficiaryOptions(t *testing.T) {
var line = "{6420}CHECK*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIPaymentMethodToBeneficiary()
require.Equal(t, err, nil)
record := r.currentFEDWireMessage.FIPaymentMethodToBeneficiary
require.Equal(t, record.String(), "{6420}CHECK *")
require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6420}CHECK*")
require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false}))
}