mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[feature] Allow admins to send test emails (#1620)
* [feature] Allow admins to send test emails * implement unwrap on new error type * add + use gtserror types * GoToSocial Email Test -> GoToSocial Test Email * add + use getInstance db call * removed unused "unknown" error type
This commit is contained in:
@@ -97,6 +97,20 @@ func (i *instanceDB) CountInstanceDomains(ctx context.Context, domain string) (i
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (i *instanceDB) GetInstance(ctx context.Context, domain string) (*gtsmodel.Instance, db.Error) {
|
||||
instance := >smodel.Instance{}
|
||||
|
||||
if err := i.conn.
|
||||
NewSelect().
|
||||
Model(instance).
|
||||
Where("? = ?", bun.Ident("instance.domain"), domain).
|
||||
Scan(ctx); err != nil {
|
||||
return nil, i.conn.ProcessError(err)
|
||||
}
|
||||
|
||||
return instance, nil
|
||||
}
|
||||
|
||||
func (i *instanceDB) GetInstancePeers(ctx context.Context, includeSuspended bool) ([]*gtsmodel.Instance, db.Error) {
|
||||
instances := []*gtsmodel.Instance{}
|
||||
|
||||
|
@@ -23,6 +23,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
)
|
||||
|
||||
type InstanceTestSuite struct {
|
||||
@@ -59,6 +60,18 @@ func (suite *InstanceTestSuite) TestCountInstanceDomains() {
|
||||
suite.Equal(2, count)
|
||||
}
|
||||
|
||||
func (suite *InstanceTestSuite) TestGetInstanceOK() {
|
||||
instance, err := suite.db.GetInstance(context.Background(), "localhost:8080")
|
||||
suite.NoError(err)
|
||||
suite.NotNil(instance)
|
||||
}
|
||||
|
||||
func (suite *InstanceTestSuite) TestGetInstanceNonexistent() {
|
||||
instance, err := suite.db.GetInstance(context.Background(), "doesnt.exist.com")
|
||||
suite.ErrorIs(err, db.ErrNoEntries)
|
||||
suite.Nil(instance)
|
||||
}
|
||||
|
||||
func (suite *InstanceTestSuite) TestGetInstancePeers() {
|
||||
peers, err := suite.db.GetInstancePeers(context.Background(), false)
|
||||
suite.NoError(err)
|
||||
|
@@ -34,6 +34,9 @@ type Instance interface {
|
||||
// CountInstanceDomains returns the number of known instances known that the given domain federates with.
|
||||
CountInstanceDomains(ctx context.Context, domain string) (int, Error)
|
||||
|
||||
// GetInstance returns the instance entry for the given domain, if it exists.
|
||||
GetInstance(ctx context.Context, domain string) (*gtsmodel.Instance, Error)
|
||||
|
||||
// GetInstanceAccounts returns a slice of accounts from the given instance, arranged by ID.
|
||||
GetInstanceAccounts(ctx context.Context, domain string, maxID string, limit int) ([]*gtsmodel.Account, Error)
|
||||
|
||||
|
Reference in New Issue
Block a user