a0b8b126c9536594ba307b875bfa41ff7477bb78
[akkoma] / test / web / mastodon_api / controllers / app_controller_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.MastodonAPI.AppControllerTest do
6 use Pleroma.Web.ConnCase, async: true
7
8 alias Pleroma.Repo
9 alias Pleroma.Web.OAuth.App
10 alias Pleroma.Web.Push
11
12 import Pleroma.Factory
13
14 test "apps/verify_credentials", %{conn: conn} do
15 token = insert(:oauth_token)
16
17 conn =
18 conn
19 |> put_req_header("authorization", "Bearer #{token.token}")
20 |> get("/api/v1/apps/verify_credentials")
21
22 app = Repo.preload(token, :app).app
23
24 expected = %{
25 "name" => app.client_name,
26 "website" => app.website,
27 "vapid_key" => Push.vapid_config() |> Keyword.get(:public_key)
28 }
29
30 assert expected == json_response_and_validate_schema(conn, 200)
31 end
32
33 test "creates an oauth app", %{conn: conn} do
34 user = insert(:user)
35 app_attrs = build(:oauth_app)
36
37 conn =
38 conn
39 |> put_req_header("content-type", "application/json")
40 |> assign(:user, user)
41 |> post("/api/v1/apps", %{
42 client_name: app_attrs.client_name,
43 redirect_uris: app_attrs.redirect_uris
44 })
45
46 [app] = Repo.all(App)
47
48 expected = %{
49 "name" => app.client_name,
50 "website" => app.website,
51 "client_id" => app.client_id,
52 "client_secret" => app.client_secret,
53 "id" => app.id |> to_string(),
54 "redirect_uri" => app.redirect_uris,
55 "vapid_key" => Push.vapid_config() |> Keyword.get(:public_key)
56 }
57
58 assert expected == json_response_and_validate_schema(conn, 200)
59 end
60 end