Unofficial N26 API Client for Golang
MIT License
Unofficial N26 API Client for Golang.
This project is NOT sponsored or funded by N26 nor any of its competitors.
The client is built on a collection of observed API calls and methods provided by Rots/n26-api.
Go >= 1.17
go get github.com/nhatthm/n26api
TBA
TBD
The services can be easily mocked by using the testkit
, all the mocked interface is provided
by stretchr/testify/mock
For example: Mocking transaction.Finder
service
package test
import (
"context"
"testing"
"time"
"github.com/google/uuid"
transactionMock "github.com/nhatthm/n26api/pkg/testkit/transaction"
"github.com/nhatthm/n26api/pkg/transaction"
"github.com/stretchr/testify/assert"
)
func TestTransactions(t *testing.T) {
t.Parallel()
from := time.Now()
to := from.Add(time.Hour)
id := uuid.New()
f := transactionMock.MockFinder(func(f *transactionMock.Finder) {
f.On("FindAllTransactionsInRange", context.Background(), from, to).
Return(
[]transaction.Transaction{
{ID: id, OriginalAmount: 3.5},
},
nil,
)
})(t)
expected := []transaction.Transaction{
{ID: id, OriginalAmount: 3.5},
}
result, err := f.FindAllTransactionsInRange(context.Background(), from, to)
assert.Equal(t, expected, result)
assert.NoError(t, err)
}
The testkit
provides a mocked API server for testing.
For example:
package test
import (
"context"
"testing"
"time"
"github.com/google/uuid"
"github.com/nhatthm/n26api"
"github.com/nhatthm/n26api/pkg/testkit"
"github.com/nhatthm/n26api/pkg/transaction"
)
func TestFindTransactions(t *testing.T) {
t.Parallel()
username := "username"
password := "password"
deviceID := uuid.New()
from := time.Now()
to := from.Add(time.Hour)
pageSize := int64(1)
id1 := uuid.New()
id2 := uuid.New()
s := testkit.MockServer(username, password, deviceID,
testkit.WithFindAllTransactionsInRange(
from, to, pageSize,
[]transaction.Transaction{{ID: id1}, {ID: id2}},
),
)(t)
c := n26api.NewClient(
n26api.WithBaseURL(s.URL()),
n26api.WithDeviceID(deviceID),
n26api.WithCredentials(username, password),
n26api.WithMFAWait(5*time.Millisecond),
n26api.WithMFATimeout(time.Second),
n26api.WithTransactionsPageSize(pageSize),
)
result, err := c.FindAllTransactionsInRange(context.Background(), from, to)
// assertions
}
WithFindAllTransactionsInRange
TBD
Run
make test
or
make test-unit
TBD
No information is used or store by this module.
If this project help you reduce time to develop, you can give me a cup of coffee :)
or scan this