apps_service_test.go raw

   1  package tests
   2  
   3  import (
   4  	"testing"
   5  
   6  	"github.com/getAlby/hub/apps"
   7  	"github.com/getAlby/hub/config"
   8  	"github.com/getAlby/hub/constants"
   9  	"github.com/getAlby/hub/tests"
  10  	"github.com/stretchr/testify/assert"
  11  	"github.com/stretchr/testify/require"
  12  )
  13  
  14  func TestHandleCreateApp_NilScopes(t *testing.T) {
  15  	// ctx := context.TODO()
  16  	svc, err := tests.CreateTestService(t)
  17  	require.NoError(t, err)
  18  	defer svc.Remove()
  19  
  20  	appsService := apps.NewAppsService(svc.DB, svc.EventPublisher, svc.Keys, svc.Cfg)
  21  	app, secretKey, err := appsService.CreateApp("Test", "", 0, "monthly", nil, nil, false, nil)
  22  
  23  	assert.Nil(t, app)
  24  	assert.Equal(t, "", secretKey)
  25  	require.Error(t, err)
  26  	assert.Equal(t, "no scopes provided", err.Error())
  27  }
  28  
  29  func TestHandleCreateApp_EmptyScopes(t *testing.T) {
  30  	// ctx := context.TODO()
  31  	svc, err := tests.CreateTestService(t)
  32  	require.NoError(t, err)
  33  	defer svc.Remove()
  34  
  35  	appsService := apps.NewAppsService(svc.DB, svc.EventPublisher, svc.Keys, svc.Cfg)
  36  	app, secretKey, err := appsService.CreateApp("Test", "", 0, "monthly", nil, []string{}, false, nil)
  37  
  38  	assert.Nil(t, app)
  39  	assert.Equal(t, "", secretKey)
  40  	require.Error(t, err)
  41  	assert.Equal(t, "no scopes provided", err.Error())
  42  }
  43  
  44  func TestHandleCreateApp_IsolatedUnsupportedBackendType(t *testing.T) {
  45  	// ctx := context.TODO()
  46  	svc, err := tests.CreateTestService(t)
  47  	require.NoError(t, err)
  48  	defer svc.Remove()
  49  	svc.Cfg.SetUpdate("BackendType", config.CashuBackendType, "")
  50  
  51  	appsService := apps.NewAppsService(svc.DB, svc.EventPublisher, svc.Keys, svc.Cfg)
  52  	app, secretKey, err := appsService.CreateApp("Test", "", 0, "monthly", nil, []string{constants.GET_INFO_SCOPE}, true, nil)
  53  
  54  	assert.Nil(t, app)
  55  	assert.Equal(t, "", secretKey)
  56  	require.Error(t, err)
  57  	assert.Equal(t, "sub-wallets are currently not supported on your node backend. Try LDK, LND, PHOENIX, BARK, or CLN", err.Error())
  58  }
  59