Skip to content

nhatthm/n26api

Repository files navigation

N26 API Client

GitHub Releases Build Status codecov Go Report Card GoDevDoc Donate

Unofficial N26 API Client for Golang.

Disclaimer

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.

Prerequisites

  • Go >= 1.17

Install

go get github.com/nhatthm/n26api

Development

API Service

TBA

API Client

TBD

Testkit

Unit Test

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)
}

Integration Test

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
}
Server Options
WithFindAllTransactionsInRange

TBD

Test

Unit Test

Run

make test

or

make test-unit

Integration Test

TBD

GDPR

No information is used or store by this module.

References

Donation

If this project help you reduce time to develop, you can give me a cup of coffee :)

Paypal donation

paypal

       or scan this