-
Notifications
You must be signed in to change notification settings - Fork 40
/
instructedAmount_test.go
144 lines (106 loc) · 4.18 KB
/
instructedAmount_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
package wire
import (
"errors"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// mockInstructedAmount creates a InstructedAmount
func mockInstructedAmount() *InstructedAmount {
ia := NewInstructedAmount()
ia.CurrencyCode = "USD"
ia.Amount = "4567,89"
return ia
}
// TestMockInstructedAmount validates mockInstructedAmount
func TestMockInstructedAmount(t *testing.T) {
ia := mockInstructedAmount()
require.NoError(t, ia.Validate(), "mockInstructedAmount does not validate and will break other tests")
}
// TestInstructedAmountAmountRequired validates InstructedAmount Amount is required
func TestInstructedAmountRequired(t *testing.T) {
ia := mockInstructedAmount()
ia.Amount = ""
err := ia.Validate()
require.EqualError(t, err, fieldError("Amount", ErrFieldRequired).Error())
}
// TestInstructedAmountCurrencyCodeRequired validates InstructedAmount CurrencyCode is required
func TestInstructedAmountCurrencyCodeRequired(t *testing.T) {
ia := mockInstructedAmount()
ia.CurrencyCode = ""
err := ia.Validate()
require.EqualError(t, err, fieldError("CurrencyCode", ErrFieldRequired).Error())
}
// TestInstructedAmountAmountValid validates Amount
func TestInstructedAmountValid(t *testing.T) {
ia := mockInstructedAmount()
ia.Amount = "X,"
err := ia.Validate()
require.EqualError(t, err, fieldError("Amount", ErrNonAmount, ia.Amount).Error())
}
// TestInstructedAmountCurrencyCodeValid validates Amount
func TestInstructedAmountCurrencyCodeValid(t *testing.T) {
ia := mockInstructedAmount()
ia.CurrencyCode = "XZP"
err := ia.Validate()
require.EqualError(t, err, fieldError("CurrencyCode", ErrNonCurrencyCode, ia.CurrencyCode).Error())
}
// TestParseInstructedAmountWrongLength parses a wrong InstructedAmount record length
func TestParseInstructedAmountWrongLength(t *testing.T) {
var line = "{3710}USD4567,89"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseInstructedAmount()
require.EqualError(t, err, r.parseError(fieldError("Amount", ErrRequireDelimiter)).Error())
}
// TestParseInstructedAmountReaderParseError parses a wrong InstructedAmount reader parse error
func TestParseInstructedAmountReaderParseError(t *testing.T) {
var line = "{3710}USD000000004567Z89*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseInstructedAmount()
require.EqualError(t, err, r.parseError(fieldError("Amount", ErrNonAmount, "000000004567Z89")).Error())
_, err = r.Read()
require.EqualError(t, err, r.parseError(fieldError("Amount", ErrNonAmount, "000000004567Z89")).Error())
}
// TestInstructedAmountTagError validates a InstructedAmount tag
func TestInstructedAmountTagError(t *testing.T) {
ia := mockInstructedAmount()
ia.tag = "{9999}"
require.EqualError(t, ia.Validate(), fieldError("tag", ErrValidTagForType, ia.tag).Error())
}
// TestStringInstructedAmountVariableLength parses using variable length
func TestStringInstructedAmountVariableLength(t *testing.T) {
var line = "{3710}USD4567,89*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseInstructedAmount()
require.Nil(t, err)
line = "{3710}USD4567,89 NNN"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseInstructedAmount()
require.ErrorContains(t, err, ErrRequireDelimiter.Error())
line = "{3710}USD4567,89***"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseInstructedAmount()
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
line = "{3710}USD4567,89*"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseInstructedAmount()
require.Equal(t, err, nil)
}
// TestStringInstructedAmountOptions validates Format() formatted according to the FormatOptions
func TestStringInstructedAmountOptions(t *testing.T) {
var line = "{3710}USD4567,89*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseInstructedAmount()
require.Equal(t, err, nil)
record := r.currentFEDWireMessage.InstructedAmount
require.Equal(t, record.String(), "{3710}USD4567,89 *")
require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3710}USD4567,89*")
require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false}))
}