-
Notifications
You must be signed in to change notification settings - Fork 1
/
fiBeneficiaryFI_test.go
114 lines (83 loc) · 3.72 KB
/
fiBeneficiaryFI_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
package wire
import (
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// mockFIBeneficiaryFI creates a FIBeneficiaryFI
func mockFIBeneficiaryFI() *FIBeneficiaryFI {
fibfi := NewFIBeneficiaryFI()
fibfi.FIToFI.LineOne = "Line One"
fibfi.FIToFI.LineTwo = "Line Two"
fibfi.FIToFI.LineThree = "Line Three"
fibfi.FIToFI.LineFour = "Line Four"
fibfi.FIToFI.LineFive = "Line Five"
fibfi.FIToFI.LineSix = "Line Six"
return fibfi
}
// TestMockFIBeneficiaryFI validates mockFIBeneficiaryFI
func TestMockFIBeneficiaryFI(t *testing.T) {
fibfi := mockFIBeneficiaryFI()
require.NoError(t, fibfi.Validate(), "mockFIBeneficiaryFI does not validate and will break other tests")
}
// TestFIBeneficiaryFILineOneAlphaNumeric validates FIBeneficiaryFI LineOne is alphanumeric
func TestFIBeneficiaryFILineOneAlphaNumeric(t *testing.T) {
fibfi := mockFIBeneficiaryFI()
fibfi.FIToFI.LineOne = "®"
err := fibfi.Validate()
require.EqualError(t, err, fieldError("LineOne", ErrNonAlphanumeric, fibfi.FIToFI.LineOne).Error())
}
// TestFIBeneficiaryFILineTwoAlphaNumeric validates FIBeneficiaryFI LineTwo is alphanumeric
func TestFIBeneficiaryFILineTwoAlphaNumeric(t *testing.T) {
fibfi := mockFIBeneficiaryFI()
fibfi.FIToFI.LineTwo = "®"
err := fibfi.Validate()
require.EqualError(t, err, fieldError("LineTwo", ErrNonAlphanumeric, fibfi.FIToFI.LineTwo).Error())
}
// TestFIBeneficiaryFILineThreeAlphaNumeric validates FIBeneficiaryFI LineThree is alphanumeric
func TestFIBeneficiaryFILineThreeAlphaNumeric(t *testing.T) {
fibfi := mockFIBeneficiaryFI()
fibfi.FIToFI.LineThree = "®"
err := fibfi.Validate()
require.EqualError(t, err, fieldError("LineThree", ErrNonAlphanumeric, fibfi.FIToFI.LineThree).Error())
}
// TestFIBeneficiaryFILineFourAlphaNumeric validates FIBeneficiaryFI LineFour is alphanumeric
func TestFIBeneficiaryFILineFourAlphaNumeric(t *testing.T) {
fibfi := mockFIBeneficiaryFI()
fibfi.FIToFI.LineFour = "®"
err := fibfi.Validate()
require.EqualError(t, err, fieldError("LineFour", ErrNonAlphanumeric, fibfi.FIToFI.LineFour).Error())
}
// TestFIBeneficiaryFILineFiveAlphaNumeric validates FIBeneficiaryFI LineFive is alphanumeric
func TestFIBeneficiaryFILineFiveAlphaNumeric(t *testing.T) {
fibfi := mockFIBeneficiaryFI()
fibfi.FIToFI.LineFive = "®"
err := fibfi.Validate()
require.EqualError(t, err, fieldError("LineFive", ErrNonAlphanumeric, fibfi.FIToFI.LineFive).Error())
}
// TestFIBeneficiaryFILineSixAlphaNumeric validates FIBeneficiaryFI LineSix is alphanumeric
func TestFIBeneficiaryFILineSixAlphaNumeric(t *testing.T) {
fibfi := mockFIBeneficiaryFI()
fibfi.FIToFI.LineSix = "®"
err := fibfi.Validate()
require.EqualError(t, err, fieldError("LineSix", ErrNonAlphanumeric, fibfi.FIToFI.LineSix).Error())
}
// TestParseFIBeneficiaryFIReaderParseError parses a wrong FIBeneficiaryFI reader parse error
func TestParseFIBeneficiaryFIReaderParseError(t *testing.T) {
var line = "{6300}Line ®ne *Line Two *Line Three *Line Four *Line Five *Line Six *"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIBeneficiaryFI()
expected := r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "Line ®ne")).Error()
require.EqualError(t, err, expected)
_, err = r.Read()
expected = r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "Line ®ne")).Error()
require.EqualError(t, err, expected)
}
// TestFIBeneficiaryFITagError validates a FIBeneficiaryFI tag
func TestFIBeneficiaryFITagError(t *testing.T) {
fibfi := mockFIBeneficiaryFI()
fibfi.tag = "{9999}"
err := fibfi.Validate()
require.EqualError(t, err, fieldError("tag", ErrValidTagForType, fibfi.tag).Error())
}