fix up more tests, fix missing required changes, etc

This commit is contained in:
kim 2025-03-25 12:12:09 +00:00
commit 64564496f1
10 changed files with 130 additions and 84 deletions

View file

@ -50,7 +50,7 @@ func (p *Processor) ListTimelineGet(
}
// Check exists.
if list != nil {
if list == nil {
const text = "list not found"
return nil, gtserror.NewErrorNotFound(
errors.New(text),

View file

@ -93,9 +93,9 @@ func (suite *PublicTestSuite) TestPublicTimelineGetNotEmpty() {
// some other statuses were filtered out.
suite.NoError(errWithCode)
suite.Len(resp.Items, 1)
suite.Equal(`<http://localhost:8080/api/v1/timelines/public?limit=1&max_id=01F8MHCP5P2NWYQ416SBA0XSEV&local=false>; rel="next", <http://localhost:8080/api/v1/timelines/public?limit=1&min_id=01HE7XJ1CG84TBKH5V9XKBVGF5&local=false>; rel="prev"`, resp.LinkHeader)
suite.Equal(`http://localhost:8080/api/v1/timelines/public?limit=1&max_id=01F8MHCP5P2NWYQ416SBA0XSEV&local=false`, resp.NextLink)
suite.Equal(`http://localhost:8080/api/v1/timelines/public?limit=1&min_id=01HE7XJ1CG84TBKH5V9XKBVGF5&local=false`, resp.PrevLink)
suite.Equal(`<http://localhost:8080/api/v1/timelines/public?limit=1&local=false&max_id=01F8MHCP5P2NWYQ416SBA0XSEV>; rel="next", <http://localhost:8080/api/v1/timelines/public?limit=1&local=false&min_id=01HE7XJ1CG84TBKH5V9XKBVGF5>; rel="prev"`, resp.LinkHeader)
suite.Equal(`http://localhost:8080/api/v1/timelines/public?limit=1&local=false&max_id=01F8MHCP5P2NWYQ416SBA0XSEV`, resp.NextLink)
suite.Equal(`http://localhost:8080/api/v1/timelines/public?limit=1&local=false&min_id=01HE7XJ1CG84TBKH5V9XKBVGF5`, resp.PrevLink)
}
// A timeline containing a status hidden due to filtering should return other statuses with no error.
@ -153,8 +153,9 @@ func (suite *PublicTestSuite) TestPublicTimelineGetHideFiltered() {
if !filteredStatusFound {
suite.FailNow("precondition failed: status we would filter isn't present in unfiltered timeline")
}
// The public timeline has no prepared status cache and doesn't need to be pruned,
// as in the home timeline version of this test.
// Clear the timeline to drop all cached statuses.
suite.state.Caches.Timelines.Public.Clear()
// Create a filter to hide one status on the timeline.
if err := suite.db.PutFilter(ctx, filter); err != nil {

View file

@ -66,8 +66,8 @@ func (p *Processor) getStatusTimeline(
requester *gtsmodel.Account,
timeline *timeline.StatusTimeline,
page *paging.Page,
pgPath string, // timeline page path
pgQuery url.Values, // timeline query parameters
pagePath string,
pageQuery url.Values,
filterCtx statusfilter.FilterContext,
loadPage func(*paging.Page) (statuses []*gtsmodel.Status, err error),
preFilter func(*gtsmodel.Status) (bool, error),
@ -153,12 +153,17 @@ func (p *Processor) getStatusTimeline(
return nil, gtserror.WrapWithCode(http.StatusInternalServerError, err)
}
// Check for empty response.
if len(apiStatuses) == 0 {
return paging.EmptyResponse(), nil
}
// Package returned API statuses as pageable response.
return paging.PackageResponse(paging.ResponseParams{
Items: xslices.ToAny(apiStatuses),
Path: pgPath,
Path: pagePath,
Next: page.Next(lo, hi),
Prev: page.Prev(lo, hi),
Query: pgQuery,
Query: pageQuery,
}), nil
}