mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-18 10:37:29 -06:00
[feature] Add /api/v1/admin/custom_emojis endpoint (#902)
* add admin emojis get path + model + docs * stub admin emojis get processor function * add id + disabled fields to admin emoji * add emoji -> api admin emoji converter * tidy up a bit * add GetEmojis function * finish up get emojis function * order by shortcodedomain * ASC * tidy up + explain * update to allow paging * make admin emojis pageable * fix mixed case paging * normalize emoji queries a bit better * test emoji get paging * make limit optional * fix incorrect path in media cleanup tests * i have bad coder syndrome * don't trimspace * rename -> GetUseableEmojis * wrap emoji query in subquery avoid selecting more than we need * fix a bit of sillyness teehee * fix subquery postgres woes
This commit is contained in:
parent
5cd087241b
commit
eb85ef7325
18 changed files with 887 additions and 9 deletions
|
|
@ -23,20 +23,108 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
)
|
||||
|
||||
type EmojiTestSuite struct {
|
||||
BunDBStandardTestSuite
|
||||
}
|
||||
|
||||
func (suite *EmojiTestSuite) TestGetCustomEmojis() {
|
||||
emojis, err := suite.db.GetCustomEmojis(context.Background())
|
||||
func (suite *EmojiTestSuite) TestGetUseableEmojis() {
|
||||
emojis, err := suite.db.GetUseableEmojis(context.Background())
|
||||
|
||||
suite.NoError(err)
|
||||
suite.Equal(1, len(emojis))
|
||||
suite.Equal("rainbow", emojis[0].Shortcode)
|
||||
}
|
||||
|
||||
func (suite *EmojiTestSuite) TestGetAllEmojis() {
|
||||
emojis, err := suite.db.GetEmojis(context.Background(), db.EmojiAllDomains, true, true, "", "", "", 0)
|
||||
|
||||
suite.NoError(err)
|
||||
suite.Equal(2, len(emojis))
|
||||
suite.Equal("rainbow", emojis[0].Shortcode)
|
||||
suite.Equal("yell", emojis[1].Shortcode)
|
||||
}
|
||||
|
||||
func (suite *EmojiTestSuite) TestGetAllEmojisLimit1() {
|
||||
emojis, err := suite.db.GetEmojis(context.Background(), db.EmojiAllDomains, true, true, "", "", "", 1)
|
||||
|
||||
suite.NoError(err)
|
||||
suite.Equal(1, len(emojis))
|
||||
suite.Equal("rainbow", emojis[0].Shortcode)
|
||||
}
|
||||
|
||||
func (suite *EmojiTestSuite) TestGetAllEmojisMaxID() {
|
||||
emojis, err := suite.db.GetEmojis(context.Background(), db.EmojiAllDomains, true, true, "", "rainbow@", "", 0)
|
||||
|
||||
suite.NoError(err)
|
||||
suite.Equal(1, len(emojis))
|
||||
suite.Equal("yell", emojis[0].Shortcode)
|
||||
}
|
||||
|
||||
func (suite *EmojiTestSuite) TestGetAllEmojisMinID() {
|
||||
emojis, err := suite.db.GetEmojis(context.Background(), db.EmojiAllDomains, true, true, "", "", "yell@fossbros-anonymous.io", 0)
|
||||
|
||||
suite.NoError(err)
|
||||
suite.Equal(1, len(emojis))
|
||||
suite.Equal("rainbow", emojis[0].Shortcode)
|
||||
}
|
||||
|
||||
func (suite *EmojiTestSuite) TestGetAllDisabledEmojis() {
|
||||
emojis, err := suite.db.GetEmojis(context.Background(), db.EmojiAllDomains, true, false, "", "", "", 0)
|
||||
|
||||
suite.ErrorIs(err, db.ErrNoEntries)
|
||||
suite.Equal(0, len(emojis))
|
||||
}
|
||||
|
||||
func (suite *EmojiTestSuite) TestGetAllEnabledEmojis() {
|
||||
emojis, err := suite.db.GetEmojis(context.Background(), db.EmojiAllDomains, false, true, "", "", "", 0)
|
||||
|
||||
suite.NoError(err)
|
||||
suite.Equal(2, len(emojis))
|
||||
suite.Equal("rainbow", emojis[0].Shortcode)
|
||||
suite.Equal("yell", emojis[1].Shortcode)
|
||||
}
|
||||
|
||||
func (suite *EmojiTestSuite) TestGetLocalEnabledEmojis() {
|
||||
emojis, err := suite.db.GetEmojis(context.Background(), "", false, true, "", "", "", 0)
|
||||
|
||||
suite.NoError(err)
|
||||
suite.Equal(1, len(emojis))
|
||||
suite.Equal("rainbow", emojis[0].Shortcode)
|
||||
}
|
||||
|
||||
func (suite *EmojiTestSuite) TestGetLocalDisabledEmojis() {
|
||||
emojis, err := suite.db.GetEmojis(context.Background(), "", true, false, "", "", "", 0)
|
||||
|
||||
suite.ErrorIs(err, db.ErrNoEntries)
|
||||
suite.Equal(0, len(emojis))
|
||||
}
|
||||
|
||||
func (suite *EmojiTestSuite) TestGetAllEmojisFromDomain() {
|
||||
emojis, err := suite.db.GetEmojis(context.Background(), "peepee.poopoo", true, true, "", "", "", 0)
|
||||
|
||||
suite.ErrorIs(err, db.ErrNoEntries)
|
||||
suite.Equal(0, len(emojis))
|
||||
}
|
||||
|
||||
func (suite *EmojiTestSuite) TestGetAllEmojisFromDomain2() {
|
||||
emojis, err := suite.db.GetEmojis(context.Background(), "fossbros-anonymous.io", true, true, "", "", "", 0)
|
||||
|
||||
suite.NoError(err)
|
||||
suite.Equal(1, len(emojis))
|
||||
suite.Equal("yell", emojis[0].Shortcode)
|
||||
}
|
||||
|
||||
func (suite *EmojiTestSuite) TestGetSpecificEmojisFromDomain2() {
|
||||
emojis, err := suite.db.GetEmojis(context.Background(), "fossbros-anonymous.io", true, true, "yell", "", "", 0)
|
||||
|
||||
suite.NoError(err)
|
||||
suite.Equal(1, len(emojis))
|
||||
suite.Equal("yell", emojis[0].Shortcode)
|
||||
}
|
||||
|
||||
func TestEmojiTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(EmojiTestSuite))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue