From 7293d6029b43db693fd170c0c087394339da0677 Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Tue, 12 Sep 2023 14:00:35 +0100 Subject: [feature] add paging to account follows, followers and follow requests endpoints (#2186) --- internal/processing/followrequest_test.go | 76 +++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 25 deletions(-) (limited to 'internal/processing/followrequest_test.go') diff --git a/internal/processing/followrequest_test.go b/internal/processing/followrequest_test.go index addb5052e..4c089be4a 100644 --- a/internal/processing/followrequest_test.go +++ b/internal/processing/followrequest_test.go @@ -30,35 +30,57 @@ import ( "github.com/superseriousbusiness/gotosocial/testrig" ) +// TODO: move this to the "internal/processing/account" pkg type FollowRequestTestSuite struct { ProcessingStandardTestSuite } func (suite *FollowRequestTestSuite) TestFollowRequestAccept() { - requestingAccount := suite.testAccounts["remote_account_2"] - targetAccount := suite.testAccounts["local_account_1"] + // The authed local account we are going to use for HTTP requests + requestingAccount := suite.testAccounts["local_account_1"] + + // The remote account whose follow request we are accepting + targetAccount := suite.testAccounts["remote_account_2"] // put a follow request in the database fr := >smodel.FollowRequest{ ID: "01FJ1S8DX3STJJ6CEYPMZ1M0R3", CreatedAt: time.Now(), UpdatedAt: time.Now(), - URI: fmt.Sprintf("%s/follow/01FJ1S8DX3STJJ6CEYPMZ1M0R3", requestingAccount.URI), - AccountID: requestingAccount.ID, - TargetAccountID: targetAccount.ID, + URI: fmt.Sprintf("%s/follow/01FJ1S8DX3STJJ6CEYPMZ1M0R3", targetAccount.URI), + AccountID: targetAccount.ID, + TargetAccountID: requestingAccount.ID, } err := suite.db.Put(context.Background(), fr) suite.NoError(err) - relationship, errWithCode := suite.processor.FollowRequestAccept(context.Background(), suite.testAutheds["local_account_1"], requestingAccount.ID) + relationship, errWithCode := suite.processor.Account().FollowRequestAccept( + context.Background(), + requestingAccount, + targetAccount.ID, + ) suite.NoError(errWithCode) - suite.EqualValues(&apimodel.Relationship{ID: "01FHMQX3GAABWSM0S2VZEC2SWC", Following: false, ShowingReblogs: false, Notifying: false, FollowedBy: true, Blocking: false, BlockedBy: false, Muting: false, MutingNotifications: false, Requested: false, DomainBlocking: false, Endorsed: false, Note: ""}, relationship) + suite.EqualValues(&apimodel.Relationship{ + ID: "01FHMQX3GAABWSM0S2VZEC2SWC", + Following: false, + ShowingReblogs: false, + Notifying: false, + FollowedBy: true, + Blocking: false, + BlockedBy: false, + Muting: false, + MutingNotifications: false, + Requested: false, + DomainBlocking: false, + Endorsed: false, + Note: "", + }, relationship) // accept should be sent to Some_User var sent [][]byte if !testrig.WaitFor(func() bool { - sentI, ok := suite.httpClient.SentMessages.Load(requestingAccount.InboxURI) + sentI, ok := suite.httpClient.SentMessages.Load(targetAccount.InboxURI) if ok { sent, ok = sentI.([][]byte) if !ok { @@ -87,41 +109,45 @@ func (suite *FollowRequestTestSuite) TestFollowRequestAccept() { err = json.Unmarshal(sent[0], accept) suite.NoError(err) - suite.Equal(targetAccount.URI, accept.Actor) - suite.Equal(requestingAccount.URI, accept.Object.Actor) + suite.Equal(requestingAccount.URI, accept.Actor) + suite.Equal(targetAccount.URI, accept.Object.Actor) suite.Equal(fr.URI, accept.Object.ID) - suite.Equal(targetAccount.URI, accept.Object.Object) - suite.Equal(targetAccount.URI, accept.Object.To) + suite.Equal(requestingAccount.URI, accept.Object.Object) + suite.Equal(requestingAccount.URI, accept.Object.To) suite.Equal("Follow", accept.Object.Type) - suite.Equal(requestingAccount.URI, accept.To) + suite.Equal(targetAccount.URI, accept.To) suite.Equal("Accept", accept.Type) } func (suite *FollowRequestTestSuite) TestFollowRequestReject() { - requestingAccount := suite.testAccounts["remote_account_2"] - targetAccount := suite.testAccounts["local_account_1"] + requestingAccount := suite.testAccounts["local_account_1"] + targetAccount := suite.testAccounts["remote_account_2"] // put a follow request in the database fr := >smodel.FollowRequest{ ID: "01FJ1S8DX3STJJ6CEYPMZ1M0R3", CreatedAt: time.Now(), UpdatedAt: time.Now(), - URI: fmt.Sprintf("%s/follow/01FJ1S8DX3STJJ6CEYPMZ1M0R3", requestingAccount.URI), - AccountID: requestingAccount.ID, - TargetAccountID: targetAccount.ID, + URI: fmt.Sprintf("%s/follow/01FJ1S8DX3STJJ6CEYPMZ1M0R3", targetAccount.URI), + AccountID: targetAccount.ID, + TargetAccountID: requestingAccount.ID, } err := suite.db.Put(context.Background(), fr) suite.NoError(err) - relationship, errWithCode := suite.processor.FollowRequestReject(context.Background(), suite.testAutheds["local_account_1"], requestingAccount.ID) + relationship, errWithCode := suite.processor.Account().FollowRequestReject( + context.Background(), + requestingAccount, + targetAccount.ID, + ) suite.NoError(errWithCode) suite.EqualValues(&apimodel.Relationship{ID: "01FHMQX3GAABWSM0S2VZEC2SWC", Following: false, ShowingReblogs: false, Notifying: false, FollowedBy: false, Blocking: false, BlockedBy: false, Muting: false, MutingNotifications: false, Requested: false, DomainBlocking: false, Endorsed: false, Note: ""}, relationship) // reject should be sent to Some_User var sent [][]byte if !testrig.WaitFor(func() bool { - sentI, ok := suite.httpClient.SentMessages.Load(requestingAccount.InboxURI) + sentI, ok := suite.httpClient.SentMessages.Load(targetAccount.InboxURI) if ok { sent, ok = sentI.([][]byte) if !ok { @@ -150,13 +176,13 @@ func (suite *FollowRequestTestSuite) TestFollowRequestReject() { err = json.Unmarshal(sent[0], reject) suite.NoError(err) - suite.Equal(targetAccount.URI, reject.Actor) - suite.Equal(requestingAccount.URI, reject.Object.Actor) + suite.Equal(requestingAccount.URI, reject.Actor) + suite.Equal(targetAccount.URI, reject.Object.Actor) suite.Equal(fr.URI, reject.Object.ID) - suite.Equal(targetAccount.URI, reject.Object.Object) - suite.Equal(targetAccount.URI, reject.Object.To) + suite.Equal(requestingAccount.URI, reject.Object.Object) + suite.Equal(requestingAccount.URI, reject.Object.To) suite.Equal("Follow", reject.Object.Type) - suite.Equal(requestingAccount.URI, reject.To) + suite.Equal(targetAccount.URI, reject.To) suite.Equal("Reject", reject.Type) } -- cgit v1.2.3