| 1 |
package segment |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
"time" |
| 6 |
|
| 7 |
"github.com/mitch000001/go-hbci/domain" |
| 8 |
"github.com/mitch000001/go-hbci/element" |
| 9 |
) |
| 10 |
|
| 11 |
func TestAccountBalanceResponseSegmentUnmarshalHBCI(t *testing.T) { |
| 12 |
test := "HISAL:4:5:3+100000000::280:10000000+Sichteinlagen+EUR+C:1000,15:EUR:20150812+C:20,:EUR:20150812+500,:EUR+1499,85:EUR'" |
| 13 |
date := time.Date(2015, 8, 12, 0, 0, 0, 0, time.Local) |
| 14 |
|
| 15 |
expectedSegment := &AccountBalanceResponseSegment{ |
| 16 |
AccountConnection: element.NewAccountConnection(domain.AccountConnection{AccountID: "100000000", CountryCode: 280, BankID: "10000000"}), |
| 17 |
AccountProductName: element.NewAlphaNumeric("Sichteinlagen", 35), |
| 18 |
AccountCurrency: element.NewCurrency("EUR"), |
| 19 |
BookedBalance: element.NewBalance(domain.Amount{Amount: 1000.15, Currency: "EUR"}, date, false), |
| 20 |
EarmarkedBalance: element.NewBalance(domain.Amount{Amount: 20, Currency: "EUR"}, date, false), |
| 21 |
CreditLimit: element.NewAmount(500, "EUR"), |
| 22 |
AvailableAmount: element.NewAmount(1499.85, "EUR"), |
| 23 |
} |
| 24 |
expectedSegment.Segment = NewReferencingBasicSegment(4, 3, expectedSegment) |
| 25 |
|
| 26 |
expected := expectedSegment.String() |
| 27 |
|
| 28 |
segment := &AccountBalanceResponseSegment{} |
| 29 |
|
| 30 |
err := segment.UnmarshalHBCI([]byte(test)) |
| 31 |
|
| 32 |
if err != nil { |
| 33 |
t.Logf("Expected error to be nil, got %T:%v\n", err, err) |
| 34 |
t.Fail() |
| 35 |
} |
| 36 |
|
| 37 |
actual := segment.String() |
| 38 |
|
| 39 |
if expected != actual { |
| 40 |
t.Logf("Expected unmarshaled value to equal\n%q\n\tgot\n%q\n", expected, actual) |
| 41 |
t.Fail() |
| 42 |
} |
| 43 |
} |