-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathdateRemittanceDocument_test.go
69 lines (50 loc) · 2.04 KB
/
dateRemittanceDocument_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"
"time"
"github.com/stretchr/testify/require"
)
// DateRemittanceDocument creates a DateRemittanceDocument
func mockDateRemittanceDocument() *DateRemittanceDocument {
drd := NewDateRemittanceDocument()
drd.DateRemittanceDocument = time.Now().Format("20060102")
return drd
}
// TestMockDateRemittanceDocument validates mockDateRemittanceDocument
func TestMockDateRemittanceDocument(t *testing.T) {
drd := mockDateRemittanceDocument()
require.NoError(t, drd.Validate(), "mockDateRemittanceDocument does not validate and will break other tests")
}
// TestDateRemittanceDocumentRequired validates DateRemittanceDocument is required
func TestDateRemittanceDocumentDateRemittanceDocumentRequired(t *testing.T) {
drd := mockDateRemittanceDocument()
drd.DateRemittanceDocument = ""
err := drd.Validate()
require.EqualError(t, err, fieldError("DateRemittanceDocument", ErrFieldRequired).Error())
}
// TestParseDateRemittanceDocumentWrongLength parses a wrong DateRemittanceDocument record length
func TestParseDateRemittanceDocumentWrongLength(t *testing.T) {
var line = "{8650}20190509 "
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseDateRemittanceDocument()
require.EqualError(t, err, r.parseError(NewTagWrongLengthErr(14, len(r.line))).Error())
}
// TestParseDateRemittanceDocumentReaderParseError parses a wrong DateRemittanceDocument reader parse error
func TestParseDateRemittanceDocumentReaderParseError(t *testing.T) {
var line = "{8650}14190509"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseDateRemittanceDocument()
require.EqualError(t, err, r.parseError(ErrValidDate).Error())
_, err = r.Read()
require.EqualError(t, err, r.parseError(ErrValidDate).Error())
}
// TestDateRemittanceDocumentTagError validates a DateRemittanceDocument tag
func TestDateRemittanceDocumentTagError(t *testing.T) {
drd := mockDateRemittanceDocument()
drd.tag = "{9999}"
err := drd.Validate()
require.EqualError(t, err, fieldError("tag", ErrValidTagForType, drd.tag).Error())
}