mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-22 21:06:14 -06:00
Add test for handling of statuses with no stored content type
This commit is contained in:
parent
921ba6481b
commit
e02eb78cec
2 changed files with 91 additions and 0 deletions
|
|
@ -161,6 +161,71 @@ func (suite *StatusEditTestSuite) TestEditChangeContentType() {
|
|||
suite.Equal(status.UpdatedAt(), previousEdit.CreatedAt)
|
||||
}
|
||||
|
||||
func (suite *StatusEditTestSuite) TestEditOnStatusWithNoContentType() {
|
||||
// Create cancellable context to use for test.
|
||||
ctx, cncl := context.WithCancel(context.Background())
|
||||
defer cncl()
|
||||
|
||||
// Get a local account to use as test requester.
|
||||
requester := suite.testAccounts["local_account_1"]
|
||||
requester, _ = suite.state.DB.GetAccountByID(ctx, requester.ID)
|
||||
|
||||
// Get requester's existing status, which has no
|
||||
// stored content type, to perform an edit on.
|
||||
status := suite.testStatuses["local_account_1_status_10"]
|
||||
status, _ = suite.state.DB.GetStatusByID(ctx, status.ID)
|
||||
|
||||
// Prepare edit without setting a new content type.
|
||||
form := &apimodel.StatusEditRequest{
|
||||
Status: "how will this text be parsed? it is a mystery",
|
||||
SpoilerText: "shhhhh",
|
||||
Sensitive: true,
|
||||
Language: "fr", // hoh hoh hoh
|
||||
MediaIDs: nil,
|
||||
MediaAttributes: nil,
|
||||
Poll: nil,
|
||||
}
|
||||
|
||||
// Pass the prepared form to the status processor to perform the edit.
|
||||
apiStatus, errWithCode := suite.status.Edit(ctx, requester, status.ID, form)
|
||||
suite.NotNil(apiStatus)
|
||||
suite.NoError(errWithCode)
|
||||
|
||||
// Check response against input form data.
|
||||
suite.Equal(form.Status, apiStatus.Text)
|
||||
suite.NotEqual(util.FormatISO8601(status.EditedAt), *apiStatus.EditedAt)
|
||||
|
||||
// Fetched the latest version of edited status from the database.
|
||||
latestStatus, err := suite.state.DB.GetStatusByID(ctx, status.ID)
|
||||
suite.NoError(err)
|
||||
|
||||
// Check latest status against input form data
|
||||
suite.Equal(form.Status, latestStatus.Text)
|
||||
suite.Equal(form.Sensitive, *latestStatus.Sensitive)
|
||||
suite.Equal(form.Language, latestStatus.Language)
|
||||
suite.Equal(len(status.EditIDs)+1, len(latestStatus.EditIDs))
|
||||
suite.NotEqual(status.UpdatedAt(), latestStatus.UpdatedAt())
|
||||
|
||||
// Check latest status against requester's default content type
|
||||
// setting (the test accounts don't actually have settings on them,
|
||||
// so instead we check that the global default content type is used)
|
||||
suite.Equal(gtsmodel.StatusContentTypeDefault, latestStatus.ContentType)
|
||||
|
||||
// Populate all historical edits for this status.
|
||||
err = suite.state.DB.PopulateStatusEdits(ctx, latestStatus)
|
||||
suite.NoError(err)
|
||||
|
||||
// Check previous status edit matches original status content.
|
||||
previousEdit := latestStatus.Edits[len(latestStatus.Edits)-1]
|
||||
suite.Equal(status.Content, previousEdit.Content)
|
||||
suite.Equal(status.Text, previousEdit.Text)
|
||||
suite.Equal(status.ContentType, previousEdit.ContentType)
|
||||
suite.Equal(status.ContentWarning, previousEdit.ContentWarning)
|
||||
suite.Equal(*status.Sensitive, *previousEdit.Sensitive)
|
||||
suite.Equal(status.Language, previousEdit.Language)
|
||||
suite.Equal(status.UpdatedAt(), previousEdit.CreatedAt)
|
||||
}
|
||||
|
||||
func (suite *StatusEditTestSuite) TestEditAddPoll() {
|
||||
// Create cancellable context to use for test.
|
||||
ctx, cncl := context.WithCancel(context.Background())
|
||||
|
|
|
|||
|
|
@ -1765,6 +1765,32 @@ func NewTestStatuses() map[string]*gtsmodel.Status {
|
|||
Federated: util.Ptr(true),
|
||||
ActivityStreamsType: ap.ObjectNote,
|
||||
},
|
||||
"local_account_1_status_10": {
|
||||
ID: "01JNKTFJCF6494E5MRR8GN47NA",
|
||||
URI: "http://localhost:8080/users/the_mighty_zork/statuses/01JNKTFJCF6494E5MRR8GN47NA",
|
||||
URL: "http://localhost:8080/@the_mighty_zork/statuses/01JNKTFJCF6494E5MRR8GN47NA",
|
||||
Content: "<p>I am an old post with no content type stored</p>",
|
||||
Text: "I am an old post with no content type stored",
|
||||
ContentType: 0,
|
||||
ContentWarning: "edited status",
|
||||
AttachmentIDs: nil,
|
||||
CreatedAt: TimeMustParse("2025-03-05T13:53:24.239-05:00"),
|
||||
EditedAt: TimeMustParse("2025-03-05T13:53:24.239-05:00"),
|
||||
Local: util.Ptr(true),
|
||||
AccountURI: "http://localhost:8080/users/the_mighty_zork",
|
||||
AccountID: "01F8MH1H7YV1Z7D2C8K2730QBF",
|
||||
InReplyToID: "",
|
||||
InReplyToAccountID: "",
|
||||
InReplyToURI: "",
|
||||
BoostOfID: "",
|
||||
ThreadID: "",
|
||||
Visibility: gtsmodel.VisibilityPublic,
|
||||
Sensitive: util.Ptr(false),
|
||||
Language: "en",
|
||||
CreatedWithApplicationID: "01F8MGY43H3N2C8EWPR2FPYEXG",
|
||||
Federated: util.Ptr(true),
|
||||
ActivityStreamsType: ap.ObjectNote,
|
||||
},
|
||||
"local_account_2_status_1": {
|
||||
ID: "01F8MHBQCBTDKN6X5VHGMMN4MA",
|
||||
URI: "http://localhost:8080/users/1happyturtle/statuses/01F8MHBQCBTDKN6X5VHGMMN4MA",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue