diff options
author | 2022-09-26 11:56:01 +0200 | |
---|---|---|
committer | 2022-09-26 11:56:01 +0200 | |
commit | c4a08292ee44bc731ff90bad18a3f37e5ee8ef22 (patch) | |
tree | 1726f8450ec37f744204a857c3be2bfab17f206c /internal/federation/dereferencing/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/federation/dereferencing/account_test.go')
-rw-r--r-- | internal/federation/dereferencing/account_test.go | 200 |
1 files changed, 200 insertions, 0 deletions
diff --git a/internal/federation/dereferencing/account_test.go b/internal/federation/dereferencing/account_test.go index 4f1a83a96..aec612ac8 100644 --- a/internal/federation/dereferencing/account_test.go +++ b/internal/federation/dereferencing/account_test.go @@ -27,6 +27,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/ap" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/federation/dereferencing" + "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/testrig" ) @@ -195,6 +196,205 @@ func (suite *AccountTestSuite) TestDereferenceLocalAccountWithUnknownUserURI() { suite.Nil(fetchedAccount) } +func (suite *AccountTestSuite) TestDereferenceRemoteAccountWithPartial() { + fetchingAccount := suite.testAccounts["local_account_1"] + + remoteAccount := suite.testAccounts["remote_account_1"] + remoteAccountPartial := >smodel.Account{ + ID: remoteAccount.ID, + ActorType: remoteAccount.ActorType, + Language: remoteAccount.Language, + CreatedAt: remoteAccount.CreatedAt, + UpdatedAt: remoteAccount.UpdatedAt, + Username: remoteAccount.Username, + Domain: remoteAccount.Domain, + DisplayName: remoteAccount.DisplayName, + URI: remoteAccount.URI, + InboxURI: remoteAccount.URI, + SharedInboxURI: remoteAccount.SharedInboxURI, + PublicKeyURI: remoteAccount.PublicKeyURI, + URL: remoteAccount.URL, + FollowingURI: remoteAccount.FollowingURI, + FollowersURI: remoteAccount.FollowersURI, + OutboxURI: remoteAccount.OutboxURI, + FeaturedCollectionURI: remoteAccount.FeaturedCollectionURI, + Emojis: []*gtsmodel.Emoji{ + // dereference an emoji we don't have stored yet + { + URI: "http://fossbros-anonymous.io/emoji/01GD5HCC2YECT012TK8PAGX4D1", + Shortcode: "kip_van_den_bos", + UpdatedAt: testrig.TimeMustParse("2022-09-13T12:13:12+02:00"), + ImageRemoteURL: "http://fossbros-anonymous.io/emoji/kip.gif", + Disabled: testrig.FalseBool(), + VisibleInPicker: testrig.FalseBool(), + Domain: "fossbros-anonymous.io", + }, + }, + } + + fetchedAccount, err := suite.dereferencer.GetRemoteAccount(context.Background(), dereferencing.GetRemoteAccountParams{ + RequestingUsername: fetchingAccount.Username, + RemoteAccountID: testrig.URLMustParse(remoteAccount.URI), + RemoteAccountHost: remoteAccount.Domain, + RemoteAccountUsername: remoteAccount.Username, + PartialAccount: remoteAccountPartial, + Blocking: true, + }) + suite.NoError(err) + suite.NotNil(fetchedAccount) + suite.NotNil(fetchedAccount.EmojiIDs) + suite.NotNil(fetchedAccount.Emojis) +} + +func (suite *AccountTestSuite) TestDereferenceRemoteAccountWithPartial2() { + fetchingAccount := suite.testAccounts["local_account_1"] + + knownEmoji := suite.testEmojis["yell"] + + remoteAccount := suite.testAccounts["remote_account_1"] + remoteAccountPartial := >smodel.Account{ + ID: remoteAccount.ID, + ActorType: remoteAccount.ActorType, + Language: remoteAccount.Language, + CreatedAt: remoteAccount.CreatedAt, + UpdatedAt: remoteAccount.UpdatedAt, + Username: remoteAccount.Username, + Domain: remoteAccount.Domain, + DisplayName: remoteAccount.DisplayName, + URI: remoteAccount.URI, + InboxURI: remoteAccount.URI, + SharedInboxURI: remoteAccount.SharedInboxURI, + PublicKeyURI: remoteAccount.PublicKeyURI, + URL: remoteAccount.URL, + FollowingURI: remoteAccount.FollowingURI, + FollowersURI: remoteAccount.FollowersURI, + OutboxURI: remoteAccount.OutboxURI, + FeaturedCollectionURI: remoteAccount.FeaturedCollectionURI, + Emojis: []*gtsmodel.Emoji{ + // an emoji we already have + { + URI: knownEmoji.URI, + Shortcode: knownEmoji.Shortcode, + UpdatedAt: knownEmoji.CreatedAt, + ImageRemoteURL: knownEmoji.ImageRemoteURL, + Disabled: knownEmoji.Disabled, + VisibleInPicker: knownEmoji.VisibleInPicker, + }, + }, + } + + fetchedAccount, err := suite.dereferencer.GetRemoteAccount(context.Background(), dereferencing.GetRemoteAccountParams{ + RequestingUsername: fetchingAccount.Username, + RemoteAccountID: testrig.URLMustParse(remoteAccount.URI), + RemoteAccountHost: remoteAccount.Domain, + RemoteAccountUsername: remoteAccount.Username, + PartialAccount: remoteAccountPartial, + Blocking: true, + }) + suite.NoError(err) + suite.NotNil(fetchedAccount) + suite.NotNil(fetchedAccount.EmojiIDs) + suite.NotNil(fetchedAccount.Emojis) +} + +func (suite *AccountTestSuite) TestDereferenceRemoteAccountWithPartial3() { + fetchingAccount := suite.testAccounts["local_account_1"] + + knownEmoji := suite.testEmojis["yell"] + + remoteAccount := suite.testAccounts["remote_account_1"] + remoteAccountPartial := >smodel.Account{ + ID: remoteAccount.ID, + ActorType: remoteAccount.ActorType, + Language: remoteAccount.Language, + CreatedAt: remoteAccount.CreatedAt, + UpdatedAt: remoteAccount.UpdatedAt, + Username: remoteAccount.Username, + Domain: remoteAccount.Domain, + DisplayName: remoteAccount.DisplayName, + URI: remoteAccount.URI, + InboxURI: remoteAccount.URI, + SharedInboxURI: remoteAccount.SharedInboxURI, + PublicKeyURI: remoteAccount.PublicKeyURI, + URL: remoteAccount.URL, + FollowingURI: remoteAccount.FollowingURI, + FollowersURI: remoteAccount.FollowersURI, + OutboxURI: remoteAccount.OutboxURI, + FeaturedCollectionURI: remoteAccount.FeaturedCollectionURI, + Emojis: []*gtsmodel.Emoji{ + // an emoji we already have + { + URI: knownEmoji.URI, + Shortcode: knownEmoji.Shortcode, + UpdatedAt: knownEmoji.CreatedAt, + ImageRemoteURL: knownEmoji.ImageRemoteURL, + Disabled: knownEmoji.Disabled, + VisibleInPicker: knownEmoji.VisibleInPicker, + }, + }, + } + + fetchedAccount, err := suite.dereferencer.GetRemoteAccount(context.Background(), dereferencing.GetRemoteAccountParams{ + RequestingUsername: fetchingAccount.Username, + RemoteAccountID: testrig.URLMustParse(remoteAccount.URI), + RemoteAccountHost: remoteAccount.Domain, + RemoteAccountUsername: remoteAccount.Username, + PartialAccount: remoteAccountPartial, + Blocking: true, + }) + suite.NoError(err) + suite.NotNil(fetchedAccount) + suite.NotNil(fetchedAccount.EmojiIDs) + suite.NotNil(fetchedAccount.Emojis) + suite.Equal(knownEmoji.URI, fetchedAccount.Emojis[0].URI) + + remoteAccountPartial2 := >smodel.Account{ + ID: remoteAccount.ID, + ActorType: remoteAccount.ActorType, + Language: remoteAccount.Language, + CreatedAt: remoteAccount.CreatedAt, + UpdatedAt: remoteAccount.UpdatedAt, + Username: remoteAccount.Username, + Domain: remoteAccount.Domain, + DisplayName: remoteAccount.DisplayName, + URI: remoteAccount.URI, + InboxURI: remoteAccount.URI, + SharedInboxURI: remoteAccount.SharedInboxURI, + PublicKeyURI: remoteAccount.PublicKeyURI, + URL: remoteAccount.URL, + FollowingURI: remoteAccount.FollowingURI, + FollowersURI: remoteAccount.FollowersURI, + OutboxURI: remoteAccount.OutboxURI, + FeaturedCollectionURI: remoteAccount.FeaturedCollectionURI, + Emojis: []*gtsmodel.Emoji{ + // dereference an emoji we don't have stored yet + { + URI: "http://fossbros-anonymous.io/emoji/01GD5HCC2YECT012TK8PAGX4D1", + Shortcode: "kip_van_den_bos", + UpdatedAt: testrig.TimeMustParse("2022-09-13T12:13:12+02:00"), + ImageRemoteURL: "http://fossbros-anonymous.io/emoji/kip.gif", + Disabled: testrig.FalseBool(), + VisibleInPicker: testrig.FalseBool(), + Domain: "fossbros-anonymous.io", + }, + }, + } + + fetchedAccount2, err := suite.dereferencer.GetRemoteAccount(context.Background(), dereferencing.GetRemoteAccountParams{ + RequestingUsername: fetchingAccount.Username, + RemoteAccountID: testrig.URLMustParse(remoteAccount.URI), + RemoteAccountHost: remoteAccount.Domain, + RemoteAccountUsername: remoteAccount.Username, + PartialAccount: remoteAccountPartial2, + Blocking: true, + }) + suite.NoError(err) + suite.NotNil(fetchedAccount2) + suite.NotNil(fetchedAccount2.EmojiIDs) + suite.NotNil(fetchedAccount2.Emojis) + suite.Equal("http://fossbros-anonymous.io/emoji/01GD5HCC2YECT012TK8PAGX4D1", fetchedAccount2.Emojis[0].URI) +} + func TestAccountTestSuite(t *testing.T) { suite.Run(t, new(AccountTestSuite)) } |