logo

pleroma

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

app_test.exs (1853B)


  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.OAuth.AppTest do
  5. use Pleroma.DataCase, async: true
  6. alias Pleroma.Web.OAuth.App
  7. import Pleroma.Factory
  8. describe "get_or_make/2" do
  9. test "gets exist app" do
  10. attrs = %{client_name: "Mastodon-Local", redirect_uris: "."}
  11. app = insert(:oauth_app, Map.merge(attrs, %{scopes: ["read", "write"]}))
  12. {:ok, %App{} = exist_app} = App.get_or_make(attrs, [])
  13. assert exist_app == app
  14. end
  15. test "make app" do
  16. attrs = %{client_name: "Mastodon-Local", redirect_uris: "."}
  17. {:ok, %App{} = app} = App.get_or_make(attrs, ["write"])
  18. assert app.scopes == ["write"]
  19. end
  20. test "gets exist app and updates scopes" do
  21. attrs = %{client_name: "Mastodon-Local", redirect_uris: "."}
  22. app = insert(:oauth_app, Map.merge(attrs, %{scopes: ["read", "write"]}))
  23. {:ok, %App{} = exist_app} = App.get_or_make(attrs, ["read", "write", "follow", "push"])
  24. assert exist_app.id == app.id
  25. assert exist_app.scopes == ["read", "write", "follow", "push"]
  26. end
  27. test "has unique client_id" do
  28. insert(:oauth_app, client_name: "", redirect_uris: "", client_id: "boop")
  29. error =
  30. catch_error(insert(:oauth_app, client_name: "", redirect_uris: "", client_id: "boop"))
  31. assert %Ecto.ConstraintError{} = error
  32. assert error.constraint == "apps_client_id_index"
  33. assert error.type == :unique
  34. end
  35. end
  36. test "get_user_apps/1" do
  37. user = insert(:user)
  38. apps = [
  39. insert(:oauth_app, user_id: user.id),
  40. insert(:oauth_app, user_id: user.id),
  41. insert(:oauth_app, user_id: user.id)
  42. ]
  43. assert Enum.sort(App.get_user_apps(user)) == Enum.sort(apps)
  44. end
  45. end