diff options
author | 2022-09-26 11:56:01 +0200 | |
---|---|---|
committer | 2022-09-26 11:56:01 +0200 | |
commit | c4a08292ee44bc731ff90bad18a3f37e5ee8ef22 (patch) | |
tree | 1726f8450ec37f744204a857c3be2bfab17f206c /internal/db/bundb/account_test.go | |
parent | [bugfix] more nil checks baybeeeeeeeeeeeeeeeeeeee (#854) (diff) | |
download | gotosocial-c4a08292ee44bc731ff90bad18a3f37e5ee8ef22.tar.xz |
[feature] Show + federate emojis in accounts (#837)
* Start adding account emoji
* get emojis serialized + deserialized nicely
* update tests
* set / retrieve emojis on accounts
* show account emojis in web view
* fetch emojis from db based on ids
* fix typo in test
* lint
* fix pg migration
* update tests
* update emoji checking logic
* update comment
* clarify comments + add some spacing
* tidy up loops a lil (thanks kim)
Diffstat (limited to 'internal/db/bundb/account_test.go')
-rw-r--r-- | internal/db/bundb/account_test.go | 59 |
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 := >smodel.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() { |