From a2c4c0ec034cc85a5597b66cd94be34fe2a890e9 Mon Sep 17 00:00:00 2001 From: tsmethurst Date: Thu, 19 Aug 2021 17:00:19 +0200 Subject: [PATCH] fix up some tests --- internal/processing/fromcommon.go | 59 +++++++++++++++++++------------ internal/timeline/index_test.go | 7 ++-- internal/timeline/manager_test.go | 10 +++--- 3 files changed, 45 insertions(+), 31 deletions(-) diff --git a/internal/processing/fromcommon.go b/internal/processing/fromcommon.go index c9d138358..82f80a479 100644 --- a/internal/processing/fromcommon.go +++ b/internal/processing/fromcommon.go @@ -102,7 +102,7 @@ func (p *processor) notifyStatus(status *gtsmodel.Status) error { return fmt.Errorf("notifyStatus: error converting notification to masto representation: %s", err) } - if err := p.streamingProcessor.StreamNotificationToAccount(mastoNotif, m.OriginAccount); err != nil { + if err := p.streamingProcessor.StreamNotificationToAccount(mastoNotif, m.TargetAccount); err != nil { return fmt.Errorf("notifyStatus: error streaming notification to account: %s", err) } } @@ -145,9 +145,9 @@ func (p *processor) notifyFollowRequest(followRequest *gtsmodel.FollowRequest, r return nil } -func (p *processor) notifyFollow(follow *gtsmodel.Follow, receivingAccount *gtsmodel.Account) error { +func (p *processor) notifyFollow(follow *gtsmodel.Follow, targetAccount *gtsmodel.Account) error { // return if this isn't a local account - if receivingAccount.Domain != "" { + if targetAccount.Domain != "" { return nil } @@ -170,7 +170,9 @@ func (p *processor) notifyFollow(follow *gtsmodel.Follow, receivingAccount *gtsm ID: notifID, NotificationType: gtsmodel.NotificationFollow, TargetAccountID: follow.TargetAccountID, + TargetAccount: follow.TargetAccount, OriginAccountID: follow.AccountID, + OriginAccount: follow.Account, } if err := p.db.Put(notif); err != nil { return fmt.Errorf("notifyFollow: error putting notification in database: %s", err) @@ -182,16 +184,16 @@ func (p *processor) notifyFollow(follow *gtsmodel.Follow, receivingAccount *gtsm return fmt.Errorf("notifyStatus: error converting notification to masto representation: %s", err) } - if err := p.streamingProcessor.StreamNotificationToAccount(mastoNotif, receivingAccount); err != nil { + if err := p.streamingProcessor.StreamNotificationToAccount(mastoNotif, targetAccount); err != nil { return fmt.Errorf("notifyStatus: error streaming notification to account: %s", err) } return nil } -func (p *processor) notifyFave(fave *gtsmodel.StatusFave, receivingAccount *gtsmodel.Account) error { +func (p *processor) notifyFave(fave *gtsmodel.StatusFave, targetAccount *gtsmodel.Account) error { // return if this isn't a local account - if receivingAccount.Domain != "" { + if targetAccount.Domain != "" { return nil } @@ -204,8 +206,11 @@ func (p *processor) notifyFave(fave *gtsmodel.StatusFave, receivingAccount *gtsm ID: notifID, NotificationType: gtsmodel.NotificationFave, TargetAccountID: fave.TargetAccountID, + TargetAccount: fave.TargetAccount, OriginAccountID: fave.AccountID, + OriginAccount: fave.Account, StatusID: fave.StatusID, + Status: fave.Status, } if err := p.db.Put(notif); err != nil { @@ -218,7 +223,7 @@ func (p *processor) notifyFave(fave *gtsmodel.StatusFave, receivingAccount *gtsm return fmt.Errorf("notifyStatus: error converting notification to masto representation: %s", err) } - if err := p.streamingProcessor.StreamNotificationToAccount(mastoNotif, receivingAccount); err != nil { + if err := p.streamingProcessor.StreamNotificationToAccount(mastoNotif, targetAccount); err != nil { return fmt.Errorf("notifyStatus: error streaming notification to account: %s", err) } @@ -231,22 +236,29 @@ func (p *processor) notifyAnnounce(status *gtsmodel.Status) error { return nil } - boostedStatus := >smodel.Status{} - if err := p.db.GetByID(status.BoostOfID, boostedStatus); err != nil { - return fmt.Errorf("notifyAnnounce: error getting status with id %s: %s", status.BoostOfID, err) + if status.BoostOf == nil { + boostedStatus, err := p.db.GetStatusByID(status.BoostOfID) + if err != nil { + return fmt.Errorf("notifyAnnounce: error getting status with id %s: %s", status.BoostOfID, err) + } + status.BoostOf = boostedStatus } - boostedAcct := >smodel.Account{} - if err := p.db.GetByID(boostedStatus.AccountID, boostedAcct); err != nil { - return fmt.Errorf("notifyAnnounce: error getting account with id %s: %s", boostedStatus.AccountID, err) + if status.BoostOfAccount == nil { + boostedAcct, err := p.db.GetAccountByID(status.BoostOfAccountID) + if err != nil { + return fmt.Errorf("notifyAnnounce: error getting account with id %s: %s", status.BoostOfAccountID, err) + } + status.BoostOf.Account = boostedAcct + status.BoostOfAccount = boostedAcct } - if boostedAcct.Domain != "" { + if status.BoostOfAccount.Domain == "" { // remote account, nothing to do return nil } - if boostedStatus.AccountID == status.AccountID { + if status.BoostOfAccountID == status.AccountID { // it's a self boost, nothing to do return nil } @@ -254,7 +266,7 @@ func (p *processor) notifyAnnounce(status *gtsmodel.Status) error { // make sure a notif doesn't already exist for this announce err := p.db.GetWhere([]db.Where{ {Key: "notification_type", Value: gtsmodel.NotificationReblog}, - {Key: "target_account_id", Value: boostedAcct.ID}, + {Key: "target_account_id", Value: status.BoostOfAccountID}, {Key: "origin_account_id", Value: status.AccountID}, {Key: "status_id", Value: status.ID}, }, >smodel.Notification{}) @@ -272,9 +284,12 @@ func (p *processor) notifyAnnounce(status *gtsmodel.Status) error { notif := >smodel.Notification{ ID: notifID, NotificationType: gtsmodel.NotificationReblog, - TargetAccountID: boostedAcct.ID, + TargetAccountID: status.BoostOfAccountID, + TargetAccount: status.BoostOfAccount, OriginAccountID: status.AccountID, + OriginAccount: status.Account, StatusID: status.ID, + Status: status, } if err := p.db.Put(notif); err != nil { @@ -287,7 +302,7 @@ func (p *processor) notifyAnnounce(status *gtsmodel.Status) error { return fmt.Errorf("notifyStatus: error converting notification to masto representation: %s", err) } - if err := p.streamingProcessor.StreamNotificationToAccount(mastoNotif, boostedAcct); err != nil { + if err := p.streamingProcessor.StreamNotificationToAccount(mastoNotif, status.BoostOfAccount); err != nil { return fmt.Errorf("notifyStatus: error streaming notification to account: %s", err) } @@ -297,8 +312,8 @@ func (p *processor) notifyAnnounce(status *gtsmodel.Status) error { func (p *processor) timelineStatus(status *gtsmodel.Status) error { // make sure the author account is pinned onto the status if status.Account == nil { - a := >smodel.Account{} - if err := p.db.GetByID(status.AccountID, a); err != nil { + a, err := p.db.GetAccountByID(status.AccountID) + if err != nil { return fmt.Errorf("timelineStatus: error getting author account with id %s: %s", status.AccountID, err) } status.Account = a @@ -353,8 +368,8 @@ func (p *processor) timelineStatusForAccount(status *gtsmodel.Status, accountID defer wg.Done() // get the timeline owner account - timelineAccount := >smodel.Account{} - if err := p.db.GetByID(accountID, timelineAccount); err != nil { + timelineAccount, err := p.db.GetAccountByID(accountID) + if err != nil { errors <- fmt.Errorf("timelineStatusForAccount: error getting account for timeline with id %s: %s", accountID, err) return } diff --git a/internal/timeline/index_test.go b/internal/timeline/index_test.go index f48b2691c..4201a27dd 100644 --- a/internal/timeline/index_test.go +++ b/internal/timeline/index_test.go @@ -67,9 +67,8 @@ func (suite *IndexTestSuite) TestIndexBeforeLowID() { suite.NoError(err) suite.Equal("01F8MHAAY43M6RJ473VQFCVH37", postID) - // indexLength should only be 9 because that's all this user has hometimelineable indexLength := suite.timeline.PostIndexLength() - suite.Equal(9, indexLength) + suite.Equal(10, indexLength) } func (suite *IndexTestSuite) TestIndexBeforeHighID() { @@ -97,9 +96,9 @@ func (suite *IndexTestSuite) TestIndexBehindHighID() { suite.NoError(err) suite.Equal("01FCTA44PW9H1TB328S9AQXKDS", postID) - // indexLength should only be 11 because that's all this user has hometimelineable + // indexLength should be 10 because that's all this user has hometimelineable indexLength := suite.timeline.PostIndexLength() - suite.Equal(11, indexLength) + suite.Equal(10, indexLength) } func (suite *IndexTestSuite) TestIndexBehindLowID() { diff --git a/internal/timeline/manager_test.go b/internal/timeline/manager_test.go index 9b975a5ce..00c6dcb4a 100644 --- a/internal/timeline/manager_test.go +++ b/internal/timeline/manager_test.go @@ -66,9 +66,9 @@ func (suite *ManagerTestSuite) TestManagerIntegration() { err = suite.manager.PrepareXFromTop(testAccount.ID, 20) suite.NoError(err) - // local_account_1 can see 11 statuses out of the testrig statuses in its home timeline + // local_account_1 can see 12 statuses out of the testrig statuses in its home timeline indexedLen = suite.manager.GetIndexedLength(testAccount.ID) - suite.Equal(11, indexedLen) + suite.Equal(12, indexedLen) // oldest should now be set oldestIndexed, err = suite.manager.GetOldestIndexedID(testAccount.ID) @@ -78,7 +78,7 @@ func (suite *ManagerTestSuite) TestManagerIntegration() { // get hometimeline statuses, err := suite.manager.HomeTimeline(testAccount.ID, "", "", "", 20, false) suite.NoError(err) - suite.Len(statuses, 11) + suite.Len(statuses, 12) // now wipe the last status from all timelines, as though it had been deleted by the owner err = suite.manager.WipeStatusFromAllTimelines("01F8MH75CBF9JFX4ZAD54N0W0R") @@ -86,7 +86,7 @@ func (suite *ManagerTestSuite) TestManagerIntegration() { // timeline should be shorter indexedLen = suite.manager.GetIndexedLength(testAccount.ID) - suite.Equal(10, indexedLen) + suite.Equal(11, indexedLen) // oldest should now be different oldestIndexed, err = suite.manager.GetOldestIndexedID(testAccount.ID) @@ -100,7 +100,7 @@ func (suite *ManagerTestSuite) TestManagerIntegration() { // timeline should be shorter indexedLen = suite.manager.GetIndexedLength(testAccount.ID) - suite.Equal(9, indexedLen) + suite.Equal(10, indexedLen) // oldest should now be different oldestIndexed, err = suite.manager.GetOldestIndexedID(testAccount.ID)