summaryrefslogtreecommitdiff
path: root/internal/typeutils/internaltofrontend_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/typeutils/internaltofrontend_test.go')
-rw-r--r--internal/typeutils/internaltofrontend_test.go63
1 files changed, 60 insertions, 3 deletions
diff --git a/internal/typeutils/internaltofrontend_test.go b/internal/typeutils/internaltofrontend_test.go
index 946e38b30..16dc27c87 100644
--- a/internal/typeutils/internaltofrontend_test.go
+++ b/internal/typeutils/internaltofrontend_test.go
@@ -26,7 +26,9 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
statusfilter "github.com/superseriousbusiness/gotosocial/internal/filter/status"
+ "github.com/superseriousbusiness/gotosocial/internal/filter/usermute"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/internal/util"
"github.com/superseriousbusiness/gotosocial/testrig"
)
@@ -428,7 +430,7 @@ func (suite *InternalToFrontendTestSuite) TestLocalInstanceAccountToFrontendBloc
func (suite *InternalToFrontendTestSuite) TestStatusToFrontend() {
testStatus := suite.testStatuses["admin_account_status_1"]
requestingAccount := suite.testAccounts["local_account_1"]
- apiStatus, err := suite.typeconverter.StatusToAPIStatus(context.Background(), testStatus, requestingAccount, statusfilter.FilterContextNone, nil)
+ apiStatus, err := suite.typeconverter.StatusToAPIStatus(context.Background(), testStatus, requestingAccount, statusfilter.FilterContextNone, nil, nil)
suite.NoError(err)
b, err := json.MarshalIndent(apiStatus, "", " ")
@@ -556,6 +558,7 @@ func (suite *InternalToFrontendTestSuite) TestWarnFilteredStatusToFrontend() {
requestingAccount,
statusfilter.FilterContextHome,
requestingAccountFilters,
+ nil,
)
suite.NoError(err)
@@ -711,6 +714,60 @@ func (suite *InternalToFrontendTestSuite) TestHideFilteredStatusToFrontend() {
requestingAccount,
statusfilter.FilterContextHome,
requestingAccountFilters,
+ nil,
+ )
+ suite.ErrorIs(err, statusfilter.ErrHideStatus)
+}
+
+// Test that a status from a user muted by the requesting user results in the ErrHideStatus error.
+func (suite *InternalToFrontendTestSuite) TestMutedStatusToFrontend() {
+ testStatus := suite.testStatuses["admin_account_status_1"]
+ requestingAccount := suite.testAccounts["local_account_1"]
+ mutes := usermute.NewCompiledUserMuteList([]*gtsmodel.UserMute{
+ {
+ AccountID: requestingAccount.ID,
+ TargetAccountID: testStatus.AccountID,
+ Notifications: util.Ptr(false),
+ },
+ })
+ _, err := suite.typeconverter.StatusToAPIStatus(
+ context.Background(),
+ testStatus,
+ requestingAccount,
+ statusfilter.FilterContextHome,
+ nil,
+ mutes,
+ )
+ suite.ErrorIs(err, statusfilter.ErrHideStatus)
+}
+
+// Test that a status replying to a user muted by the requesting user results in the ErrHideStatus error.
+func (suite *InternalToFrontendTestSuite) TestMutedReplyStatusToFrontend() {
+ mutedAccount := suite.testAccounts["local_account_2"]
+ testStatus := suite.testStatuses["admin_account_status_1"]
+ testStatus.InReplyToID = suite.testStatuses["local_account_2_status_1"].ID
+ testStatus.InReplyToAccountID = mutedAccount.ID
+ requestingAccount := suite.testAccounts["local_account_1"]
+ mutes := usermute.NewCompiledUserMuteList([]*gtsmodel.UserMute{
+ {
+ AccountID: requestingAccount.ID,
+ TargetAccountID: mutedAccount.ID,
+ Notifications: util.Ptr(false),
+ },
+ })
+ // Populate status so the converter has the account objects it needs for muting.
+ err := suite.db.PopulateStatus(context.Background(), testStatus)
+ if err != nil {
+ suite.FailNow(err.Error())
+ }
+ // Convert the status to API format, which should fail.
+ _, err = suite.typeconverter.StatusToAPIStatus(
+ context.Background(),
+ testStatus,
+ requestingAccount,
+ statusfilter.FilterContextHome,
+ nil,
+ mutes,
)
suite.ErrorIs(err, statusfilter.ErrHideStatus)
}
@@ -719,7 +776,7 @@ func (suite *InternalToFrontendTestSuite) TestStatusToFrontendUnknownAttachments
testStatus := suite.testStatuses["remote_account_2_status_1"]
requestingAccount := suite.testAccounts["admin_account"]
- apiStatus, err := suite.typeconverter.StatusToAPIStatus(context.Background(), testStatus, requestingAccount, statusfilter.FilterContextNone, nil)
+ apiStatus, err := suite.typeconverter.StatusToAPIStatus(context.Background(), testStatus, requestingAccount, statusfilter.FilterContextNone, nil, nil)
suite.NoError(err)
b, err := json.MarshalIndent(apiStatus, "", " ")
@@ -952,7 +1009,7 @@ func (suite *InternalToFrontendTestSuite) TestStatusToFrontendUnknownLanguage()
*testStatus = *suite.testStatuses["admin_account_status_1"]
testStatus.Language = ""
requestingAccount := suite.testAccounts["local_account_1"]
- apiStatus, err := suite.typeconverter.StatusToAPIStatus(context.Background(), testStatus, requestingAccount, statusfilter.FilterContextNone, nil)
+ apiStatus, err := suite.typeconverter.StatusToAPIStatus(context.Background(), testStatus, requestingAccount, statusfilter.FilterContextNone, nil, nil)
suite.NoError(err)
b, err := json.MarshalIndent(apiStatus, "", " ")