alby-hub/tests/test_service.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

86 lines
1.7 KiB
Go

package tests
import (
"strconv"
"testing"
"github.com/sirupsen/logrus"
"github.com/getAlby/hub/apps"
"github.com/getAlby/hub/logger"
"github.com/getAlby/hub/tests/db"
"gorm.io/gorm"
"github.com/getAlby/hub/config"
"github.com/getAlby/hub/events"
"github.com/getAlby/hub/lnclient"
"github.com/getAlby/hub/service/keys"
)
func CreateTestService(t *testing.T) (svc *TestService, err error) {
return CreateTestServiceWithMnemonic(t, "", "")
}
func CreateTestServiceWithMnemonic(t *testing.T, mnemonic string, unlockPassword string) (svc *TestService, err error) {
logger.Init(strconv.Itoa(int(logrus.DebugLevel)))
gormDb, err := db.NewDB(t)
if err != nil {
return nil, err
}
mockLn, err := NewMockLn()
if err != nil {
return nil, err
}
appConfig := &config.AppConfig{
Workdir: ".test",
}
cfg, err := config.NewConfig(
appConfig,
gormDb,
)
if err != nil {
return nil, err
}
keys := keys.NewKeys()
if mnemonic != "" {
if err = cfg.SetUpdate("Mnemonic", mnemonic, unlockPassword); err != nil {
return nil, err
}
}
if err = keys.Init(cfg, unlockPassword); err != nil {
return nil, err
}
eventPublisher := events.NewEventPublisher()
appsService := apps.NewAppsService(gormDb, eventPublisher, keys, cfg)
return &TestService{
Cfg: cfg,
LNClient: mockLn,
EventPublisher: eventPublisher,
DB: gormDb,
Keys: keys,
AppsService: appsService,
}, nil
}
type TestService struct {
Keys keys.Keys
Cfg config.Config
LNClient lnclient.LNClient
EventPublisher events.EventPublisher
AppsService apps.AppsService
DB *gorm.DB
}
func (s *TestService) Remove() {
db.CloseDB(s.DB)
}