-
Notifications
You must be signed in to change notification settings - Fork 40
/
grossAmountRemittanceDocument_test.go
138 lines (104 loc) · 4.8 KB
/
grossAmountRemittanceDocument_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
package wire
import (
"errors"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// GrossAmountRemittanceDocument creates a GrossAmountRemittanceDocument
func mockGrossAmountRemittanceDocument() *GrossAmountRemittanceDocument {
gard := NewGrossAmountRemittanceDocument()
gard.RemittanceAmount.CurrencyCode = "USD"
gard.RemittanceAmount.Amount = "1234.56"
return gard
}
// TestMockGrossAmountRemittanceDocument validates mockGrossAmountRemittanceDocument
func TestMockGrossAmountRemittanceDocument(t *testing.T) {
gard := mockGrossAmountRemittanceDocument()
require.NoError(t, gard.Validate(), "mockGrossAmountRemittanceDocument does not validate and will break other tests")
}
// TestGrossAmountRemittanceAmountRequired validates GrossAmountRemittance Amount is required
func TestGrossAmountRemittanceAmountRequired(t *testing.T) {
gard := mockGrossAmountRemittanceDocument()
gard.RemittanceAmount.Amount = ""
require.EqualError(t, gard.Validate(), fieldError("Amount", ErrFieldRequired).Error())
}
// TestGrossAmountRemittanceCurrencyCodeRequired validates GrossAmountRemittance CurrencyCode is required
func TestGrossAmountRemittanceCurrencyCodeRequired(t *testing.T) {
gard := mockGrossAmountRemittanceDocument()
gard.RemittanceAmount.CurrencyCode = ""
require.EqualError(t, gard.Validate(), fieldError("CurrencyCode", ErrFieldRequired).Error())
}
// TestGrossAmountRemittanceAmountValid validates Amount
func TestGrossAmountRemittanceAmountValid(t *testing.T) {
gard := mockGrossAmountRemittanceDocument()
gard.RemittanceAmount.Amount = "X,"
require.EqualError(t, gard.Validate(), fieldError("Amount", ErrNonAmount, gard.RemittanceAmount.Amount).Error())
}
// TestGrossAmountRemittanceCurrencyCodeValid validates CurrencyCode
func TestGrossAmountRemittanceCurrencyCodeValid(t *testing.T) {
gard := mockGrossAmountRemittanceDocument()
gard.RemittanceAmount.CurrencyCode = "XZP"
require.EqualError(t, gard.Validate(), fieldError("CurrencyCode", ErrNonCurrencyCode, gard.RemittanceAmount.CurrencyCode).Error())
}
// TestParseGrossAmountRemittanceWrongLength parses a wrong GrossAmountRemittance record length
func TestParseGrossAmountRemittanceWrongLength(t *testing.T) {
var line = "{8500}USD1234.56 "
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseGrossAmountRemittanceDocument()
require.EqualError(t, err, r.parseError(fieldError("Amount", ErrRequireDelimiter)).Error())
}
// TestParseGrossAmountRemittanceReaderParseError parses a wrong GrossAmountRemittance reader parse error
func TestParseGrossAmountRemittanceReaderParseError(t *testing.T) {
var line = "{8500}USD1234.56Z *"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseGrossAmountRemittanceDocument()
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)
}
// TestGrossAmountRemittanceTagError validates a GrossAmountRemittance tag
func TestGrossAmountRemittanceTagError(t *testing.T) {
gard := mockGrossAmountRemittanceDocument()
gard.tag = "{9999}"
require.EqualError(t, gard.Validate(), fieldError("tag", ErrValidTagForType, gard.tag).Error())
}
// TestStringGrossAmountRemittanceDocumentVariableLength parses using variable length
func TestStringGrossAmountRemittanceDocumentVariableLength(t *testing.T) {
var line = "{8500}USD1234.56*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseGrossAmountRemittanceDocument()
require.Nil(t, err)
line = "{8500}USD1234.56 NNN"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseGrossAmountRemittanceDocument()
require.ErrorContains(t, err, ErrRequireDelimiter.Error())
line = "{8500}USD1234.56***"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseGrossAmountRemittanceDocument()
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
line = "{8500}USD1234.56*"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseGrossAmountRemittanceDocument()
require.Equal(t, err, nil)
}
// TestStringGrossAmountRemittanceDocumentOptions validates Format() formatted according to the FormatOptions
func TestStringGrossAmountRemittanceDocumentOptions(t *testing.T) {
var line = "{8500}USD1234.56*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseGrossAmountRemittanceDocument()
require.Equal(t, err, nil)
record := r.currentFEDWireMessage.GrossAmountRemittanceDocument
require.Equal(t, record.String(), "{8500}USD1234.56 *")
require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{8500}USD1234.56*")
require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false}))
}