Add spec for AccountController.relationships

This commit is contained in:
Egor Kislitsyn 2020-04-07 18:29:05 +04:00
commit d7d6a83233
No known key found for this signature in database
GPG key ID: 1B49CB15B71E7805
6 changed files with 156 additions and 8 deletions

View file

@ -9,6 +9,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperationTest do
alias Pleroma.Web.ApiSpec.Schemas.Account
alias Pleroma.Web.ApiSpec.Schemas.AccountCreateRequest
alias Pleroma.Web.ApiSpec.Schemas.AccountCreateResponse
alias Pleroma.Web.ApiSpec.Schemas.AccountRelationshipsResponse
alias Pleroma.Web.ApiSpec.Schemas.AccountUpdateCredentialsRequest
import OpenApiSpex.TestAssertions
@ -84,4 +85,27 @@ defmodule Pleroma.Web.ApiSpec.AccountOperationTest do
assert_schema(json, "Account", api_spec)
end
test "AccountRelationshipsResponse example matches schema" do
api_spec = ApiSpec.spec()
schema = AccountRelationshipsResponse.schema()
assert_schema(schema.example, "AccountRelationshipsResponse", api_spec)
end
test "/api/v1/accounts/relationships produces AccountRelationshipsResponse", %{
conn: conn
} do
token = insert(:oauth_token, scopes: ["read", "write"])
other_user = insert(:user)
{:ok, _user} = Pleroma.User.follow(token.user, other_user)
api_spec = ApiSpec.spec()
assert [relationship] =
conn
|> put_req_header("authorization", "Bearer " <> token.token)
|> get("/api/v1/accounts/relationships?id=#{other_user.id}")
|> json_response(:ok)
assert_schema([relationship], "AccountRelationshipsResponse", api_spec)
end
end

View file

@ -1062,14 +1062,18 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
setup do: oauth_access(["read:follows"])
test "returns the relationships for the current user", %{user: user, conn: conn} do
other_user = insert(:user)
%{id: other_user_id} = other_user = insert(:user)
{:ok, _user} = User.follow(user, other_user)
conn = get(conn, "/api/v1/accounts/relationships", %{"id" => [other_user.id]})
assert [%{"id" => ^other_user_id}] =
conn
|> get("/api/v1/accounts/relationships?id=#{other_user.id}")
|> json_response(200)
assert [relationship] = json_response(conn, 200)
assert to_string(other_user.id) == relationship["id"]
assert [%{"id" => ^other_user_id}] =
conn
|> get("/api/v1/accounts/relationships?id[]=#{other_user.id}")
|> json_response(200)
end
test "returns an empty list on a bad request", %{conn: conn} do