logo

pleroma

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

app_test.exs (1751B)


  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 Mix.Tasks.Pleroma.AppTest do
  5. use Pleroma.DataCase, async: true
  6. setup_all do
  7. Mix.shell(Mix.Shell.Process)
  8. on_exit(fn ->
  9. Mix.shell(Mix.Shell.IO)
  10. end)
  11. end
  12. describe "creates new app" do
  13. test "with default scopes" do
  14. name = "Some name"
  15. redirect = "https://example.com"
  16. Mix.Tasks.Pleroma.App.run(["create", "-n", name, "-r", redirect])
  17. assert_app(name, redirect, ["read", "write", "follow", "push"])
  18. end
  19. test "with custom scopes" do
  20. name = "Another name"
  21. redirect = "https://example.com"
  22. Mix.Tasks.Pleroma.App.run([
  23. "create",
  24. "-n",
  25. name,
  26. "-r",
  27. redirect,
  28. "-s",
  29. "read,write,follow,push,admin"
  30. ])
  31. assert_app(name, redirect, ["read", "write", "follow", "push", "admin"])
  32. end
  33. end
  34. test "with errors" do
  35. Mix.Tasks.Pleroma.App.run(["create"])
  36. {:mix_shell, :error, ["Creating failed:"]}
  37. {:mix_shell, :error, ["name: can't be blank"]}
  38. {:mix_shell, :error, ["redirect_uris: can't be blank"]}
  39. end
  40. defp assert_app(name, redirect, scopes) do
  41. app = Repo.get_by(Pleroma.Web.OAuth.App, client_name: name)
  42. assert_receive {:mix_shell, :info, [message]}
  43. assert message == "#{name} successfully created:"
  44. assert_receive {:mix_shell, :info, [message]}
  45. assert message == "App client_id: #{app.client_id}"
  46. assert_receive {:mix_shell, :info, [message]}
  47. assert message == "App client_secret: #{app.client_secret}"
  48. assert app.scopes == scopes
  49. assert app.redirect_uris == redirect
  50. end
  51. end