Debian Codegraph @

segment/basic_account_information_unmarshaler_test.go

raw
1 package segment
2
3 import (
4 "testing"
5
6 "github.com/mitch000001/go-hbci/domain"
7 "github.com/mitch000001/go-hbci/element"
8 )
9
10 func TestAccountInformationSegmentUnmarshalHBCI(t *testing.T) {
11 testCases := []struct {
12 desc string
13 rawSegment string
14 expectedSegmentBuilder func() *AccountInformationSegment
15 expectedError error
16 }{
17 {
18 desc: "fully specced version 4 segment",
19 rawSegment: "HIUPD:1:4:4+123456::280:10000000+12345+EUR+Muster+Max+Sichteinlagen++DKPAE:1'",
20 expectedSegmentBuilder: func() *AccountInformationSegment {
21 v4 := &AccountInformationV4{
22 AccountConnection: element.NewAccountConnection(domain.AccountConnection{AccountID: "123456", CountryCode: 280, BankID: "10000000"}),
23 UserID: element.NewIdentification("12345"),
24 AccountCurrency: element.NewCurrency("EUR"),
25 Name1: element.NewAlphaNumeric("Muster", 27),
26 Name2: element.NewAlphaNumeric("Max", 27),
27 AccountProductID: element.NewAlphaNumeric("Sichteinlagen", 30),
28 AllowedBusinessTransactions: element.NewAllowedBusinessTransactions(
29 domain.BusinessTransaction{ID: "DKPAE", NeededSignatures: 1},
30 ),
31 }
32 v4.Segment = NewReferencingBasicSegment(1, 4, v4)
33 return &AccountInformationSegment{v4}
34 },
35 },
36 {
37 desc: "barebone version 5 segment",
38 rawSegment: "HIUPD:1:5:4++Login+++Name++++HKPSA:1'",
39 expectedSegmentBuilder: func() *AccountInformationSegment {
40 v5 := &AccountInformationV5{
41 UserID: element.NewIdentification("Login"),
42 Name1: element.NewAlphaNumeric("Name", 27),
43 AllowedBusinessTransactions: element.NewAllowedBusinessTransactions(
44 domain.BusinessTransaction{ID: "HKPSA", NeededSignatures: 1},
45 ),
46 }
47 v5.Segment = NewReferencingBasicSegment(1, 4, v5)
48 return &AccountInformationSegment{v5}
49 },
50 },
51 }
52
53 for _, tt := range testCases {
54 t.Run(tt.desc, func(t *testing.T) {
55 account := &AccountInformationSegment{}
56
57 err := account.UnmarshalHBCI([]byte(tt.rawSegment))
58
59 if err != nil {
60 t.Logf("Expected no error, got %T:%v\n", err, err)
61 t.Fail()
62 }
63
64 expected := tt.expectedSegmentBuilder()
65
66 compareAccountInformationSegments(t, expected, account)
67 })
68 }
69 }
70
71 func compareAccountInformationSegments(t *testing.T, expected, actual *AccountInformationSegment) {
72 t.Helper()
73 var expectedString, actualString string = "<nil>", "<nil>"
74 if expected != nil {
75 expectedString = expected.String()
76 }
77 if actual != nil {
78 actualString = actual.String()
79 }
80 if expectedString != actualString {
81 t.Logf("Expected unmarshaled value to equal\n%q\n\tgot\n%q\n", expectedString, actualString)
82 t.Fail()
83 }
84 }