summaryrefslogtreecommitdiff
path: root/internal/processing/fromclientapi_test.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-05-18 23:13:03 +0200
committerLibravatar GitHub <noreply@github.com>2022-05-18 22:13:03 +0100
commitb2810fedf201dc9ae80ea8ec6d48e5cf7e21e6ea (patch)
treea6d7c2b7f349d72a383a7124e796c746c6a37111 /internal/processing/fromclientapi_test.go
parent[performance] Add further indexes to mitigate laggy queries (#586) (diff)
downloadgotosocial-b2810fedf201dc9ae80ea8ec6d48e5cf7e21e6ea.tar.xz
[bugfix] Clean up boosts of status when the status itself is deleted (#579)
* move status wiping logic to fromcommon.go * delete reblogs of status when a status is deleted * add admin boost of zork to test model * update tests to make them more determinate * Merge branch 'main' into status_reblog_cleanup * move status wiping logic to fromcommon.go * delete reblogs of status when a status is deleted * add admin boost of zork to test model * update tests to make them more determinate * Merge branch 'main' into status_reblog_cleanup * test status delete via client api * go fmt
Diffstat (limited to 'internal/processing/fromclientapi_test.go')
-rw-r--r--internal/processing/fromclientapi_test.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/internal/processing/fromclientapi_test.go b/internal/processing/fromclientapi_test.go
index fd89be270..014266b37 100644
--- a/internal/processing/fromclientapi_test.go
+++ b/internal/processing/fromclientapi_test.go
@@ -26,6 +26,7 @@ import (
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/api/model"
+ "github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/messages"
"github.com/superseriousbusiness/gotosocial/internal/stream"
@@ -113,6 +114,52 @@ func (suite *FromClientAPITestSuite) TestProcessStreamNewStatus() {
suite.Empty(irrelevantStream.Messages)
}
+func (suite *FromClientAPITestSuite) TestProcessStatusDelete() {
+ ctx := context.Background()
+
+ deletingAccount := suite.testAccounts["local_account_1"]
+ receivingAccount := suite.testAccounts["local_account_2"]
+
+ deletedStatus := suite.testStatuses["local_account_1_status_1"]
+ boostOfDeletedStatus := suite.testStatuses["admin_account_status_4"]
+
+ // open a home timeline stream for turtle, who follows zork
+ wssStream, errWithCode := suite.processor.OpenStreamForAccount(ctx, receivingAccount, stream.TimelineHome)
+ suite.NoError(errWithCode)
+
+ // delete the status from the db first, to mimic what would have already happened earlier up the flow
+ err := suite.db.DeleteByID(ctx, deletedStatus.ID, &gtsmodel.Status{})
+ suite.NoError(err)
+
+ // process the status delete
+ err = suite.processor.ProcessFromClientAPI(ctx, messages.FromClientAPI{
+ APObjectType: ap.ObjectNote,
+ APActivityType: ap.ActivityDelete,
+ GTSModel: deletedStatus,
+ OriginAccount: deletingAccount,
+ })
+ suite.NoError(err)
+
+ // turtle's stream should have the delete of admin's boost in it now
+ msg := <-wssStream.Messages
+ suite.Equal(stream.EventTypeDelete, msg.Event)
+ suite.Equal(boostOfDeletedStatus.ID, msg.Payload)
+ suite.EqualValues([]string{stream.TimelineHome}, msg.Stream)
+
+ // turtle's stream should also have the delete of the message itself in it
+ msg = <-wssStream.Messages
+ suite.Equal(stream.EventTypeDelete, msg.Event)
+ suite.Equal(deletedStatus.ID, msg.Payload)
+ suite.EqualValues([]string{stream.TimelineHome}, msg.Stream)
+
+ // stream should now be empty
+ suite.Empty(wssStream.Messages)
+
+ // the boost should no longer be in the database
+ _, err = suite.db.GetStatusByID(ctx, boostOfDeletedStatus.ID)
+ suite.ErrorIs(err, db.ErrNoEntries)
+}
+
func TestFromClientAPITestSuite(t *testing.T) {
suite.Run(t, &FromClientAPITestSuite{})
}