gtsocial-umbx

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

statusbookmark_test.go (4253B)


      1 /*
      2    GoToSocial
      3    Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
      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 
     19 package bundb_test
     20 
     21 import (
     22 	"context"
     23 	"errors"
     24 	"testing"
     25 
     26 	"github.com/stretchr/testify/suite"
     27 	"github.com/superseriousbusiness/gotosocial/internal/db"
     28 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
     29 )
     30 
     31 type StatusBookmarkTestSuite struct {
     32 	BunDBStandardTestSuite
     33 }
     34 
     35 func (suite *StatusBookmarkTestSuite) TestGetStatusBookmarkIDOK() {
     36 	testBookmark := suite.testBookmarks["local_account_1_admin_account_status_1"]
     37 
     38 	id, err := suite.db.GetStatusBookmarkID(context.Background(), testBookmark.AccountID, testBookmark.StatusID)
     39 	if err != nil {
     40 		suite.FailNow(err.Error())
     41 	}
     42 
     43 	suite.Equal(testBookmark.ID, id)
     44 }
     45 
     46 func (suite *StatusBookmarkTestSuite) TestGetStatusBookmarkIDNonexisting() {
     47 	id, err := suite.db.GetStatusBookmarkID(context.Background(), "01GVAVGD06YJ2FSB5GJSMF8M2K", "01GVAVGKGR1MK9ZN7JCJFYSFZV")
     48 	suite.Empty(id)
     49 	suite.ErrorIs(err, db.ErrNoEntries)
     50 }
     51 
     52 func (suite *StatusBookmarkTestSuite) TestDeleteStatusBookmarksOriginatingFromAccount() {
     53 	testAccount := suite.testAccounts["local_account_1"]
     54 
     55 	if err := suite.db.DeleteStatusBookmarks(context.Background(), "", testAccount.ID); err != nil {
     56 		suite.FailNow(err.Error())
     57 	}
     58 
     59 	bookmarks := []*gtsmodel.StatusBookmark{}
     60 	if err := suite.db.GetAll(context.Background(), &bookmarks); err != nil && !errors.Is(err, db.ErrNoEntries) {
     61 		suite.FailNow(err.Error())
     62 	}
     63 
     64 	for _, b := range bookmarks {
     65 		if b.AccountID == testAccount.ID {
     66 			suite.FailNowf("", "no StatusBookmarks with account id %s should remain", testAccount.ID)
     67 		}
     68 	}
     69 }
     70 
     71 func (suite *StatusBookmarkTestSuite) TestDeleteStatusBookmarksTargetingAccount() {
     72 	testAccount := suite.testAccounts["local_account_1"]
     73 
     74 	if err := suite.db.DeleteStatusBookmarks(context.Background(), testAccount.ID, ""); err != nil {
     75 		suite.FailNow(err.Error())
     76 	}
     77 
     78 	bookmarks := []*gtsmodel.StatusBookmark{}
     79 	if err := suite.db.GetAll(context.Background(), &bookmarks); err != nil && !errors.Is(err, db.ErrNoEntries) {
     80 		suite.FailNow(err.Error())
     81 	}
     82 
     83 	for _, b := range bookmarks {
     84 		if b.TargetAccountID == testAccount.ID {
     85 			suite.FailNowf("", "no StatusBookmarks with target account id %s should remain", testAccount.ID)
     86 		}
     87 	}
     88 }
     89 
     90 func (suite *StatusBookmarkTestSuite) TestDeleteStatusBookmarksTargetingStatus() {
     91 	testStatus := suite.testStatuses["local_account_1_status_1"]
     92 
     93 	if err := suite.db.DeleteStatusBookmarksForStatus(context.Background(), testStatus.ID); err != nil {
     94 		suite.FailNow(err.Error())
     95 	}
     96 
     97 	bookmarks := []*gtsmodel.StatusBookmark{}
     98 	if err := suite.db.GetAll(context.Background(), &bookmarks); err != nil && !errors.Is(err, db.ErrNoEntries) {
     99 		suite.FailNow(err.Error())
    100 	}
    101 
    102 	for _, b := range bookmarks {
    103 		if b.StatusID == testStatus.ID {
    104 			suite.FailNowf("", "no StatusBookmarks with status id %s should remain", testStatus.ID)
    105 		}
    106 	}
    107 }
    108 
    109 func (suite *StatusBookmarkTestSuite) TestDeleteStatusBookmark() {
    110 	testBookmark := suite.testBookmarks["local_account_1_admin_account_status_1"]
    111 	ctx := context.Background()
    112 
    113 	if err := suite.db.DeleteStatusBookmark(ctx, testBookmark.ID); err != nil {
    114 		suite.FailNow(err.Error())
    115 	}
    116 
    117 	bookmark, err := suite.db.GetStatusBookmark(ctx, testBookmark.ID)
    118 	suite.ErrorIs(err, db.ErrNoEntries)
    119 	suite.Nil(bookmark)
    120 }
    121 
    122 func (suite *StatusBookmarkTestSuite) TestDeleteStatusBookmarkNonExisting() {
    123 	err := suite.db.DeleteStatusBookmark(context.Background(), "01GVAV715K6Y2SG9ZKS9ZA8G7G")
    124 	suite.NoError(err)
    125 }
    126 
    127 func TestStatusBookmarkTestSuite(t *testing.T) {
    128 	suite.Run(t, new(StatusBookmarkTestSuite))
    129 }