gtsocial-umbx

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

emoji_test.go (5435B)


      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 bundb_test
     19 
     20 import (
     21 	"context"
     22 	"testing"
     23 
     24 	"github.com/stretchr/testify/suite"
     25 	"github.com/superseriousbusiness/gotosocial/internal/db"
     26 	"github.com/superseriousbusiness/gotosocial/testrig"
     27 )
     28 
     29 type EmojiTestSuite struct {
     30 	BunDBStandardTestSuite
     31 }
     32 
     33 func (suite *EmojiTestSuite) TestGetUseableEmojis() {
     34 	emojis, err := suite.db.GetUseableEmojis(context.Background())
     35 
     36 	suite.NoError(err)
     37 	suite.Equal(1, len(emojis))
     38 	suite.Equal("rainbow", emojis[0].Shortcode)
     39 }
     40 
     41 func (suite *EmojiTestSuite) TestDeleteEmojiByID() {
     42 	testEmoji := suite.testEmojis["rainbow"]
     43 
     44 	err := suite.db.DeleteEmojiByID(context.Background(), testEmoji.ID)
     45 	suite.NoError(err)
     46 
     47 	dbEmoji, err := suite.db.GetEmojiByID(context.Background(), testEmoji.ID)
     48 	suite.Nil(dbEmoji)
     49 	suite.ErrorIs(err, db.ErrNoEntries)
     50 }
     51 
     52 func (suite *EmojiTestSuite) TestGetEmojiByStaticURL() {
     53 	emoji, err := suite.db.GetEmojiByStaticURL(context.Background(), "http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/emoji/static/01F8MH9H8E4VG3KDYJR9EGPXCQ.png")
     54 	suite.NoError(err)
     55 	suite.NotNil(emoji)
     56 	suite.Equal("rainbow", emoji.Shortcode)
     57 	suite.NotNil(emoji.Category)
     58 	suite.Equal("reactions", emoji.Category.Name)
     59 }
     60 
     61 func (suite *EmojiTestSuite) TestGetAllEmojis() {
     62 	emojis, err := suite.db.GetEmojis(context.Background(), db.EmojiAllDomains, true, true, "", "", "", 0)
     63 
     64 	suite.NoError(err)
     65 	suite.Equal(2, len(emojis))
     66 	suite.Equal("rainbow", emojis[0].Shortcode)
     67 	suite.Equal("yell", emojis[1].Shortcode)
     68 }
     69 
     70 func (suite *EmojiTestSuite) TestGetAllEmojisLimit1() {
     71 	emojis, err := suite.db.GetEmojis(context.Background(), db.EmojiAllDomains, true, true, "", "", "", 1)
     72 
     73 	suite.NoError(err)
     74 	suite.Equal(1, len(emojis))
     75 	suite.Equal("rainbow", emojis[0].Shortcode)
     76 }
     77 
     78 func (suite *EmojiTestSuite) TestGetAllEmojisMaxID() {
     79 	emojis, err := suite.db.GetEmojis(context.Background(), db.EmojiAllDomains, true, true, "", "rainbow@", "", 0)
     80 
     81 	suite.NoError(err)
     82 	suite.Equal(1, len(emojis))
     83 	suite.Equal("yell", emojis[0].Shortcode)
     84 }
     85 
     86 func (suite *EmojiTestSuite) TestGetAllEmojisMinID() {
     87 	emojis, err := suite.db.GetEmojis(context.Background(), db.EmojiAllDomains, true, true, "", "", "yell@fossbros-anonymous.io", 0)
     88 
     89 	suite.NoError(err)
     90 	suite.Equal(1, len(emojis))
     91 	suite.Equal("rainbow", emojis[0].Shortcode)
     92 }
     93 
     94 func (suite *EmojiTestSuite) TestGetAllDisabledEmojis() {
     95 	emojis, err := suite.db.GetEmojis(context.Background(), db.EmojiAllDomains, true, false, "", "", "", 0)
     96 
     97 	suite.ErrorIs(err, db.ErrNoEntries)
     98 	suite.Equal(0, len(emojis))
     99 }
    100 
    101 func (suite *EmojiTestSuite) TestGetAllEnabledEmojis() {
    102 	emojis, err := suite.db.GetEmojis(context.Background(), db.EmojiAllDomains, false, true, "", "", "", 0)
    103 
    104 	suite.NoError(err)
    105 	suite.Equal(2, len(emojis))
    106 	suite.Equal("rainbow", emojis[0].Shortcode)
    107 	suite.Equal("yell", emojis[1].Shortcode)
    108 }
    109 
    110 func (suite *EmojiTestSuite) TestGetLocalEnabledEmojis() {
    111 	emojis, err := suite.db.GetEmojis(context.Background(), "", false, true, "", "", "", 0)
    112 
    113 	suite.NoError(err)
    114 	suite.Equal(1, len(emojis))
    115 	suite.Equal("rainbow", emojis[0].Shortcode)
    116 }
    117 
    118 func (suite *EmojiTestSuite) TestGetLocalDisabledEmojis() {
    119 	emojis, err := suite.db.GetEmojis(context.Background(), "", true, false, "", "", "", 0)
    120 
    121 	suite.ErrorIs(err, db.ErrNoEntries)
    122 	suite.Equal(0, len(emojis))
    123 }
    124 
    125 func (suite *EmojiTestSuite) TestGetAllEmojisFromDomain() {
    126 	emojis, err := suite.db.GetEmojis(context.Background(), "peepee.poopoo", true, true, "", "", "", 0)
    127 
    128 	suite.ErrorIs(err, db.ErrNoEntries)
    129 	suite.Equal(0, len(emojis))
    130 }
    131 
    132 func (suite *EmojiTestSuite) TestGetAllEmojisFromDomain2() {
    133 	emojis, err := suite.db.GetEmojis(context.Background(), "fossbros-anonymous.io", true, true, "", "", "", 0)
    134 
    135 	suite.NoError(err)
    136 	suite.Equal(1, len(emojis))
    137 	suite.Equal("yell", emojis[0].Shortcode)
    138 }
    139 
    140 func (suite *EmojiTestSuite) TestGetSpecificEmojisFromDomain2() {
    141 	emojis, err := suite.db.GetEmojis(context.Background(), "fossbros-anonymous.io", true, true, "yell", "", "", 0)
    142 
    143 	suite.NoError(err)
    144 	suite.Equal(1, len(emojis))
    145 	suite.Equal("yell", emojis[0].Shortcode)
    146 }
    147 
    148 func (suite *EmojiTestSuite) TestGetEmojiCategories() {
    149 	categories, err := suite.db.GetEmojiCategories(context.Background())
    150 	suite.NoError(err)
    151 	suite.Len(categories, 2)
    152 	// check alphabetical order
    153 	suite.Equal(categories[0].Name, "cute stuff")
    154 	suite.Equal(categories[1].Name, "reactions")
    155 }
    156 
    157 func (suite *EmojiTestSuite) TestGetEmojiCategory() {
    158 	category, err := suite.db.GetEmojiCategory(context.Background(), testrig.NewTestEmojiCategories()["reactions"].ID)
    159 	suite.NoError(err)
    160 	suite.NotNil(category)
    161 }
    162 
    163 func TestEmojiTestSuite(t *testing.T) {
    164 	suite.Run(t, new(EmojiTestSuite))
    165 }