summaryrefslogtreecommitdiff
path: root/internal/db/bundb/account_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/db/bundb/account_test.go')
-rw-r--r--internal/db/bundb/account_test.go59
1 files changed, 57 insertions, 2 deletions
diff --git a/internal/db/bundb/account_test.go b/internal/db/bundb/account_test.go
index 3c19e84d9..1e6dc4436 100644
--- a/internal/db/bundb/account_test.go
+++ b/internal/db/bundb/account_test.go
@@ -27,7 +27,9 @@ import (
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/ap"
+ "github.com/superseriousbusiness/gotosocial/internal/db/bundb"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/uptrace/bun"
)
type AccountTestSuite struct {
@@ -71,17 +73,70 @@ func (suite *AccountTestSuite) TestGetAccountByUsernameDomain() {
}
func (suite *AccountTestSuite) TestUpdateAccount() {
+ ctx := context.Background()
+
testAccount := suite.testAccounts["local_account_1"]
testAccount.DisplayName = "new display name!"
+ testAccount.EmojiIDs = []string{"01GD36ZKWTKY3T1JJ24JR7KY1Q", "01GD36ZV904SHBHNAYV6DX5QEF"}
+
+ _, err := suite.db.UpdateAccount(ctx, testAccount)
+ suite.NoError(err)
+
+ updated, err := suite.db.GetAccountByID(ctx, testAccount.ID)
+ suite.NoError(err)
+ suite.Equal("new display name!", updated.DisplayName)
+ suite.Equal([]string{"01GD36ZKWTKY3T1JJ24JR7KY1Q", "01GD36ZV904SHBHNAYV6DX5QEF"}, updated.EmojiIDs)
+ suite.WithinDuration(time.Now(), updated.UpdatedAt, 5*time.Second)
+
+ // get account without cache + make sure it's really in the db as desired
+ dbService, ok := suite.db.(*bundb.DBService)
+ if !ok {
+ panic("db was not *bundb.DBService")
+ }
+
+ noCache := &gtsmodel.Account{}
+ err = dbService.GetConn().
+ NewSelect().
+ Model(noCache).
+ Where("account.id = ?", bun.Ident(testAccount.ID)).
+ Relation("AvatarMediaAttachment").
+ Relation("HeaderMediaAttachment").
+ Relation("Emojis").
+ Scan(ctx)
+
+ suite.NoError(err)
+ suite.Equal("new display name!", noCache.DisplayName)
+ suite.Equal([]string{"01GD36ZKWTKY3T1JJ24JR7KY1Q", "01GD36ZV904SHBHNAYV6DX5QEF"}, noCache.EmojiIDs)
+ suite.WithinDuration(time.Now(), noCache.UpdatedAt, 5*time.Second)
+ suite.NotNil(noCache.AvatarMediaAttachment)
+ suite.NotNil(noCache.HeaderMediaAttachment)
- _, err := suite.db.UpdateAccount(context.Background(), testAccount)
+ // update again to remove emoji associations
+ testAccount.EmojiIDs = []string{}
+
+ _, err = suite.db.UpdateAccount(ctx, testAccount)
suite.NoError(err)
- updated, err := suite.db.GetAccountByID(context.Background(), testAccount.ID)
+ updated, err = suite.db.GetAccountByID(ctx, testAccount.ID)
suite.NoError(err)
suite.Equal("new display name!", updated.DisplayName)
+ suite.Empty(updated.EmojiIDs)
suite.WithinDuration(time.Now(), updated.UpdatedAt, 5*time.Second)
+
+ err = dbService.GetConn().
+ NewSelect().
+ Model(noCache).
+ Where("account.id = ?", bun.Ident(testAccount.ID)).
+ Relation("AvatarMediaAttachment").
+ Relation("HeaderMediaAttachment").
+ Relation("Emojis").
+ Scan(ctx)
+
+ suite.NoError(err)
+ suite.Equal("new display name!", noCache.DisplayName)
+ suite.Empty(noCache.EmojiIDs)
+ suite.WithinDuration(time.Now(), noCache.UpdatedAt, 5*time.Second)
}
func (suite *AccountTestSuite) TestInsertAccountWithDefaults() {