mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-12-27 17:46:31 +00:00
083099a957
* reference logrus' global logger instead of passing and storing a logger reference everywhere * always directly use global logrus logger instead of referencing an instance * test suites should also directly use the global logrus logger * rename gin logging function to clarify that it's middleware * correct comments which erroneously referenced removed logger parameter * setting log level for tests now uses logrus' exported type instead of the string value, to guarantee error isn't possible
163 lines
5.4 KiB
Go
163 lines
5.4 KiB
Go
/*
|
|
GoToSocial
|
|
Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package text_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
|
"github.com/superseriousbusiness/gotosocial/internal/text"
|
|
"github.com/superseriousbusiness/gotosocial/testrig"
|
|
)
|
|
|
|
const (
|
|
replaceMentionsString = `Another test @foss_satan@fossbros-anonymous.io
|
|
|
|
#Hashtag
|
|
|
|
Text`
|
|
replaceMentionsExpected = `Another test <span class="h-card"><a href="http://fossbros-anonymous.io/@foss_satan" class="u-url mention">@<span>foss_satan</span></a></span>
|
|
|
|
#Hashtag
|
|
|
|
Text`
|
|
|
|
replaceHashtagsExpected = `Another test @foss_satan@fossbros-anonymous.io
|
|
|
|
<a href="http://localhost:8080/tags/Hashtag" class="mention hashtag" rel="tag">#<span>Hashtag</span></a>
|
|
|
|
Text`
|
|
|
|
replaceHashtagsAfterMentionsExpected = `Another test <span class="h-card"><a href="http://fossbros-anonymous.io/@foss_satan" class="u-url mention">@<span>foss_satan</span></a></span>
|
|
|
|
<a href="http://localhost:8080/tags/Hashtag" class="mention hashtag" rel="tag">#<span>Hashtag</span></a>
|
|
|
|
Text`
|
|
|
|
replaceMentionsWithLinkString = `Another test @foss_satan@fossbros-anonymous.io
|
|
|
|
http://fossbros-anonymous.io/@foss_satan/statuses/6675ee73-fccc-4562-a46a-3e8cd9798060`
|
|
|
|
replaceMentionsWithLinkStringExpected = `Another test <span class="h-card"><a href="http://fossbros-anonymous.io/@foss_satan" class="u-url mention">@<span>foss_satan</span></a></span>
|
|
|
|
http://fossbros-anonymous.io/@foss_satan/statuses/6675ee73-fccc-4562-a46a-3e8cd9798060`
|
|
|
|
replaceMentionsWithLinkSelfString = `Mentioning myself: @the_mighty_zork
|
|
|
|
and linking to my own status: https://localhost:8080/@the_mighty_zork/statuses/01FGXKJRX2PMERJQ9EQF8Y6HCR`
|
|
|
|
replaceMemtionsWithLinkSelfExpected = `Mentioning myself: <span class="h-card"><a href="http://localhost:8080/@the_mighty_zork" class="u-url mention">@<span>the_mighty_zork</span></a></span>
|
|
|
|
and linking to my own status: https://localhost:8080/@the_mighty_zork/statuses/01FGXKJRX2PMERJQ9EQF8Y6HCR`
|
|
)
|
|
|
|
type CommonTestSuite struct {
|
|
TextStandardTestSuite
|
|
}
|
|
|
|
func (suite *CommonTestSuite) SetupSuite() {
|
|
suite.testTokens = testrig.NewTestTokens()
|
|
suite.testClients = testrig.NewTestClients()
|
|
suite.testApplications = testrig.NewTestApplications()
|
|
suite.testUsers = testrig.NewTestUsers()
|
|
suite.testAccounts = testrig.NewTestAccounts()
|
|
suite.testAttachments = testrig.NewTestAttachments()
|
|
suite.testStatuses = testrig.NewTestStatuses()
|
|
suite.testTags = testrig.NewTestTags()
|
|
suite.testMentions = testrig.NewTestMentions()
|
|
}
|
|
|
|
func (suite *CommonTestSuite) SetupTest() {
|
|
suite.config = testrig.NewTestConfig()
|
|
suite.db = testrig.NewTestDB()
|
|
suite.formatter = text.NewFormatter(suite.config, suite.db)
|
|
|
|
testrig.StandardDBSetup(suite.db, nil)
|
|
}
|
|
|
|
func (suite *CommonTestSuite) TearDownTest() {
|
|
testrig.StandardDBTeardown(suite.db)
|
|
}
|
|
|
|
func (suite *CommonTestSuite) TestReplaceMentions() {
|
|
foundMentions := []*gtsmodel.Mention{
|
|
suite.testMentions["zork_mention_foss_satan"],
|
|
}
|
|
|
|
f := suite.formatter.ReplaceMentions(context.Background(), replaceMentionsString, foundMentions)
|
|
suite.Equal(replaceMentionsExpected, f)
|
|
}
|
|
|
|
func (suite *CommonTestSuite) TestReplaceHashtags() {
|
|
foundTags := []*gtsmodel.Tag{
|
|
suite.testTags["Hashtag"],
|
|
}
|
|
|
|
f := suite.formatter.ReplaceTags(context.Background(), replaceMentionsString, foundTags)
|
|
|
|
suite.Equal(replaceHashtagsExpected, f)
|
|
}
|
|
|
|
func (suite *CommonTestSuite) TestReplaceHashtagsAfterReplaceMentions() {
|
|
foundTags := []*gtsmodel.Tag{
|
|
suite.testTags["Hashtag"],
|
|
}
|
|
|
|
f := suite.formatter.ReplaceTags(context.Background(), replaceMentionsExpected, foundTags)
|
|
|
|
suite.Equal(replaceHashtagsAfterMentionsExpected, f)
|
|
}
|
|
|
|
func (suite *CommonTestSuite) TestReplaceMentionsWithLink() {
|
|
foundMentions := []*gtsmodel.Mention{
|
|
suite.testMentions["zork_mention_foss_satan"],
|
|
}
|
|
|
|
f := suite.formatter.ReplaceMentions(context.Background(), replaceMentionsWithLinkString, foundMentions)
|
|
suite.Equal(replaceMentionsWithLinkStringExpected, f)
|
|
}
|
|
|
|
func (suite *CommonTestSuite) TestReplaceMentionsWithLinkSelf() {
|
|
mentioningAccount := suite.testAccounts["local_account_1"]
|
|
|
|
foundMentions := []*gtsmodel.Mention{
|
|
{
|
|
ID: "01FGXKN5F815DVFVD53PN9NYM6",
|
|
CreatedAt: time.Now(),
|
|
UpdatedAt: time.Now(),
|
|
StatusID: "01FGXKP0S5THQXFC1D9R141DDR",
|
|
OriginAccountID: mentioningAccount.ID,
|
|
TargetAccountID: mentioningAccount.ID,
|
|
NameString: "@the_mighty_zork",
|
|
TargetAccountURI: mentioningAccount.URI,
|
|
TargetAccountURL: mentioningAccount.URL,
|
|
},
|
|
}
|
|
|
|
f := suite.formatter.ReplaceMentions(context.Background(), replaceMentionsWithLinkSelfString, foundMentions)
|
|
suite.Equal(replaceMemtionsWithLinkSelfExpected, f)
|
|
}
|
|
|
|
func TestCommonTestSuite(t *testing.T) {
|
|
suite.Run(t, new(CommonTestSuite))
|
|
}
|