gtsocial-umbx

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

emoji_test.go (3617B)


      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 dereferencing_test
     19 
     20 import (
     21 	"context"
     22 	"testing"
     23 	"time"
     24 
     25 	"github.com/stretchr/testify/suite"
     26 	"github.com/superseriousbusiness/gotosocial/internal/media"
     27 )
     28 
     29 type EmojiTestSuite struct {
     30 	DereferencerStandardTestSuite
     31 }
     32 
     33 func (suite *EmojiTestSuite) TestDereferenceEmojiBlocking() {
     34 	ctx := context.Background()
     35 	fetchingAccount := suite.testAccounts["local_account_1"]
     36 	emojiImageRemoteURL := "http://example.org/media/emojis/1781772.gif"
     37 	emojiImageStaticRemoteURL := "http://example.org/media/emojis/1781772.gif"
     38 	emojiURI := "http://example.org/emojis/1781772"
     39 	emojiShortcode := "peglin"
     40 	emojiID := "01GCBMGNZBKMEE1KTZ6PMJEW5D"
     41 	emojiDomain := "example.org"
     42 	emojiDisabled := false
     43 	emojiVisibleInPicker := false
     44 
     45 	ai := &media.AdditionalEmojiInfo{
     46 		Domain:               &emojiDomain,
     47 		ImageRemoteURL:       &emojiImageRemoteURL,
     48 		ImageStaticRemoteURL: &emojiImageStaticRemoteURL,
     49 		Disabled:             &emojiDisabled,
     50 		VisibleInPicker:      &emojiVisibleInPicker,
     51 	}
     52 
     53 	processingEmoji, err := suite.dereferencer.GetRemoteEmoji(ctx, fetchingAccount.Username, emojiImageRemoteURL, emojiShortcode, emojiDomain, emojiID, emojiURI, ai, false)
     54 	suite.NoError(err)
     55 
     56 	// make a blocking call to load the emoji from the in-process media
     57 	emoji, err := processingEmoji.LoadEmoji(ctx)
     58 	suite.NoError(err)
     59 	suite.NotNil(emoji)
     60 
     61 	suite.Equal(emojiID, emoji.ID)
     62 	suite.WithinDuration(time.Now(), emoji.CreatedAt, 10*time.Second)
     63 	suite.WithinDuration(time.Now(), emoji.UpdatedAt, 10*time.Second)
     64 	suite.Equal(emojiShortcode, emoji.Shortcode)
     65 	suite.Equal(emojiDomain, emoji.Domain)
     66 	suite.Equal(emojiImageRemoteURL, emoji.ImageRemoteURL)
     67 	suite.Equal(emojiImageStaticRemoteURL, emoji.ImageStaticRemoteURL)
     68 	suite.Contains(emoji.ImageURL, "/emoji/original/01GCBMGNZBKMEE1KTZ6PMJEW5D.gif")
     69 	suite.Contains(emoji.ImageStaticURL, "emoji/static/01GCBMGNZBKMEE1KTZ6PMJEW5D.png")
     70 	suite.Contains(emoji.ImagePath, "/emoji/original/01GCBMGNZBKMEE1KTZ6PMJEW5D.gif")
     71 	suite.Contains(emoji.ImageStaticPath, "/emoji/static/01GCBMGNZBKMEE1KTZ6PMJEW5D.png")
     72 	suite.Equal("image/gif", emoji.ImageContentType)
     73 	suite.Equal("image/png", emoji.ImageStaticContentType)
     74 	suite.Equal(37796, emoji.ImageFileSize)
     75 	suite.Equal(7951, emoji.ImageStaticFileSize)
     76 	suite.WithinDuration(time.Now(), emoji.ImageUpdatedAt, 10*time.Second)
     77 	suite.False(*emoji.Disabled)
     78 	suite.Equal(emojiURI, emoji.URI)
     79 	suite.False(*emoji.VisibleInPicker)
     80 	suite.Empty(emoji.CategoryID)
     81 
     82 	// ensure that emoji is now in storage
     83 	stored, err := suite.storage.Get(ctx, emoji.ImagePath)
     84 	suite.NoError(err)
     85 	suite.Len(stored, emoji.ImageFileSize)
     86 
     87 	storedStatic, err := suite.storage.Get(ctx, emoji.ImageStaticPath)
     88 	suite.NoError(err)
     89 	suite.Len(storedStatic, emoji.ImageStaticFileSize)
     90 }
     91 
     92 func TestEmojiTestSuite(t *testing.T) {
     93 	suite.Run(t, new(EmojiTestSuite))
     94 }