gtsocial-umbx

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

status_test.go (7351B)


      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 dereferencing_test
     19 
     20 import (
     21 	"context"
     22 	"testing"
     23 
     24 	"github.com/stretchr/testify/suite"
     25 	"github.com/superseriousbusiness/gotosocial/internal/ap"
     26 	"github.com/superseriousbusiness/gotosocial/internal/db"
     27 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
     28 	"github.com/superseriousbusiness/gotosocial/testrig"
     29 )
     30 
     31 type StatusTestSuite struct {
     32 	DereferencerStandardTestSuite
     33 }
     34 
     35 func (suite *StatusTestSuite) TestDereferenceSimpleStatus() {
     36 	fetchingAccount := suite.testAccounts["local_account_1"]
     37 
     38 	statusURL := testrig.URLMustParse("https://unknown-instance.com/users/brand_new_person/statuses/01FE4NTHKWW7THT67EF10EB839")
     39 	status, _, err := suite.dereferencer.GetStatusByURI(context.Background(), fetchingAccount.Username, statusURL)
     40 	suite.NoError(err)
     41 	suite.NotNil(status)
     42 
     43 	// status values should be set
     44 	suite.Equal("https://unknown-instance.com/users/brand_new_person/statuses/01FE4NTHKWW7THT67EF10EB839", status.URI)
     45 	suite.Equal("https://unknown-instance.com/users/@brand_new_person/01FE4NTHKWW7THT67EF10EB839", status.URL)
     46 	suite.Equal("Hello world!", status.Content)
     47 	suite.Equal("https://unknown-instance.com/users/brand_new_person", status.AccountURI)
     48 	suite.False(*status.Local)
     49 	suite.Empty(status.ContentWarning)
     50 	suite.Equal(gtsmodel.VisibilityPublic, status.Visibility)
     51 	suite.Equal(ap.ObjectNote, status.ActivityStreamsType)
     52 
     53 	// status should be in the database
     54 	dbStatus, err := suite.db.GetStatusByURI(context.Background(), status.URI)
     55 	suite.NoError(err)
     56 	suite.Equal(status.ID, dbStatus.ID)
     57 	suite.True(*dbStatus.Federated)
     58 	suite.True(*dbStatus.Boostable)
     59 	suite.True(*dbStatus.Replyable)
     60 	suite.True(*dbStatus.Likeable)
     61 
     62 	// account should be in the database now too
     63 	account, err := suite.db.GetAccountByURI(context.Background(), status.AccountURI)
     64 	suite.NoError(err)
     65 	suite.NotNil(account)
     66 	suite.True(*account.Discoverable)
     67 	suite.Equal("https://unknown-instance.com/users/brand_new_person", account.URI)
     68 	suite.Equal("hey I'm a new person, your instance hasn't seen me yet uwu", account.Note)
     69 	suite.Equal("Geoff Brando New Personson", account.DisplayName)
     70 	suite.Equal("brand_new_person", account.Username)
     71 	suite.NotNil(account.PublicKey)
     72 	suite.Nil(account.PrivateKey)
     73 }
     74 
     75 func (suite *StatusTestSuite) TestDereferenceStatusWithMention() {
     76 	fetchingAccount := suite.testAccounts["local_account_1"]
     77 
     78 	statusURL := testrig.URLMustParse("https://unknown-instance.com/users/brand_new_person/statuses/01FE5Y30E3W4P7TRE0R98KAYQV")
     79 	status, _, err := suite.dereferencer.GetStatusByURI(context.Background(), fetchingAccount.Username, statusURL)
     80 	suite.NoError(err)
     81 	suite.NotNil(status)
     82 
     83 	// status values should be set
     84 	suite.Equal("https://unknown-instance.com/users/brand_new_person/statuses/01FE5Y30E3W4P7TRE0R98KAYQV", status.URI)
     85 	suite.Equal("https://unknown-instance.com/users/@brand_new_person/01FE5Y30E3W4P7TRE0R98KAYQV", status.URL)
     86 	suite.Equal("Hey @the_mighty_zork@localhost:8080 how's it going?", status.Content)
     87 	suite.Equal("https://unknown-instance.com/users/brand_new_person", status.AccountURI)
     88 	suite.False(*status.Local)
     89 	suite.Empty(status.ContentWarning)
     90 	suite.Equal(gtsmodel.VisibilityPublic, status.Visibility)
     91 	suite.Equal(ap.ObjectNote, status.ActivityStreamsType)
     92 
     93 	// status should be in the database
     94 	dbStatus, err := suite.db.GetStatusByURI(context.Background(), status.URI)
     95 	suite.NoError(err)
     96 	suite.Equal(status.ID, dbStatus.ID)
     97 	suite.True(*dbStatus.Federated)
     98 	suite.True(*dbStatus.Boostable)
     99 	suite.True(*dbStatus.Replyable)
    100 	suite.True(*dbStatus.Likeable)
    101 
    102 	// account should be in the database now too
    103 	account, err := suite.db.GetAccountByURI(context.Background(), status.AccountURI)
    104 	suite.NoError(err)
    105 	suite.NotNil(account)
    106 	suite.True(*account.Discoverable)
    107 	suite.Equal("https://unknown-instance.com/users/brand_new_person", account.URI)
    108 	suite.Equal("hey I'm a new person, your instance hasn't seen me yet uwu", account.Note)
    109 	suite.Equal("Geoff Brando New Personson", account.DisplayName)
    110 	suite.Equal("brand_new_person", account.Username)
    111 	suite.NotNil(account.PublicKey)
    112 	suite.Nil(account.PrivateKey)
    113 
    114 	// we should have a mention in the database
    115 	m := &gtsmodel.Mention{}
    116 	err = suite.db.GetWhere(context.Background(), []db.Where{{Key: "status_id", Value: status.ID}}, m)
    117 	suite.NoError(err)
    118 	suite.NotNil(m)
    119 	suite.Equal(status.ID, m.StatusID)
    120 	suite.Equal(account.ID, m.OriginAccountID)
    121 	suite.Equal(fetchingAccount.ID, m.TargetAccountID)
    122 	suite.Equal(account.URI, m.OriginAccountURI)
    123 	suite.False(*m.Silent)
    124 }
    125 
    126 func (suite *StatusTestSuite) TestDereferenceStatusWithImageAndNoContent() {
    127 	fetchingAccount := suite.testAccounts["local_account_1"]
    128 
    129 	statusURL := testrig.URLMustParse("https://turnip.farm/users/turniplover6969/statuses/70c53e54-3146-42d5-a630-83c8b6c7c042")
    130 	status, _, err := suite.dereferencer.GetStatusByURI(context.Background(), fetchingAccount.Username, statusURL)
    131 	suite.NoError(err)
    132 	suite.NotNil(status)
    133 
    134 	// status values should be set
    135 	suite.Equal("https://turnip.farm/users/turniplover6969/statuses/70c53e54-3146-42d5-a630-83c8b6c7c042", status.URI)
    136 	suite.Equal("https://turnip.farm/@turniplover6969/70c53e54-3146-42d5-a630-83c8b6c7c042", status.URL)
    137 	suite.Equal("", status.Content)
    138 	suite.Equal("https://turnip.farm/users/turniplover6969", status.AccountURI)
    139 	suite.False(*status.Local)
    140 	suite.Empty(status.ContentWarning)
    141 	suite.Equal(gtsmodel.VisibilityPublic, status.Visibility)
    142 	suite.Equal(ap.ObjectNote, status.ActivityStreamsType)
    143 
    144 	// status should be in the database
    145 	dbStatus, err := suite.db.GetStatusByURI(context.Background(), status.URI)
    146 	suite.NoError(err)
    147 	suite.Equal(status.ID, dbStatus.ID)
    148 	suite.True(*dbStatus.Federated)
    149 	suite.True(*dbStatus.Boostable)
    150 	suite.True(*dbStatus.Replyable)
    151 	suite.True(*dbStatus.Likeable)
    152 
    153 	// account should be in the database now too
    154 	account, err := suite.db.GetAccountByURI(context.Background(), status.AccountURI)
    155 	suite.NoError(err)
    156 	suite.NotNil(account)
    157 	suite.True(*account.Discoverable)
    158 	suite.Equal("https://turnip.farm/users/turniplover6969", account.URI)
    159 	suite.Equal("I just think they're neat", account.Note)
    160 	suite.Equal("Turnip Lover 6969", account.DisplayName)
    161 	suite.Equal("turniplover6969", account.Username)
    162 	suite.NotNil(account.PublicKey)
    163 	suite.Nil(account.PrivateKey)
    164 
    165 	// we should have an attachment in the database
    166 	a := &gtsmodel.MediaAttachment{}
    167 	err = suite.db.GetWhere(context.Background(), []db.Where{{Key: "status_id", Value: status.ID}}, a)
    168 	suite.NoError(err)
    169 }
    170 
    171 func TestStatusTestSuite(t *testing.T) {
    172 	suite.Run(t, new(StatusTestSuite))
    173 }