diff options
author | 2023-04-10 21:56:02 +0200 | |
---|---|---|
committer | 2023-04-10 20:56:02 +0100 | |
commit | 093cf2ab12a1f6bfa9629917101afffd2aeb8376 (patch) | |
tree | c0897a610b884cdf8e9b9d88b01c1e062a45f1a3 /internal/processing/fromclientapi_test.go | |
parent | [chore]: Bump golang.org/x/oauth2 from 0.6.0 to 0.7.0 (#1684) (diff) | |
download | gotosocial-093cf2ab12a1f6bfa9629917101afffd2aeb8376.tar.xz |
[feature] Receive notification when followed account posts (if desired) (#1680)
* start working on notifs for new posts
* tidy up a bit
* update swagger
* carry over show reblogs + notify from follow req
* test notify on status post
* update column slice
* dedupe update logic + add tests
* fix own boosts not being timelined
* avoid type check, passing unnecessary accounts
* remove unnecessary 'inReplyToID' check
* add a couple todo's for future db functions
Diffstat (limited to 'internal/processing/fromclientapi_test.go')
-rw-r--r-- | internal/processing/fromclientapi_test.go | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/internal/processing/fromclientapi_test.go b/internal/processing/fromclientapi_test.go index 0923fdf5b..0b641c091 100644 --- a/internal/processing/fromclientapi_test.go +++ b/internal/processing/fromclientapi_test.go @@ -159,6 +159,79 @@ func (suite *FromClientAPITestSuite) TestProcessStatusDelete() { suite.ErrorIs(err, db.ErrNoEntries) } +func (suite *FromClientAPITestSuite) TestProcessNewStatusWithNotification() { + ctx := context.Background() + postingAccount := suite.testAccounts["admin_account"] + receivingAccount := suite.testAccounts["local_account_1"] + + // Update the follow from receiving account -> posting account so + // that receiving account wants notifs when posting account posts. + follow := >smodel.Follow{} + *follow = *suite.testFollows["local_account_1_admin_account"] + follow.Notify = testrig.TrueBool() + if err := suite.db.UpdateFollow(ctx, follow); err != nil { + suite.FailNow(err.Error()) + } + + // Make a new status from admin account. + newStatus := >smodel.Status{ + ID: "01FN4B2F88TF9676DYNXWE1WSS", + URI: "http://localhost:8080/users/admin/statuses/01FN4B2F88TF9676DYNXWE1WSS", + URL: "http://localhost:8080/@admin/statuses/01FN4B2F88TF9676DYNXWE1WSS", + Content: "this status should create a notification", + AttachmentIDs: []string{}, + TagIDs: []string{}, + MentionIDs: []string{}, + EmojiIDs: []string{}, + CreatedAt: testrig.TimeMustParse("2021-10-20T11:36:45Z"), + UpdatedAt: testrig.TimeMustParse("2021-10-20T11:36:45Z"), + Local: testrig.TrueBool(), + AccountURI: "http://localhost:8080/users/admin", + AccountID: "01F8MH17FWEB39HZJ76B6VXSKF", + InReplyToID: "", + BoostOfID: "", + ContentWarning: "", + Visibility: gtsmodel.VisibilityFollowersOnly, + Sensitive: testrig.FalseBool(), + Language: "en", + CreatedWithApplicationID: "01F8MGXQRHYF5QPMTMXP78QC2F", + Federated: testrig.FalseBool(), + Boostable: testrig.TrueBool(), + Replyable: testrig.TrueBool(), + Likeable: testrig.TrueBool(), + ActivityStreamsType: ap.ObjectNote, + } + + // Put the status in the db first, to mimic what + // would have already happened earlier up the flow. + err := suite.db.PutStatus(ctx, newStatus) + suite.NoError(err) + + // Process the new status. + if err := suite.processor.ProcessFromClientAPI(ctx, messages.FromClientAPI{ + APObjectType: ap.ObjectNote, + APActivityType: ap.ActivityCreate, + GTSModel: newStatus, + OriginAccount: postingAccount, + }); err != nil { + suite.FailNow(err.Error()) + } + + // Wait for a notification to appear for the status. + if !testrig.WaitFor(func() bool { + _, err := suite.db.GetNotification( + ctx, + gtsmodel.NotificationStatus, + receivingAccount.ID, + postingAccount.ID, + newStatus.ID, + ) + return err == nil + }) { + suite.FailNow("timed out waiting for new status notification") + } +} + func TestFromClientAPITestSuite(t *testing.T) { suite.Run(t, &FromClientAPITestSuite{}) } |