diff options
author | 2021-09-27 17:42:20 +0200 | |
---|---|---|
committer | 2021-09-27 17:42:20 +0200 | |
commit | b3fd9c39a3a6ecdac87b27684e7dbc54ce19b312 (patch) | |
tree | ecd482e18eb6131d07a092949556fec623ec2ec7 /internal/processing/fromfederator_test.go | |
parent | Unblock fix (#247) (diff) | |
download | gotosocial-b3fd9c39a3a6ecdac87b27684e7dbc54ce19b312.tar.xz |
Weird notif issue (#248)
* start working on weird issue
* go fmt ./...
* more tests
Diffstat (limited to 'internal/processing/fromfederator_test.go')
-rw-r--r-- | internal/processing/fromfederator_test.go | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/internal/processing/fromfederator_test.go b/internal/processing/fromfederator_test.go index c58334787..ba2aaf03e 100644 --- a/internal/processing/fromfederator_test.go +++ b/internal/processing/fromfederator_test.go @@ -151,6 +151,131 @@ func (suite *FromFederatorTestSuite) TestProcessReplyMention() { suite.False(notif.Read) } +func (suite *FromFederatorTestSuite) TestProcessFave() { + favedAccount := suite.testAccounts["local_account_1"] + favedStatus := suite.testStatuses["local_account_1_status_1"] + favingAccount := suite.testAccounts["remote_account_1"] + + stream, errWithCode := suite.processor.OpenStreamForAccount(context.Background(), favedAccount, "user") + suite.NoError(errWithCode) + + fave := >smodel.StatusFave{ + ID: "01FGKJPXFTVQPG9YSSZ95ADS7Q", + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + AccountID: favingAccount.ID, + Account: favingAccount, + TargetAccountID: favedAccount.ID, + TargetAccount: favedAccount, + StatusID: favedStatus.ID, + Status: favedStatus, + URI: favingAccount.URI + "/faves/aaaaaaaaaaaa", + } + + err := suite.db.Put(context.Background(), fave) + suite.NoError(err) + + err = suite.processor.ProcessFromFederator(context.Background(), messages.FromFederator{ + APObjectType: ap.ActivityLike, + APActivityType: ap.ActivityCreate, + GTSModel: fave, + ReceivingAccount: favedAccount, + }) + suite.NoError(err) + + // side effects should be triggered + // 1. a notification should exist for the fave + where := []db.Where{ + { + Key: "status_id", + Value: favedStatus.ID, + }, + { + Key: "origin_account_id", + Value: favingAccount.ID, + }, + } + + notif := >smodel.Notification{} + err = suite.db.GetWhere(context.Background(), where, notif) + suite.NoError(err) + suite.Equal(gtsmodel.NotificationFave, notif.NotificationType) + suite.Equal(fave.TargetAccountID, notif.TargetAccountID) + suite.Equal(fave.AccountID, notif.OriginAccountID) + suite.Equal(fave.StatusID, notif.StatusID) + suite.False(notif.Read) + + // 2. a notification should be streamed + msg := <-stream.Messages + suite.Equal("notification", msg.Event) + suite.NotEmpty(msg.Payload) + suite.EqualValues([]string{"user"}, msg.Stream) +} + +// TestProcessFaveWithDifferentReceivingAccount ensures that when an account receives a fave that's for +// another account in their AP inbox, a notification isn't streamed to the receiving account. +// +// This tests for an issue we were seeing where Misskey sends out faves to inboxes of people that don't own +// the fave, but just follow the actor who received the fave. +func (suite *FromFederatorTestSuite) TestProcessFaveWithDifferentReceivingAccount() { + receivingAccount := suite.testAccounts["local_account_2"] + favedAccount := suite.testAccounts["local_account_1"] + favedStatus := suite.testStatuses["local_account_1_status_1"] + favingAccount := suite.testAccounts["remote_account_1"] + + stream, errWithCode := suite.processor.OpenStreamForAccount(context.Background(), receivingAccount, "user") + suite.NoError(errWithCode) + + fave := >smodel.StatusFave{ + ID: "01FGKJPXFTVQPG9YSSZ95ADS7Q", + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + AccountID: favingAccount.ID, + Account: favingAccount, + TargetAccountID: favedAccount.ID, + TargetAccount: favedAccount, + StatusID: favedStatus.ID, + Status: favedStatus, + URI: favingAccount.URI + "/faves/aaaaaaaaaaaa", + } + + err := suite.db.Put(context.Background(), fave) + suite.NoError(err) + + err = suite.processor.ProcessFromFederator(context.Background(), messages.FromFederator{ + APObjectType: ap.ActivityLike, + APActivityType: ap.ActivityCreate, + GTSModel: fave, + ReceivingAccount: receivingAccount, + }) + suite.NoError(err) + + // side effects should be triggered + // 1. a notification should exist for the fave + where := []db.Where{ + { + Key: "status_id", + Value: favedStatus.ID, + }, + { + Key: "origin_account_id", + Value: favingAccount.ID, + }, + } + + notif := >smodel.Notification{} + err = suite.db.GetWhere(context.Background(), where, notif) + suite.NoError(err) + suite.Equal(gtsmodel.NotificationFave, notif.NotificationType) + suite.Equal(fave.TargetAccountID, notif.TargetAccountID) + suite.Equal(fave.AccountID, notif.OriginAccountID) + suite.Equal(fave.StatusID, notif.StatusID) + suite.False(notif.Read) + + // 2. no notification should be streamed to the account that received the fave message, because they weren't the target + suite.Empty(stream.Messages) +} + func TestFromFederatorTestSuite(t *testing.T) { suite.Run(t, &FromFederatorTestSuite{}) } |