Add spec for AccountController.verify_credentials
[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
13 import OpenApiSpex.TestAssertions
14 import Pleroma.Factory
15
16 test "Account example matches schema" do
17 api_spec = ApiSpec.spec()
18 schema = Account.schema()
19 assert_schema(schema.example, "Account", api_spec)
20 end
21
22 test "AccountCreateRequest example matches schema" do
23 api_spec = ApiSpec.spec()
24 schema = AccountCreateRequest.schema()
25 assert_schema(schema.example, "AccountCreateRequest", api_spec)
26 end
27
28 test "AccountCreateResponse example matches schema" do
29 api_spec = ApiSpec.spec()
30 schema = AccountCreateResponse.schema()
31 assert_schema(schema.example, "AccountCreateResponse", api_spec)
32 end
33
34 test "AccountController produces a AccountCreateResponse", %{conn: conn} do
35 api_spec = ApiSpec.spec()
36 app_token = insert(:oauth_token, user: nil)
37
38 json =
39 conn
40 |> put_req_header("authorization", "Bearer " <> app_token.token)
41 |> put_req_header("content-type", "application/json")
42 |> post(
43 "/api/v1/accounts",
44 %{
45 username: "foo",
46 email: "bar@example.org",
47 password: "qwerty",
48 agreement: true
49 }
50 )
51 |> json_response(200)
52
53 assert_schema(json, "AccountCreateResponse", api_spec)
54 end
55 end