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, async: true
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.AccountUpdateCredentialsRequest
14 import OpenApiSpex.TestAssertions
15 import Pleroma.Factory
17 test "Account example matches schema" do
18 api_spec = ApiSpec.spec()
19 schema = Account.schema()
20 assert_schema(schema.example, "Account", api_spec)
23 test "AccountCreateRequest example matches schema" do
24 api_spec = ApiSpec.spec()
25 schema = AccountCreateRequest.schema()
26 assert_schema(schema.example, "AccountCreateRequest", api_spec)
29 test "AccountCreateResponse example matches schema" do
30 api_spec = ApiSpec.spec()
31 schema = AccountCreateResponse.schema()
32 assert_schema(schema.example, "AccountCreateResponse", api_spec)
35 test "AccountUpdateCredentialsRequest example matches schema" do
36 api_spec = ApiSpec.spec()
37 schema = AccountUpdateCredentialsRequest.schema()
38 assert_schema(schema.example, "AccountUpdateCredentialsRequest", api_spec)
41 test "AccountController produces a AccountCreateResponse", %{conn: conn} do
42 api_spec = ApiSpec.spec()
43 app_token = insert(:oauth_token, user: nil)
47 |> put_req_header("authorization", "Bearer " <> app_token.token)
48 |> put_req_header("content-type", "application/json")
53 email: "bar@example.org",
60 assert_schema(json, "AccountCreateResponse", api_spec)
63 test "AccountUpdateCredentialsRequest produces an Account", %{conn: conn} do
64 api_spec = ApiSpec.spec()
65 token = insert(:oauth_token, scopes: ["read", "write"])
69 |> put_req_header("authorization", "Bearer " <> token.token)
70 |> put_req_header("content-type", "application/json")
72 "/api/v1/accounts/update_credentials",
74 hide_followers_count: "true",
75 hide_follows_count: "true",
76 skip_thread_containment: "true",
78 pleroma_settings_store: %{"pleroma-fe" => %{"key" => "val"}},
80 fields_attributes: [%{name: "foo", value: "bar"}]
85 assert_schema(json, "Account", api_spec)