-
Notifications
You must be signed in to change notification settings - Fork 1
/
currencyInstructedAmount_test.go
69 lines (50 loc) · 2.17 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
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.CurrencyCode = "USD"
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())
}
// TestParseCurrencyInstructedAmountReaderParseError parses a wrong CurrencyInstructedAmount reader parse error
func TestParseCurrencyInstructedAmountReaderParseError(t *testing.T) {
var line = "{7033}Swift*USD00000Z001500,49*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseCurrencyInstructedAmount()
require.EqualError(t, err, r.parseError(fieldError("Amount", ErrNonAmount, "00000Z001500,49")).Error())
_, err = r.Read()
require.EqualError(t, err, r.parseError(fieldError("Amount", ErrNonAmount, "00000Z001500,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())
}