gtsocial-umbx

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

index_test.go (3043B)


      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 timeline_test
     19 
     20 import (
     21 	"context"
     22 	"testing"
     23 	"time"
     24 
     25 	"github.com/stretchr/testify/suite"
     26 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
     27 )
     28 
     29 type IndexTestSuite struct {
     30 	TimelineStandardTestSuite
     31 }
     32 
     33 func (suite *IndexTestSuite) TestOldestIndexedItemIDEmpty() {
     34 	var (
     35 		ctx           = context.Background()
     36 		testAccountID = suite.testAccounts["local_account_1"].ID
     37 	)
     38 
     39 	// the oldest indexed post should be an empty string since there's nothing indexed yet
     40 	postID := suite.state.Timelines.Home.GetOldestIndexedID(ctx, testAccountID)
     41 	suite.Empty(postID)
     42 
     43 	// indexLength should be 0
     44 	suite.Zero(0, suite.state.Timelines.Home.GetIndexedLength(ctx, testAccountID))
     45 }
     46 
     47 func (suite *IndexTestSuite) TestIndexAlreadyIndexed() {
     48 	var (
     49 		ctx           = context.Background()
     50 		testAccountID = suite.testAccounts["local_account_1"].ID
     51 		testStatus    = suite.testStatuses["local_account_1_status_1"]
     52 	)
     53 
     54 	// index one post -- it should be indexed
     55 	indexed, err := suite.state.Timelines.Home.IngestOne(ctx, testAccountID, testStatus)
     56 	suite.NoError(err)
     57 	suite.True(indexed)
     58 
     59 	// try to index the same post again -- it should not be indexed
     60 	indexed, err = suite.state.Timelines.Home.IngestOne(ctx, testAccountID, testStatus)
     61 	suite.NoError(err)
     62 	suite.False(indexed)
     63 }
     64 
     65 func (suite *IndexTestSuite) TestIndexBoostOfAlreadyIndexed() {
     66 	var (
     67 		ctx               = context.Background()
     68 		testAccountID     = suite.testAccounts["local_account_1"].ID
     69 		testStatus        = suite.testStatuses["local_account_1_status_1"]
     70 		boostOfTestStatus = &gtsmodel.Status{
     71 			CreatedAt:        time.Now(),
     72 			ID:               "01FD4TA6G2Z6M7W8NJQ3K5WXYD",
     73 			BoostOfID:        testStatus.ID,
     74 			AccountID:        "01FD4TAY1C0NGEJVE9CCCX7QKS",
     75 			BoostOfAccountID: testStatus.AccountID,
     76 		}
     77 	)
     78 
     79 	// index one post -- it should be indexed
     80 	indexed, err := suite.state.Timelines.Home.IngestOne(ctx, testAccountID, testStatus)
     81 	suite.NoError(err)
     82 	suite.True(indexed)
     83 
     84 	// try to index the a boost of that post -- it should not be indexed
     85 	indexed, err = suite.state.Timelines.Home.IngestOne(ctx, testAccountID, boostOfTestStatus)
     86 	suite.NoError(err)
     87 	suite.False(indexed)
     88 }
     89 
     90 func TestIndexTestSuite(t *testing.T) {
     91 	suite.Run(t, new(IndexTestSuite))
     92 }