summaryrefslogtreecommitdiff
path: root/internal/db/bundb/instance_test.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-03-19 13:11:46 +0100
committerLibravatar GitHub <noreply@github.com>2023-03-19 13:11:46 +0100
commit7db81cde444f6bc95e79527af0997de1788d48c7 (patch)
treef6c077ec298a4f018d0870798bc46bd64ba70069 /internal/db/bundb/instance_test.go
parent[docs] Update docs on how to login (#1626) (diff)
downloadgotosocial-7db81cde444f6bc95e79527af0997de1788d48c7.tar.xz
[feature] Email notifications for new / closed moderation reports (#1628)
* start fiddling about with email sending to allow multiple recipients * do some fiddling * notifs working * notify on closed report * finishing up * envparsing * use strings.ContainsAny
Diffstat (limited to 'internal/db/bundb/instance_test.go')
-rw-r--r--internal/db/bundb/instance_test.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/internal/db/bundb/instance_test.go b/internal/db/bundb/instance_test.go
index 4269df5ca..580a7699b 100644
--- a/internal/db/bundb/instance_test.go
+++ b/internal/db/bundb/instance_test.go
@@ -24,6 +24,8 @@ import (
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
+ "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/testrig"
)
type InstanceTestSuite struct {
@@ -90,6 +92,42 @@ func (suite *InstanceTestSuite) TestGetInstanceAccounts() {
suite.Len(accounts, 1)
}
+func (suite *InstanceTestSuite) TestGetInstanceModeratorAddressesOK() {
+ // We have one admin user by default.
+ addresses, err := suite.db.GetInstanceModeratorAddresses(context.Background())
+ suite.NoError(err)
+ suite.EqualValues([]string{"admin@example.org"}, addresses)
+}
+
+func (suite *InstanceTestSuite) TestGetInstanceModeratorAddressesZorkAsModerator() {
+ // Promote zork to moderator role.
+ testUser := &gtsmodel.User{}
+ *testUser = *suite.testUsers["local_account_1"]
+ testUser.Moderator = testrig.TrueBool()
+ if err := suite.db.UpdateUser(context.Background(), testUser, "moderator"); err != nil {
+ suite.FailNow(err.Error())
+ }
+
+ addresses, err := suite.db.GetInstanceModeratorAddresses(context.Background())
+ suite.NoError(err)
+ suite.EqualValues([]string{"admin@example.org", "zork@example.org"}, addresses)
+}
+
+func (suite *InstanceTestSuite) TestGetInstanceModeratorAddressesNoAdmin() {
+ // Demote admin from admin + moderator roles.
+ testUser := &gtsmodel.User{}
+ *testUser = *suite.testUsers["admin_account"]
+ testUser.Admin = testrig.FalseBool()
+ testUser.Moderator = testrig.FalseBool()
+ if err := suite.db.UpdateUser(context.Background(), testUser, "admin", "moderator"); err != nil {
+ suite.FailNow(err.Error())
+ }
+
+ addresses, err := suite.db.GetInstanceModeratorAddresses(context.Background())
+ suite.ErrorIs(err, db.ErrNoEntries)
+ suite.Empty(addresses)
+}
+
func TestInstanceTestSuite(t *testing.T) {
suite.Run(t, new(InstanceTestSuite))
}