diff options
author | 2024-03-06 09:05:45 -0800 | |
---|---|---|
committer | 2024-03-06 18:05:45 +0100 | |
commit | fc3741365c27f1d703e8a736af95b95ff811cc45 (patch) | |
tree | 929f1d5e20d1469d63a3dfe81d38d89f9a073c5a /internal/api/client/statuses | |
parent | [chore/bugfix] Little DB fixes (#2726) (diff) | |
download | gotosocial-fc3741365c27f1d703e8a736af95b95ff811cc45.tar.xz |
[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>
Diffstat (limited to 'internal/api/client/statuses')
-rw-r--r-- | internal/api/client/statuses/statuscreate.go | 139 | ||||
-rw-r--r-- | internal/api/client/statuses/statuscreate_test.go | 70 |
2 files changed, 209 insertions, 0 deletions
diff --git a/internal/api/client/statuses/statuscreate.go b/internal/api/client/statuses/statuscreate.go index 929adaa6f..efbe79223 100644 --- a/internal/api/client/statuses/statuscreate.go +++ b/internal/api/client/statuses/statuscreate.go @@ -48,6 +48,145 @@ import ( // - application/xml // - application/x-www-form-urlencoded // +// parameters: +// - +// name: status +// x-go-name: Status +// description: |- +// Text content of the status. +// If media_ids is provided, this becomes optional. +// Attaching a poll is optional while status is provided. +// type: string +// in: formData +// - +// name: media_ids +// x-go-name: MediaIDs +// description: |- +// Array of Attachment ids to be attached as media. +// If provided, status becomes optional, and poll cannot be used. +// +// If the status is being submitted as a form, the key is 'media_ids[]', +// but if it's json or xml, the key is 'media_ids'. +// type: array +// items: +// type: string +// in: formData +// - +// name: poll[options][] +// x-go-name: PollOptions +// description: |- +// Array of possible poll answers. +// If provided, media_ids cannot be used, and poll[expires_in] must be provided. +// type: array +// items: +// type: string +// in: formData +// - +// name: poll[expires_in] +// x-go-name: PollExpiresIn +// description: |- +// Duration the poll should be open, in seconds. +// If provided, media_ids cannot be used, and poll[options] must be provided. +// type: integer +// format: int64 +// in: formData +// - +// name: poll[multiple] +// x-go-name: PollMultiple +// description: Allow multiple choices on this poll. +// type: boolean +// default: false +// in: formData +// - +// name: poll[hide_totals] +// x-go-name: PollHideTotals +// description: Hide vote counts until the poll ends. +// type: boolean +// default: true +// in: formData +// - +// name: in_reply_to_id +// x-go-name: InReplyToID +// description: ID of the status being replied to, if status is a reply. +// type: string +// in: formData +// - +// name: sensitive +// x-go-name: Sensitive +// description: Status and attached media should be marked as sensitive. +// type: boolean +// in: formData +// - +// name: spoiler_text +// x-go-name: SpoilerText +// description: |- +// Text to be shown as a warning or subject before the actual content. +// Statuses are generally collapsed behind this field. +// type: string +// in: formData +// - +// name: visibility +// x-go-name: Visibility +// description: Visibility of the posted status. +// type: string +// enum: +// - public +// - unlisted +// - private +// - mutuals_only +// - direct +// in: formData +// - +// name: scheduled_at +// x-go-name: ScheduledAt +// description: |- +// ISO 8601 Datetime at which to schedule a status. +// Providing this parameter will cause ScheduledStatus to be returned instead of Status. +// Must be at least 5 minutes in the future. +// +// This feature isn't implemented yet. +// type: string +// in: formData +// - +// name: language +// x-go-name: Language +// description: ISO 639 language code for this status. +// type: string +// in: formData +// - +// name: content_type +// x-go-name: ContentType +// description: Content type to use when parsing this status. +// type: string +// enum: +// - text/plain +// - text/markdown +// in: formData +// - +// name: federated +// x-go-name: Federated +// description: This status will be federated beyond the local timeline(s). +// in: formData +// type: boolean +// - +// name: boostable +// x-go-name: Boostable +// description: This status can be boosted/reblogged. +// in: formData +// type: boolean +// - +// name: replyable +// x-go-name: Replyable +// description: This status can be replied to. +// in: formData +// type: boolean +// - +// name: likeable +// x-go-name: Likeable +// description: This status can be liked/faved. +// in: formData +// type: boolean +// // produces: // - application/json // diff --git a/internal/api/client/statuses/statuscreate_test.go b/internal/api/client/statuses/statuscreate_test.go index 881943450..ab7c67abf 100644 --- a/internal/api/client/statuses/statuscreate_test.go +++ b/internal/api/client/statuses/statuscreate_test.go @@ -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)) } |