2023-03-12 15:00:57 +00:00
|
|
|
// GoToSocial
|
|
|
|
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
//
|
|
|
|
// 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/>.
|
2022-05-20 08:34:36 +00:00
|
|
|
|
|
|
|
package bundb_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
2022-10-12 13:01:42 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
2024-01-29 14:57:22 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
2022-11-14 22:47:27 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/testrig"
|
2022-05-20 08:34:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type EmojiTestSuite struct {
|
|
|
|
BunDBStandardTestSuite
|
|
|
|
}
|
|
|
|
|
2022-10-12 13:01:42 +00:00
|
|
|
func (suite *EmojiTestSuite) TestGetUseableEmojis() {
|
|
|
|
emojis, err := suite.db.GetUseableEmojis(context.Background())
|
2022-05-20 08:34:36 +00:00
|
|
|
|
|
|
|
suite.NoError(err)
|
|
|
|
suite.Equal(1, len(emojis))
|
|
|
|
suite.Equal("rainbow", emojis[0].Shortcode)
|
|
|
|
}
|
|
|
|
|
2022-10-14 15:30:04 +00:00
|
|
|
func (suite *EmojiTestSuite) TestDeleteEmojiByID() {
|
|
|
|
testEmoji := suite.testEmojis["rainbow"]
|
|
|
|
|
|
|
|
err := suite.db.DeleteEmojiByID(context.Background(), testEmoji.ID)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
dbEmoji, err := suite.db.GetEmojiByID(context.Background(), testEmoji.ID)
|
|
|
|
suite.Nil(dbEmoji)
|
|
|
|
suite.ErrorIs(err, db.ErrNoEntries)
|
|
|
|
}
|
|
|
|
|
2022-10-13 13:16:24 +00:00
|
|
|
func (suite *EmojiTestSuite) TestGetEmojiByStaticURL() {
|
2022-11-30 15:20:57 +00:00
|
|
|
emoji, err := suite.db.GetEmojiByStaticURL(context.Background(), "http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/emoji/static/01F8MH9H8E4VG3KDYJR9EGPXCQ.png")
|
2022-10-13 13:16:24 +00:00
|
|
|
suite.NoError(err)
|
|
|
|
suite.NotNil(emoji)
|
|
|
|
suite.Equal("rainbow", emoji.Shortcode)
|
2022-11-14 22:47:27 +00:00
|
|
|
suite.NotNil(emoji.Category)
|
|
|
|
suite.Equal("reactions", emoji.Category.Name)
|
2022-10-13 13:16:24 +00:00
|
|
|
}
|
|
|
|
|
2022-10-12 13:01:42 +00:00
|
|
|
func (suite *EmojiTestSuite) TestGetAllEmojis() {
|
2023-06-22 19:46:36 +00:00
|
|
|
emojis, err := suite.db.GetEmojisBy(context.Background(), db.EmojiAllDomains, true, true, "", "", "", 0)
|
2022-10-12 13:01:42 +00:00
|
|
|
|
|
|
|
suite.NoError(err)
|
|
|
|
suite.Equal(2, len(emojis))
|
|
|
|
suite.Equal("rainbow", emojis[0].Shortcode)
|
|
|
|
suite.Equal("yell", emojis[1].Shortcode)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *EmojiTestSuite) TestGetAllEmojisLimit1() {
|
2023-06-22 19:46:36 +00:00
|
|
|
emojis, err := suite.db.GetEmojisBy(context.Background(), db.EmojiAllDomains, true, true, "", "", "", 1)
|
2022-10-12 13:01:42 +00:00
|
|
|
|
|
|
|
suite.NoError(err)
|
|
|
|
suite.Equal(1, len(emojis))
|
|
|
|
suite.Equal("rainbow", emojis[0].Shortcode)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *EmojiTestSuite) TestGetAllEmojisMaxID() {
|
2023-06-22 19:46:36 +00:00
|
|
|
emojis, err := suite.db.GetEmojisBy(context.Background(), db.EmojiAllDomains, true, true, "", "rainbow@", "", 0)
|
2022-10-12 13:01:42 +00:00
|
|
|
|
|
|
|
suite.NoError(err)
|
|
|
|
suite.Equal(1, len(emojis))
|
|
|
|
suite.Equal("yell", emojis[0].Shortcode)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *EmojiTestSuite) TestGetAllEmojisMinID() {
|
2023-06-22 19:46:36 +00:00
|
|
|
emojis, err := suite.db.GetEmojisBy(context.Background(), db.EmojiAllDomains, true, true, "", "", "yell@fossbros-anonymous.io", 0)
|
2022-10-12 13:01:42 +00:00
|
|
|
|
|
|
|
suite.NoError(err)
|
|
|
|
suite.Equal(1, len(emojis))
|
|
|
|
suite.Equal("rainbow", emojis[0].Shortcode)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *EmojiTestSuite) TestGetAllDisabledEmojis() {
|
2023-06-22 19:46:36 +00:00
|
|
|
emojis, err := suite.db.GetEmojisBy(context.Background(), db.EmojiAllDomains, true, false, "", "", "", 0)
|
2022-10-12 13:01:42 +00:00
|
|
|
|
|
|
|
suite.ErrorIs(err, db.ErrNoEntries)
|
|
|
|
suite.Equal(0, len(emojis))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *EmojiTestSuite) TestGetAllEnabledEmojis() {
|
2023-06-22 19:46:36 +00:00
|
|
|
emojis, err := suite.db.GetEmojisBy(context.Background(), db.EmojiAllDomains, false, true, "", "", "", 0)
|
2022-10-12 13:01:42 +00:00
|
|
|
|
|
|
|
suite.NoError(err)
|
|
|
|
suite.Equal(2, len(emojis))
|
|
|
|
suite.Equal("rainbow", emojis[0].Shortcode)
|
|
|
|
suite.Equal("yell", emojis[1].Shortcode)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *EmojiTestSuite) TestGetLocalEnabledEmojis() {
|
2023-06-22 19:46:36 +00:00
|
|
|
emojis, err := suite.db.GetEmojisBy(context.Background(), "", false, true, "", "", "", 0)
|
2022-10-12 13:01:42 +00:00
|
|
|
|
|
|
|
suite.NoError(err)
|
|
|
|
suite.Equal(1, len(emojis))
|
|
|
|
suite.Equal("rainbow", emojis[0].Shortcode)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *EmojiTestSuite) TestGetLocalDisabledEmojis() {
|
2023-06-22 19:46:36 +00:00
|
|
|
emojis, err := suite.db.GetEmojisBy(context.Background(), "", true, false, "", "", "", 0)
|
2022-10-12 13:01:42 +00:00
|
|
|
|
|
|
|
suite.ErrorIs(err, db.ErrNoEntries)
|
|
|
|
suite.Equal(0, len(emojis))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *EmojiTestSuite) TestGetAllEmojisFromDomain() {
|
2023-06-22 19:46:36 +00:00
|
|
|
emojis, err := suite.db.GetEmojisBy(context.Background(), "peepee.poopoo", true, true, "", "", "", 0)
|
2022-10-12 13:01:42 +00:00
|
|
|
|
|
|
|
suite.ErrorIs(err, db.ErrNoEntries)
|
|
|
|
suite.Equal(0, len(emojis))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *EmojiTestSuite) TestGetAllEmojisFromDomain2() {
|
2023-06-22 19:46:36 +00:00
|
|
|
emojis, err := suite.db.GetEmojisBy(context.Background(), "fossbros-anonymous.io", true, true, "", "", "", 0)
|
2022-10-12 13:01:42 +00:00
|
|
|
|
|
|
|
suite.NoError(err)
|
|
|
|
suite.Equal(1, len(emojis))
|
|
|
|
suite.Equal("yell", emojis[0].Shortcode)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *EmojiTestSuite) TestGetSpecificEmojisFromDomain2() {
|
2023-06-22 19:46:36 +00:00
|
|
|
emojis, err := suite.db.GetEmojisBy(context.Background(), "fossbros-anonymous.io", true, true, "yell", "", "", 0)
|
2022-10-12 13:01:42 +00:00
|
|
|
|
|
|
|
suite.NoError(err)
|
|
|
|
suite.Equal(1, len(emojis))
|
|
|
|
suite.Equal("yell", emojis[0].Shortcode)
|
|
|
|
}
|
|
|
|
|
2022-11-14 22:47:27 +00:00
|
|
|
func (suite *EmojiTestSuite) TestGetEmojiCategories() {
|
|
|
|
categories, err := suite.db.GetEmojiCategories(context.Background())
|
|
|
|
suite.NoError(err)
|
|
|
|
suite.Len(categories, 2)
|
|
|
|
// check alphabetical order
|
|
|
|
suite.Equal(categories[0].Name, "cute stuff")
|
|
|
|
suite.Equal(categories[1].Name, "reactions")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *EmojiTestSuite) TestGetEmojiCategory() {
|
|
|
|
category, err := suite.db.GetEmojiCategory(context.Background(), testrig.NewTestEmojiCategories()["reactions"].ID)
|
|
|
|
suite.NoError(err)
|
|
|
|
suite.NotNil(category)
|
|
|
|
}
|
|
|
|
|
2024-01-29 14:57:22 +00:00
|
|
|
func (suite *EmojiTestSuite) TestUpdateEmojiCategory() {
|
|
|
|
testEmoji := new(gtsmodel.Emoji)
|
|
|
|
*testEmoji = *suite.testEmojis["rainbow"]
|
|
|
|
|
|
|
|
testEmoji.CategoryID = ""
|
|
|
|
|
|
|
|
err := suite.db.UpdateEmoji(context.Background(), testEmoji, "category_id")
|
|
|
|
suite.NoError(err)
|
|
|
|
}
|
|
|
|
|
2022-05-20 08:34:36 +00:00
|
|
|
func TestEmojiTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(EmojiTestSuite))
|
|
|
|
}
|