mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[bugfix] Fix Swagger spec and add test script (#2698)
* Add Swagger spec test script * Fix Swagger spec errors not related to statuses with polls * Add API tests that post a status with a poll * Fix creating a status with a poll from form params * Fix Swagger spec errors related to statuses with polls (this is the last error) * Fix Swagger spec warnings not related to unused definitions * Suppress a duplicate list update params definition that was somehow causing wrong param names * Add Swagger test to CI - updates Drone config - vendorizes go-swagger - fixes a file extension issue that caused the test script to generate JSON instead of YAML with the vendorized version * Put `Sample: ` on its own line everywhere * Remove unused id param from emojiCategoriesGet * Add 5 more pairs of profile fields to account update API Swagger * Remove Swagger prefix from dummy fields It makes the generated code look weird * Manually annotate params for statusCreate operation * Fix all remaining Swagger spec warnings - Change some models into operation parameters - Ignore models that already correspond to manually documented operation parameters but can't be trivially changed (those with file fields) * Documented that creating a status with scheduled_at isn't implemented yet * sign drone.yml * Fix filter API Swagger errors * fixup! Fix filter API Swagger errors --------- Co-authored-by: tobi <tobi.smethurst@protonmail.com>
This commit is contained in:
@ -21,10 +21,12 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
@ -427,6 +429,74 @@ func (suite *StatusCreateTestSuite) TestPostNewStatusWithNoncanonicalLanguageTag
|
||||
suite.Equal("en-US", *statusReply.Language)
|
||||
}
|
||||
|
||||
// Post a new status with an attached poll.
|
||||
func (suite *StatusCreateTestSuite) testPostNewStatusWithPoll(configure func(request *http.Request)) {
|
||||
t := suite.testTokens["local_account_1"]
|
||||
oauthToken := oauth.DBTokenToToken(t)
|
||||
|
||||
// setup
|
||||
recorder := httptest.NewRecorder()
|
||||
ctx, _ := testrig.CreateGinTestContext(recorder, nil)
|
||||
ctx.Set(oauth.SessionAuthorizedApplication, suite.testApplications["application_1"])
|
||||
ctx.Set(oauth.SessionAuthorizedToken, oauthToken)
|
||||
ctx.Set(oauth.SessionAuthorizedUser, suite.testUsers["local_account_1"])
|
||||
ctx.Set(oauth.SessionAuthorizedAccount, suite.testAccounts["local_account_1"])
|
||||
ctx.Request = httptest.NewRequest(http.MethodPost, fmt.Sprintf("http://localhost:8080/%s", statuses.BasePath), nil) // the endpoint we're hitting
|
||||
ctx.Request.Header.Set("accept", "application/json")
|
||||
configure(ctx.Request)
|
||||
suite.statusModule.StatusCreatePOSTHandler(ctx)
|
||||
|
||||
suite.EqualValues(http.StatusOK, recorder.Code)
|
||||
|
||||
result := recorder.Result()
|
||||
defer result.Body.Close()
|
||||
b, err := ioutil.ReadAll(result.Body)
|
||||
suite.NoError(err)
|
||||
|
||||
statusReply := &apimodel.Status{}
|
||||
err = json.Unmarshal(b, statusReply)
|
||||
suite.NoError(err)
|
||||
|
||||
suite.Equal("<p>this is a status with a poll!</p>", statusReply.Content)
|
||||
suite.Equal(apimodel.VisibilityPublic, statusReply.Visibility)
|
||||
if suite.NotNil(statusReply.Poll) {
|
||||
if suite.Len(statusReply.Poll.Options, 2) {
|
||||
suite.Equal("first option", statusReply.Poll.Options[0].Title)
|
||||
suite.Equal("second option", statusReply.Poll.Options[1].Title)
|
||||
}
|
||||
suite.NotZero(statusReply.Poll.ExpiresAt)
|
||||
suite.False(statusReply.Poll.Expired)
|
||||
suite.True(statusReply.Poll.Multiple)
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *StatusCreateTestSuite) TestPostNewStatusWithPollForm() {
|
||||
suite.testPostNewStatusWithPoll(func(request *http.Request) {
|
||||
request.Form = url.Values{
|
||||
"status": {"this is a status with a poll!"},
|
||||
"visibility": {"public"},
|
||||
"poll[options][]": {"first option", "second option"},
|
||||
"poll[expires_in]": {"3600"},
|
||||
"poll[multiple]": {"true"},
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (suite *StatusCreateTestSuite) TestPostNewStatusWithPollJSON() {
|
||||
suite.testPostNewStatusWithPoll(func(request *http.Request) {
|
||||
request.Header.Set("content-type", "application/json")
|
||||
request.Body = io.NopCloser(strings.NewReader(`{
|
||||
"status": "this is a status with a poll!",
|
||||
"visibility": "public",
|
||||
"poll": {
|
||||
"options": ["first option", "second option"],
|
||||
"expires_in": 3600,
|
||||
"multiple": true
|
||||
}
|
||||
}`))
|
||||
})
|
||||
}
|
||||
|
||||
func TestStatusCreateTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(StatusCreateTestSuite))
|
||||
}
|
||||
|
Reference in New Issue
Block a user