OpenAPI: Add :id to follower/following endpoints, fixes #1958

This commit is contained in:
Alex Gleason 2020-07-16 21:39:10 -05:00
parent 3a2b2cb6f2
commit 48f8b26c92
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
3 changed files with 35 additions and 0 deletions

View file

@ -159,6 +159,7 @@ def followers_operation do
"Accounts which follow the given account, if network is not hidden by the account owner.", "Accounts which follow the given account, if network is not hidden by the account owner.",
parameters: [ parameters: [
%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}, %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
Operation.parameter(:id, :query, :string, "ID of the resource owner"),
with_relationships_param() | pagination_params() with_relationships_param() | pagination_params()
], ],
responses: %{ responses: %{
@ -177,6 +178,7 @@ def following_operation do
"Accounts which the given account is following, if network is not hidden by the account owner.", "Accounts which the given account is following, if network is not hidden by the account owner.",
parameters: [ parameters: [
%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}, %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
Operation.parameter(:id, :query, :string, "ID of the resource owner"),
with_relationships_param() | pagination_params() with_relationships_param() | pagination_params()
], ],
responses: %{200 => Operation.response("Accounts", "application/json", array_of_accounts())} responses: %{200 => Operation.response("Accounts", "application/json", array_of_accounts())}

View file

@ -54,6 +54,20 @@ test "paginates by min_id & limit", %{notes: notes} do
assert length(paginated) == 1 assert length(paginated) == 1
end 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 end
describe "offset" do describe "offset" do

View file

@ -583,6 +583,15 @@ test "getting followers, pagination", %{user: user, conn: conn} do
|> get("/api/v1/accounts/#{user.id}/followers?max_id=#{follower3_id}") |> get("/api/v1/accounts/#{user.id}/followers?max_id=#{follower3_id}")
|> json_response_and_validate_schema(200) |> 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}") 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) assert [%{"id" => ^follower2_id}] = json_response_and_validate_schema(res_conn, 200)
@ -654,6 +663,16 @@ test "getting following, pagination", %{user: user, conn: conn} do
assert id2 == following2.id assert id2 == following2.id
assert id1 == following1.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 = res_conn =
get(conn, "/api/v1/accounts/#{user.id}/following?limit=1&max_id=#{following3.id}") get(conn, "/api/v1/accounts/#{user.id}/following?limit=1&max_id=#{following3.id}")