2023-10-25 16:04:53 +02:00
|
|
|
// 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"
|
|
|
|
apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/testrig"
|
|
|
|
)
|
|
|
|
|
|
|
|
type StatusMuteTestSuite struct {
|
|
|
|
StatusStandardTestSuite
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *StatusMuteTestSuite) post(path string, handler func(*gin.Context), targetStatusID string) (int, string) {
|
|
|
|
t := suite.testTokens["local_account_1"]
|
|
|
|
oauthToken := oauth.DBTokenToToken(t)
|
|
|
|
|
|
|
|
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, path, nil) // the endpoint we're hitting
|
|
|
|
ctx.Request.Header.Set("accept", "application/json")
|
|
|
|
|
|
|
|
// normally the router would populate these params from the path values,
|
|
|
|
// but because we're calling the function directly, we need to set them manually.
|
|
|
|
ctx.Params = gin.Params{
|
|
|
|
gin.Param{
|
|
|
|
Key: apiutil.IDKey,
|
|
|
|
Value: targetStatusID,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
handler(ctx)
|
|
|
|
|
|
|
|
result := recorder.Result()
|
|
|
|
defer result.Body.Close()
|
|
|
|
|
|
|
|
b, err := io.ReadAll(result.Body)
|
|
|
|
if err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
indented := bytes.Buffer{}
|
|
|
|
if err := json.Indent(&indented, b, "", " "); err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return recorder.Code, indented.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *StatusMuteTestSuite) TestMuteUnmuteStatus() {
|
|
|
|
var (
|
|
|
|
targetStatus = suite.testStatuses["local_account_1_status_1"]
|
|
|
|
path = fmt.Sprintf("http://localhost:8080/api%s", strings.ReplaceAll(statuses.MutePath, ":id", targetStatus.ID))
|
|
|
|
)
|
|
|
|
|
|
|
|
// Mute the status, ensure `muted` is `true`.
|
|
|
|
code, muted := suite.post(path, suite.statusModule.StatusMutePOSTHandler, targetStatus.ID)
|
|
|
|
suite.Equal(http.StatusOK, code)
|
|
|
|
suite.Equal(`{
|
|
|
|
"id": "01F8MHAMCHF6Y650WCRSCP4WMY",
|
|
|
|
"created_at": "2021-10-20T10:40:37.000Z",
|
2024-12-05 14:35:07 +01:00
|
|
|
"edited_at": null,
|
2023-10-25 16:04:53 +02:00
|
|
|
"in_reply_to_id": null,
|
|
|
|
"in_reply_to_account_id": null,
|
|
|
|
"sensitive": true,
|
|
|
|
"spoiler_text": "introduction post",
|
|
|
|
"visibility": "public",
|
|
|
|
"language": "en",
|
|
|
|
"uri": "http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY",
|
|
|
|
"url": "http://localhost:8080/@the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY",
|
|
|
|
"replies_count": 2,
|
|
|
|
"reblogs_count": 1,
|
|
|
|
"favourites_count": 1,
|
|
|
|
"favourited": false,
|
|
|
|
"reblogged": false,
|
|
|
|
"muted": true,
|
|
|
|
"bookmarked": false,
|
|
|
|
"pinned": false,
|
|
|
|
"content": "hello everyone!",
|
|
|
|
"reblog": null,
|
|
|
|
"application": {
|
|
|
|
"name": "really cool gts application",
|
|
|
|
"website": "https://reallycool.app"
|
|
|
|
},
|
|
|
|
"account": {
|
|
|
|
"id": "01F8MH1H7YV1Z7D2C8K2730QBF",
|
|
|
|
"username": "the_mighty_zork",
|
|
|
|
"acct": "the_mighty_zork",
|
|
|
|
"display_name": "original zork (he/they)",
|
|
|
|
"locked": false,
|
|
|
|
"discoverable": true,
|
|
|
|
"bot": false,
|
|
|
|
"created_at": "2022-05-20T11:09:18.000Z",
|
|
|
|
"note": "\u003cp\u003ehey yo this is my profile!\u003c/p\u003e",
|
|
|
|
"url": "http://localhost:8080/@the_mighty_zork",
|
|
|
|
"avatar": "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/avatar/original/01F8MH58A357CV5K7R7TJMSH6S.jpg",
|
2024-07-19 17:28:43 +02:00
|
|
|
"avatar_static": "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/avatar/small/01F8MH58A357CV5K7R7TJMSH6S.webp",
|
2024-07-08 15:47:03 +02:00
|
|
|
"avatar_description": "a green goblin looking nasty",
|
2024-10-21 14:04:50 +02:00
|
|
|
"avatar_media_id": "01F8MH58A357CV5K7R7TJMSH6S",
|
2023-10-25 16:04:53 +02:00
|
|
|
"header": "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/header/original/01PFPMWK2FF0D9WMHEJHR07C3Q.jpg",
|
2024-07-19 17:28:43 +02:00
|
|
|
"header_static": "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/header/small/01PFPMWK2FF0D9WMHEJHR07C3Q.webp",
|
2024-07-08 15:47:03 +02:00
|
|
|
"header_description": "A very old-school screenshot of the original team fortress mod for quake",
|
2024-10-21 14:04:50 +02:00
|
|
|
"header_media_id": "01PFPMWK2FF0D9WMHEJHR07C3Q",
|
2023-10-25 16:04:53 +02:00
|
|
|
"followers_count": 2,
|
|
|
|
"following_count": 2,
|
2024-12-05 14:35:07 +01:00
|
|
|
"statuses_count": 9,
|
|
|
|
"last_status_at": "2024-11-01",
|
2023-10-25 16:04:53 +02:00
|
|
|
"emojis": [],
|
|
|
|
"fields": [],
|
2024-07-31 18:26:09 +02:00
|
|
|
"enable_rss": true
|
2023-10-25 16:04:53 +02:00
|
|
|
},
|
|
|
|
"media_attachments": [],
|
|
|
|
"mentions": [],
|
|
|
|
"tags": [],
|
|
|
|
"emojis": [],
|
|
|
|
"card": null,
|
|
|
|
"poll": null,
|
2024-07-17 16:46:52 +02:00
|
|
|
"text": "hello everyone!",
|
|
|
|
"interaction_policy": {
|
|
|
|
"can_favourite": {
|
|
|
|
"always": [
|
2024-07-24 13:27:42 +02:00
|
|
|
"public",
|
|
|
|
"me"
|
2024-07-17 16:46:52 +02:00
|
|
|
],
|
|
|
|
"with_approval": []
|
|
|
|
},
|
|
|
|
"can_reply": {
|
|
|
|
"always": [
|
2024-07-24 13:27:42 +02:00
|
|
|
"public",
|
|
|
|
"me"
|
2024-07-17 16:46:52 +02:00
|
|
|
],
|
|
|
|
"with_approval": []
|
|
|
|
},
|
|
|
|
"can_reblog": {
|
|
|
|
"always": [
|
2024-07-24 13:27:42 +02:00
|
|
|
"public",
|
|
|
|
"me"
|
2024-07-17 16:46:52 +02:00
|
|
|
],
|
|
|
|
"with_approval": []
|
|
|
|
}
|
|
|
|
}
|
2023-10-25 16:04:53 +02:00
|
|
|
}`, muted)
|
|
|
|
|
|
|
|
// Unmute the status, ensure `muted` is `false`.
|
|
|
|
code, unmuted := suite.post(path, suite.statusModule.StatusUnmutePOSTHandler, targetStatus.ID)
|
|
|
|
suite.Equal(http.StatusOK, code)
|
|
|
|
suite.Equal(`{
|
|
|
|
"id": "01F8MHAMCHF6Y650WCRSCP4WMY",
|
|
|
|
"created_at": "2021-10-20T10:40:37.000Z",
|
2024-12-05 14:35:07 +01:00
|
|
|
"edited_at": null,
|
2023-10-25 16:04:53 +02:00
|
|
|
"in_reply_to_id": null,
|
|
|
|
"in_reply_to_account_id": null,
|
|
|
|
"sensitive": true,
|
|
|
|
"spoiler_text": "introduction post",
|
|
|
|
"visibility": "public",
|
|
|
|
"language": "en",
|
|
|
|
"uri": "http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY",
|
|
|
|
"url": "http://localhost:8080/@the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY",
|
|
|
|
"replies_count": 2,
|
|
|
|
"reblogs_count": 1,
|
|
|
|
"favourites_count": 1,
|
|
|
|
"favourited": false,
|
|
|
|
"reblogged": false,
|
|
|
|
"muted": false,
|
|
|
|
"bookmarked": false,
|
|
|
|
"pinned": false,
|
|
|
|
"content": "hello everyone!",
|
|
|
|
"reblog": null,
|
|
|
|
"application": {
|
|
|
|
"name": "really cool gts application",
|
|
|
|
"website": "https://reallycool.app"
|
|
|
|
},
|
|
|
|
"account": {
|
|
|
|
"id": "01F8MH1H7YV1Z7D2C8K2730QBF",
|
|
|
|
"username": "the_mighty_zork",
|
|
|
|
"acct": "the_mighty_zork",
|
|
|
|
"display_name": "original zork (he/they)",
|
|
|
|
"locked": false,
|
|
|
|
"discoverable": true,
|
|
|
|
"bot": false,
|
|
|
|
"created_at": "2022-05-20T11:09:18.000Z",
|
|
|
|
"note": "\u003cp\u003ehey yo this is my profile!\u003c/p\u003e",
|
|
|
|
"url": "http://localhost:8080/@the_mighty_zork",
|
|
|
|
"avatar": "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/avatar/original/01F8MH58A357CV5K7R7TJMSH6S.jpg",
|
2024-07-19 17:28:43 +02:00
|
|
|
"avatar_static": "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/avatar/small/01F8MH58A357CV5K7R7TJMSH6S.webp",
|
2024-07-08 15:47:03 +02:00
|
|
|
"avatar_description": "a green goblin looking nasty",
|
2024-10-21 14:04:50 +02:00
|
|
|
"avatar_media_id": "01F8MH58A357CV5K7R7TJMSH6S",
|
2023-10-25 16:04:53 +02:00
|
|
|
"header": "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/header/original/01PFPMWK2FF0D9WMHEJHR07C3Q.jpg",
|
2024-07-19 17:28:43 +02:00
|
|
|
"header_static": "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/header/small/01PFPMWK2FF0D9WMHEJHR07C3Q.webp",
|
2024-07-08 15:47:03 +02:00
|
|
|
"header_description": "A very old-school screenshot of the original team fortress mod for quake",
|
2024-10-21 14:04:50 +02:00
|
|
|
"header_media_id": "01PFPMWK2FF0D9WMHEJHR07C3Q",
|
2023-10-25 16:04:53 +02:00
|
|
|
"followers_count": 2,
|
|
|
|
"following_count": 2,
|
2024-12-05 14:35:07 +01:00
|
|
|
"statuses_count": 9,
|
|
|
|
"last_status_at": "2024-11-01",
|
2023-10-25 16:04:53 +02:00
|
|
|
"emojis": [],
|
|
|
|
"fields": [],
|
2024-07-31 18:26:09 +02:00
|
|
|
"enable_rss": true
|
2023-10-25 16:04:53 +02:00
|
|
|
},
|
|
|
|
"media_attachments": [],
|
|
|
|
"mentions": [],
|
|
|
|
"tags": [],
|
|
|
|
"emojis": [],
|
|
|
|
"card": null,
|
|
|
|
"poll": null,
|
2024-07-17 16:46:52 +02:00
|
|
|
"text": "hello everyone!",
|
|
|
|
"interaction_policy": {
|
|
|
|
"can_favourite": {
|
|
|
|
"always": [
|
2024-07-24 13:27:42 +02:00
|
|
|
"public",
|
|
|
|
"me"
|
2024-07-17 16:46:52 +02:00
|
|
|
],
|
|
|
|
"with_approval": []
|
|
|
|
},
|
|
|
|
"can_reply": {
|
|
|
|
"always": [
|
2024-07-24 13:27:42 +02:00
|
|
|
"public",
|
|
|
|
"me"
|
2024-07-17 16:46:52 +02:00
|
|
|
],
|
|
|
|
"with_approval": []
|
|
|
|
},
|
|
|
|
"can_reblog": {
|
|
|
|
"always": [
|
2024-07-24 13:27:42 +02:00
|
|
|
"public",
|
|
|
|
"me"
|
2024-07-17 16:46:52 +02:00
|
|
|
],
|
|
|
|
"with_approval": []
|
|
|
|
}
|
|
|
|
}
|
2023-10-25 16:04:53 +02:00
|
|
|
}`, unmuted)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStatusMuteTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(StatusMuteTestSuite))
|
|
|
|
}
|