-
Notifications
You must be signed in to change notification settings - Fork 40
/
businessFunctionCode_test.go
142 lines (106 loc) · 4.44 KB
/
businessFunctionCode_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
package wire
import (
"errors"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// mockBusinessFunctionCode creates a BusinessFunctionCode
func mockBusinessFunctionCode() *BusinessFunctionCode {
bfc := NewBusinessFunctionCode()
bfc.BusinessFunctionCode = CustomerTransfer
bfc.TransactionTypeCode = " "
return bfc
}
// TestMockBusinessFunctionCode validates mockBusinessFunctionCode
func TestMockBusinessFunctionCode(t *testing.T) {
bfc := mockBusinessFunctionCode()
require.NoError(t, bfc.Validate(), "mockBusinessFunctionCode does not validate and will break other tests")
}
// TestBusinessFunctionCodeValid validates BusinessFunctionCode
func TestBusinessFunctionCodeValid(t *testing.T) {
bfc := mockBusinessFunctionCode()
bfc.BusinessFunctionCode = "ZZZ"
err := bfc.Validate()
require.EqualError(t, err, fieldError("BusinessFunctionCode", ErrBusinessFunctionCode, bfc.BusinessFunctionCode).Error())
}
// TestBusinessFunctionCodeRequired validates BusinessFunctionCode is required
func TestBusinessFunctionCodeRequired(t *testing.T) {
bfc := mockBusinessFunctionCode()
bfc.BusinessFunctionCode = ""
err := bfc.Validate()
require.EqualError(t, err, fieldError("BusinessFunctionCode", ErrFieldRequired, bfc.BusinessFunctionCode).Error())
}
// TestParseBusinessFunctionCodeWrongLength parses a wrong BusinessFunctionCode record length
func TestParseBusinessFunctionCodeWrongLength(t *testing.T) {
var line = "{3600}CT"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseBusinessFunctionCode()
require.EqualError(t, err, r.parseError(NewTagMinLengthErr(9, len(r.line))).Error())
}
// TestParseBusinessFunctionCodeReaderParseError parses a wrong BusinessFunctionCode reader parse error
func TestParseBusinessFunctionCodeReaderParseError(t *testing.T) {
var line = "{3600}CTAXXY*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseBusinessFunctionCode()
expected := r.parseError(fieldError("BusinessFunctionCode", ErrBusinessFunctionCode, "CTA")).Error()
require.EqualError(t, err, expected)
_, err = r.Read()
expected = r.parseError(fieldError("BusinessFunctionCode", ErrBusinessFunctionCode, "CTA")).Error()
require.EqualError(t, err, expected)
}
// TestBusinessFunctionCodeTagError validates a BusinessFunctionCode tag
func TestBusinessFunctionCodeTagError(t *testing.T) {
bfc := mockBusinessFunctionCode()
bfc.tag = "{9999}"
err := bfc.Validate()
require.EqualError(t, err, fieldError("tag", ErrValidTagForType, bfc.tag).Error())
}
func TestBusinessFunctionCodeDelimiter(t *testing.T) {
bfc := NewBusinessFunctionCode()
bfc.BusinessFunctionCode = CustomerTransfer
require.Equal(t, "{3600}CTR", bfc.String())
require.Equal(t, "{3600}CTR", bfc.Format(FormatOptions{VariableLengthFields: true}))
bfc.TransactionTypeCode = "23"
require.Equal(t, "{3600}CTR23 *", bfc.String())
require.Equal(t, "{3600}CTR23*", bfc.Format(FormatOptions{VariableLengthFields: true}))
}
// TestStringBusinessFunctionCodeVariableLength parses using variable length
func TestStringBusinessFunctionCodeVariableLength(t *testing.T) {
var line = "{3600}"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseBusinessFunctionCode()
expected := r.parseError(NewTagMinLengthErr(9, len(r.line))).Error()
require.EqualError(t, err, expected)
line = "{3600}BTR NNN"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseBusinessFunctionCode()
require.ErrorContains(t, err, ErrRequireDelimiter.Error())
line = "{3600}BTR***"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseBusinessFunctionCode()
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
line = "{3600}BTR*"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseBusinessFunctionCode()
require.Equal(t, err, nil)
}
// TestStringBusinessFunctionCodeOptions validates Format() formatted according to the FormatOptions
func TestStringBusinessFunctionCodeOptions(t *testing.T) {
var line = "{3600}BTR"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseBusinessFunctionCode()
require.Equal(t, err, nil)
bfc := r.currentFEDWireMessage.BusinessFunctionCode
require.Equal(t, "{3600}BTR", bfc.String())
require.Equal(t, "{3600}BTR", bfc.Format(FormatOptions{VariableLengthFields: true}))
require.Equal(t, "{3600}BTR", bfc.Format(FormatOptions{VariableLengthFields: false}))
require.Equal(t, bfc.Format(FormatOptions{VariableLengthFields: false}), bfc.String())
}