follow_test.go (4796B)
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 account_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/testrig" 27 ) 28 29 type FollowTestSuite struct { 30 AccountStandardTestSuite 31 } 32 33 func (suite *FollowTestSuite) TestUpdateExistingFollowChangeBoth() { 34 ctx := context.Background() 35 requestingAccount := suite.testAccounts["local_account_1"] 36 targetAccount := suite.testAccounts["admin_account"] 37 38 // Change both Reblogs and Notify. 39 // Trace logs should show a query similar to this: 40 // UPDATE "follows" AS "follow" SET "show_reblogs" = FALSE, "notify" = TRUE, "updated_at" = '2023-04-09 11:42:39.424705+00:00' WHERE ("follow"."id" = '01F8PY8RHWRQZV038T4E8T9YK8') 41 relationship, err := suite.accountProcessor.FollowCreate(ctx, requestingAccount, &apimodel.AccountFollowRequest{ 42 ID: targetAccount.ID, 43 Reblogs: testrig.FalseBool(), 44 Notify: testrig.TrueBool(), 45 }) 46 47 if err != nil { 48 suite.FailNow(err.Error()) 49 } 50 51 suite.False(relationship.ShowingReblogs) 52 suite.True(relationship.Notifying) 53 } 54 55 func (suite *FollowTestSuite) TestUpdateExistingFollowChangeNotifyIgnoreReblogs() { 56 ctx := context.Background() 57 requestingAccount := suite.testAccounts["local_account_1"] 58 targetAccount := suite.testAccounts["admin_account"] 59 60 // Change Notify, ignore Reblogs. 61 // Trace logs should show a query similar to this: 62 // UPDATE "follows" AS "follow" SET "notify" = TRUE, "updated_at" = '2023-04-09 11:40:33.827858+00:00' WHERE ("follow"."id" = '01F8PY8RHWRQZV038T4E8T9YK8') 63 relationship, err := suite.accountProcessor.FollowCreate(ctx, requestingAccount, &apimodel.AccountFollowRequest{ 64 ID: targetAccount.ID, 65 Notify: testrig.TrueBool(), 66 }) 67 68 if err != nil { 69 suite.FailNow(err.Error()) 70 } 71 72 suite.True(relationship.ShowingReblogs) 73 suite.True(relationship.Notifying) 74 } 75 76 func (suite *FollowTestSuite) TestUpdateExistingFollowChangeNotifySetReblogs() { 77 ctx := context.Background() 78 requestingAccount := suite.testAccounts["local_account_1"] 79 targetAccount := suite.testAccounts["admin_account"] 80 81 // Change Notify, set Reblogs to same value as before. 82 // Trace logs should show a query similar to this: 83 // UPDATE "follows" AS "follow" SET "notify" = TRUE, "updated_at" = '2023-04-09 11:40:33.827858+00:00' WHERE ("follow"."id" = '01F8PY8RHWRQZV038T4E8T9YK8') 84 relationship, err := suite.accountProcessor.FollowCreate(ctx, requestingAccount, &apimodel.AccountFollowRequest{ 85 ID: targetAccount.ID, 86 Notify: testrig.TrueBool(), 87 Reblogs: testrig.TrueBool(), 88 }) 89 90 if err != nil { 91 suite.FailNow(err.Error()) 92 } 93 94 suite.True(relationship.ShowingReblogs) 95 suite.True(relationship.Notifying) 96 } 97 98 func (suite *FollowTestSuite) TestUpdateExistingFollowChangeNothing() { 99 ctx := context.Background() 100 requestingAccount := suite.testAccounts["local_account_1"] 101 targetAccount := suite.testAccounts["admin_account"] 102 103 // Set Notify and Reblogs to same values as before. 104 // Trace logs should show no update query. 105 relationship, err := suite.accountProcessor.FollowCreate(ctx, requestingAccount, &apimodel.AccountFollowRequest{ 106 ID: targetAccount.ID, 107 Notify: testrig.FalseBool(), 108 Reblogs: testrig.TrueBool(), 109 }) 110 111 if err != nil { 112 suite.FailNow(err.Error()) 113 } 114 115 suite.True(relationship.ShowingReblogs) 116 suite.False(relationship.Notifying) 117 } 118 119 func (suite *FollowTestSuite) TestUpdateExistingFollowSetNothing() { 120 ctx := context.Background() 121 requestingAccount := suite.testAccounts["local_account_1"] 122 targetAccount := suite.testAccounts["admin_account"] 123 124 // Don't set Notify or Reblogs. 125 // Trace logs should show no update query. 126 relationship, err := suite.accountProcessor.FollowCreate(ctx, requestingAccount, &apimodel.AccountFollowRequest{ 127 ID: targetAccount.ID, 128 }) 129 130 if err != nil { 131 suite.FailNow(err.Error()) 132 } 133 134 suite.True(relationship.ShowingReblogs) 135 suite.False(relationship.Notifying) 136 } 137 138 func TestFollowTestS(t *testing.T) { 139 suite.Run(t, new(FollowTestSuite)) 140 }