gtsocial-umbx

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

announce_test.go (3717B)


      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 
     23 	"github.com/stretchr/testify/suite"
     24 	"github.com/superseriousbusiness/activity/streams/vocab"
     25 	"github.com/superseriousbusiness/gotosocial/internal/ap"
     26 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
     27 	"github.com/superseriousbusiness/gotosocial/internal/id"
     28 )
     29 
     30 type AnnounceTestSuite struct {
     31 	FederatingDBTestSuite
     32 }
     33 
     34 func (suite *AnnounceTestSuite) TestNewAnnounce() {
     35 	receivingAccount1 := suite.testAccounts["local_account_1"]
     36 	announcingAccount := suite.testAccounts["remote_account_1"]
     37 
     38 	ctx := createTestContext(receivingAccount1, announcingAccount)
     39 	announce1 := suite.testActivities["announce_forwarded_1_zork"]
     40 
     41 	err := suite.federatingDB.Announce(ctx, announce1.Activity.(vocab.ActivityStreamsAnnounce))
     42 	suite.NoError(err)
     43 
     44 	// should be a message heading to the processor now, which we can intercept here
     45 	msg := <-suite.fromFederator
     46 	suite.Equal(ap.ActivityAnnounce, msg.APObjectType)
     47 	suite.Equal(ap.ActivityCreate, msg.APActivityType)
     48 
     49 	boost, ok := msg.GTSModel.(*gtsmodel.Status)
     50 	suite.True(ok)
     51 	suite.Equal(announcingAccount.ID, boost.AccountID)
     52 
     53 	// only the URI will be set on the boosted status because it still needs to be dereferenced
     54 	suite.NotEmpty(boost.BoostOf.URI)
     55 }
     56 
     57 func (suite *AnnounceTestSuite) TestAnnounceTwice() {
     58 	receivingAccount1 := suite.testAccounts["local_account_1"]
     59 	receivingAccount2 := suite.testAccounts["local_account_2"]
     60 
     61 	announcingAccount := suite.testAccounts["remote_account_1"]
     62 
     63 	ctx1 := createTestContext(receivingAccount1, announcingAccount)
     64 	announce1 := suite.testActivities["announce_forwarded_1_zork"]
     65 
     66 	err := suite.federatingDB.Announce(ctx1, announce1.Activity.(vocab.ActivityStreamsAnnounce))
     67 	suite.NoError(err)
     68 
     69 	// should be a message heading to the processor now, which we can intercept here
     70 	msg := <-suite.fromFederator
     71 	suite.Equal(ap.ActivityAnnounce, msg.APObjectType)
     72 	suite.Equal(ap.ActivityCreate, msg.APActivityType)
     73 	boost, ok := msg.GTSModel.(*gtsmodel.Status)
     74 	suite.True(ok)
     75 	suite.Equal(announcingAccount.ID, boost.AccountID)
     76 
     77 	// Insert the boost-of status into the
     78 	// DB cache to emulate processor handling
     79 	boost.ID, _ = id.NewULIDFromTime(boost.CreatedAt)
     80 	suite.state.Caches.GTS.Status().Store(boost, func() error {
     81 		return nil
     82 	})
     83 
     84 	// only the URI will be set on the boosted status because it still needs to be dereferenced
     85 	suite.NotEmpty(boost.BoostOf.URI)
     86 
     87 	ctx2 := createTestContext(receivingAccount2, announcingAccount)
     88 	announce2 := suite.testActivities["announce_forwarded_1_turtle"]
     89 
     90 	err = suite.federatingDB.Announce(ctx2, announce2.Activity.(vocab.ActivityStreamsAnnounce))
     91 	suite.NoError(err)
     92 
     93 	// since this is a repeat announce with the same URI, just delivered to a different inbox,
     94 	// we should have nothing in the messages channel...
     95 	suite.Empty(suite.fromFederator)
     96 }
     97 
     98 func TestAnnounceTestSuite(t *testing.T) {
     99 	suite.Run(t, &AnnounceTestSuite{})
    100 }