-
Notifications
You must be signed in to change notification settings - Fork 39
/
accountCreditedDrawdown_test.go
137 lines (104 loc) · 4.56 KB
/
accountCreditedDrawdown_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
package wire
import (
"errors"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// mockAccountCreditedDrawdown creates a AccountCreditedDrawdown
func mockAccountCreditedDrawdown() *AccountCreditedDrawdown {
creditDD := NewAccountCreditedDrawdown()
creditDD.DrawdownCreditAccountNumber = "123456789"
return creditDD
}
// TestMockAccountCreditedDrawdown validates mockAccountCreditedDrawdown
func TestMockAccountCreditedDrawdown(t *testing.T) {
creditDD := mockAccountCreditedDrawdown()
require.NoError(t, creditDD.Validate(), "mockAccountCreditedDrawdown does not validate and will break other tests")
}
// TestAccountCreditedDrawDownNumberAlphaNumeric validates AccountCreditedDrawdown is alphanumeric
func TestDrawdownCreditAccountNumberAlphaNumeric(t *testing.T) {
creditDD := mockAccountCreditedDrawdown()
creditDD.DrawdownCreditAccountNumber = "®"
expected := fieldError("DrawdownCreditAccountNumber", ErrNonNumeric, creditDD.DrawdownCreditAccountNumber).Error()
require.EqualError(t, creditDD.Validate(), expected)
}
// TestAccountCreditedDrawdownNumberRequired validates AccountCreditedDrawdown is required
func TestDrawdownCreditAccountNumberRequired(t *testing.T) {
creditDD := mockAccountCreditedDrawdown()
creditDD.DrawdownCreditAccountNumber = ""
expected := fieldError("DrawdownCreditAccountNumber", ErrFieldRequired).Error()
require.EqualError(t, creditDD.Validate(), expected)
}
// TestParseAccountCreditedDrawdownWrongLength parses a wrong AccountCreditedDrawdown record length
func TestParseAccountCreditedDrawdownWrongLength(t *testing.T) {
var line = "{5400}12345678"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseAccountCreditedDrawdown()
expected := r.parseError(fieldError("DrawdownCreditAccountNumber", ErrValidLength)).Error()
require.EqualError(t, err, expected)
}
// TestParseAccountCreditedDrawdownReaderParseError parses a wrong AccountCreditedDrawdown reader parse error
func TestParseAccountCreditedDrawdownReaderParseError(t *testing.T) {
var line = "{5400}12345678Z"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseAccountCreditedDrawdown()
expected := r.parseError(fieldError("DrawdownCreditAccountNumber", ErrNonNumeric, "12345678Z")).Error()
require.EqualError(t, err, expected)
_, err = r.Read()
expected = r.parseError(fieldError("DrawdownCreditAccountNumber", ErrNonNumeric, "12345678Z")).Error()
require.EqualError(t, err, expected)
}
// TestAccountCreditedDrawdownTagError validates AccountCreditedDrawdown tag
func TestAccountCreditedDrawdownTagError(t *testing.T) {
creditDD := mockAccountCreditedDrawdown()
creditDD.tag = "{9999}"
err := creditDD.Validate()
expected := fieldError("tag", ErrValidTagForType, creditDD.tag).Error()
require.EqualError(t, err, expected)
}
// TestStringAccountCreditedDrawdownVariableLength parses using variable length
func TestStringAccountCreditedDrawdownVariableLength(t *testing.T) {
var line = "{5400}"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseAccountCreditedDrawdown()
expected := r.parseError(NewTagMinLengthErr(7, len(r.line))).Error()
require.EqualError(t, err, expected)
line = "{5400}1234567890123"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseAccountCreditedDrawdown()
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
line = "{5400} *"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseAccountCreditedDrawdown()
expected = r.parseError(fieldError("DrawdownCreditAccountNumber", ErrValidLength)).Error()
require.EqualError(t, err, expected)
line = "{5400}1*"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseAccountCreditedDrawdown()
expected = r.parseError(fieldError("DrawdownCreditAccountNumber", ErrValidLength)).Error()
require.EqualError(t, err, expected)
line = "{5400}1 *"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseAccountCreditedDrawdown()
require.NoError(t, err)
}
// TestStringAccountCreditedDrawdownOptions validates Format() formatted according to the FormatOptions
func TestStringAccountCreditedDrawdownOptions(t *testing.T) {
var line = "{5400}1 "
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseAccountCreditedDrawdown()
require.Equal(t, err, nil)
acd := r.currentFEDWireMessage.AccountCreditedDrawdown
require.Equal(t, acd.String(), "{5400}1 ")
require.Equal(t, acd.Format(FormatOptions{VariableLengthFields: true}), "{5400}1 ")
require.Equal(t, acd.String(), acd.Format(FormatOptions{VariableLengthFields: false}))
}