Skip to content
/ n26api Public

Unofficial N26 API Client for Golang

License

Notifications You must be signed in to change notification settings

nhatthm/n26api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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