-
Notifications
You must be signed in to change notification settings - Fork 40
/
amountNegotiatedDiscount_test.go
149 lines (110 loc) · 4.84 KB
/
amountNegotiatedDiscount_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
package wire
import (
"errors"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// AmountNegotiatedDiscount creates a AmountNegotiatedDiscount
func mockAmountNegotiatedDiscount() *AmountNegotiatedDiscount {
nd := NewAmountNegotiatedDiscount()
nd.RemittanceAmount.CurrencyCode = "USD"
nd.RemittanceAmount.Amount = "1234.56"
return nd
}
// TestMockAmountNegotiatedDiscount validates mockAmountNegotiatedDiscount
func TestMockAmountNegotiatedDiscount(t *testing.T) {
nd := mockAmountNegotiatedDiscount()
require.NoError(t, nd.Validate(), "mockAmountNegotiatedDiscount does not validate and will break other tests")
}
// TestAmountNegotiatedDiscountAmountValid validates AmountNegotiatedDiscount Amount
func TestAmountNegotiatedDiscountValid(t *testing.T) {
nd := mockAmountNegotiatedDiscount()
nd.RemittanceAmount.Amount = "X,"
err := nd.Validate()
require.EqualError(t, err, fieldError("Amount", ErrNonAmount, nd.RemittanceAmount.Amount).Error())
}
// TestAmountNegotiatedDiscountCurrencyCodeValid validates AmountNegotiatedDiscount CurrencyCode
func TestAmountNegotiatedDiscountCurrencyCodeValid(t *testing.T) {
nd := mockAmountNegotiatedDiscount()
nd.RemittanceAmount.CurrencyCode = "XZP"
err := nd.Validate()
require.EqualError(t, err, fieldError("CurrencyCode", ErrNonCurrencyCode, nd.RemittanceAmount.CurrencyCode).Error())
}
// TestAmountNegotiatedDiscountAmountRequired validates AmountNegotiatedDiscount Amount is required
func TestAmountNegotiatedDiscountRequired(t *testing.T) {
nd := mockAmountNegotiatedDiscount()
nd.RemittanceAmount.Amount = ""
err := nd.Validate()
require.EqualError(t, err, fieldError("Amount", ErrFieldRequired).Error())
}
// TestAmountNegotiatedDiscountCurrencyCodeRequired validates AmountNegotiatedDiscount CurrencyCode is required
func TestAmountNegotiatedDiscountCurrencyCodeRequired(t *testing.T) {
nd := mockAmountNegotiatedDiscount()
nd.RemittanceAmount.CurrencyCode = ""
err := nd.Validate()
require.EqualError(t, err, fieldError("CurrencyCode", ErrFieldRequired).Error())
}
// TestParseAmountNegotiatedDiscountWrongLength parses a wrong AmountNegotiatedDiscount record length
func TestParseAmountNegotiatedDiscountWrongLength(t *testing.T) {
var line = "{8550}USD1234.56 "
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseAmountNegotiatedDiscount()
require.EqualError(t, err, r.parseError(fieldError("Amount", ErrRequireDelimiter)).Error())
}
// TestParseAmountNegotiatedDiscountReaderParseError parses a wrong AmountNegotiatedDiscount reader parse error
func TestParseAmountNegotiatedDiscountReaderParseError(t *testing.T) {
var line = "{8550}USD1234.56Z *"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseAmountNegotiatedDiscount()
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)
}
// TestAmountNegotiatedDiscountTagError validates AmountNegotiatedDiscount tag
func TestAmountNegotiatedDiscountTagError(t *testing.T) {
nd := mockAmountNegotiatedDiscount()
nd.tag = "{9999}"
err := nd.Validate()
require.EqualError(t, err, fieldError("tag", ErrValidTagForType, nd.tag).Error())
}
// TestStringAmountNegotiatedDiscountVariableLength parses using variable length
func TestStringAmountNegotiatedDiscountVariableLength(t *testing.T) {
var line = "{8600}"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseAmountNegotiatedDiscount()
expected := r.parseError(NewTagMinLengthErr(8, len(r.line))).Error()
require.EqualError(t, err, expected)
line = "{8550}USD1234.56 NNN"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseAmountNegotiatedDiscount()
require.ErrorContains(t, err, ErrRequireDelimiter.Error())
line = "{8550}USD1234.56***"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseAmountNegotiatedDiscount()
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
line = "{8550}USD1234.56*"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseAmountNegotiatedDiscount()
require.Equal(t, err, nil)
}
// TestStringAmountNegotiatedDiscountOptions validates Format() formatted according to the FormatOptions
func TestStringAmountNegotiatedDiscountOptions(t *testing.T) {
var line = "{8550}USD1234.56*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseAmountNegotiatedDiscount()
require.Equal(t, err, nil)
and := r.currentFEDWireMessage.AmountNegotiatedDiscount
require.Equal(t, and.String(), "{8550}USD1234.56 *")
require.Equal(t, and.Format(FormatOptions{VariableLengthFields: true}), "{8550}USD1234.56*")
require.Equal(t, and.String(), and.Format(FormatOptions{VariableLengthFields: false}))
}