logo

pleroma

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

controller_test.exs (2284B)


  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.TwitterAPI.ControllerTest do
  5. use Pleroma.Web.ConnCase, async: true
  6. alias Pleroma.Repo
  7. alias Pleroma.User
  8. alias Pleroma.Web.OAuth.Token
  9. import Pleroma.Factory
  10. describe "GET /api/account/confirm_email/:id/:token" do
  11. setup do
  12. {:ok, user} =
  13. insert(:user)
  14. |> User.confirmation_changeset(set_confirmation: false)
  15. |> Repo.update()
  16. refute user.is_confirmed
  17. [user: user]
  18. end
  19. test "it redirects to root url", %{conn: conn, user: user} do
  20. conn = get(conn, "/api/account/confirm_email/#{user.id}/#{user.confirmation_token}")
  21. assert 302 == conn.status
  22. end
  23. test "it confirms the user account", %{conn: conn, user: user} do
  24. get(conn, "/api/account/confirm_email/#{user.id}/#{user.confirmation_token}")
  25. user = User.get_cached_by_id(user.id)
  26. assert user.is_confirmed
  27. refute user.confirmation_token
  28. end
  29. test "it returns 500 if user cannot be found by id", %{conn: conn, user: user} do
  30. conn = get(conn, "/api/account/confirm_email/0/#{user.confirmation_token}")
  31. assert 500 == conn.status
  32. end
  33. test "it returns 500 if token is invalid", %{conn: conn, user: user} do
  34. conn = get(conn, "/api/account/confirm_email/#{user.id}/wrong_token")
  35. assert 500 == conn.status
  36. end
  37. end
  38. describe "GET /api/oauth_tokens" do
  39. setup do
  40. token = insert(:oauth_token) |> Repo.preload(:user)
  41. %{token: token}
  42. end
  43. test "renders list", %{token: token} do
  44. response =
  45. build_conn()
  46. |> assign(:user, token.user)
  47. |> get("/api/oauth_tokens")
  48. keys =
  49. json_response(response, 200)
  50. |> hd()
  51. |> Map.keys()
  52. assert Enum.sort(keys) == Enum.sort(["id", "app_name", "valid_until", "scopes"])
  53. end
  54. test "revoke token", %{token: token} do
  55. response =
  56. build_conn()
  57. |> assign(:user, token.user)
  58. |> delete("/api/oauth_tokens/#{token.id}")
  59. tokens = Token.get_user_tokens(token.user)
  60. assert tokens == []
  61. assert response.status == 201
  62. end
  63. end
  64. end