1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ApiSpec.AccountOperationTest do
6 use Pleroma.Web.ConnCase
8 alias Pleroma.Web.ApiSpec
9 alias Pleroma.Web.ApiSpec.Schemas.Account
10 alias Pleroma.Web.ApiSpec.Schemas.AccountCreateRequest
11 alias Pleroma.Web.ApiSpec.Schemas.AccountCreateResponse
12 alias Pleroma.Web.ApiSpec.Schemas.AccountRelationshipsResponse
13 alias Pleroma.Web.ApiSpec.Schemas.AccountUpdateCredentialsRequest
15 import OpenApiSpex.TestAssertions
16 import Pleroma.Factory
18 test "Account example matches schema" do
19 api_spec = ApiSpec.spec()
20 schema = Account.schema()
21 assert_schema(schema.example, "Account", api_spec)
24 test "AccountCreateRequest example matches schema" do
25 api_spec = ApiSpec.spec()
26 schema = AccountCreateRequest.schema()
27 assert_schema(schema.example, "AccountCreateRequest", api_spec)
30 test "AccountCreateResponse example matches schema" do
31 api_spec = ApiSpec.spec()
32 schema = AccountCreateResponse.schema()
33 assert_schema(schema.example, "AccountCreateResponse", api_spec)
36 test "AccountUpdateCredentialsRequest example matches schema" do
37 api_spec = ApiSpec.spec()
38 schema = AccountUpdateCredentialsRequest.schema()
39 assert_schema(schema.example, "AccountUpdateCredentialsRequest", api_spec)
42 test "AccountController produces a AccountCreateResponse", %{conn: conn} do
43 api_spec = ApiSpec.spec()
44 app_token = insert(:oauth_token, user: nil)
48 |> put_req_header("authorization", "Bearer " <> app_token.token)
49 |> put_req_header("content-type", "application/json")
54 email: "bar@example.org",
61 assert_schema(json, "AccountCreateResponse", api_spec)
64 test "AccountUpdateCredentialsRequest produces an Account", %{conn: conn} do
65 api_spec = ApiSpec.spec()
66 token = insert(:oauth_token, scopes: ["read", "write"])
70 |> put_req_header("authorization", "Bearer " <> token.token)
71 |> put_req_header("content-type", "application/json")
73 "/api/v1/accounts/update_credentials",
75 hide_followers_count: "true",
76 hide_follows_count: "true",
77 skip_thread_containment: "true",
79 pleroma_settings_store: %{"pleroma-fe" => %{"key" => "val"}},
81 fields_attributes: [%{name: "foo", value: "bar"}]
86 assert_schema(json, "Account", api_spec)
89 test "AccountRelationshipsResponse example matches schema" do
90 api_spec = ApiSpec.spec()
91 schema = AccountRelationshipsResponse.schema()
92 assert_schema(schema.example, "AccountRelationshipsResponse", api_spec)
95 test "/api/v1/accounts/relationships produces AccountRelationshipsResponse", %{
98 token = insert(:oauth_token, scopes: ["read", "write"])
99 other_user = insert(:user)
100 {:ok, _user} = Pleroma.User.follow(token.user, other_user)
101 api_spec = ApiSpec.spec()
103 assert [relationship] =
105 |> put_req_header("authorization", "Bearer " <> token.token)
106 |> get("/api/v1/accounts/relationships?id=#{other_user.id}")
107 |> json_response(:ok)
109 assert_schema([relationship], "AccountRelationshipsResponse", api_spec)
112 test "/api/v1/accounts/:id produces Account", %{
116 api_spec = ApiSpec.spec()
120 |> get("/api/v1/accounts/#{user.id}")
121 |> json_response(:ok)
123 assert_schema(resp, "Account", api_spec)
126 test "/api/v1/accounts/:id/statuses produces StatusesResponse", %{
130 Pleroma.Web.CommonAPI.post(user, %{"status" => "foobar"})
132 api_spec = ApiSpec.spec()
136 |> get("/api/v1/accounts/#{user.id}/statuses")
137 |> json_response(:ok)
139 assert_schema(resp, "StatusesResponse", api_spec)