| 
									
										
										
										
											2023-03-12 16:00:57 +01:00
										 |  |  | // GoToSocial | 
					
						
							|  |  |  | // Copyright (C) GoToSocial Authors admin@gotosocial.org | 
					
						
							|  |  |  | // SPDX-License-Identifier: AGPL-3.0-or-later | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // This program is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  | // it under the terms of the GNU Affero General Public License as published by | 
					
						
							|  |  |  | // the Free Software Foundation, either version 3 of the License, or | 
					
						
							|  |  |  | // (at your option) any later version. | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  | // GNU Affero General Public License for more details. | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // You should have received a copy of the GNU Affero General Public License | 
					
						
							|  |  |  | // along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
					
						
							| 
									
										
										
										
											2021-08-15 18:43:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | package timeline_test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2021-08-25 15:34:33 +02:00
										 |  |  | 	"context" | 
					
						
							| 
									
										
										
										
											2021-08-15 18:43:08 +02:00
										 |  |  | 	"testing" | 
					
						
							|  |  |  | 	"time" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/stretchr/testify/suite" | 
					
						
							|  |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type IndexTestSuite struct { | 
					
						
							|  |  |  | 	TimelineStandardTestSuite | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-04 18:55:30 +02:00
										 |  |  | func (suite *IndexTestSuite) TestOldestIndexedItemIDEmpty() { | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		ctx           = context.Background() | 
					
						
							|  |  |  | 		testAccountID = suite.testAccounts["local_account_1"].ID | 
					
						
							| 
									
										
										
										
											2022-02-05 12:47:38 +01:00
										 |  |  | 	) | 
					
						
							| 
									
										
										
										
											2021-08-15 18:43:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// the oldest indexed post should be an empty string since there's nothing indexed yet | 
					
						
							| 
									
										
										
										
											2023-06-04 18:55:30 +02:00
										 |  |  | 	postID := suite.state.Timelines.Home.GetOldestIndexedID(ctx, testAccountID) | 
					
						
							| 
									
										
										
										
											2021-08-15 18:43:08 +02:00
										 |  |  | 	suite.Empty(postID) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// indexLength should be 0 | 
					
						
							| 
									
										
										
										
											2023-06-04 18:55:30 +02:00
										 |  |  | 	suite.Zero(0, suite.state.Timelines.Home.GetIndexedLength(ctx, testAccountID)) | 
					
						
							| 
									
										
										
										
											2021-08-15 18:43:08 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *IndexTestSuite) TestIndexAlreadyIndexed() { | 
					
						
							| 
									
										
										
										
											2023-06-04 18:55:30 +02:00
										 |  |  | 	var ( | 
					
						
							|  |  |  | 		ctx           = context.Background() | 
					
						
							|  |  |  | 		testAccountID = suite.testAccounts["local_account_1"].ID | 
					
						
							|  |  |  | 		testStatus    = suite.testStatuses["local_account_1_status_1"] | 
					
						
							|  |  |  | 	) | 
					
						
							| 
									
										
										
										
											2021-08-15 18:43:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// index one post -- it should be indexed | 
					
						
							| 
									
										
										
										
											2023-06-04 18:55:30 +02:00
										 |  |  | 	indexed, err := suite.state.Timelines.Home.IngestOne(ctx, testAccountID, testStatus) | 
					
						
							| 
									
										
										
										
											2021-08-15 18:43:08 +02:00
										 |  |  | 	suite.NoError(err) | 
					
						
							|  |  |  | 	suite.True(indexed) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// try to index the same post again -- it should not be indexed | 
					
						
							| 
									
										
										
										
											2023-06-04 18:55:30 +02:00
										 |  |  | 	indexed, err = suite.state.Timelines.Home.IngestOne(ctx, testAccountID, testStatus) | 
					
						
							| 
									
										
										
										
											2021-08-15 18:43:08 +02:00
										 |  |  | 	suite.NoError(err) | 
					
						
							|  |  |  | 	suite.False(indexed) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *IndexTestSuite) TestIndexBoostOfAlreadyIndexed() { | 
					
						
							| 
									
										
										
										
											2023-06-04 18:55:30 +02:00
										 |  |  | 	var ( | 
					
						
							|  |  |  | 		ctx               = context.Background() | 
					
						
							|  |  |  | 		testAccountID     = suite.testAccounts["local_account_1"].ID | 
					
						
							|  |  |  | 		testStatus        = suite.testStatuses["local_account_1_status_1"] | 
					
						
							|  |  |  | 		boostOfTestStatus = >smodel.Status{ | 
					
						
							|  |  |  | 			CreatedAt:        time.Now(), | 
					
						
							|  |  |  | 			ID:               "01FD4TA6G2Z6M7W8NJQ3K5WXYD", | 
					
						
							|  |  |  | 			BoostOfID:        testStatus.ID, | 
					
						
							|  |  |  | 			AccountID:        "01FD4TAY1C0NGEJVE9CCCX7QKS", | 
					
						
							|  |  |  | 			BoostOfAccountID: testStatus.AccountID, | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	) | 
					
						
							| 
									
										
										
										
											2021-08-15 18:43:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// index one post -- it should be indexed | 
					
						
							| 
									
										
										
										
											2023-06-04 18:55:30 +02:00
										 |  |  | 	indexed, err := suite.state.Timelines.Home.IngestOne(ctx, testAccountID, testStatus) | 
					
						
							| 
									
										
										
										
											2021-08-15 18:43:08 +02:00
										 |  |  | 	suite.NoError(err) | 
					
						
							|  |  |  | 	suite.True(indexed) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// try to index the a boost of that post -- it should not be indexed | 
					
						
							| 
									
										
										
										
											2023-06-04 18:55:30 +02:00
										 |  |  | 	indexed, err = suite.state.Timelines.Home.IngestOne(ctx, testAccountID, boostOfTestStatus) | 
					
						
							| 
									
										
										
										
											2021-08-15 18:43:08 +02:00
										 |  |  | 	suite.NoError(err) | 
					
						
							|  |  |  | 	suite.False(indexed) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestIndexTestSuite(t *testing.T) { | 
					
						
							|  |  |  | 	suite.Run(t, new(IndexTestSuite)) | 
					
						
							|  |  |  | } |