-
Notifications
You must be signed in to change notification settings - Fork 1
/
beneficiary_test.go
141 lines (103 loc) · 4.57 KB
/
beneficiary_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
package wire
import (
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// mockBeneficiary creates a Beneficiary
func mockBeneficiary() *Beneficiary {
ben := NewBeneficiary()
ben.Personal.IdentificationCode = DriversLicenseNumber
ben.Personal.Identifier = "1234"
ben.Personal.Name = "Name"
ben.Personal.Address.AddressLineOne = "Address One"
ben.Personal.Address.AddressLineTwo = "Address Two"
ben.Personal.Address.AddressLineThree = "Address Three"
return ben
}
// TestMockBeneficiary validates mockBeneficiary
func TestMockBeneficiary(t *testing.T) {
ben := mockBeneficiary()
require.NoError(t, ben.Validate(), "mockBeneficiary does not validate and will break other tests")
}
// TestBeneficiaryIdentificationCodeValid validates Beneficiary IdentificationCode
func TestBeneficiaryIdentificationCodeValid(t *testing.T) {
ben := mockBeneficiary()
ben.Personal.IdentificationCode = "Baseball Card ID"
err := ben.Validate()
require.EqualError(t, err, fieldError("IdentificationCode", ErrIdentificationCode, ben.Personal.IdentificationCode).Error())
}
func TestBeneficiaryIdentificationCodeMissing(t *testing.T) {
ben := mockBeneficiary()
ben.Personal.IdentificationCode = ""
ben.Personal.Identifier = ""
require.NoError(t, ben.Validate())
}
// TestBeneficiaryIdentifierAlphaNumeric validates Beneficiary Identifier is alphanumeric
func TestBeneficiaryIdentifierAlphaNumeric(t *testing.T) {
ben := mockBeneficiary()
ben.Personal.Identifier = "®"
err := ben.Validate()
require.EqualError(t, err, fieldError("Identifier", ErrNonAlphanumeric, ben.Personal.Identifier).Error())
}
// TestBeneficiaryNameAlphaNumeric validates Beneficiary Name is alphanumeric
func TestBeneficiaryNameAlphaNumeric(t *testing.T) {
ben := mockBeneficiary()
ben.Personal.Name = "®"
err := ben.Validate()
require.EqualError(t, err, fieldError("Name", ErrNonAlphanumeric, ben.Personal.Name).Error())
}
// TestBeneficiaryAddressLineOneAlphaNumeric validates Beneficiary AddressLineOne is alphanumeric
func TestBeneficiaryAddressLineOneAlphaNumeric(t *testing.T) {
ben := mockBeneficiary()
ben.Personal.Address.AddressLineOne = "®"
err := ben.Validate()
require.EqualError(t, err, fieldError("AddressLineOne", ErrNonAlphanumeric, ben.Personal.Address.AddressLineOne).Error())
}
// TestBeneficiaryAddressLineTwoAlphaNumeric validates Beneficiary AddressLineTwo is alphanumeric
func TestBeneficiaryAddressLineTwoAlphaNumeric(t *testing.T) {
ben := mockBeneficiary()
ben.Personal.Address.AddressLineTwo = "®"
err := ben.Validate()
require.EqualError(t, err, fieldError("AddressLineTwo", ErrNonAlphanumeric, ben.Personal.Address.AddressLineTwo).Error())
}
// TestBeneficiaryAddressLineThreeAlphaNumeric validates Beneficiary AddressLineThree is alphanumeric
func TestBeneficiaryAddressLineThreeAlphaNumeric(t *testing.T) {
ben := mockBeneficiary()
ben.Personal.Address.AddressLineThree = "®"
err := ben.Validate()
require.EqualError(t, err, fieldError("AddressLineThree", ErrNonAlphanumeric, ben.Personal.Address.AddressLineThree).Error())
}
// TestBeneficiaryIdentificationCodeRequired validates Beneficiary IdentificationCode is required
func TestBeneficiaryIdentificationCodeRequired(t *testing.T) {
ben := mockBeneficiary()
ben.Personal.IdentificationCode = ""
err := ben.Validate()
require.EqualError(t, err, fieldError("IdentificationCode", ErrFieldRequired).Error())
}
// TestBeneficiaryIdentifierRequired validates Beneficiary Identifier is required
func TestBeneficiaryIdentifierRequired(t *testing.T) {
ben := mockBeneficiary()
ben.Personal.Identifier = ""
err := ben.Validate()
require.EqualError(t, err, fieldError("Identifier", ErrFieldRequired).Error())
}
// TestParseBeneficiaryReaderParseError parses a wrong Beneficiary reader parse error
func TestParseBeneficiaryReaderParseError(t *testing.T) {
var line = "{4200}31234 *Na®e *Address One *Address Two *Address Three *"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseBeneficiary()
expected := r.parseError(fieldError("Name", ErrNonAlphanumeric, "Na®e")).Error()
require.EqualError(t, err, expected)
_, err = r.Read()
expected = r.parseError(fieldError("Name", ErrNonAlphanumeric, "Na®e")).Error()
require.EqualError(t, err, expected)
}
// TestBeneficiaryTagError validates Beneficiary tag
func TestBeneficiaryTagError(t *testing.T) {
ben := mockBeneficiary()
ben.tag = "{9999}"
err := ben.Validate()
require.EqualError(t, err, fieldError("tag", ErrValidTagForType, ben.tag).Error())
}