logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

app_controller_test.exs (1632B)


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