create_test.go (7053B)
1 // GoToSocial 2 // Copyright (C) GoToSocial Authors admin@gotosocial.org 3 // SPDX-License-Identifier: AGPL-3.0-or-later 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 package status_test 19 20 import ( 21 "context" 22 "testing" 23 24 "github.com/stretchr/testify/suite" 25 apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" 26 "github.com/superseriousbusiness/gotosocial/internal/config" 27 "github.com/superseriousbusiness/gotosocial/internal/db" 28 "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" 29 ) 30 31 type StatusCreateTestSuite struct { 32 StatusStandardTestSuite 33 } 34 35 func (suite *StatusCreateTestSuite) TestProcessContentWarningWithQuotationMarks() { 36 ctx := context.Background() 37 38 creatingAccount := suite.testAccounts["local_account_1"] 39 creatingApplication := suite.testApplications["application_1"] 40 41 statusCreateForm := &apimodel.AdvancedStatusCreateForm{ 42 StatusCreateRequest: apimodel.StatusCreateRequest{ 43 Status: "poopoo peepee", 44 MediaIDs: []string{}, 45 Poll: nil, 46 InReplyToID: "", 47 Sensitive: false, 48 SpoilerText: "\"test\"", // these should not be html-escaped when the final text is rendered 49 Visibility: apimodel.VisibilityPublic, 50 ScheduledAt: "", 51 Language: "en", 52 ContentType: apimodel.StatusContentTypePlain, 53 }, 54 AdvancedVisibilityFlagsForm: apimodel.AdvancedVisibilityFlagsForm{ 55 Federated: nil, 56 Boostable: nil, 57 Replyable: nil, 58 Likeable: nil, 59 }, 60 } 61 62 apiStatus, err := suite.status.Create(ctx, creatingAccount, creatingApplication, statusCreateForm) 63 suite.NoError(err) 64 suite.NotNil(apiStatus) 65 66 suite.Equal("\"test\"", apiStatus.SpoilerText) 67 } 68 69 func (suite *StatusCreateTestSuite) TestProcessContentWarningWithHTMLEscapedQuotationMarks() { 70 ctx := context.Background() 71 72 creatingAccount := suite.testAccounts["local_account_1"] 73 creatingApplication := suite.testApplications["application_1"] 74 75 statusCreateForm := &apimodel.AdvancedStatusCreateForm{ 76 StatusCreateRequest: apimodel.StatusCreateRequest{ 77 Status: "poopoo peepee", 78 MediaIDs: []string{}, 79 Poll: nil, 80 InReplyToID: "", 81 Sensitive: false, 82 SpoilerText: ""test"", // the html-escaped quotation marks should appear as normal quotation marks in the finished text 83 Visibility: apimodel.VisibilityPublic, 84 ScheduledAt: "", 85 Language: "en", 86 ContentType: apimodel.StatusContentTypePlain, 87 }, 88 AdvancedVisibilityFlagsForm: apimodel.AdvancedVisibilityFlagsForm{ 89 Federated: nil, 90 Boostable: nil, 91 Replyable: nil, 92 Likeable: nil, 93 }, 94 } 95 96 apiStatus, err := suite.status.Create(ctx, creatingAccount, creatingApplication, statusCreateForm) 97 suite.NoError(err) 98 suite.NotNil(apiStatus) 99 100 suite.Equal("\"test\"", apiStatus.SpoilerText) 101 } 102 103 func (suite *StatusCreateTestSuite) TestProcessStatusMarkdownWithUnderscoreEmoji() { 104 ctx := context.Background() 105 106 // update the shortcode of the rainbow emoji to surround it in underscores 107 if err := suite.db.UpdateWhere(ctx, []db.Where{{Key: "shortcode", Value: "rainbow"}}, "shortcode", "_rainbow_", >smodel.Emoji{}); err != nil { 108 suite.FailNow(err.Error()) 109 } 110 111 creatingAccount := suite.testAccounts["local_account_1"] 112 creatingApplication := suite.testApplications["application_1"] 113 114 statusCreateForm := &apimodel.AdvancedStatusCreateForm{ 115 StatusCreateRequest: apimodel.StatusCreateRequest{ 116 Status: "poopoo peepee :_rainbow_:", 117 MediaIDs: []string{}, 118 Poll: nil, 119 InReplyToID: "", 120 Sensitive: false, 121 Visibility: apimodel.VisibilityPublic, 122 ScheduledAt: "", 123 Language: "en", 124 ContentType: apimodel.StatusContentTypeMarkdown, 125 }, 126 AdvancedVisibilityFlagsForm: apimodel.AdvancedVisibilityFlagsForm{ 127 Federated: nil, 128 Boostable: nil, 129 Replyable: nil, 130 Likeable: nil, 131 }, 132 } 133 134 apiStatus, err := suite.status.Create(ctx, creatingAccount, creatingApplication, statusCreateForm) 135 suite.NoError(err) 136 suite.NotNil(apiStatus) 137 138 suite.Equal("<p>poopoo peepee :_rainbow_:</p>", apiStatus.Content) 139 suite.NotEmpty(apiStatus.Emojis) 140 } 141 142 func (suite *StatusCreateTestSuite) TestProcessStatusMarkdownWithSpoilerTextEmoji() { 143 ctx := context.Background() 144 creatingAccount := suite.testAccounts["local_account_1"] 145 creatingApplication := suite.testApplications["application_1"] 146 147 statusCreateForm := &apimodel.AdvancedStatusCreateForm{ 148 StatusCreateRequest: apimodel.StatusCreateRequest{ 149 Status: "poopoo peepee", 150 SpoilerText: "testing something :rainbow:", 151 MediaIDs: []string{}, 152 Poll: nil, 153 InReplyToID: "", 154 Sensitive: false, 155 Visibility: apimodel.VisibilityPublic, 156 ScheduledAt: "", 157 Language: "en", 158 ContentType: apimodel.StatusContentTypeMarkdown, 159 }, 160 AdvancedVisibilityFlagsForm: apimodel.AdvancedVisibilityFlagsForm{ 161 Federated: nil, 162 Boostable: nil, 163 Replyable: nil, 164 Likeable: nil, 165 }, 166 } 167 168 apiStatus, err := suite.status.Create(ctx, creatingAccount, creatingApplication, statusCreateForm) 169 suite.NoError(err) 170 suite.NotNil(apiStatus) 171 172 suite.Equal("<p>poopoo peepee</p>", apiStatus.Content) 173 suite.Equal("testing something :rainbow:", apiStatus.SpoilerText) 174 suite.NotEmpty(apiStatus.Emojis) 175 } 176 177 func (suite *StatusCreateTestSuite) TestProcessMediaDescriptionTooShort() { 178 ctx := context.Background() 179 180 config.SetMediaDescriptionMinChars(100) 181 182 creatingAccount := suite.testAccounts["local_account_1"] 183 creatingApplication := suite.testApplications["application_1"] 184 185 statusCreateForm := &apimodel.AdvancedStatusCreateForm{ 186 StatusCreateRequest: apimodel.StatusCreateRequest{ 187 Status: "poopoo peepee", 188 MediaIDs: []string{suite.testAttachments["local_account_1_unattached_1"].ID}, 189 Poll: nil, 190 InReplyToID: "", 191 Sensitive: false, 192 SpoilerText: "", 193 Visibility: apimodel.VisibilityPublic, 194 ScheduledAt: "", 195 Language: "en", 196 ContentType: apimodel.StatusContentTypePlain, 197 }, 198 AdvancedVisibilityFlagsForm: apimodel.AdvancedVisibilityFlagsForm{ 199 Federated: nil, 200 Boostable: nil, 201 Replyable: nil, 202 Likeable: nil, 203 }, 204 } 205 206 apiStatus, err := suite.status.Create(ctx, creatingAccount, creatingApplication, statusCreateForm) 207 suite.EqualError(err, "ProcessMediaIDs: description too short! media description of at least 100 chararacters is required but 15 was provided for media with id 01F8MH8RMYQ6MSNY3JM2XT1CQ5") 208 suite.Nil(apiStatus) 209 } 210 211 func TestStatusCreateTestSuite(t *testing.T) { 212 suite.Run(t, new(StatusCreateTestSuite)) 213 }