OpenAPI: Add :id to follower/following endpoints, fixes #1958
authorAlex Gleason <alex@alexgleason.me>
Fri, 17 Jul 2020 02:39:10 +0000 (21:39 -0500)
committerAlex Gleason <alex@alexgleason.me>
Fri, 17 Jul 2020 17:35:28 +0000 (12:35 -0500)
lib/pleroma/web/api_spec/operations/account_operation.ex
test/pagination_test.exs
test/web/mastodon_api/controllers/account_controller_test.exs

index 952d9347b0013721efaa4a038744609038d07641..50c8e0242e0b161bda0787bbff5b4cb3dd2e82e1 100644 (file)
@@ -159,6 +159,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
         "Accounts which follow the given account, if network is not hidden by the account owner.",
       parameters: [
         %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
+        Operation.parameter(:id, :query, :string, "ID of the resource owner"),
         with_relationships_param() | pagination_params()
       ],
       responses: %{
@@ -177,6 +178,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
         "Accounts which the given account is following, if network is not hidden by the account owner.",
       parameters: [
         %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
+        Operation.parameter(:id, :query, :string, "ID of the resource owner"),
         with_relationships_param() | pagination_params()
       ],
       responses: %{200 => Operation.response("Accounts", "application/json", array_of_accounts())}
index 9165427aee6030584eb4edb199091f86082bcedf..e526f23e89731c27fa0c63476aaced445748ab38 100644 (file)
@@ -54,6 +54,20 @@ defmodule Pleroma.PaginationTest do
 
       assert length(paginated) == 1
     end
+
+    test "handles id gracefully", %{notes: notes} do
+      id = Enum.at(notes, 1).id |> Integer.to_string()
+
+      paginated =
+        Pagination.fetch_paginated(Object, %{
+          id: "9s99Hq44Cnv8PKBwWG",
+          max_id: id,
+          limit: 20,
+          offset: 0
+        })
+
+      assert length(paginated) == 1
+    end
   end
 
   describe "offset" do
index 9c7b5e9b22394389f9536e78a3743bfaeee1d4e7..c304487eae581373957b7c04ee475ee627c0ee7d 100644 (file)
@@ -583,6 +583,15 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
                |> get("/api/v1/accounts/#{user.id}/followers?max_id=#{follower3_id}")
                |> json_response_and_validate_schema(200)
 
+      assert [%{"id" => ^follower2_id}, %{"id" => ^follower1_id}] =
+               conn
+               |> get(
+                 "/api/v1/accounts/#{user.id}/followers?id=#{user.id}&limit=20&max_id=#{
+                   follower3_id
+                 }"
+               )
+               |> json_response_and_validate_schema(200)
+
       res_conn = get(conn, "/api/v1/accounts/#{user.id}/followers?limit=1&max_id=#{follower3_id}")
 
       assert [%{"id" => ^follower2_id}] = json_response_and_validate_schema(res_conn, 200)
@@ -654,6 +663,16 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
       assert id2 == following2.id
       assert id1 == following1.id
 
+      res_conn =
+        get(
+          conn,
+          "/api/v1/accounts/#{user.id}/following?id=#{user.id}&limit=20&max_id=#{following3.id}"
+        )
+
+      assert [%{"id" => id2}, %{"id" => id1}] = json_response_and_validate_schema(res_conn, 200)
+      assert id2 == following2.id
+      assert id1 == following1.id
+
       res_conn =
         get(conn, "/api/v1/accounts/#{user.id}/following?limit=1&max_id=#{following3.id}")