alby-hub/nip47/controllers/lookup_invoice_controller_test.go
Roland 3e1d16d423
Feat: NWA auth for self-hosted hubs (#1016)
* feat: nwc create_connection command (WIP)

* feat: allow creating superuser apps from the ui

* fix: pass methods rather than scopes in create_connection method

* chore: add extra tests

* fix: use browser router in http mode

* fix: update links to not use hash router

* fix: add redirect from hash router url

* fix: return nostrWalletConnectUrl in nwc connection success event and message

* feat: publish nwa event

* chore: use nwc info event instead of nwa event

* feat: create custom alby go detail page

* chore: allow creating/editing apps with the same name

* fix: convert budget from msats to sats (#1111)

* chore: address NWA feedback

* chore: address feedback

- adjust button copy
- make create_connection methods consistent with http deeplink flow
- remove unused constant
- add empty string check before adding lud16 tag
- fix test

* feat: add support for notification_types in create_connection method

* fix: shorter button copy

* fix: do not include lud16 tag in published info event

* Feat: add lud16 to get_info response (#1128)

feat: add lud16 to get_info response

* chore: minor alby go screen improvements

* fix: incorrect unlock password error message to create app with superuser access

* chore: minor ui improvements on alby go detail page

* chore: avoid duplicate app names by adding a suffix

* chore: move scopes check to apps service, add new tests, DRY controller test setup

* fix: scopes component full access scopes and isolated scope group check

* fix: use supported capabilities for Alby Go

* fix: return correct app name

* chore: address minor comments

---------

Co-authored-by: im-adithya <imadithyavardhan@gmail.com>
2025-02-27 19:12:55 +07:00

81 lines
2.7 KiB
Go

package controllers
import (
"context"
"encoding/json"
"testing"
"time"
"github.com/nbd-wtf/go-nostr"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/getAlby/hub/db"
"github.com/getAlby/hub/nip47/models"
"github.com/getAlby/hub/tests"
)
var nip47LookupInvoiceJson = `
{
"method": "lookup_invoice",
"params": {
"payment_hash": "` + tests.MockLNClientTransaction.PaymentHash + `"
}
}
`
func TestHandleLookupInvoiceEvent(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
nip47Request := &models.Request{}
err = json.Unmarshal([]byte(nip47LookupInvoiceJson), nip47Request)
assert.NoError(t, err)
app, _, err := tests.CreateApp(svc)
assert.NoError(t, err)
dbRequestEvent := &db.RequestEvent{
AppId: &app.ID,
}
err = svc.DB.Create(&dbRequestEvent).Error
assert.NoError(t, err)
settledAt := time.Unix(*tests.MockLNClientTransaction.SettledAt, 0)
err = svc.DB.Create(&db.Transaction{
Type: tests.MockLNClientTransaction.Type,
PaymentRequest: tests.MockLNClientTransaction.Invoice,
Description: tests.MockLNClientTransaction.Description,
DescriptionHash: tests.MockLNClientTransaction.DescriptionHash,
Preimage: &tests.MockLNClientTransaction.Preimage,
PaymentHash: tests.MockLNClientTransaction.PaymentHash,
AmountMsat: uint64(tests.MockLNClientTransaction.Amount),
FeeMsat: uint64(tests.MockLNClientTransaction.FeesPaid),
SettledAt: &settledAt,
AppId: &app.ID,
}).Error
assert.NoError(t, err)
var publishedResponse *models.Response
publishResponse := func(response *models.Response, tags nostr.Tags) {
publishedResponse = response
}
NewTestNip47Controller(svc).
HandleLookupInvoiceEvent(ctx, nip47Request, dbRequestEvent.ID, *dbRequestEvent.AppId, publishResponse)
assert.Nil(t, publishedResponse.Error)
transaction := publishedResponse.Result.(*lookupInvoiceResponse)
assert.Equal(t, tests.MockLNClientTransaction.Type, transaction.Type)
assert.Equal(t, tests.MockLNClientTransaction.Invoice, transaction.Invoice)
assert.Equal(t, tests.MockLNClientTransaction.Description, transaction.Description)
assert.Equal(t, tests.MockLNClientTransaction.DescriptionHash, transaction.DescriptionHash)
assert.Equal(t, tests.MockLNClientTransaction.Preimage, transaction.Preimage)
assert.Equal(t, tests.MockLNClientTransaction.PaymentHash, transaction.PaymentHash)
assert.Equal(t, tests.MockLNClientTransaction.Amount, transaction.Amount)
assert.Equal(t, tests.MockLNClientTransaction.FeesPaid, transaction.FeesPaid)
assert.Equal(t, tests.MockLNClientTransaction.SettledAt, transaction.SettledAt)
}