-
Notifications
You must be signed in to change notification settings - Fork 39
/
currencyInstructedAmount_test.go
115 lines (84 loc) · 3.86 KB
/
currencyInstructedAmount_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
package wire
import (
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// CurrencyInstructedAmount creates a CurrencyInstructedAmount
func mockCurrencyInstructedAmount() *CurrencyInstructedAmount {
cia := NewCurrencyInstructedAmount()
cia.SwiftFieldTag = "Swift Field Tag"
cia.Amount = "1500,49"
return cia
}
// TestMockCurrencyInstructedAmount validates mockCurrencyInstructedAmount
func TestMockCurrencyInstructedAmount(t *testing.T) {
cia := mockCurrencyInstructedAmount()
require.NoError(t, cia.Validate(), "mockCurrencyInstructedAmount does not validate and will break other tests")
}
// TestCurrencyInstructedAmountSwiftFieldTagAlphaNumeric validates CurrencyInstructedAmount SwiftFieldTag is alphanumeric
func TestCurrencyInstructedAmountSwiftFieldTagAlphaNumeric(t *testing.T) {
cia := mockCurrencyInstructedAmount()
cia.SwiftFieldTag = "®"
err := cia.Validate()
require.EqualError(t, err, fieldError("SwiftFieldTag", ErrNonAlphanumeric, cia.SwiftFieldTag).Error())
}
// TestCurrencyInstructedAmountValid validates CurrencyInstructedAmount Amount is valid
func TestCurrencyInstructedAmountValid(t *testing.T) {
cia := mockCurrencyInstructedAmount()
cia.Amount = "1-0"
err := cia.Validate()
require.EqualError(t, err, fieldError("Amount", ErrNonAmount, cia.Amount).Error())
}
// TestParseCurrencyInstructedAmountWrongLength parses a wrong CurrencyInstructedAmount record length
func TestParseCurrencyInstructedAmountWrongLength(t *testing.T) {
var line = "{7033}Swift*000000000001500,4"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseCurrencyInstructedAmount()
require.EqualError(t, err, r.parseError(fieldError("Amount", ErrRequireDelimiter)).Error())
_, err = r.Read()
require.EqualError(t, err, r.parseError(fieldError("Amount", ErrRequireDelimiter)).Error())
}
// TestParseCurrencyInstructedAmountReaderParseError parses a wrong CurrencyInstructedAmount reader parse error
func TestParseCurrencyInstructedAmountReaderParseError(t *testing.T) {
var line = "{7033}Swift*00000000Z001500,49*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseCurrencyInstructedAmount()
require.EqualError(t, err, r.parseError(fieldError("Amount", ErrNonAmount, "00000000Z001500,49")).Error())
_, err = r.Read()
require.EqualError(t, err, r.parseError(fieldError("Amount", ErrNonAmount, "00000000Z001500,49")).Error())
}
// TestCurrencyInstructedAmountTagError validates a CurrencyInstructedAmount tag
func TestCurrencyInstructedAmountTagError(t *testing.T) {
cia := mockCurrencyInstructedAmount()
cia.tag = "{9999}"
err := cia.Validate()
require.EqualError(t, err, fieldError("tag", ErrValidTagForType, cia.tag).Error())
}
// TestStringCurrencyInstructedAmountVariableLength parses using variable length
func TestStringCurrencyInstructedAmountVariableLength(t *testing.T) {
var line = "{7033}*000000000001500,49*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseCurrencyInstructedAmount()
require.Nil(t, err)
line = "{7033}B NNN"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseCurrencyInstructedAmount()
require.ErrorContains(t, err, ErrRequireDelimiter.Error())
}
// TestStringCurrencyInstructedAmountOptions validates Format() formatted according to the FormatOptions
func TestStringCurrencyInstructedAmountOptions(t *testing.T) {
var line = "{7033}*000000000001500,49*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseCurrencyInstructedAmount()
require.Equal(t, err, nil)
record := r.currentFEDWireMessage.CurrencyInstructedAmount
require.Equal(t, record.String(), "{7033} *000000000001500,49*")
require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{7033}*000000000001500,49*")
require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false}))
}