gtsocial-umbx

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

delete_test.go (3594B)


      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 	"net"
     23 	"testing"
     24 	"time"
     25 
     26 	"github.com/stretchr/testify/suite"
     27 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
     28 )
     29 
     30 type AccountDeleteTestSuite struct {
     31 	AccountStandardTestSuite
     32 }
     33 
     34 func (suite *AccountDeleteTestSuite) TestAccountDeleteLocal() {
     35 	ctx := context.Background()
     36 
     37 	// Keep a reference around to the original account
     38 	// and user, before the delete was processed.
     39 	ogAccount := suite.testAccounts["local_account_1"]
     40 	ogUser := suite.testUsers["local_account_1"]
     41 
     42 	testAccount := &gtsmodel.Account{}
     43 	*testAccount = *ogAccount
     44 
     45 	suspensionOrigin := "01GWVP2A8J38Q2J2FDZ6TS8AQG"
     46 	if err := suite.accountProcessor.Delete(ctx, testAccount, suspensionOrigin); err != nil {
     47 		suite.FailNow(err.Error())
     48 	}
     49 
     50 	updatedAccount, err := suite.db.GetAccountByID(ctx, ogAccount.ID)
     51 	if err != nil {
     52 		suite.FailNow(err.Error())
     53 	}
     54 
     55 	suite.WithinDuration(time.Now(), updatedAccount.UpdatedAt, 1*time.Minute)
     56 	suite.Zero(updatedAccount.FetchedAt)
     57 	suite.Zero(updatedAccount.AvatarMediaAttachmentID)
     58 	suite.Zero(updatedAccount.AvatarRemoteURL)
     59 	suite.Zero(updatedAccount.HeaderMediaAttachmentID)
     60 	suite.Zero(updatedAccount.HeaderRemoteURL)
     61 	suite.Zero(updatedAccount.DisplayName)
     62 	suite.Nil(updatedAccount.EmojiIDs)
     63 	suite.Nil(updatedAccount.Emojis)
     64 	suite.Nil(updatedAccount.Fields)
     65 	suite.Zero(updatedAccount.Note)
     66 	suite.Zero(updatedAccount.NoteRaw)
     67 	suite.False(*updatedAccount.Memorial)
     68 	suite.Zero(updatedAccount.AlsoKnownAs)
     69 	suite.Zero(updatedAccount.Reason)
     70 	suite.False(*updatedAccount.Discoverable)
     71 	suite.Zero(updatedAccount.StatusContentType)
     72 	suite.Zero(updatedAccount.CustomCSS)
     73 	suite.WithinDuration(time.Now(), updatedAccount.SuspendedAt, 1*time.Minute)
     74 	suite.Equal(suspensionOrigin, updatedAccount.SuspensionOrigin)
     75 	suite.True(*updatedAccount.HideCollections)
     76 	suite.False(*updatedAccount.EnableRSS)
     77 
     78 	updatedUser, err := suite.db.GetUserByAccountID(ctx, testAccount.ID)
     79 	if err != nil {
     80 		suite.FailNow(err.Error())
     81 	}
     82 
     83 	suite.WithinDuration(time.Now(), updatedUser.UpdatedAt, 1*time.Minute)
     84 	suite.NotEqual(updatedUser.EncryptedPassword, ogUser.EncryptedPassword)
     85 	suite.Equal(net.IPv4zero, updatedUser.SignUpIP)
     86 	suite.Zero(updatedUser.CurrentSignInAt)
     87 	suite.Equal(net.IPv4zero, updatedUser.CurrentSignInIP)
     88 	suite.Zero(updatedUser.LastSignInAt)
     89 	suite.Equal(net.IPv4zero, updatedUser.LastSignInIP)
     90 	suite.Equal(1, updatedUser.SignInCount)
     91 	suite.Zero(updatedUser.Locale)
     92 	suite.Zero(updatedUser.CreatedByApplicationID)
     93 	suite.Zero(updatedUser.LastEmailedAt)
     94 	suite.Zero(updatedUser.ConfirmationToken)
     95 	suite.Zero(updatedUser.ConfirmationSentAt)
     96 	suite.Zero(updatedUser.ResetPasswordToken)
     97 	suite.Zero(updatedUser.ResetPasswordSentAt)
     98 }
     99 
    100 func TestAccountDeleteTestSuite(t *testing.T) {
    101 	suite.Run(t, new(AccountDeleteTestSuite))
    102 }