File: account_balance_test.go

package info (click to toggle)
golang-github-mitch000001-go-hbci 0.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,468 kB
  • sloc: java: 1,092; makefile: 5
file content (43 lines) | stat: -rw-r--r-- 1,465 bytes parent folder | download | duplicates (2)
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
package segment

import (
	"testing"
	"time"

	"github.com/mitch000001/go-hbci/domain"
	"github.com/mitch000001/go-hbci/element"
)

func TestAccountBalanceResponseSegmentUnmarshalHBCI(t *testing.T) {
	test := "HISAL:4:5:3+100000000::280:10000000+Sichteinlagen+EUR+C:1000,15:EUR:20150812+C:20,:EUR:20150812+500,:EUR+1499,85:EUR'"
	date := time.Date(2015, 8, 12, 0, 0, 0, 0, time.Local)

	expectedSegment := &AccountBalanceResponseSegment{
		AccountConnection:  element.NewAccountConnection(domain.AccountConnection{AccountID: "100000000", CountryCode: 280, BankID: "10000000"}),
		AccountProductName: element.NewAlphaNumeric("Sichteinlagen", 35),
		AccountCurrency:    element.NewCurrency("EUR"),
		BookedBalance:      element.NewBalance(domain.Amount{Amount: 1000.15, Currency: "EUR"}, date, false),
		EarmarkedBalance:   element.NewBalance(domain.Amount{Amount: 20, Currency: "EUR"}, date, false),
		CreditLimit:        element.NewAmount(500, "EUR"),
		AvailableAmount:    element.NewAmount(1499.85, "EUR"),
	}
	expectedSegment.Segment = NewReferencingBasicSegment(4, 3, expectedSegment)

	expected := expectedSegment.String()

	segment := &AccountBalanceResponseSegment{}

	err := segment.UnmarshalHBCI([]byte(test))

	if err != nil {
		t.Logf("Expected error to be nil, 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()
	}
}