//go:build integration

package cache_test

import (
	"context"
	"strconv"
	"testing"

	"gogs.inhome.blapointe.com/ana-ledger/src/bank/cache"
	"gogs.inhome.blapointe.com/ana-ledger/src/bank/teller"
)

func Test(t *testing.T) {
	tellerC, err := teller.New()
	if err != nil {
		t.Fatal(err)
	}
	client := cache.New(tellerC)

	ctx := context.Background()

	for i := 0; i < 2; i++ {
		i := i
		client := client
		t.Run(strconv.Itoa(i), func(t *testing.T) {
			accounts, err := client.Accounts(ctx)
			if err != nil {
				t.Fatal(err)
			}

			for _, account := range accounts {
				account := account
				t.Run(account.Account, func(t *testing.T) {
					transactions, err := client.Transactions(ctx, account)
					if err != nil {
						t.Fatal(err)
					}

					for i, tr := range transactions {
						t.Logf("[%d] %+v", i, tr)
					}
				})
				break
			}

		})
		client.Client = nil
	}
}
