-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathorderingCustomer_test.go
178 lines (131 loc) · 6.54 KB
/
orderingCustomer_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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package wire
import (
"errors"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// OrderingCustomer creates a OrderingCustomer
func mockOrderingCustomer() *OrderingCustomer {
oc := NewOrderingCustomer()
oc.CoverPayment.SwiftFieldTag = "Swift Field Tag"
oc.CoverPayment.SwiftLineOne = "Swift Line One"
oc.CoverPayment.SwiftLineTwo = "Swift Line Two"
oc.CoverPayment.SwiftLineThree = "Swift Line Three"
oc.CoverPayment.SwiftLineFour = "Swift Line Four"
oc.CoverPayment.SwiftLineFive = "Swift Line Five"
return oc
}
// TestMockOrderingCustomer validates mockOrderingCustomer
func TestMockOrderingCustomer(t *testing.T) {
oc := mockOrderingCustomer()
require.NoError(t, oc.Validate(), "mockOrderingCustomer does not validate and will break other tests")
}
// TestOrderingCustomerSwiftFieldTagAlphaNumeric validates OrderingCustomer SwiftFieldTag is alphanumeric
func TestOrderingCustomerSwiftFieldTagAlphaNumeric(t *testing.T) {
oc := mockOrderingCustomer()
oc.CoverPayment.SwiftFieldTag = "®"
err := oc.Validate()
require.EqualError(t, err, fieldError("SwiftFieldTag", ErrNonAlphanumeric, oc.CoverPayment.SwiftFieldTag).Error())
}
// TestOrderingCustomerSwiftLineOneAlphaNumeric validates OrderingCustomer SwiftLineOne is alphanumeric
func TestOrderingCustomerSwiftLineOneAlphaNumeric(t *testing.T) {
oc := mockOrderingCustomer()
oc.CoverPayment.SwiftLineOne = "®"
err := oc.Validate()
require.EqualError(t, err, fieldError("SwiftLineOne", ErrNonAlphanumeric, oc.CoverPayment.SwiftLineOne).Error())
}
// TestOrderingCustomerSwiftLineTwoAlphaNumeric validates OrderingCustomer SwiftLineTwo is alphanumeric
func TestOrderingCustomerSwiftLineTwoAlphaNumeric(t *testing.T) {
oc := mockOrderingCustomer()
oc.CoverPayment.SwiftLineTwo = "®"
err := oc.Validate()
require.EqualError(t, err, fieldError("SwiftLineTwo", ErrNonAlphanumeric, oc.CoverPayment.SwiftLineTwo).Error())
}
// TestOrderingCustomerSwiftLineThreeAlphaNumeric validates OrderingCustomer SwiftLineThree is alphanumeric
func TestOrderingCustomerSwiftLineThreeAlphaNumeric(t *testing.T) {
oc := mockOrderingCustomer()
oc.CoverPayment.SwiftLineThree = "®"
err := oc.Validate()
require.EqualError(t, err, fieldError("SwiftLineThree", ErrNonAlphanumeric, oc.CoverPayment.SwiftLineThree).Error())
}
// TestOrderingCustomerSwiftLineFourAlphaNumeric validates OrderingCustomer SwiftLineFour is alphanumeric
func TestOrderingCustomerSwiftLineFourAlphaNumeric(t *testing.T) {
oc := mockOrderingCustomer()
oc.CoverPayment.SwiftLineFour = "®"
err := oc.Validate()
require.EqualError(t, err, fieldError("SwiftLineFour", ErrNonAlphanumeric, oc.CoverPayment.SwiftLineFour).Error())
}
// TestOrderingCustomerSwiftLineFiveAlphaNumeric validates OrderingCustomer SwiftLineFive is alphanumeric
func TestOrderingCustomerSwiftLineFiveAlphaNumeric(t *testing.T) {
oc := mockOrderingCustomer()
oc.CoverPayment.SwiftLineFive = "®"
err := oc.Validate()
require.EqualError(t, err, fieldError("SwiftLineFive", ErrNonAlphanumeric, oc.CoverPayment.SwiftLineFive).Error())
}
// TestOrderingCustomerSwiftLineSixAlphaNumeric validates OrderingCustomer SwiftLineSix is alphanumeric
func TestOrderingCustomerSwiftLineSixAlphaNumeric(t *testing.T) {
oc := mockOrderingCustomer()
oc.CoverPayment.SwiftLineSix = "Test"
err := oc.Validate()
require.EqualError(t, err, fieldError("SwiftLineSix", ErrInvalidProperty, oc.CoverPayment.SwiftLineSix).Error())
}
// TestParseOrderingCustomerWrongLength parses a wrong OrderingCustomer record length
func TestParseOrderingCustomerWrongLength(t *testing.T) {
var line = "{7050}SwiftSwift Line One Swift Line Two Swift Line Three Swift Line Four Swift Line Five "
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseOrderingCustomer()
require.EqualError(t, err, r.parseError(fieldError("SwiftFieldTag", ErrRequireDelimiter)).Error())
}
// TestParseOrderingCustomerReaderParseError parses a wrong OrderingCustomer reader parse error
func TestParseOrderingCustomerReaderParseError(t *testing.T) {
var line = "{7050}Swift*Swift ®ine One *Swift Line Two *Swift Line Three *Swift Line Four *Swift Line Five *"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseOrderingCustomer()
require.EqualError(t, err, r.parseError(fieldError("SwiftLineOne", ErrNonAlphanumeric, "Swift ®ine One")).Error())
_, err = r.Read()
require.EqualError(t, err, r.parseError(fieldError("SwiftLineOne", ErrNonAlphanumeric, "Swift ®ine One")).Error())
}
// TestOrderingCustomerTagError validates a OrderingCustomer tag
func TestOrderingCustomerTagError(t *testing.T) {
oc := mockOrderingCustomer()
oc.tag = "{9999}"
require.EqualError(t, oc.Validate(), fieldError("tag", ErrValidTagForType, oc.tag).Error())
}
// TestStringOrderingCustomerVariableLength parses using variable length
func TestStringOrderingCustomerVariableLength(t *testing.T) {
var line = "{7050}"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseOrderingCustomer()
require.NoError(t, err)
line = "{7050} NNN"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseOrderingCustomer()
require.ErrorContains(t, err, ErrRequireDelimiter.Error())
line = "{7050}********"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseOrderingCustomer()
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
line = "{7050}*"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseOrderingCustomer()
require.NoError(t, err)
}
// TestStringOrderingCustomerOptions validates Format() formatted according to the FormatOptions
func TestStringOrderingCustomerOptions(t *testing.T) {
var line = "{7050}"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseOrderingCustomer()
require.NoError(t, err)
record := r.currentFEDWireMessage.OrderingCustomer
require.Equal(t, "{7050} * * * * * *", record.String())
require.Equal(t, "{7050}*", record.Format(FormatOptions{VariableLengthFields: true}))
require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false}))
}