Add spec for AccountController.following
This commit is contained in:
parent
bd6e2b300f
commit
e105cc12b6
@ -150,8 +150,40 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||||||
parameters: [
|
parameters: [
|
||||||
%Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
|
%Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
|
||||||
Operation.parameter(:max_id, :query, :string, "Max ID"),
|
Operation.parameter(:max_id, :query, :string, "Max ID"),
|
||||||
|
Operation.parameter(:min_id, :query, :string, "Mix ID"),
|
||||||
Operation.parameter(:since_id, :query, :string, "Since ID"),
|
Operation.parameter(:since_id, :query, :string, "Since ID"),
|
||||||
Operation.parameter(:limit, :query, :integer, "Limit")
|
Operation.parameter(
|
||||||
|
:limit,
|
||||||
|
:query,
|
||||||
|
%Schema{type: :integer, default: 20, maximum: 40},
|
||||||
|
"Limit"
|
||||||
|
)
|
||||||
|
],
|
||||||
|
responses: %{
|
||||||
|
200 => Operation.response("Accounts", "application/json", AccountsResponse)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def following_operation do
|
||||||
|
%Operation{
|
||||||
|
tags: ["accounts"],
|
||||||
|
summary: "Following",
|
||||||
|
operationId: "AccountController.following",
|
||||||
|
security: [%{"oAuth" => ["read:accounts"]}],
|
||||||
|
description:
|
||||||
|
"Accounts which the given account is following, if network is not hidden by the account owner.",
|
||||||
|
parameters: [
|
||||||
|
%Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
|
||||||
|
Operation.parameter(:max_id, :query, :string, "Max ID"),
|
||||||
|
Operation.parameter(:min_id, :query, :string, "Mix ID"),
|
||||||
|
Operation.parameter(:since_id, :query, :string, "Since ID"),
|
||||||
|
Operation.parameter(
|
||||||
|
:limit,
|
||||||
|
:query,
|
||||||
|
%Schema{type: :integer, default: 20, maximum: 40},
|
||||||
|
"Limit"
|
||||||
|
)
|
||||||
],
|
],
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => Operation.response("Accounts", "application/json", AccountsResponse)
|
200 => Operation.response("Accounts", "application/json", AccountsResponse)
|
||||||
@ -159,7 +191,6 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def following_operation, do: :ok
|
|
||||||
def lists_operation, do: :ok
|
def lists_operation, do: :ok
|
||||||
def follow_operation, do: :ok
|
def follow_operation, do: :ok
|
||||||
def unfollow_operation, do: :ok
|
def unfollow_operation, do: :ok
|
||||||
|
@ -90,7 +90,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
|
|||||||
:relationships,
|
:relationships,
|
||||||
:show,
|
:show,
|
||||||
:statuses,
|
:statuses,
|
||||||
:followers
|
:followers,
|
||||||
|
:following
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -304,6 +305,11 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
|
|||||||
|
|
||||||
@doc "GET /api/v1/accounts/:id/following"
|
@doc "GET /api/v1/accounts/:id/following"
|
||||||
def following(%{assigns: %{user: for_user, account: user}} = conn, params) do
|
def following(%{assigns: %{user: for_user, account: user}} = conn, params) do
|
||||||
|
params =
|
||||||
|
params
|
||||||
|
|> Enum.map(fn {key, value} -> {to_string(key), value} end)
|
||||||
|
|> Enum.into(%{})
|
||||||
|
|
||||||
followers =
|
followers =
|
||||||
cond do
|
cond do
|
||||||
for_user && user.id == for_user.id -> MastodonAPI.get_friends(user, params)
|
for_user && user.id == for_user.id -> MastodonAPI.get_friends(user, params)
|
||||||
|
@ -584,6 +584,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||||||
|
|
||||||
assert [%{"id" => id}] = json_response(conn, 200)
|
assert [%{"id" => id}] = json_response(conn, 200)
|
||||||
assert id == to_string(other_user.id)
|
assert id == to_string(other_user.id)
|
||||||
|
assert_schema(json_response(conn, 200), "AccountsResponse", ApiSpec.spec())
|
||||||
end
|
end
|
||||||
|
|
||||||
test "getting following, hide_follows, other user requesting" do
|
test "getting following, hide_follows, other user requesting" do
|
||||||
@ -598,6 +599,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||||||
|> get("/api/v1/accounts/#{user.id}/following")
|
|> get("/api/v1/accounts/#{user.id}/following")
|
||||||
|
|
||||||
assert [] == json_response(conn, 200)
|
assert [] == json_response(conn, 200)
|
||||||
|
assert_schema(json_response(conn, 200), "AccountsResponse", ApiSpec.spec())
|
||||||
end
|
end
|
||||||
|
|
||||||
test "getting following, hide_follows, same user requesting" do
|
test "getting following, hide_follows, same user requesting" do
|
||||||
@ -627,12 +629,14 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||||||
assert [%{"id" => id3}, %{"id" => id2}] = json_response(res_conn, 200)
|
assert [%{"id" => id3}, %{"id" => id2}] = json_response(res_conn, 200)
|
||||||
assert id3 == following3.id
|
assert id3 == following3.id
|
||||||
assert id2 == following2.id
|
assert id2 == following2.id
|
||||||
|
assert_schema(json_response(res_conn, 200), "AccountsResponse", ApiSpec.spec())
|
||||||
|
|
||||||
res_conn = get(conn, "/api/v1/accounts/#{user.id}/following?max_id=#{following3.id}")
|
res_conn = get(conn, "/api/v1/accounts/#{user.id}/following?max_id=#{following3.id}")
|
||||||
|
|
||||||
assert [%{"id" => id2}, %{"id" => id1}] = json_response(res_conn, 200)
|
assert [%{"id" => id2}, %{"id" => id1}] = json_response(res_conn, 200)
|
||||||
assert id2 == following2.id
|
assert id2 == following2.id
|
||||||
assert id1 == following1.id
|
assert id1 == following1.id
|
||||||
|
assert_schema(json_response(res_conn, 200), "AccountsResponse", ApiSpec.spec())
|
||||||
|
|
||||||
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}")
|
||||||
@ -643,6 +647,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||||||
assert [link_header] = get_resp_header(res_conn, "link")
|
assert [link_header] = get_resp_header(res_conn, "link")
|
||||||
assert link_header =~ ~r/min_id=#{following2.id}/
|
assert link_header =~ ~r/min_id=#{following2.id}/
|
||||||
assert link_header =~ ~r/max_id=#{following2.id}/
|
assert link_header =~ ~r/max_id=#{following2.id}/
|
||||||
|
assert_schema(json_response(res_conn, 200), "AccountsResponse", ApiSpec.spec())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user