Debian Codegraph @

segment/business_transaction_test.go

raw
1 package segment
2
3 import (
4 "reflect"
5 "testing"
6
7 "github.com/mitch000001/go-hbci/domain"
8 "github.com/mitch000001/go-hbci/element"
9 )
10
11 func TestBusinessTransactionParamsSegment(t *testing.T) {
12 test := "DIDFBS:21:1:4+1+1+1'"
13
14 segment := &BusinessTransactionParamsSegment{}
15
16 expectedSegment := &BusinessTransactionParamsSegment{
17 id: "DIDFBS",
18 version: 1,
19 MaxJobs: element.NewNumber(1, 1),
20 MinSignatures: element.NewNumber(1, 1),
21 }
22 expectedSegment.Segment = NewReferencingBasicSegment(21, 4, expectedSegment)
23 expected := expectedSegment.String()
24
25 err := segment.UnmarshalHBCI([]byte(test))
26
27 if err != nil {
28 t.Logf("Expected no error, got %T:%v\n", err, err)
29 t.Fail()
30 }
31
32 actual := segment.String()
33
34 if expected != actual {
35 t.Logf("Expected unmarshaled value to equal\n%q\n\tgot\n%q\n", expected, actual)
36 t.Fail()
37 }
38 }
39
40 func TestPinTanBusinessTransactionParamsSegmentUnmarshalHBCI(t *testing.T) {
41 test := "DIPINS:3:1:4+1+1+HKSAL:N:HKUEB:J'"
42
43 segment := &PinTanBusinessTransactionParamsSegment{}
44
45 pinTanBusinessTransactions := []domain.PinTanBusinessTransaction{
46 {
47 SegmentID: "HKSAL",
48 NeedsTan: false,
49 },
50 {
51 SegmentID: "HKUEB",
52 NeedsTan: true,
53 },
54 }
55 pinTanDataElement := element.NewPinTanBusinessTransactionParameters(pinTanBusinessTransactions)
56 expectedSegment := &PinTanBusinessTransactionParamsSegment{
57 BusinessTransactionParamsSegment: &BusinessTransactionParamsSegment{
58 MaxJobs: element.NewNumber(1, 1),
59 MinSignatures: element.NewNumber(1, 1),
60 Params: pinTanDataElement,
61 },
62 }
63 expectedSegment.Segment = NewReferencingBasicSegment(3, 4, expectedSegment)
64 expected := expectedSegment.String()
65
66 err := segment.UnmarshalHBCI([]byte(test))
67
68 if err != nil {
69 t.Logf("Expected no error, got %T:%v\n", err, err)
70 t.Fail()
71 }
72
73 actual := segment.String()
74
75 if expected != actual {
76 t.Logf("Expected unmarshaled value to equal\n%q\n\tgot\n%q\n", expected, actual)
77 t.Fail()
78 }
79 }
80
81 func TestPinTanBusinessTransactionParamsSegmentPinTanBusinessTransactions(t *testing.T) {
82 pinTanBusinessTransactions := []domain.PinTanBusinessTransaction{
83 {
84 SegmentID: "HKSAL",
85 NeedsTan: false,
86 },
87 {
88 SegmentID: "HKUEB",
89 NeedsTan: true,
90 },
91 }
92 pinTanDataElement := element.NewPinTanBusinessTransactionParameters(pinTanBusinessTransactions)
93 segment := &PinTanBusinessTransactionParamsSegment{
94 BusinessTransactionParamsSegment: &BusinessTransactionParamsSegment{
95 MaxJobs: element.NewNumber(1, 1),
96 MinSignatures: element.NewNumber(1, 1),
97 Params: pinTanDataElement,
98 },
99 }
100 segment.Segment = NewReferencingBasicSegment(3, 4, segment)
101
102 expectedTransactions := []domain.PinTanBusinessTransaction{
103 {SegmentID: "HKSAL", NeedsTan: false},
104 {SegmentID: "HKUEB", NeedsTan: true},
105 }
106
107 pinTanTransactions := segment.PinTanBusinessTransactions()
108
109 if !reflect.DeepEqual(expectedTransactions, pinTanTransactions) {
110 t.Logf("Expected pinTanBusinessTransactions to return\n%+#v\n\tgot\n%+#v\n", expectedTransactions, pinTanTransactions)
111 t.Fail()
112 }
113 }