Add spec for AccountController.unfollow

This commit is contained in:
Egor Kislitsyn 2020-04-09 17:57:21 +04:00
parent 854780c72b
commit aa958a6dda
No known key found for this signature in database
GPG key ID: 1B49CB15B71E7805
3 changed files with 28 additions and 6 deletions

View file

@ -225,7 +225,20 @@ def follow_operation do
} }
end end
def unfollow_operation, do: :ok def unfollow_operation do
%Operation{
tags: ["accounts"],
summary: "Unfollow",
operationId: "AccountController.unfollow",
security: [%{"oAuth" => ["follow", "write:follows"]}],
description: "Unfollow the given account",
parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
responses: %{
200 => Operation.response("Relationship", "application/json", AccountRelationship)
}
}
end
def mute_operation, do: :ok def mute_operation, do: :ok
def unmute_operation, do: :ok def unmute_operation, do: :ok
def block_operation, do: :ok def block_operation, do: :ok

View file

@ -93,7 +93,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
:followers, :followers,
:following, :following,
:lists, :lists,
:follow :follow,
:unfollow
] ]
) )

View file

@ -660,10 +660,12 @@ test "following / unfollowing a user", %{conn: conn} do
ret_conn = post(conn, "/api/v1/accounts/#{other_user.id}/follow") ret_conn = post(conn, "/api/v1/accounts/#{other_user.id}/follow")
assert %{"id" => _id, "following" => true} = json_response(ret_conn, 200) assert %{"id" => _id, "following" => true} = json_response(ret_conn, 200)
assert_schema(json_response(ret_conn, 200), "AccountRelationship", ApiSpec.spec())
ret_conn = post(conn, "/api/v1/accounts/#{other_user.id}/unfollow") ret_conn = post(conn, "/api/v1/accounts/#{other_user.id}/unfollow")
assert %{"id" => _id, "following" => false} = json_response(ret_conn, 200) assert %{"id" => _id, "following" => false} = json_response(ret_conn, 200)
assert_schema(json_response(ret_conn, 200), "AccountRelationship", ApiSpec.spec())
conn = post(conn, "/api/v1/follows", %{"uri" => other_user.nickname}) conn = post(conn, "/api/v1/follows", %{"uri" => other_user.nickname})
@ -675,11 +677,15 @@ test "following / unfollowing a user", %{conn: conn} do
test "cancelling follow request", %{conn: conn} do test "cancelling follow request", %{conn: conn} do
%{id: other_user_id} = insert(:user, %{locked: true}) %{id: other_user_id} = insert(:user, %{locked: true})
assert %{"id" => ^other_user_id, "following" => false, "requested" => true} = resp = conn |> post("/api/v1/accounts/#{other_user_id}/follow") |> json_response(:ok)
conn |> post("/api/v1/accounts/#{other_user_id}/follow") |> json_response(:ok)
assert %{"id" => ^other_user_id, "following" => false, "requested" => false} = assert %{"id" => ^other_user_id, "following" => false, "requested" => true} = resp
conn |> post("/api/v1/accounts/#{other_user_id}/unfollow") |> json_response(:ok) assert_schema(resp, "AccountRelationship", ApiSpec.spec())
resp = conn |> post("/api/v1/accounts/#{other_user_id}/unfollow") |> json_response(:ok)
assert %{"id" => ^other_user_id, "following" => false, "requested" => false} = resp
assert_schema(resp, "AccountRelationship", ApiSpec.spec())
end end
test "following without reblogs" do test "following without reblogs" do
@ -690,6 +696,7 @@ test "following without reblogs" do
ret_conn = post(conn, "/api/v1/accounts/#{followed.id}/follow?reblogs=false") ret_conn = post(conn, "/api/v1/accounts/#{followed.id}/follow?reblogs=false")
assert %{"showing_reblogs" => false} = json_response(ret_conn, 200) assert %{"showing_reblogs" => false} = json_response(ret_conn, 200)
assert_schema(json_response(ret_conn, 200), "AccountRelationship", ApiSpec.spec())
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "hey"}) {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hey"})
{:ok, reblog, _} = CommonAPI.repeat(activity.id, followed) {:ok, reblog, _} = CommonAPI.repeat(activity.id, followed)
@ -701,6 +708,7 @@ test "following without reblogs" do
ret_conn = post(conn, "/api/v1/accounts/#{followed.id}/follow?reblogs=true") ret_conn = post(conn, "/api/v1/accounts/#{followed.id}/follow?reblogs=true")
assert %{"showing_reblogs" => true} = json_response(ret_conn, 200) assert %{"showing_reblogs" => true} = json_response(ret_conn, 200)
assert_schema(json_response(ret_conn, 200), "AccountRelationship", ApiSpec.spec())
conn = get(conn, "/api/v1/timelines/home") conn = get(conn, "/api/v1/timelines/home")