gotosocial/internal/api/client/statuses/statussource_test.go
kim fe8d5f2307
[feature] add support for clients editing statuses and fetching status revision history (#3628)
* start adding client support for making status edits and viewing history

* modify 'freshest' freshness window to be 5s, add typeutils test for status -> api edits

* only populate the status edits when specifically requested

* start adding some simple processor status edit tests

* add test editing status but adding a poll

* test edits appropriately adding poll expiry handlers

* finish adding status edit tests

* store both new and old revision emojis in status

* add code comment

* ensure the requester's account is populated before status edits

* add code comments for status edit tests

* update status edit form swagger comments

* remove unused function

* fix status source test

* add more code comments, move media description check back to media process in status create

* fix tests, add necessary form struct tag
2024-12-23 17:54:44 +00:00

102 lines
3 KiB
Go

// 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/>.
package statuses_test
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/api/client/statuses"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
"github.com/superseriousbusiness/gotosocial/testrig"
)
type StatusSourceTestSuite struct {
StatusStandardTestSuite
}
func (suite *StatusSourceTestSuite) TestGetSource() {
var (
testApplication = suite.testApplications["application_1"]
testAccount = suite.testAccounts["local_account_1"]
testUser = suite.testUsers["local_account_1"]
testToken = oauth.DBTokenToToken(suite.testTokens["local_account_1"])
targetStatusID = suite.testStatuses["local_account_1_status_1"].ID
target = fmt.Sprintf("http://localhost:8080%s", strings.ReplaceAll(statuses.SourcePath, ":id", targetStatusID))
)
// Setup request.
recorder := httptest.NewRecorder()
request := httptest.NewRequest(http.MethodGet, target, nil)
request.Header.Set("accept", "application/json")
ctx, _ := testrig.CreateGinTestContext(recorder, request)
// Set auth + path params.
ctx.Set(oauth.SessionAuthorizedApplication, testApplication)
ctx.Set(oauth.SessionAuthorizedToken, testToken)
ctx.Set(oauth.SessionAuthorizedUser, testUser)
ctx.Set(oauth.SessionAuthorizedAccount, testAccount)
ctx.Params = gin.Params{
gin.Param{
Key: statuses.IDKey,
Value: targetStatusID,
},
}
// Call the handler.
suite.statusModule.StatusSourceGETHandler(ctx)
// Check code.
if code := recorder.Code; code != http.StatusOK {
suite.FailNow("", "unexpected http code: %d", code)
}
// Read body.
result := recorder.Result()
defer result.Body.Close()
b, err := io.ReadAll(result.Body)
if err != nil {
suite.FailNow(err.Error())
}
// Indent nicely.
dst := new(bytes.Buffer)
if err := json.Indent(dst, b, "", " "); err != nil {
suite.FailNow(err.Error())
}
suite.Equal(`{
"id": "01F8MHAMCHF6Y650WCRSCP4WMY",
"text": "hello everyone!",
"spoiler_text": "introduction post"
}`, dst.String())
}
func TestStatusSourceTestSuite(t *testing.T) {
suite.Run(t, new(StatusSourceTestSuite))
}