gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

status_test.go (5375B)


      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 visibility_test
     19 
     20 import (
     21 	"context"
     22 	"testing"
     23 
     24 	"github.com/stretchr/testify/suite"
     25 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
     26 )
     27 
     28 type StatusVisibleTestSuite struct {
     29 	FilterStandardTestSuite
     30 }
     31 
     32 func (suite *StatusVisibleTestSuite) TestOwnStatusVisible() {
     33 	testStatus := suite.testStatuses["local_account_1_status_1"]
     34 	testAccount := suite.testAccounts["local_account_1"]
     35 	ctx := context.Background()
     36 
     37 	visible, err := suite.filter.StatusVisible(ctx, testAccount, testStatus)
     38 	suite.NoError(err)
     39 
     40 	suite.True(visible)
     41 }
     42 
     43 func (suite *StatusVisibleTestSuite) TestOwnDMVisible() {
     44 	ctx := context.Background()
     45 
     46 	testStatusID := suite.testStatuses["local_account_2_status_6"].ID
     47 	testStatus, err := suite.db.GetStatusByID(ctx, testStatusID)
     48 	suite.NoError(err)
     49 	testAccount := suite.testAccounts["local_account_2"]
     50 
     51 	visible, err := suite.filter.StatusVisible(ctx, testAccount, testStatus)
     52 	suite.NoError(err)
     53 
     54 	suite.True(visible)
     55 }
     56 
     57 func (suite *StatusVisibleTestSuite) TestDMVisibleToTarget() {
     58 	ctx := context.Background()
     59 
     60 	testStatusID := suite.testStatuses["local_account_2_status_6"].ID
     61 	testStatus, err := suite.db.GetStatusByID(ctx, testStatusID)
     62 	suite.NoError(err)
     63 	testAccount := suite.testAccounts["local_account_1"]
     64 
     65 	visible, err := suite.filter.StatusVisible(ctx, testAccount, testStatus)
     66 	suite.NoError(err)
     67 
     68 	suite.True(visible)
     69 }
     70 
     71 func (suite *StatusVisibleTestSuite) TestDMNotVisibleIfNotMentioned() {
     72 	ctx := context.Background()
     73 
     74 	testStatusID := suite.testStatuses["local_account_2_status_6"].ID
     75 	testStatus, err := suite.db.GetStatusByID(ctx, testStatusID)
     76 	suite.NoError(err)
     77 	testAccount := suite.testAccounts["admin_account"]
     78 
     79 	visible, err := suite.filter.StatusVisible(ctx, testAccount, testStatus)
     80 	suite.NoError(err)
     81 
     82 	suite.False(visible)
     83 }
     84 
     85 func (suite *StatusVisibleTestSuite) TestStatusNotVisibleIfNotMutuals() {
     86 	ctx := context.Background()
     87 
     88 	suite.db.DeleteByID(ctx, suite.testFollows["local_account_2_local_account_1"].ID, &gtsmodel.Follow{})
     89 
     90 	testStatusID := suite.testStatuses["local_account_1_status_4"].ID
     91 	testStatus, err := suite.db.GetStatusByID(ctx, testStatusID)
     92 	suite.NoError(err)
     93 	testAccount := suite.testAccounts["local_account_2"]
     94 
     95 	visible, err := suite.filter.StatusVisible(ctx, testAccount, testStatus)
     96 	suite.NoError(err)
     97 
     98 	suite.False(visible)
     99 }
    100 
    101 func (suite *StatusVisibleTestSuite) TestStatusNotVisibleIfNotFollowing() {
    102 	ctx := context.Background()
    103 
    104 	suite.db.DeleteByID(ctx, suite.testFollows["admin_account_local_account_1"].ID, &gtsmodel.Follow{})
    105 
    106 	testStatusID := suite.testStatuses["local_account_1_status_5"].ID
    107 	testStatus, err := suite.db.GetStatusByID(ctx, testStatusID)
    108 	suite.NoError(err)
    109 	testAccount := suite.testAccounts["admin_account"]
    110 
    111 	visible, err := suite.filter.StatusVisible(ctx, testAccount, testStatus)
    112 	suite.NoError(err)
    113 
    114 	suite.False(visible)
    115 }
    116 
    117 func (suite *StatusVisibleTestSuite) TestStatusNotVisibleIfNotMutualsCached() {
    118 	ctx := context.Background()
    119 	testStatusID := suite.testStatuses["local_account_1_status_4"].ID
    120 	testStatus, err := suite.db.GetStatusByID(ctx, testStatusID)
    121 	suite.NoError(err)
    122 	testAccount := suite.testAccounts["local_account_2"]
    123 
    124 	// Perform a status visibility check while mutuals, this shsould be true.
    125 	visible, err := suite.filter.StatusVisible(ctx, testAccount, testStatus)
    126 	suite.NoError(err)
    127 	suite.True(visible)
    128 
    129 	err = suite.db.DeleteFollowByID(ctx, suite.testFollows["local_account_2_local_account_1"].ID)
    130 	suite.NoError(err)
    131 
    132 	// Perform a status visibility check after unfollow, this should be false.
    133 	visible, err = suite.filter.StatusVisible(ctx, testAccount, testStatus)
    134 	suite.NoError(err)
    135 	suite.False(visible)
    136 }
    137 
    138 func (suite *StatusVisibleTestSuite) TestStatusNotVisibleIfNotFollowingCached() {
    139 	ctx := context.Background()
    140 	testStatusID := suite.testStatuses["local_account_1_status_5"].ID
    141 	testStatus, err := suite.db.GetStatusByID(ctx, testStatusID)
    142 	suite.NoError(err)
    143 	testAccount := suite.testAccounts["admin_account"]
    144 
    145 	// Perform a status visibility check while following, this shsould be true.
    146 	visible, err := suite.filter.StatusVisible(ctx, testAccount, testStatus)
    147 	suite.NoError(err)
    148 	suite.True(visible)
    149 
    150 	err = suite.db.DeleteFollowByID(ctx, suite.testFollows["admin_account_local_account_1"].ID)
    151 	suite.NoError(err)
    152 
    153 	// Perform a status visibility check after unfollow, this should be false.
    154 	visible, err = suite.filter.StatusVisible(ctx, testAccount, testStatus)
    155 	suite.NoError(err)
    156 	suite.False(visible)
    157 }
    158 
    159 func TestStatusVisibleTestSuite(t *testing.T) {
    160 	suite.Run(t, new(StatusVisibleTestSuite))
    161 }