[bugfix] Prevent future statuses showing in timelines (#932)

This commit is contained in:
tobi 2022-10-29 17:10:28 +02:00 committed by GitHub
commit c7ba195907
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 93 additions and 5 deletions

View file

@ -21,8 +21,13 @@ package bundb_test
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/id"
"github.com/superseriousbusiness/gotosocial/testrig"
)
type TimelineTestSuite struct {
@ -38,6 +43,20 @@ func (suite *TimelineTestSuite) TestGetPublicTimeline() {
suite.Len(s, 6)
}
func (suite *TimelineTestSuite) TestGetPublicTimelineWithFutureStatus() {
viewingAccount := suite.testAccounts["local_account_1"]
futureStatus := getFutureStatus()
if err := suite.db.Put(context.Background(), futureStatus); err != nil {
suite.FailNow(err.Error())
}
s, err := suite.db.GetPublicTimeline(context.Background(), viewingAccount.ID, "", "", "", 20, false)
suite.NoError(err)
suite.Len(s, 6)
}
func (suite *TimelineTestSuite) TestGetHomeTimeline() {
viewingAccount := suite.testAccounts["local_account_1"]
@ -47,6 +66,58 @@ func (suite *TimelineTestSuite) TestGetHomeTimeline() {
suite.Len(s, 16)
}
func (suite *TimelineTestSuite) TestGetHomeTimelineWithFutureStatus() {
viewingAccount := suite.testAccounts["local_account_1"]
futureStatus := getFutureStatus()
if err := suite.db.Put(context.Background(), futureStatus); err != nil {
suite.FailNow(err.Error())
}
s, err := suite.db.GetHomeTimeline(context.Background(), viewingAccount.ID, "", "", "", 20, false)
suite.NoError(err)
suite.Len(s, 16)
}
func getFutureStatus() *gtsmodel.Status {
theDistantFuture := time.Now().Add(876600 * time.Hour)
id, err := id.NewULIDFromTime(theDistantFuture)
if err != nil {
panic(err)
}
return &gtsmodel.Status{
ID: id,
URI: "http://localhost:8080/users/admin/statuses/" + id,
URL: "http://localhost:8080/@admin/statuses/" + id,
Content: "it's the future, wooooooooooooooooooooooooooooooooo",
Text: "it's the future, wooooooooooooooooooooooooooooooooo",
AttachmentIDs: []string{},
TagIDs: []string{},
MentionIDs: []string{},
EmojiIDs: []string{},
CreatedAt: theDistantFuture,
UpdatedAt: theDistantFuture,
Local: testrig.TrueBool(),
AccountURI: "http://localhost:8080/users/admin",
AccountID: "01F8MH17FWEB39HZJ76B6VXSKF",
InReplyToID: "",
BoostOfID: "",
ContentWarning: "",
Visibility: gtsmodel.VisibilityPublic,
Sensitive: testrig.FalseBool(),
Language: "en",
CreatedWithApplicationID: "01F8MGXQRHYF5QPMTMXP78QC2F",
Pinned: testrig.FalseBool(),
Federated: testrig.TrueBool(),
Boostable: testrig.TrueBool(),
Replyable: testrig.TrueBool(),
Likeable: testrig.TrueBool(),
ActivityStreamsType: ap.ObjectNote,
}
}
func TestTimelineTestSuite(t *testing.T) {
suite.Run(t, new(TimelineTestSuite))
}