From 24cec4e7aab33b6c44ba6d1ecf16895f254351b8 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Wed, 1 Mar 2023 18:52:44 +0100 Subject: [feature] Federate pinned posts (aka `featuredCollection`) in and out (#1560) * start fiddling * the ol' fiddle + update * start working on fetching statuses * poopy doopy doo where r u uwu * further adventures in featuring statuses * finishing up * fmt * simply status unpin loop * move empty featured check back to caller function * remove unnecessary log.WithContext calls * remove unnecessary IsIRI() checks * add explanatory comment about status URIs * change log level to error * better test names --- internal/typeutils/internaltoas_test.go | 92 +++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) (limited to 'internal/typeutils/internaltoas_test.go') diff --git a/internal/typeutils/internaltoas_test.go b/internal/typeutils/internaltoas_test.go index 2ea393db3..887d78884 100644 --- a/internal/typeutils/internaltoas_test.go +++ b/internal/typeutils/internaltoas_test.go @@ -21,11 +21,13 @@ package typeutils_test import ( "context" "encoding/json" + "errors" "strings" "testing" "github.com/stretchr/testify/suite" "github.com/superseriousbusiness/activity/streams" + "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/testrig" ) @@ -544,6 +546,96 @@ func (suite *InternalToASTestSuite) TestReportToAS() { }`, string(bytes)) } +func (suite *InternalToASTestSuite) TestPinnedStatusesToASSomeItems() { + ctx := context.Background() + + testAccount := suite.testAccounts["admin_account"] + statuses, err := suite.db.GetAccountPinnedStatuses(ctx, testAccount.ID) + if err != nil { + suite.FailNow(err.Error()) + } + + collection, err := suite.typeconverter.StatusesToASFeaturedCollection(ctx, testAccount.FeaturedCollectionURI, statuses) + if err != nil { + suite.FailNow(err.Error()) + } + + ser, err := streams.Serialize(collection) + suite.NoError(err) + + bytes, err := json.MarshalIndent(ser, "", " ") + suite.NoError(err) + + suite.Equal(`{ + "@context": "https://www.w3.org/ns/activitystreams", + "id": "http://localhost:8080/users/admin/collections/featured", + "orderedItems": [ + "http://localhost:8080/users/admin/statuses/01F8MHAAY43M6RJ473VQFCVH37", + "http://localhost:8080/users/admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R" + ], + "totalItems": 2, + "type": "OrderedCollection" +}`, string(bytes)) +} + +func (suite *InternalToASTestSuite) TestPinnedStatusesToASNoItems() { + ctx := context.Background() + + testAccount := suite.testAccounts["local_account_1"] + statuses, err := suite.db.GetAccountPinnedStatuses(ctx, testAccount.ID) + if err != nil && !errors.Is(err, db.ErrNoEntries) { + suite.FailNow(err.Error()) + } + + collection, err := suite.typeconverter.StatusesToASFeaturedCollection(ctx, testAccount.FeaturedCollectionURI, statuses) + if err != nil { + suite.FailNow(err.Error()) + } + + ser, err := streams.Serialize(collection) + suite.NoError(err) + + bytes, err := json.MarshalIndent(ser, "", " ") + suite.NoError(err) + + suite.Equal(`{ + "@context": "https://www.w3.org/ns/activitystreams", + "id": "http://localhost:8080/users/the_mighty_zork/collections/featured", + "orderedItems": [], + "totalItems": 0, + "type": "OrderedCollection" +}`, string(bytes)) +} + +func (suite *InternalToASTestSuite) TestPinnedStatusesToASOneItem() { + ctx := context.Background() + + testAccount := suite.testAccounts["local_account_2"] + statuses, err := suite.db.GetAccountPinnedStatuses(ctx, testAccount.ID) + if err != nil { + suite.FailNow(err.Error()) + } + + collection, err := suite.typeconverter.StatusesToASFeaturedCollection(ctx, testAccount.FeaturedCollectionURI, statuses) + if err != nil { + suite.FailNow(err.Error()) + } + + ser, err := streams.Serialize(collection) + suite.NoError(err) + + bytes, err := json.MarshalIndent(ser, "", " ") + suite.NoError(err) + + suite.Equal(`{ + "@context": "https://www.w3.org/ns/activitystreams", + "id": "http://localhost:8080/users/1happyturtle/collections/featured", + "orderedItems": "http://localhost:8080/users/1happyturtle/statuses/01G20ZM733MGN8J344T4ZDDFY1", + "totalItems": 1, + "type": "OrderedCollection" +}`, string(bytes)) +} + func TestInternalToASTestSuite(t *testing.T) { suite.Run(t, new(InternalToASTestSuite)) } -- cgit v1.2.3