gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

reject_test.go (3446B)


      1 // GoToSocial
      2 // Copyright (C) GoToSocial Authors admin@gotosocial.org
      3 // SPDX-License-Identifier: AGPL-3.0-or-later
      4 //
      5 // This program is free software: you can redistribute it and/or modify
      6 // it under the terms of the GNU Affero General Public License as published by
      7 // the Free Software Foundation, either version 3 of the License, or
      8 // (at your option) any later version.
      9 //
     10 // This program is distributed in the hope that it will be useful,
     11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 // GNU Affero General Public License for more details.
     14 //
     15 // You should have received a copy of the GNU Affero General Public License
     16 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 
     18 package federatingdb_test
     19 
     20 import (
     21 	"testing"
     22 	"time"
     23 
     24 	"github.com/stretchr/testify/suite"
     25 	"github.com/superseriousbusiness/activity/streams"
     26 	"github.com/superseriousbusiness/gotosocial/internal/db"
     27 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
     28 	"github.com/superseriousbusiness/gotosocial/internal/uris"
     29 	"github.com/superseriousbusiness/gotosocial/testrig"
     30 )
     31 
     32 type RejectTestSuite struct {
     33 	FederatingDBTestSuite
     34 }
     35 
     36 func (suite *RejectTestSuite) TestRejectFollowRequest() {
     37 	// local_account_1 sent a follow request to remote_account_2;
     38 	// remote_account_2 rejects the follow request
     39 	followingAccount := suite.testAccounts["local_account_1"]
     40 	followedAccount := suite.testAccounts["remote_account_2"]
     41 	ctx := createTestContext(followingAccount, followedAccount)
     42 
     43 	// put the follow request in the database
     44 	fr := &gtsmodel.FollowRequest{
     45 		ID:              "01FJ1S8DX3STJJ6CEYPMZ1M0R3",
     46 		CreatedAt:       time.Now(),
     47 		UpdatedAt:       time.Now(),
     48 		URI:             uris.GenerateURIForFollow(followingAccount.Username, "01FJ1S8DX3STJJ6CEYPMZ1M0R3"),
     49 		AccountID:       followingAccount.ID,
     50 		TargetAccountID: followedAccount.ID,
     51 	}
     52 	err := suite.db.Put(ctx, fr)
     53 	suite.NoError(err)
     54 
     55 	asFollow, err := suite.tc.FollowToAS(ctx, suite.tc.FollowRequestToFollow(ctx, fr), followingAccount, followedAccount)
     56 	suite.NoError(err)
     57 
     58 	rejectingAccountURI := testrig.URLMustParse(followedAccount.URI)
     59 	requestingAccountURI := testrig.URLMustParse(followingAccount.URI)
     60 
     61 	// create a Reject
     62 	reject := streams.NewActivityStreamsReject()
     63 
     64 	// set the rejecting actor on it
     65 	acceptActorProp := streams.NewActivityStreamsActorProperty()
     66 	acceptActorProp.AppendIRI(rejectingAccountURI)
     67 	reject.SetActivityStreamsActor(acceptActorProp)
     68 
     69 	// Set the recreated follow as the 'object' property.
     70 	acceptObject := streams.NewActivityStreamsObjectProperty()
     71 	acceptObject.AppendActivityStreamsFollow(asFollow)
     72 	reject.SetActivityStreamsObject(acceptObject)
     73 
     74 	// Set the To of the reject as the originator of the follow
     75 	acceptTo := streams.NewActivityStreamsToProperty()
     76 	acceptTo.AppendIRI(requestingAccountURI)
     77 	reject.SetActivityStreamsTo(acceptTo)
     78 
     79 	// process the reject in the federating database
     80 	err = suite.federatingDB.Reject(ctx, reject)
     81 	suite.NoError(err)
     82 
     83 	// there should be nothing in the federator channel since nothing needs to be passed
     84 	suite.Empty(suite.fromFederator)
     85 
     86 	// the follow request should not be in the database anymore -- it's been rejected
     87 	err = suite.db.GetByID(ctx, fr.ID, &gtsmodel.FollowRequest{})
     88 	suite.ErrorIs(err, db.ErrNoEntries)
     89 }
     90 
     91 func TestRejectTestSuite(t *testing.T) {
     92 	suite.Run(t, &RejectTestSuite{})
     93 }