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
}
TBD
Run
make test
or
make test-unit
TBD
No information is used or store by this module.
- https://github.com/guitmz/n26 (for MFA)
- https://github.com/Rots/n26-api (for OpenAPI doc)
If this project help you reduce time to develop, you can give me a cup of coffee :)
or scan this