a540590743d27555fc25a824eec1863630b63fbd
[akkoma] / test / web / api_spec / account_operation_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ApiSpec.AccountOperationTest do
6 use Pleroma.Web.ConnCase, async: true
7
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
13
14 import OpenApiSpex.TestAssertions
15 import Pleroma.Factory
16
17 test "Account example matches schema" do
18 api_spec = ApiSpec.spec()
19 schema = Account.schema()
20 assert_schema(schema.example, "Account", api_spec)
21 end
22
23 test "AccountCreateRequest example matches schema" do
24 api_spec = ApiSpec.spec()
25 schema = AccountCreateRequest.schema()
26 assert_schema(schema.example, "AccountCreateRequest", api_spec)
27 end
28
29 test "AccountCreateResponse example matches schema" do
30 api_spec = ApiSpec.spec()
31 schema = AccountCreateResponse.schema()
32 assert_schema(schema.example, "AccountCreateResponse", api_spec)
33 end
34
35 test "AccountUpdateCredentialsRequest example matches schema" do
36 api_spec = ApiSpec.spec()
37 schema = AccountUpdateCredentialsRequest.schema()
38 assert_schema(schema.example, "AccountUpdateCredentialsRequest", api_spec)
39 end
40
41 test "AccountController produces a AccountCreateResponse", %{conn: conn} do
42 api_spec = ApiSpec.spec()
43 app_token = insert(:oauth_token, user: nil)
44
45 json =
46 conn
47 |> put_req_header("authorization", "Bearer " <> app_token.token)
48 |> put_req_header("content-type", "application/json")
49 |> post(
50 "/api/v1/accounts",
51 %{
52 username: "foo",
53 email: "bar@example.org",
54 password: "qwerty",
55 agreement: true
56 }
57 )
58 |> json_response(200)
59
60 assert_schema(json, "AccountCreateResponse", api_spec)
61 end
62
63 test "AccountUpdateCredentialsRequest produces an Account", %{conn: conn} do
64 api_spec = ApiSpec.spec()
65 token = insert(:oauth_token, scopes: ["read", "write"])
66
67 json =
68 conn
69 |> put_req_header("authorization", "Bearer " <> token.token)
70 |> put_req_header("content-type", "application/json")
71 |> patch(
72 "/api/v1/accounts/update_credentials",
73 %{
74 hide_followers_count: "true",
75 hide_follows_count: "true",
76 skip_thread_containment: "true",
77 hide_follows: "true",
78 pleroma_settings_store: %{"pleroma-fe" => %{"key" => "val"}},
79 note: "foobar",
80 fields_attributes: [%{name: "foo", value: "bar"}]
81 }
82 )
83 |> json_response(200)
84
85 assert_schema(json, "Account", api_spec)
86 end
87 end