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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
package client_test
import (
"encoding/json"
"fmt"
"os"
"strconv"
"testing"
"time"
"github.com/mitch000001/go-hbci/client"
"github.com/mitch000001/go-hbci/domain"
"github.com/mitch000001/go-hbci/iban"
)
var testAccount domain.AccountConnection
var sepaTestAccount domain.InternationalAccountConnection
func TestClientAccountTransactions(t *testing.T) {
skipWhenE2EDisabled(t)
c := newClient()
timeframe := domain.Timeframe{
StartDate: domain.NewShortDate(time.Now().AddDate(0, 0, -90)),
}
transactions, err := c.AccountTransactions(testAccount, timeframe, false, "")
if err != nil {
t.Logf("Expected error to be nil, got %T:%v\n", err, err)
t.Fail()
}
if transactions == nil {
t.Logf("Expected transactions not to be nil\n")
t.Fail()
}
for _, tr := range transactions {
fmt.Printf("Transaction: %s\n", tr)
}
}
func TestClientSepaAccountTransactions(t *testing.T) {
skipWhenE2EDisabled(t)
c := newClient()
timeframe := domain.Timeframe{
StartDate: domain.NewShortDate(time.Now().AddDate(0, 0, -90)),
}
transactions, err := c.SepaAccountTransactions(sepaTestAccount, timeframe, false, "")
if err != nil {
t.Logf("Expected error to be nil, got %T:%v\n", err, err)
t.Fail()
}
if transactions == nil {
t.Logf("Expected transactions not to be nil\n")
t.Fail()
}
for _, tr := range transactions {
fmt.Printf("Transaction: %s\n", tr)
}
}
func TestClientAccountInformation(t *testing.T) {
skipWhenE2EDisabled(t)
c := newClient()
err := c.AccountInformation(testAccount, true)
if err != nil {
t.Logf("Expected error to be nil, got %T:%v\n", err, err)
// t.Fail()
}
}
func TestClientAccountBalances(t *testing.T) {
skipWhenE2EDisabled(t)
c := newClient()
balances, err := c.AccountBalances(testAccount, true)
if err != nil {
t.Logf("Expected error to be nil, got %T:%v\n", err, err)
t.Fail()
}
if balances == nil {
t.Logf("Expected balances not to be nil\n")
t.Fail()
}
for _, balance := range balances {
t.Logf("Balance: %s\n", balance)
}
}
func TestClientAccounts(t *testing.T) {
skipWhenE2EDisabled(t)
c := newClient()
accounts, err := c.Accounts()
if err != nil {
t.Logf("Expected error to be nil, got %T:%v\n", err, err)
t.Fail()
}
if accounts == nil {
t.Logf("Expected accounts not to be nil\n")
t.Fail()
}
for _, account := range accounts {
t.Logf("Account: %s\tProduct name: %s\tCurrency: %s\n", account.AccountConnection.AccountID, account.ProductID, account.Currency)
t.Logf("Allowed transactions:\n")
for _, allowedTransaction := range account.AllowedBusinessTransactions {
t.Logf("ID: %s\tNeeded signatures: %d\n", allowedTransaction.ID, allowedTransaction.NeededSignatures)
}
}
}
func TestClientStatus(t *testing.T) {
skipWhenE2EDisabled(t)
c := newClient()
statuus, err := c.Status(time.Now().Add(-48*time.Hour), time.Now(), 10, "")
if err != nil {
t.Logf("Expected error to be nil, got %T:%v\n", err, err)
t.Fail()
}
for _, status := range statuus {
t.Logf("Status: %s\n", status)
}
}
func TestAnonymousClientCommunicationAccess(t *testing.T) {
skipWhenE2EDisabled(t)
a := &client.AnonymousClient{
Client: newClient(),
}
from := domain.BankID{280, "78050000"}
to := domain.BankID{280, "78050000"}
res, err := a.CommunicationAccess(from, to, 10)
if err != nil {
t.Logf("Expected error to be nil, got %T:%v\n", err, err)
// t.Fail()
}
if res != nil {
t.Logf("Response: %s\n", res)
}
}
func newClient() *client.Client {
configFile, err := os.Open("../.fints300.json")
if err != nil && !os.IsNotExist(err) {
panic(err)
}
var config client.Config
if configFile != nil {
jsonDecoder := json.NewDecoder(configFile)
err = jsonDecoder.Decode(&config)
if err != nil {
panic(err)
}
} else {
config = client.Config{
URL: os.Getenv("GOHBCI_URL"),
AccountID: os.Getenv("GOHBCI_USERID"),
BankID: os.Getenv("GOHBCI_BLZ"),
PIN: os.Getenv("GOHBCI_PIN"),
}
}
testAccount = domain.AccountConnection{AccountID: config.AccountID, CountryCode: 280, BankID: config.BankID}
i, err := iban.NewGerman(config.BankID, config.AccountID)
if err != nil {
panic(err)
}
sepaTestAccount = domain.InternationalAccountConnection{
IBAN: string(i),
AccountID: config.AccountID,
BankID: domain.BankID{CountryCode: 280, ID: config.BankID},
}
c, err := client.New(config)
if err != nil {
panic(err)
}
return c
}
func skipWhenE2EDisabled(t *testing.T) {
if testE2E() {
return
}
t.Skip("Enable client e2e tests by setting env var `GOHBCI_TEST_E2E_CLIENT` to `true`")
}
func testE2E() bool {
val, ok := os.LookupEnv("GOHBCI_TEST_E2E_CLIENT")
if !ok {
return false
}
testE2E, err := strconv.ParseBool(val)
if err != nil {
return false
}
return testE2E
}
|