logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

app_controller_test.exs (1505B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.PleromaAPI.AppControllerTest do
  5. use Pleroma.Web.ConnCase, async: true
  6. alias Pleroma.Web.OAuth.App
  7. alias Pleroma.Web.Push
  8. import Pleroma.Factory
  9. test "apps", %{conn: conn} do
  10. user = insert(:user)
  11. app_attrs = build(:oauth_app)
  12. creation =
  13. conn
  14. |> put_req_header("content-type", "application/json")
  15. |> assign(:user, user)
  16. |> post("/api/v1/apps", %{
  17. client_name: app_attrs.client_name,
  18. redirect_uris: app_attrs.redirect_uris
  19. })
  20. [app] = App.get_user_apps(user)
  21. expected = %{
  22. "name" => app.client_name,
  23. "website" => app.website,
  24. "client_id" => app.client_id,
  25. "client_secret" => app.client_secret,
  26. "id" => app.id |> to_string(),
  27. "redirect_uri" => app.redirect_uris,
  28. "vapid_key" => Push.vapid_config() |> Keyword.get(:public_key)
  29. }
  30. assert expected == json_response_and_validate_schema(creation, 200)
  31. response =
  32. conn
  33. |> put_req_header("content-type", "application/json")
  34. |> assign(:user, user)
  35. |> assign(:token, insert(:oauth_token, user: user, scopes: ["read", "follow"]))
  36. |> get("/api/v1/pleroma/apps")
  37. |> json_response_and_validate_schema(200)
  38. [apps] = response
  39. assert length(response) == 1
  40. assert apps["client_id"] == app.client_id
  41. end
  42. end