publish_nip47_info_test.go raw

   1  package nip47
   2  
   3  import (
   4  	"context"
   5  	"testing"
   6  
   7  	"github.com/getAlby/go-nostr"
   8  	"github.com/stretchr/testify/assert"
   9  	"github.com/stretchr/testify/require"
  10  	"gorm.io/gorm"
  11  
  12  	"github.com/getAlby/hub/alby"
  13  	"github.com/getAlby/hub/tests"
  14  )
  15  
  16  // When an app connection has been deleted, publishing its NIP47 info must
  17  // surface gorm.ErrRecordNotFound so the publish queue can drop the item
  18  // instead of retrying forever.
  19  func TestPublishNip47Info_AppNotFound(t *testing.T) {
  20  	svc, err := tests.CreateTestService(t)
  21  	require.NoError(t, err)
  22  	defer svc.Remove()
  23  
  24  	albyOAuthSvc := alby.NewAlbyOAuthService(svc.DB, svc.Cfg, svc.Keys, svc.EventPublisher)
  25  	nip47svc := NewNip47Service(svc.DB, svc.Cfg, svc.Keys, svc.EventPublisher, albyOAuthSvc)
  26  
  27  	walletPrivKey := nostr.GeneratePrivateKey()
  28  	walletPubKey, err := nostr.GetPublicKey(walletPrivKey)
  29  	require.NoError(t, err)
  30  
  31  	// app id 9999999 does not exist; the DB lookup fails before the relay pool
  32  	// is ever used, so a nil pool/lnClient is fine here.
  33  	_, err = nip47svc.PublishNip47Info(context.Background(), nil, 9999999, walletPubKey, walletPrivKey, "wss://relay.example.com", nil)
  34  	require.Error(t, err)
  35  	assert.ErrorIs(t, err, gorm.ErrRecordNotFound)
  36  }
  37