summaryrefslogtreecommitdiff
path: root/internal/typeutils/internaltoas_test.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-03-01 18:52:44 +0100
committerLibravatar GitHub <noreply@github.com>2023-03-01 17:52:44 +0000
commit24cec4e7aab33b6c44ba6d1ecf16895f254351b8 (patch)
treecf0107a34e0fa00ab1b68aed4b52afe502147393 /internal/typeutils/internaltoas_test.go
parent[chore/performance] simplify storage driver to use storage.Storage directly (... (diff)
downloadgotosocial-24cec4e7aab33b6c44ba6d1ecf16895f254351b8.tar.xz
[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
Diffstat (limited to 'internal/typeutils/internaltoas_test.go')
-rw-r--r--internal/typeutils/internaltoas_test.go92
1 files changed, 92 insertions, 0 deletions
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))
}