-
Notifications
You must be signed in to change notification settings - Fork 39
/
actualAmountPaid_test.go
155 lines (115 loc) · 4.54 KB
/
actualAmountPaid_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
package wire
import (
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// ActualAmountPaid creates a ActualAmountPaid
func mockActualAmountPaid() *ActualAmountPaid {
aap := NewActualAmountPaid()
aap.RemittanceAmount.CurrencyCode = "USD"
aap.RemittanceAmount.Amount = "1234.56"
return aap
}
// TestMockActualAmountPaid validates mockActualAmountPaid
func TestMockActualAmountPaid(t *testing.T) {
aap := mockActualAmountPaid()
require.NoError(t, aap.Validate(), "mockActualAmountPaid does not validate and will break other tests")
}
// TestActualAmountPaidAmountRequired validates ActualAmountPaid Amount is required
func TestActualAmountPaidAmountRequired(t *testing.T) {
aap := mockActualAmountPaid()
aap.RemittanceAmount.Amount = ""
err := aap.Validate()
require.EqualError(t, err, fieldError("Amount", ErrFieldRequired).Error())
}
// TestActualAmountPaidCurrencyCodeRequired validates ActualAmountPaid CurrencyCode is required
func TestCurrencyCodeRequired(t *testing.T) {
aap := mockActualAmountPaid()
aap.RemittanceAmount.CurrencyCode = ""
err := aap.Validate()
require.EqualError(t, err, fieldError("CurrencyCode", ErrFieldRequired).Error())
}
// TestActualAmountPaidAmountValid validates Amount
func TestActualAmountPaidAmountValid(t *testing.T) {
aap := mockActualAmountPaid()
aap.RemittanceAmount.Amount = "X,"
err := aap.Validate()
require.EqualError(t, err, fieldError("Amount", ErrNonAmount, aap.RemittanceAmount.Amount).Error())
}
// TestActualAmountPaidCurrencyCodeValid validates Amount
func TestActualAmountPaidCurrencyCodeValid(t *testing.T) {
aap := mockActualAmountPaid()
aap.RemittanceAmount.CurrencyCode = "XZP"
err := aap.Validate()
require.EqualError(t, err, fieldError("CurrencyCode", ErrNonCurrencyCode, aap.RemittanceAmount.CurrencyCode).Error())
}
// TestParseActualAmountPaidWrongLength parses a wrong ActualAmountPaid record length
func TestParseActualAmountPaidWrongLength(t *testing.T) {
var line = "{8450}USD1234.56 *"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseActualAmountPaid()
require.NoError(t, err)
}
// TestParseActualAmountPaidReaderParseError parses a wrong ActualAmountPaid reader parse error
func TestParseActualAmountPaidReaderParseError(t *testing.T) {
var line = "{8450}USD1234.56Z *"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseActualAmountPaid()
expected := r.parseError(fieldError("Amount", ErrNonAmount, "1234.56Z")).Error()
require.EqualError(t, err, expected)
_, err = r.Read()
expected = r.parseError(fieldError("Amount", ErrNonAmount, "1234.56Z")).Error()
require.EqualError(t, err, expected)
}
// TestActualAmountPaidTagError validates ActualAmountPaid tag
func TestActualAmountPaidTagError(t *testing.T) {
aap := mockActualAmountPaid()
aap.tag = "{9999}"
err := aap.Validate()
require.EqualError(t, err, fieldError("tag", ErrValidTagForType, aap.tag).Error())
}
// TestStringActualAmountPaidVariableLength parses using variable length
func TestStringActualAmountPaidVariableLength(t *testing.T) {
var line = "{8450}"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseActualAmountPaid()
expected := r.parseError(NewTagMinLengthErr(8, len(r.line))).Error()
require.EqualError(t, err, expected)
line = "{8450}USD1234.56 NNN*"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseActualAmountPaid()
require.ErrorContains(t, err, ErrNonAmount.Error())
line = "{8450}****"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseActualAmountPaid()
require.ErrorContains(t, err, ErrValidLength.Error())
line = "{8450}USD*"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseActualAmountPaid()
expected = r.parseError(fieldError("Amount", ErrFieldRequired)).Error()
require.EqualError(t, err, expected)
line = "{8450}USD1234.56*"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseActualAmountPaid()
require.Equal(t, err, nil)
}
// TestStringActualAmountPaidOptions validates Format() formatted according to the FormatOptions
func TestStringActualAmountPaidOptions(t *testing.T) {
var line = "{8450}USD1234.56*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseActualAmountPaid()
require.Equal(t, err, nil)
aap := r.currentFEDWireMessage.ActualAmountPaid
require.Equal(t, aap.String(), "{8450}USD1234.56 *")
require.Equal(t, aap.Format(FormatOptions{VariableLengthFields: true}), "{8450}USD1234.56*")
require.Equal(t, aap.String(), aap.Format(FormatOptions{VariableLengthFields: false}))
}