From f46583be48051fa7b31cfca1516b4b07cf315b30 Mon Sep 17 00:00:00 2001 From: ewin Date: Wed, 5 Mar 2025 15:15:34 -0500 Subject: [PATCH] Add test to ensure newly created statuses always have content type saved --- internal/processing/status/create_test.go | 36 +++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/internal/processing/status/create_test.go b/internal/processing/status/create_test.go index 16cefcebf..e0fa67bb5 100644 --- a/internal/processing/status/create_test.go +++ b/internal/processing/status/create_test.go @@ -238,6 +238,42 @@ func (suite *StatusCreateTestSuite) TestProcessReplyToUnthreadedRemoteStatus() { suite.NotEmpty(dbStatus.ThreadID) } +func (suite *StatusCreateTestSuite) TestProcessNoContentTypeUsesDefault() { + ctx := context.Background() + creatingAccount := suite.testAccounts["local_account_1"] + creatingApplication := suite.testApplications["application_1"] + + statusCreateForm := &apimodel.StatusCreateRequest{ + Status: "poopoo peepee", + SpoilerText: "", + MediaIDs: []string{}, + Poll: nil, + InReplyToID: "", + Sensitive: false, + Visibility: apimodel.VisibilityPublic, + LocalOnly: util.Ptr(false), + ScheduledAt: nil, + Language: "en", + ContentType: "", + } + + apiStatus, errWithCode := suite.status.Create(ctx, creatingAccount, creatingApplication, statusCreateForm) + suite.NoError(errWithCode) + suite.NotNil(apiStatus) + + suite.Equal("

poopoo peepee

", apiStatus.Content) + + // content type isn't actually returned when creating a + // status, so we have to fetch from the database to check + createdStatus, err := suite.state.DB.GetStatusByID(ctx, apiStatus.ID) + suite.NoError(err) + + // Check created 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, createdStatus.ContentType) +} + func TestStatusCreateTestSuite(t *testing.T) { suite.Run(t, new(StatusCreateTestSuite)) }