-
Notifications
You must be signed in to change notification settings - Fork 39
/
adjustment_test.go
191 lines (141 loc) · 6.15 KB
/
adjustment_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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package wire
import (
"errors"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// MockAdjustment creates a Adjustment
func mockAdjustment() *Adjustment {
adj := NewAdjustment()
adj.AdjustmentReasonCode = PricingError
adj.CreditDebitIndicator = CreditIndicator
adj.RemittanceAmount.CurrencyCode = "USD"
adj.RemittanceAmount.Amount = "1234.56"
adj.AdditionalInfo = " Adjustment Additional Information"
return adj
}
// TestMockAdjustment validates mockAdjustment
func TestMockAdjustment(t *testing.T) {
adj := mockAdjustment()
require.NoError(t, adj.Validate(), "mockAdjustment does not validate and will break other tests")
}
// TestAdjustmentReasonCodeValid validates Adjustment AdjustmentReasonCode
func TestAdjustmentReasonCodeValid(t *testing.T) {
adj := mockAdjustment()
adj.AdjustmentReasonCode = "ZZ"
err := adj.Validate()
require.EqualError(t, err, fieldError("AdjustmentReasonCode", ErrAdjustmentReasonCode, adj.AdjustmentReasonCode).Error())
}
// TestCreditDebitIndicatorValid validates Adjustment CreditDebitIndicator
func TestCreditDebitIndicatorValid(t *testing.T) {
adj := mockAdjustment()
adj.CreditDebitIndicator = "ZZZZ"
err := adj.Validate()
require.EqualError(t, err, fieldError("CreditDebitIndicator", ErrCreditDebitIndicator, adj.CreditDebitIndicator).Error())
}
// TestAdjustmentAmountValid validates Adjustment Amount
func TestAdjustmentAmountValid(t *testing.T) {
adj := mockAdjustment()
adj.RemittanceAmount.Amount = "X,"
err := adj.Validate()
require.EqualError(t, err, fieldError("Amount", ErrNonAmount, adj.RemittanceAmount.Amount).Error())
}
// TestAdjustmentCurrencyCodeValid validates Adjustment CurrencyCode
func TestAdjustmentCurrencyCodeValid(t *testing.T) {
adj := mockAdjustment()
adj.RemittanceAmount.CurrencyCode = "XZP"
err := adj.Validate()
require.EqualError(t, err, fieldError("CurrencyCode", ErrNonCurrencyCode, adj.RemittanceAmount.CurrencyCode).Error())
}
// TestAdjustmentReasonCodeRequired validates Adjustment AdjustmentReasonCode is required
func TestAdjustmentReasonCodeRequired(t *testing.T) {
adj := mockAdjustment()
adj.AdjustmentReasonCode = ""
err := adj.Validate()
require.EqualError(t, err, fieldError("AdjustmentReasonCode", ErrFieldRequired).Error())
}
// TestCreditDebitIndicatorRequired validates Adjustment CreditDebitIndicator is required
func TestCreditDebitIndicatorRequired(t *testing.T) {
adj := mockAdjustment()
adj.CreditDebitIndicator = ""
err := adj.Validate()
require.EqualError(t, err, fieldError("CreditDebitIndicator", ErrFieldRequired).Error())
}
// TestAdjustmentAmountRequired validates Adjustment Amount is required
func TestAdjustmentAmountRequired(t *testing.T) {
adj := mockAdjustment()
adj.RemittanceAmount.Amount = ""
err := adj.Validate()
require.EqualError(t, err, fieldError("Amount", ErrFieldRequired).Error())
}
// TestAdjustmentCurrencyCodeRequired validates Adjustment CurrencyCode is required
func TestAdjustmentCurrencyCodeRequired(t *testing.T) {
adj := mockAdjustment()
adj.RemittanceAmount.CurrencyCode = ""
err := adj.Validate()
require.EqualError(t, err, fieldError("CurrencyCode", ErrFieldRequired).Error())
}
// TestParseAdjustmentWrongLength parses a wrong Adjustment record length
func TestParseAdjustmentWrongLength(t *testing.T) {
var line = "{8600}01CRDTUSD1234.56 *Additional Information *"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseAdjustment()
require.NoError(t, err)
}
// TestParseAdjustmentReaderParseError parses a wrong Adjustment reader parse error
func TestParseAdjustmentReaderParseError(t *testing.T) {
var line = "{8600}01CRDTUSD1234.56Z *Additional Information *"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseAdjustment()
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)
}
// TestAdjustmentTagError validates Adjustment tag
func TestAdjustmentTagError(t *testing.T) {
adj := mockAdjustment()
adj.tag = "{9999}"
err := adj.Validate()
require.EqualError(t, err, fieldError("tag", ErrValidTagForType, adj.tag).Error())
}
// TestStringAdjustmentVariableLength parses using variable length
func TestStringAdjustmentVariableLength(t *testing.T) {
var line = "{8600}"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseAdjustment()
expected := r.parseError(NewTagMinLengthErr(10, len(r.line))).Error()
require.EqualError(t, err, expected)
line = "{8600}01CRDTUSD1234.56 NNN"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseAdjustment()
require.ErrorContains(t, err, ErrRequireDelimiter.Error())
line = "{8600}01CRDTUSD1234.56****"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseAdjustment()
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
line = "{8600}01CRDTUSD1234.56*"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseAdjustment()
require.Equal(t, err, nil)
}
// TestStringAdjustmentOptions validates Format() formatted according to the FormatOptions
func TestStringAdjustmentOptions(t *testing.T) {
var line = "{8600}01CRDTUSD1234.56 *"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseAdjustment()
require.Equal(t, err, nil)
adj := r.currentFEDWireMessage.Adjustment
require.Equal(t, adj.String(), "{8600}01CRDTUSD1234.56 * *")
require.Equal(t, adj.Format(FormatOptions{VariableLengthFields: true}), "{8600}01CRDTUSD1234.56*")
require.Equal(t, adj.String(), adj.Format(FormatOptions{VariableLengthFields: false}))
}