diff options
author | 2023-03-20 19:10:08 +0100 | |
---|---|---|
committer | 2023-03-20 18:10:08 +0000 | |
commit | e8595f0c64f527af0913d1a426b697e67ff74ac9 (patch) | |
tree | a5d45b1ad8b96318944408a23fda91f008643900 /internal/db/bundb/relationship_test.go | |
parent | [chore]: Bump github.com/miekg/dns from 1.1.51 to 1.1.52 (#1636) (diff) | |
download | gotosocial-e8595f0c64f527af0913d1a426b697e67ff74ac9.tar.xz |
[chore] Refactor account deleting/block logic, tidy up some other processing things (#1599)
* start refactoring account deletion
* update to use state.DB
* further messing about
* some more tidying up
* more tidying, cleaning, nice-making
* further adventures in refactoring and the woes of technical debt
* update fr accept/reject
* poking + prodding
* fix up deleting
* create fave uri
* don't log using requestingAccount.ID because it might be nil
* move getBookmarks function
* use exists query to check for status bookmark
* use deletenotifications func
* fiddle
* delete follow request notif
* split up some db functions
* Fix possible nil pointer panic
* fix more possible nil pointers
* fix license headers
* warn when follow missing (target) account
* return wrapped err when bookmark/fave models can't be retrieved
* simplify self account delete
* warn log likely race condition
* de-sillify status delete loop
* move error check due north
* warn when unfollowSideEffects has no target account
* warn when no boost account is found
* warn + dump follow when no account
* more warnings
* warn on fave account not set
* move for loop inside anonymous function
* fix funky logic
* don't remove mutual account items on block;
do make sure unfollow occurs in both directions!
Diffstat (limited to 'internal/db/bundb/relationship_test.go')
-rw-r--r-- | internal/db/bundb/relationship_test.go | 129 |
1 files changed, 110 insertions, 19 deletions
diff --git a/internal/db/bundb/relationship_test.go b/internal/db/bundb/relationship_test.go index 04a04b088..3d307ecde 100644 --- a/internal/db/bundb/relationship_test.go +++ b/internal/db/bundb/relationship_test.go @@ -289,6 +289,47 @@ func (suite *RelationshipTestSuite) TestAcceptFollowRequestOK() { suite.FailNow(err.Error()) } + followRequestNotification := >smodel.Notification{ + ID: "01GV8MY1Q9KX2ZSWN4FAQ3V1PB", + OriginAccountID: account.ID, + TargetAccountID: targetAccount.ID, + NotificationType: gtsmodel.NotificationFollowRequest, + } + + if err := suite.db.Put(ctx, followRequestNotification); err != nil { + suite.FailNow(err.Error()) + } + + follow, err := suite.db.AcceptFollowRequest(ctx, account.ID, targetAccount.ID) + suite.NoError(err) + suite.NotNil(follow) + suite.Equal(followRequest.URI, follow.URI) + + // Ensure notification is deleted. + notification, err := suite.db.GetNotification(ctx, followRequestNotification.ID) + suite.ErrorIs(err, db.ErrNoEntries) + suite.Nil(notification) +} + +func (suite *RelationshipTestSuite) TestAcceptFollowRequestNoNotification() { + ctx := context.Background() + account := suite.testAccounts["admin_account"] + targetAccount := suite.testAccounts["local_account_2"] + + followRequest := >smodel.FollowRequest{ + ID: "01GEF753FWHCHRDWR0QEHBXM8W", + URI: "http://localhost:8080/weeeeeeeeeeeeeeeee", + AccountID: account.ID, + TargetAccountID: targetAccount.ID, + } + + if err := suite.db.Put(ctx, followRequest); err != nil { + suite.FailNow(err.Error()) + } + + // Unlike the above test, don't create a notification. + // Follow request accept should still produce no error. + follow, err := suite.db.AcceptFollowRequest(ctx, account.ID, targetAccount.ID) suite.NoError(err) suite.NotNil(follow) @@ -352,9 +393,25 @@ func (suite *RelationshipTestSuite) TestRejectFollowRequestOK() { suite.FailNow(err.Error()) } + followRequestNotification := >smodel.Notification{ + ID: "01GV8MY1Q9KX2ZSWN4FAQ3V1PB", + OriginAccountID: account.ID, + TargetAccountID: targetAccount.ID, + NotificationType: gtsmodel.NotificationFollowRequest, + } + + if err := suite.db.Put(ctx, followRequestNotification); err != nil { + suite.FailNow(err.Error()) + } + rejectedFollowRequest, err := suite.db.RejectFollowRequest(ctx, account.ID, targetAccount.ID) suite.NoError(err) suite.NotNil(rejectedFollowRequest) + + // Ensure notification is deleted. + notification, err := suite.db.GetNotification(ctx, followRequestNotification.ID) + suite.ErrorIs(err, db.ErrNoEntries) + suite.Nil(notification) } func (suite *RelationshipTestSuite) TestRejectFollowRequestNotExisting() { @@ -383,58 +440,92 @@ func (suite *RelationshipTestSuite) TestGetAccountFollowRequests() { suite.FailNow(err.Error()) } - followRequests, err := suite.db.GetAccountFollowRequests(ctx, targetAccount.ID) + followRequests, err := suite.db.GetFollowRequests(ctx, "", targetAccount.ID) suite.NoError(err) suite.Len(followRequests, 1) } func (suite *RelationshipTestSuite) TestGetAccountFollows() { account := suite.testAccounts["local_account_1"] - follows, err := suite.db.GetAccountFollows(context.Background(), account.ID) + follows, err := suite.db.GetFollows(context.Background(), account.ID, "") suite.NoError(err) suite.Len(follows, 2) } -func (suite *RelationshipTestSuite) TestCountAccountFollowsLocalOnly() { - account := suite.testAccounts["local_account_1"] - followsCount, err := suite.db.CountAccountFollows(context.Background(), account.ID, true) - suite.NoError(err) - suite.Equal(2, followsCount) -} - func (suite *RelationshipTestSuite) TestCountAccountFollows() { account := suite.testAccounts["local_account_1"] - followsCount, err := suite.db.CountAccountFollows(context.Background(), account.ID, false) + followsCount, err := suite.db.CountFollows(context.Background(), account.ID, "") suite.NoError(err) suite.Equal(2, followsCount) } func (suite *RelationshipTestSuite) TestGetAccountFollowedBy() { account := suite.testAccounts["local_account_1"] - follows, err := suite.db.GetAccountFollowedBy(context.Background(), account.ID, false) + follows, err := suite.db.GetFollows(context.Background(), "", account.ID) suite.NoError(err) suite.Len(follows, 2) } -func (suite *RelationshipTestSuite) TestGetAccountFollowedByLocalOnly() { +func (suite *RelationshipTestSuite) TestGetLocalFollowersIDs() { account := suite.testAccounts["local_account_1"] - follows, err := suite.db.GetAccountFollowedBy(context.Background(), account.ID, true) + accountIDs, err := suite.db.GetLocalFollowersIDs(context.Background(), account.ID) suite.NoError(err) - suite.Len(follows, 2) + suite.EqualValues([]string{"01F8MH5NBDF2MV7CTC4Q5128HF", "01F8MH17FWEB39HZJ76B6VXSKF"}, accountIDs) } func (suite *RelationshipTestSuite) TestCountAccountFollowedBy() { account := suite.testAccounts["local_account_1"] - followsCount, err := suite.db.CountAccountFollowedBy(context.Background(), account.ID, false) + followsCount, err := suite.db.CountFollows(context.Background(), "", account.ID) suite.NoError(err) suite.Equal(2, followsCount) } -func (suite *RelationshipTestSuite) TestCountAccountFollowedByLocalOnly() { - account := suite.testAccounts["local_account_1"] - followsCount, err := suite.db.CountAccountFollowedBy(context.Background(), account.ID, true) +func (suite *RelationshipTestSuite) TestUnfollowExisting() { + originAccount := suite.testAccounts["local_account_1"] + targetAccount := suite.testAccounts["admin_account"] + + uri, err := suite.db.Unfollow(context.Background(), originAccount.ID, targetAccount.ID) suite.NoError(err) - suite.Equal(2, followsCount) + suite.Equal("http://localhost:8080/users/the_mighty_zork/follow/01F8PY8RHWRQZV038T4E8T9YK8", uri) +} + +func (suite *RelationshipTestSuite) TestUnfollowNotExisting() { + originAccount := suite.testAccounts["local_account_1"] + targetAccountID := "01GTVD9N484CZ6AM90PGGNY7GQ" + + uri, err := suite.db.Unfollow(context.Background(), originAccount.ID, targetAccountID) + suite.NoError(err) + suite.Empty(uri) +} + +func (suite *RelationshipTestSuite) TestUnfollowRequestExisting() { + ctx := context.Background() + originAccount := suite.testAccounts["admin_account"] + targetAccount := suite.testAccounts["local_account_2"] + + followRequest := >smodel.FollowRequest{ + ID: "01GEF753FWHCHRDWR0QEHBXM8W", + URI: "http://localhost:8080/weeeeeeeeeeeeeeeee", + AccountID: originAccount.ID, + TargetAccountID: targetAccount.ID, + } + + if err := suite.db.Put(ctx, followRequest); err != nil { + suite.FailNow(err.Error()) + } + + uri, err := suite.db.UnfollowRequest(context.Background(), originAccount.ID, targetAccount.ID) + suite.NoError(err) + suite.Equal("http://localhost:8080/weeeeeeeeeeeeeeeee", uri) +} + +func (suite *RelationshipTestSuite) TestUnfollowRequestNotExisting() { + originAccount := suite.testAccounts["local_account_1"] + targetAccountID := "01GTVD9N484CZ6AM90PGGNY7GQ" + + uri, err := suite.db.UnfollowRequest(context.Background(), originAccount.ID, targetAccountID) + suite.NoError(err) + suite.Empty(uri) } func TestRelationshipTestSuite(t *testing.T) { |