summaryrefslogtreecommitdiff
path: root/internal/processing/workers/fromfediapi_test.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-03-12 15:34:08 +0100
committerLibravatar GitHub <noreply@github.com>2024-03-12 14:34:08 +0000
commit1bcdf1da3bb10d564a6a56a89af5afa53e5cd78f (patch)
tree83716cea30d236c48e1655193c3adfc232e5bc75 /internal/processing/workers/fromfediapi_test.go
parent[chore] Update usage of OTEL libraries (#2725) (diff)
downloadgotosocial-1bcdf1da3bb10d564a6a56a89af5afa53e5cd78f.tar.xz
[feature] Process incoming `Move` activity (#2724)
* [feature] Process incoming account Move activity * fix targetAcct typo * put move origin account on fMsg * shift more move functionality back to the worker fn * simplify error logic
Diffstat (limited to 'internal/processing/workers/fromfediapi_test.go')
-rw-r--r--internal/processing/workers/fromfediapi_test.go69
1 files changed, 69 insertions, 0 deletions
diff --git a/internal/processing/workers/fromfediapi_test.go b/internal/processing/workers/fromfediapi_test.go
index 60a9e785e..b7466ec73 100644
--- a/internal/processing/workers/fromfediapi_test.go
+++ b/internal/processing/workers/fromfediapi_test.go
@@ -536,6 +536,75 @@ func (suite *FromFediAPITestSuite) TestCreateStatusFromIRI() {
suite.Equal(statusCreator.URI, s.AccountURI)
}
+func (suite *FromFediAPITestSuite) TestMoveAccount() {
+ // We're gonna migrate foss_satan to our local admin account.
+ ctx := context.Background()
+ receivingAcct := suite.testAccounts["local_account_1"]
+
+ // Copy requesting and target accounts
+ // since we'll be changing these.
+ requestingAcct := &gtsmodel.Account{}
+ *requestingAcct = *suite.testAccounts["remote_account_1"]
+ targetAcct := &gtsmodel.Account{}
+ *targetAcct = *suite.testAccounts["admin_account"]
+
+ // Set alsoKnownAs on the admin account.
+ targetAcct.AlsoKnownAsURIs = []string{requestingAcct.URI}
+ if err := suite.state.DB.UpdateAccount(ctx, targetAcct, "also_known_as_uris"); err != nil {
+ suite.FailNow(err.Error())
+ }
+
+ // Remove existing follow from zork to admin account.
+ if err := suite.state.DB.DeleteFollowByID(
+ ctx,
+ suite.testFollows["local_account_1_admin_account"].ID,
+ ); err != nil {
+ suite.FailNow(err.Error())
+ }
+
+ // Have Zork follow foss_satan instead.
+ if err := suite.state.DB.PutFollow(ctx, &gtsmodel.Follow{
+ ID: "01HRA0XZYFZC5MNWTKEBR58SSE",
+ URI: "http://localhost:8080/users/the_mighty_zork/follows/01HRA0XZYFZC5MNWTKEBR58SSE",
+ AccountID: receivingAcct.ID,
+ TargetAccountID: requestingAcct.ID,
+ }); err != nil {
+ suite.FailNow(err.Error())
+ }
+
+ // Process the Move.
+ err := suite.processor.Workers().ProcessFromFediAPI(ctx, messages.FromFediAPI{
+ APObjectType: ap.ObjectProfile,
+ APActivityType: ap.ActivityMove,
+ GTSModel: &gtsmodel.Move{
+ OriginURI: requestingAcct.URI,
+ Origin: testrig.URLMustParse(requestingAcct.URI),
+ TargetURI: targetAcct.URI,
+ Target: testrig.URLMustParse(targetAcct.URI),
+ URI: "https://fossbros-anonymous.io/users/foss_satan/moves/01HRA064871MR8HGVSAFJ333GM",
+ },
+ ReceivingAccount: receivingAcct,
+ RequestingAccount: requestingAcct,
+ })
+ suite.NoError(err)
+
+ // Zork should now be following admin account.
+ follows, err := suite.state.DB.IsFollowing(ctx, receivingAcct.ID, targetAcct.ID)
+ if err != nil {
+ suite.FailNow(err.Error())
+ }
+ suite.True(follows)
+
+ // Move should be in the DB.
+ move, err := suite.state.DB.GetMoveByURI(ctx, "https://fossbros-anonymous.io/users/foss_satan/moves/01HRA064871MR8HGVSAFJ333GM")
+ if err != nil {
+ suite.FailNow(err.Error())
+ }
+
+ // Move should be marked as completed.
+ suite.WithinDuration(time.Now(), move.SucceededAt, 1*time.Minute)
+}
+
func TestFromFederatorTestSuite(t *testing.T) {
suite.Run(t, &FromFediAPITestSuite{})
}