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
|
package segment
import (
"reflect"
"testing"
"github.com/mitch000001/go-hbci/domain"
"github.com/mitch000001/go-hbci/element"
)
func TestBusinessTransactionParamsSegment(t *testing.T) {
test := "DIDFBS:21:1:4+1+1+1'"
segment := &BusinessTransactionParamsSegment{}
expectedSegment := &BusinessTransactionParamsSegment{
id: "DIDFBS",
version: 1,
MaxJobs: element.NewNumber(1, 1),
MinSignatures: element.NewNumber(1, 1),
}
expectedSegment.Segment = NewReferencingBasicSegment(21, 4, expectedSegment)
expected := expectedSegment.String()
err := segment.UnmarshalHBCI([]byte(test))
if err != nil {
t.Logf("Expected no error, got %T:%v\n", err, err)
t.Fail()
}
actual := segment.String()
if expected != actual {
t.Logf("Expected unmarshaled value to equal\n%q\n\tgot\n%q\n", expected, actual)
t.Fail()
}
}
func TestPinTanBusinessTransactionParamsSegmentUnmarshalHBCI(t *testing.T) {
test := "DIPINS:3:1:4+1+1+HKSAL:N:HKUEB:J'"
segment := &PinTanBusinessTransactionParamsSegment{}
pinTanBusinessTransactions := []domain.PinTanBusinessTransaction{
{
SegmentID: "HKSAL",
NeedsTan: false,
},
{
SegmentID: "HKUEB",
NeedsTan: true,
},
}
pinTanDataElement := element.NewPinTanBusinessTransactionParameters(pinTanBusinessTransactions)
expectedSegment := &PinTanBusinessTransactionParamsSegment{
BusinessTransactionParamsSegment: &BusinessTransactionParamsSegment{
MaxJobs: element.NewNumber(1, 1),
MinSignatures: element.NewNumber(1, 1),
Params: pinTanDataElement,
},
}
expectedSegment.Segment = NewReferencingBasicSegment(3, 4, expectedSegment)
expected := expectedSegment.String()
err := segment.UnmarshalHBCI([]byte(test))
if err != nil {
t.Logf("Expected no error, got %T:%v\n", err, err)
t.Fail()
}
actual := segment.String()
if expected != actual {
t.Logf("Expected unmarshaled value to equal\n%q\n\tgot\n%q\n", expected, actual)
t.Fail()
}
}
func TestPinTanBusinessTransactionParamsSegmentPinTanBusinessTransactions(t *testing.T) {
pinTanBusinessTransactions := []domain.PinTanBusinessTransaction{
{
SegmentID: "HKSAL",
NeedsTan: false,
},
{
SegmentID: "HKUEB",
NeedsTan: true,
},
}
pinTanDataElement := element.NewPinTanBusinessTransactionParameters(pinTanBusinessTransactions)
segment := &PinTanBusinessTransactionParamsSegment{
BusinessTransactionParamsSegment: &BusinessTransactionParamsSegment{
MaxJobs: element.NewNumber(1, 1),
MinSignatures: element.NewNumber(1, 1),
Params: pinTanDataElement,
},
}
segment.Segment = NewReferencingBasicSegment(3, 4, segment)
expectedTransactions := []domain.PinTanBusinessTransaction{
{SegmentID: "HKSAL", NeedsTan: false},
{SegmentID: "HKUEB", NeedsTan: true},
}
pinTanTransactions := segment.PinTanBusinessTransactions()
if !reflect.DeepEqual(expectedTransactions, pinTanTransactions) {
t.Logf("Expected pinTanBusinessTransactions to return\n%+#v\n\tgot\n%+#v\n", expectedTransactions, pinTanTransactions)
t.Fail()
}
}
|