gtsocial-umbx

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

opengraph_test.go (3828B)


      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 web
     19 
     20 import (
     21 	"fmt"
     22 	"testing"
     23 
     24 	"github.com/stretchr/testify/suite"
     25 	apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
     26 )
     27 
     28 type OpenGraphTestSuite struct {
     29 	suite.Suite
     30 }
     31 
     32 func (suite *OpenGraphTestSuite) TestParseDescription() {
     33 	tests := []struct {
     34 		name, in, exp string
     35 	}{
     36 		{name: "shellcmd", in: `echo '\e]8;;http://example.com\e\This is a link\e]8;;\e'`, exp: `echo &#39;&bsol;e]8;;http://example.com&bsol;e&bsol;This is a link&bsol;e]8;;&bsol;e&#39;`},
     37 		{name: "newlines", in: "test\n\ntest\ntest", exp: "test test test"},
     38 	}
     39 
     40 	for _, tt := range tests {
     41 		tt := tt
     42 		suite.Run(tt.name, func() {
     43 			suite.Equal(fmt.Sprintf("content=\"%s\"", tt.exp), parseDescription(tt.in))
     44 		})
     45 	}
     46 }
     47 
     48 func (suite *OpenGraphTestSuite) TestWithAccountWithNote() {
     49 	baseMeta := ogBase(&apimodel.InstanceV1{
     50 		AccountDomain: "example.org",
     51 		Languages:     []string{"en"},
     52 	})
     53 
     54 	accountMeta := baseMeta.withAccount(&apimodel.Account{
     55 		Acct:        "example_account",
     56 		DisplayName: "example person!!",
     57 		URL:         "https://example.org/@example_account",
     58 		Note:        "<p>This is my profile, read it and weep! Weep then!</p>",
     59 		Username:    "example_account",
     60 	})
     61 
     62 	suite.EqualValues(ogMeta{
     63 		Title:                "example person!! (@example_account@example.org)",
     64 		Type:                 "profile",
     65 		Locale:               "en",
     66 		URL:                  "https://example.org/@example_account",
     67 		SiteName:             "example.org",
     68 		Description:          "content=\"This is my profile, read it and weep! Weep then!\"",
     69 		Image:                "",
     70 		ImageWidth:           "",
     71 		ImageHeight:          "",
     72 		ImageAlt:             "Avatar for example_account",
     73 		ArticlePublisher:     "",
     74 		ArticleAuthor:        "",
     75 		ArticleModifiedTime:  "",
     76 		ArticlePublishedTime: "",
     77 		ProfileUsername:      "example_account",
     78 	}, *accountMeta)
     79 }
     80 
     81 func (suite *OpenGraphTestSuite) TestWithAccountNoNote() {
     82 	baseMeta := ogBase(&apimodel.InstanceV1{
     83 		AccountDomain: "example.org",
     84 		Languages:     []string{"en"},
     85 	})
     86 
     87 	accountMeta := baseMeta.withAccount(&apimodel.Account{
     88 		Acct:        "example_account",
     89 		DisplayName: "example person!!",
     90 		URL:         "https://example.org/@example_account",
     91 		Note:        "", // <- empty
     92 		Username:    "example_account",
     93 	})
     94 
     95 	suite.EqualValues(ogMeta{
     96 		Title:                "example person!! (@example_account@example.org)",
     97 		Type:                 "profile",
     98 		Locale:               "en",
     99 		URL:                  "https://example.org/@example_account",
    100 		SiteName:             "example.org",
    101 		Description:          "content=\"This GoToSocial user hasn't written a bio yet!\"",
    102 		Image:                "",
    103 		ImageWidth:           "",
    104 		ImageHeight:          "",
    105 		ImageAlt:             "Avatar for example_account",
    106 		ArticlePublisher:     "",
    107 		ArticleAuthor:        "",
    108 		ArticleModifiedTime:  "",
    109 		ArticlePublishedTime: "",
    110 		ProfileUsername:      "example_account",
    111 	}, *accountMeta)
    112 }
    113 
    114 func TestOpenGraphTestSuite(t *testing.T) {
    115 	suite.Run(t, &OpenGraphTestSuite{})
    116 }