mirror of
https://github.com/getAlby/hub.git
synced 2026-08-13 12:33:39 +02:00
* feat: filter transactions * fix: harden transaction filters * refactor: use explicit nullable transaction filters with HideFailed polarity Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat: set transaction filters in a dialog from wallet actions menu Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat: filter transactions by search term and type Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix: reject invalid transaction filters and reset page synchronously Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix: parse complete minimum amount value in transactions filter dialog Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Roland Bewick <roland.bewick@gmail.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
98 lines
2.4 KiB
Go
98 lines
2.4 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/getAlby/hub/tests"
|
|
"github.com/getAlby/hub/tests/mocks"
|
|
"github.com/getAlby/hub/transactions"
|
|
)
|
|
|
|
func TestCreateInvoice_ToApp(t *testing.T) {
|
|
ctx := context.TODO()
|
|
|
|
testSvc, err := tests.CreateTestService(t)
|
|
require.NoError(t, err)
|
|
defer testSvc.Remove()
|
|
|
|
app, _, err := tests.CreateApp(testSvc)
|
|
require.NoError(t, err)
|
|
|
|
svc := mocks.NewMockService(t)
|
|
svc.On("GetLNClient").Return(testSvc.LNClient)
|
|
svc.On("GetTransactionsService").Return(transactions.NewTransactionsService(testSvc.DB, testSvc.EventPublisher))
|
|
|
|
theAPI := &api{
|
|
appsSvc: testSvc.AppsService,
|
|
svc: svc,
|
|
}
|
|
|
|
transaction, err := theAPI.CreateInvoice(ctx, 1000, "Hello world", &app.ID)
|
|
|
|
require.NoError(t, err)
|
|
require.NotNil(t, transaction.AppId)
|
|
assert.Equal(t, app.ID, *transaction.AppId)
|
|
}
|
|
|
|
func TestCreateInvoice_ToAppNotFound(t *testing.T) {
|
|
ctx := context.TODO()
|
|
|
|
testSvc, err := tests.CreateTestService(t)
|
|
require.NoError(t, err)
|
|
defer testSvc.Remove()
|
|
|
|
svc := mocks.NewMockService(t)
|
|
svc.On("GetLNClient").Return(testSvc.LNClient)
|
|
|
|
theAPI := &api{
|
|
appsSvc: testSvc.AppsService,
|
|
svc: svc,
|
|
}
|
|
|
|
missingAppId := uint(999)
|
|
transaction, err := theAPI.CreateInvoice(ctx, 1000, "Hello world", &missingAppId)
|
|
|
|
assert.Nil(t, transaction)
|
|
require.Error(t, err)
|
|
assert.Equal(t, "app does not exist", err.Error())
|
|
}
|
|
|
|
func TestParseListTransactionsFilters(t *testing.T) {
|
|
minAmountMsat := uint64(1000_000)
|
|
outgoing := "outgoing"
|
|
|
|
filters, err := ParseListTransactionsFilters(url.Values{
|
|
"type": {"outgoing"},
|
|
"minAmountSat": {"1000"},
|
|
"hideFailed": {"true"},
|
|
"search": {" coffee "},
|
|
})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, ListTransactionsFilters{
|
|
Type: &outgoing,
|
|
MinAmountMsat: &minAmountMsat,
|
|
HideFailed: true,
|
|
SearchTerm: "coffee",
|
|
}, filters)
|
|
|
|
filters, err = ParseListTransactionsFilters(url.Values{})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, ListTransactionsFilters{}, filters)
|
|
|
|
for _, invalidQuery := range []url.Values{
|
|
{"type": {"sideways"}},
|
|
{"minAmountSat": {"abc"}},
|
|
{"minAmountSat": {"-1"}},
|
|
{"minAmountSat": {"0"}},
|
|
{"minAmountSat": {"18446744073709551615"}},
|
|
{"hideFailed": {"maybe"}},
|
|
} {
|
|
_, err = ParseListTransactionsFilters(invalidQuery)
|
|
assert.Error(t, err, "query: %v", invalidQuery)
|
|
}
|
|
}
|