gtsocial-umbx

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

inbox_test.go (2769B)


      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 	"context"
     22 	"testing"
     23 
     24 	"github.com/stretchr/testify/suite"
     25 	"github.com/superseriousbusiness/gotosocial/testrig"
     26 )
     27 
     28 type InboxTestSuite struct {
     29 	FederatingDBTestSuite
     30 }
     31 
     32 func (suite *InboxTestSuite) TestInboxesForFollowersIRI() {
     33 	ctx := context.Background()
     34 	testAccount := suite.testAccounts["local_account_1"]
     35 
     36 	inboxIRIs, err := suite.federatingDB.InboxesForIRI(ctx, testrig.URLMustParse(testAccount.FollowersURI))
     37 	suite.NoError(err)
     38 
     39 	asStrings := []string{}
     40 	for _, i := range inboxIRIs {
     41 		asStrings = append(asStrings, i.String())
     42 	}
     43 
     44 	suite.Len(asStrings, 2)
     45 	suite.Contains(asStrings, suite.testAccounts["local_account_2"].InboxURI)
     46 	suite.Contains(asStrings, suite.testAccounts["admin_account"].InboxURI)
     47 }
     48 
     49 func (suite *InboxTestSuite) TestInboxesForAccountIRI() {
     50 	ctx := context.Background()
     51 	testAccount := suite.testAccounts["local_account_1"]
     52 
     53 	inboxIRIs, err := suite.federatingDB.InboxesForIRI(ctx, testrig.URLMustParse(testAccount.URI))
     54 	suite.NoError(err)
     55 
     56 	asStrings := []string{}
     57 	for _, i := range inboxIRIs {
     58 		asStrings = append(asStrings, i.String())
     59 	}
     60 
     61 	suite.Len(asStrings, 1)
     62 	suite.Contains(asStrings, suite.testAccounts["local_account_1"].InboxURI)
     63 }
     64 
     65 func (suite *InboxTestSuite) TestInboxesForAccountIRIWithSharedInbox() {
     66 	ctx := context.Background()
     67 	testAccount := suite.testAccounts["local_account_1"]
     68 	sharedInbox := "http://some-inbox-iri/weeeeeeeeeeeee"
     69 	testAccount.SharedInboxURI = &sharedInbox
     70 	if err := suite.db.UpdateAccount(ctx, testAccount); err != nil {
     71 		suite.FailNow("error updating account")
     72 	}
     73 
     74 	inboxIRIs, err := suite.federatingDB.InboxesForIRI(ctx, testrig.URLMustParse(testAccount.URI))
     75 	suite.NoError(err)
     76 
     77 	asStrings := []string{}
     78 	for _, i := range inboxIRIs {
     79 		asStrings = append(asStrings, i.String())
     80 	}
     81 
     82 	suite.Len(asStrings, 1)
     83 	suite.Contains(asStrings, "http://some-inbox-iri/weeeeeeeeeeeee")
     84 }
     85 
     86 func TestInboxTestSuite(t *testing.T) {
     87 	suite.Run(t, &InboxTestSuite{})
     88 }