From 1bcdf1da3bb10d564a6a56a89af5afa53e5cd78f Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Tue, 12 Mar 2024 15:34:08 +0100 Subject: [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 --- internal/processing/workers/fromfediapi_test.go | 69 +++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'internal/processing/workers/fromfediapi_test.go') 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 := >smodel.Account{} + *requestingAcct = *suite.testAccounts["remote_account_1"] + targetAcct := >smodel.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, >smodel.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: >smodel.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{}) } -- cgit v1.2.3