summaryrefslogtreecommitdiff
path: root/internal/ap
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-04-02 11:42:24 +0200
committerLibravatar GitHub <noreply@github.com>2024-04-02 10:42:24 +0100
commitf05874be3095d3fb3cefd1a92b3c35fe3ae3bf28 (patch)
tree52f1616259b51d0a8a94a786278b9c0aa5ab2298 /internal/ap
parent[feature] Add `enable` command to mirror existing `disable` command; update d... (diff)
downloadgotosocial-f05874be3095d3fb3cefd1a92b3c35fe3ae3bf28.tar.xz
[feature] Option to hide followers/following (#2788)
Diffstat (limited to 'internal/ap')
-rw-r--r--internal/ap/activitystreams_test.go60
-rw-r--r--internal/ap/collections.go7
2 files changed, 66 insertions, 1 deletions
diff --git a/internal/ap/activitystreams_test.go b/internal/ap/activitystreams_test.go
index d769fa42f..edade9718 100644
--- a/internal/ap/activitystreams_test.go
+++ b/internal/ap/activitystreams_test.go
@@ -49,6 +49,7 @@ func TestASCollection(t *testing.T) {
// Create new collection using builder function.
c := ap.NewASCollection(ap.CollectionParams{
ID: parseURI(idURI),
+ First: new(paging.Page),
Query: url.Values{"limit": []string{"40"}},
Total: total,
})
@@ -60,6 +61,37 @@ func TestASCollection(t *testing.T) {
assert.Equal(t, expect, s)
}
+func TestASCollectionTotalOnly(t *testing.T) {
+ const (
+ proto = "https"
+ host = "zorg.flabormagorg.xyz"
+ path = "/users/itsa_me_mario"
+
+ idURI = proto + "://" + host + path
+ total = 10
+ )
+
+ // Create JSON string of expected output.
+ expect := toJSON(map[string]any{
+ "@context": "https://www.w3.org/ns/activitystreams",
+ "type": "Collection",
+ "id": idURI,
+ "totalItems": total,
+ })
+
+ // Create new collection using builder function.
+ c := ap.NewASCollection(ap.CollectionParams{
+ ID: parseURI(idURI),
+ Total: total,
+ })
+
+ // Serialize collection.
+ s := toJSON(c)
+
+ // Ensure outputs are equal.
+ assert.Equal(t, expect, s)
+}
+
func TestASCollectionPage(t *testing.T) {
const (
proto = "https"
@@ -132,6 +164,7 @@ func TestASOrderedCollection(t *testing.T) {
// Create new collection using builder function.
c := ap.NewASOrderedCollection(ap.CollectionParams{
ID: parseURI(idURI),
+ First: new(paging.Page),
Query: url.Values{"limit": []string{"40"}},
Total: total,
})
@@ -143,6 +176,33 @@ func TestASOrderedCollection(t *testing.T) {
assert.Equal(t, expect, s)
}
+func TestASOrderedCollectionTotalOnly(t *testing.T) {
+ const (
+ idURI = "https://zorg.flabormagorg.xyz/users/itsa_me_mario"
+ total = 10
+ )
+
+ // Create JSON string of expected output.
+ expect := toJSON(map[string]any{
+ "@context": "https://www.w3.org/ns/activitystreams",
+ "type": "OrderedCollection",
+ "id": idURI,
+ "totalItems": total,
+ })
+
+ // Create new collection using builder function.
+ c := ap.NewASOrderedCollection(ap.CollectionParams{
+ ID: parseURI(idURI),
+ Total: total,
+ })
+
+ // Serialize collection.
+ s := toJSON(c)
+
+ // Ensure outputs are equal.
+ assert.Equal(t, expect, s)
+}
+
func TestASOrderedCollectionPage(t *testing.T) {
const (
proto = "https"
diff --git a/internal/ap/collections.go b/internal/ap/collections.go
index da789e179..c55bbe70b 100644
--- a/internal/ap/collections.go
+++ b/internal/ap/collections.go
@@ -281,7 +281,7 @@ type CollectionParams struct {
ID *url.URL
// First page details.
- First paging.Page
+ First *paging.Page
Query url.Values
// Total no. items.
@@ -377,6 +377,11 @@ func buildCollection[C CollectionBuilder](collection C, params CollectionParams)
totalItems.Set(params.Total)
collection.SetActivityStreamsTotalItems(totalItems)
+ // No First page means we're done.
+ if params.First == nil {
+ return
+ }
+
// Append paging query params
// to those already in ID prop.
pageQueryParams := appendQuery(