-
Notifications
You must be signed in to change notification settings - Fork 39
/
charges_test.go
92 lines (71 loc) · 2.43 KB
/
charges_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
package wire
import (
"errors"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// mockCharges creates a Charges
func mockCharges() *Charges {
c := NewCharges()
c.ChargeDetails = "B"
c.SendersChargesOne = "USD0,99"
c.SendersChargesTwo = "USD2,99"
c.SendersChargesThree = "USD3,99"
c.SendersChargesFour = "USD1,00"
return c
}
// TestMockCharges validates mockCharges
func TestMockCharges(t *testing.T) {
c := mockCharges()
require.NoError(t, c.Validate(), "mockCharges does not validate and will break other tests")
}
// TestChargeDetailsValid validates ChargeDetails is valid
func TestPaymentNotificationIndicatorValid(t *testing.T) {
c := mockCharges()
c.ChargeDetails = "F"
err := c.Validate()
require.EqualError(t, err, fieldError("ChargeDetails", ErrChargeDetails, c.ChargeDetails).Error())
}
func TestChargesCrash(t *testing.T) {
c := &Charges{}
c.Parse("{3700}") // invalid, caused a fuzz crash
require.Empty(t, c.tag)
require.Empty(t, c.ChargeDetails)
}
// TestStringChargesVariableLength parses using variable length
func TestStringChargesVariableLength(t *testing.T) {
var line = "{3700}"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseCharges()
expected := r.parseError(NewTagMinLengthErr(7, len(r.line))).Error()
require.EqualError(t, err, expected)
line = "{3700}B NNN"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseCharges()
require.ErrorContains(t, err, ErrRequireDelimiter.Error())
line = "{3700}B******"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseCharges()
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
line = "{3700}B*"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseCharges()
require.Equal(t, err, nil)
}
// TestStringChargesOptions validates Format() formatted according to the FormatOptions
func TestStringChargesOptions(t *testing.T) {
var line = "{3700}B*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseCharges()
require.Equal(t, err, nil)
record := r.currentFEDWireMessage.Charges
require.Equal(t, record.String(), "{3700}B * * * *")
require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3700}B*")
require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false}))
}