From a6ec2a5bc260aa1be0e97c4be674266748fe093d Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Wed, 3 May 2023 16:18:34 +0200 Subject: [bugfix] Fix invalid og:description on account w/ empty note (#1733) --- internal/web/opengraph_test.go | 67 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'internal/web/opengraph_test.go') diff --git a/internal/web/opengraph_test.go b/internal/web/opengraph_test.go index 1cfbd7c70..06e97cdce 100644 --- a/internal/web/opengraph_test.go +++ b/internal/web/opengraph_test.go @@ -22,6 +22,7 @@ import ( "testing" "github.com/stretchr/testify/suite" + apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" ) type OpenGraphTestSuite struct { @@ -44,6 +45,72 @@ func (suite *OpenGraphTestSuite) TestParseDescription() { } } +func (suite *OpenGraphTestSuite) TestWithAccountWithNote() { + baseMeta := ogBase(&apimodel.InstanceV1{ + AccountDomain: "example.org", + Languages: []string{"en"}, + }) + + accountMeta := baseMeta.withAccount(&apimodel.Account{ + Acct: "example_account", + DisplayName: "example person!!", + URL: "https://example.org/@example_account", + Note: "
This is my profile, read it and weep! Weep then!
", + Username: "example_account", + }) + + suite.EqualValues(ogMeta{ + Title: "example person!! (@example_account@example.org)", + Type: "profile", + Locale: "en", + URL: "https://example.org/@example_account", + SiteName: "example.org", + Description: "content=\"This is my profile, read it and weep! Weep then!\"", + Image: "", + ImageWidth: "", + ImageHeight: "", + ImageAlt: "Avatar for example_account", + ArticlePublisher: "", + ArticleAuthor: "", + ArticleModifiedTime: "", + ArticlePublishedTime: "", + ProfileUsername: "example_account", + }, *accountMeta) +} + +func (suite *OpenGraphTestSuite) TestWithAccountNoNote() { + baseMeta := ogBase(&apimodel.InstanceV1{ + AccountDomain: "example.org", + Languages: []string{"en"}, + }) + + accountMeta := baseMeta.withAccount(&apimodel.Account{ + Acct: "example_account", + DisplayName: "example person!!", + URL: "https://example.org/@example_account", + Note: "", // <- empty + Username: "example_account", + }) + + suite.EqualValues(ogMeta{ + Title: "example person!! (@example_account@example.org)", + Type: "profile", + Locale: "en", + URL: "https://example.org/@example_account", + SiteName: "example.org", + Description: "content=\"This GoToSocial user hasn't written a bio yet!\"", + Image: "", + ImageWidth: "", + ImageHeight: "", + ImageAlt: "Avatar for example_account", + ArticlePublisher: "", + ArticleAuthor: "", + ArticleModifiedTime: "", + ArticlePublishedTime: "", + ProfileUsername: "example_account", + }, *accountMeta) +} + func TestOpenGraphTestSuite(t *testing.T) { suite.Run(t, &OpenGraphTestSuite{}) } -- cgit v1.2.3