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