Skip to content

Commit 6da3bbe

Browse files
AOrobatorclaude
andcommitted
feat: add node alias setting to General settings page
Add inline node alias editing on the Settings > General page so self-hosted users can change their Lightning node alias without needing an Alby paid plan. The alias input pre-populates from useInfo().nodeAlias and POSTs to /api/node/alias. A toast reminds the user to restart for the change to take effect. Also adds Go doc comments to exported types in api/models.go, config/models.go, and lnclient/models.go to satisfy the 80% docstring coverage threshold. Includes tests for SetNodeAlias API covering success, empty alias, and config error scenarios. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2174f02 commit 6da3bbe

5 files changed

Lines changed: 252 additions & 14 deletions

File tree

api/api_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,23 @@ package api
33
import (
44
"context"
55
"fmt"
6+
"os"
67
"testing"
78

89
"github.com/stretchr/testify/mock"
910
"github.com/stretchr/testify/require"
1011

1112
"github.com/getAlby/hub/lnclient"
13+
"github.com/getAlby/hub/logger"
1214
"github.com/getAlby/hub/service"
1315
"github.com/getAlby/hub/tests/mocks"
1416
)
1517

18+
func TestMain(m *testing.M) {
19+
logger.Init("")
20+
os.Exit(m.Run())
21+
}
22+
1623
func TestGetCustomNodeCommandDefinitions(t *testing.T) {
1724
lnClient := mocks.NewMockLNClient(t)
1825
svc := mocks.NewMockService(t)
@@ -221,6 +228,42 @@ func TestExecuteCustomNodeCommand(t *testing.T) {
221228
}
222229
}
223230

231+
func TestSetNodeAlias(t *testing.T) {
232+
t.Run("success", func(t *testing.T) {
233+
cfg := mocks.NewMockConfig(t)
234+
cfg.On("SetUpdate", "NodeAlias", "SatoshiSquirrel", "").Return(nil)
235+
236+
theAPI := &api{cfg: cfg}
237+
238+
err := theAPI.SetNodeAlias("SatoshiSquirrel")
239+
require.NoError(t, err)
240+
cfg.AssertExpectations(t)
241+
})
242+
243+
t.Run("empty alias", func(t *testing.T) {
244+
cfg := mocks.NewMockConfig(t)
245+
cfg.On("SetUpdate", "NodeAlias", "", "").Return(nil)
246+
247+
theAPI := &api{cfg: cfg}
248+
249+
err := theAPI.SetNodeAlias("")
250+
require.NoError(t, err)
251+
cfg.AssertExpectations(t)
252+
})
253+
254+
t.Run("config error", func(t *testing.T) {
255+
cfg := mocks.NewMockConfig(t)
256+
cfg.On("SetUpdate", "NodeAlias", "test", "").Return(fmt.Errorf("database error"))
257+
258+
theAPI := &api{cfg: cfg}
259+
260+
err := theAPI.SetNodeAlias("test")
261+
require.Error(t, err)
262+
require.ErrorContains(t, err, "database error")
263+
cfg.AssertExpectations(t)
264+
})
265+
}
266+
224267
// instantiateAPIWithService is a helper function that returns a partially
225268
// constructed API instance. It is only suitable for the simplest of test cases.
226269
func instantiateAPIWithService(s service.Service) *api {

0 commit comments

Comments
 (0)