fix typo, test paging up

This commit is contained in:
tobi 2024-05-01 11:02:56 +02:00
parent 39e1c77312
commit 61c139934c
2 changed files with 82 additions and 1 deletions

View File

@ -25,6 +25,7 @@ import (
"net/http/httptest"
"testing"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/api/client/admin"
)
@ -460,6 +461,86 @@ func (suite *AccountsGetTestSuite) TestAccountsGetFromTop() {
]`, dst.String())
}
func (suite *AccountsGetTestSuite) TestAccountsMinID() {
recorder := httptest.NewRecorder()
path := admin.AccountsV2Path + "?limit=1&min_id=/@the_mighty_zork"
ctx := suite.newContext(recorder, http.MethodGet, nil, path, "application/json")
ctx.Params = gin.Params{
{
Key: "min_id",
Value: "/@the_mighty_zork",
},
{
Key: "limit",
Value: "1",
},
}
suite.adminModule.AccountsGETV2Handler(ctx)
suite.Equal(http.StatusOK, recorder.Code)
b, err := io.ReadAll(recorder.Body)
if err != nil {
suite.FailNow(err.Error())
}
suite.NotNil(b)
dst := new(bytes.Buffer)
err = json.Indent(dst, b, "", " ")
if err != nil {
suite.FailNow(err.Error())
}
link := recorder.Header().Get("Link")
suite.Equal(`<http://localhost:8080/api/v2/admin/accounts?limit=1&max_id=%2F%40localhost%3A8080>; rel="next", <http://localhost:8080/api/v2/admin/accounts?limit=1&min_id=%2F%40localhost%3A8080>; rel="prev"`, link)
suite.Equal(`[
{
"id": "01AY6P665V14JJR0AFVRT7311Y",
"username": "localhost:8080",
"domain": null,
"created_at": "2020-05-17T13:10:59.000Z",
"email": "",
"ip": null,
"ips": [],
"locale": "",
"invite_request": null,
"role": {
"name": "user"
},
"confirmed": false,
"approved": false,
"disabled": false,
"silenced": false,
"suspended": false,
"account": {
"id": "01AY6P665V14JJR0AFVRT7311Y",
"username": "localhost:8080",
"acct": "localhost:8080",
"display_name": "",
"locked": false,
"discoverable": true,
"bot": false,
"created_at": "2020-05-17T13:10:59.000Z",
"note": "",
"url": "http://localhost:8080/@localhost:8080",
"avatar": "",
"avatar_static": "",
"header": "http://localhost:8080/assets/default_header.png",
"header_static": "http://localhost:8080/assets/default_header.png",
"followers_count": 0,
"following_count": 0,
"statuses_count": 0,
"last_status_at": null,
"emojis": [],
"fields": []
}
}
]`, dst.String())
}
func TestAccountsGetTestSuite(t *testing.T) {
suite.Run(t, &AccountsGetTestSuite{})
}

View File

@ -376,7 +376,7 @@ func (a *accountDB) GetAccounts(
if minID != "" {
if dbDialect == dialect.SQLite {
// Use aliased column.
q = q.Where("? < ?", bun.Ident("domain_username"), maxID)
q = q.Where("? < ?", bun.Ident("domain_username"), minID)
} else {
q = q.Where("? < ?", subQ, minID)
}