formatter_test.go (3726B)
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 text_test 19 20 import ( 21 "context" 22 23 "github.com/stretchr/testify/suite" 24 "github.com/superseriousbusiness/gotosocial/internal/db" 25 "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" 26 "github.com/superseriousbusiness/gotosocial/internal/processing" 27 "github.com/superseriousbusiness/gotosocial/internal/state" 28 "github.com/superseriousbusiness/gotosocial/internal/text" 29 "github.com/superseriousbusiness/gotosocial/testrig" 30 ) 31 32 type TextStandardTestSuite struct { 33 // standard suite interfaces 34 suite.Suite 35 db db.DB 36 parseMention gtsmodel.ParseMentionFunc 37 38 // standard suite models 39 testTokens map[string]*gtsmodel.Token 40 testClients map[string]*gtsmodel.Client 41 testApplications map[string]*gtsmodel.Application 42 testUsers map[string]*gtsmodel.User 43 testAccounts map[string]*gtsmodel.Account 44 testAttachments map[string]*gtsmodel.MediaAttachment 45 testStatuses map[string]*gtsmodel.Status 46 testTags map[string]*gtsmodel.Tag 47 testMentions map[string]*gtsmodel.Mention 48 testEmojis map[string]*gtsmodel.Emoji 49 50 // module being tested 51 formatter text.Formatter 52 } 53 54 func (suite *TextStandardTestSuite) SetupSuite() { 55 suite.testTokens = testrig.NewTestTokens() 56 suite.testClients = testrig.NewTestClients() 57 suite.testApplications = testrig.NewTestApplications() 58 suite.testUsers = testrig.NewTestUsers() 59 suite.testAccounts = testrig.NewTestAccounts() 60 suite.testAttachments = testrig.NewTestAttachments() 61 suite.testStatuses = testrig.NewTestStatuses() 62 suite.testTags = testrig.NewTestTags() 63 suite.testMentions = testrig.NewTestMentions() 64 suite.testEmojis = testrig.NewTestEmojis() 65 } 66 67 func (suite *TextStandardTestSuite) SetupTest() { 68 var state state.State 69 state.Caches.Init() 70 71 testrig.InitTestLog() 72 testrig.InitTestConfig() 73 74 suite.db = testrig.NewTestDB(&state) 75 76 federator := testrig.NewTestFederator(&state, testrig.NewTestTransportController(&state, testrig.NewMockHTTPClient(nil, "../../testrig/media")), nil) 77 suite.parseMention = processing.GetParseMentionFunc(suite.db, federator) 78 79 suite.formatter = text.NewFormatter(suite.db) 80 81 testrig.StandardDBSetup(suite.db, nil) 82 } 83 84 func (suite *TextStandardTestSuite) TearDownTest() { 85 testrig.StandardDBTeardown(suite.db) 86 } 87 88 func (suite *TextStandardTestSuite) FromMarkdown(text string) *text.FormatResult { 89 return suite.formatter.FromMarkdown(context.Background(), suite.parseMention, suite.testAccounts["local_account_1"].ID, "status_ID", text) 90 } 91 92 func (suite *TextStandardTestSuite) FromPlain(text string) *text.FormatResult { 93 return suite.formatter.FromPlain(context.Background(), suite.parseMention, suite.testAccounts["local_account_1"].ID, "status_ID", text) 94 } 95 96 func (suite *TextStandardTestSuite) FromPlainNoParagraph(text string) *text.FormatResult { 97 return suite.formatter.FromPlainNoParagraph(context.Background(), suite.parseMention, suite.testAccounts["local_account_1"].ID, "status_ID", text) 98 }