1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.TwitterAPI.ControllerTest do
6 use Pleroma.Web.ConnCase, async: true
10 alias Pleroma.Web.OAuth.Token
12 import Pleroma.Factory
14 describe "GET /api/account/confirm_email/:id/:token" do
18 |> User.confirmation_changeset(set_confirmation: false)
21 refute user.is_confirmed
26 test "it redirects to root url", %{conn: conn, user: user} do
27 conn = get(conn, "/api/account/confirm_email/#{user.id}/#{user.confirmation_token}")
29 assert 302 == conn.status
32 test "it confirms the user account", %{conn: conn, user: user} do
33 get(conn, "/api/account/confirm_email/#{user.id}/#{user.confirmation_token}")
35 user = User.get_cached_by_id(user.id)
37 assert user.is_confirmed
38 refute user.confirmation_token
41 test "it returns 500 if user cannot be found by id", %{conn: conn, user: user} do
42 conn = get(conn, "/api/account/confirm_email/0/#{user.confirmation_token}")
44 assert 500 == conn.status
47 test "it returns 500 if token is invalid", %{conn: conn, user: user} do
48 conn = get(conn, "/api/account/confirm_email/#{user.id}/wrong_token")
50 assert 500 == conn.status
54 describe "GET /api/oauth_tokens" do
56 token = insert(:oauth_token) |> Repo.preload(:user)
61 test "renders list", %{token: token} do
64 |> assign(:user, token.user)
65 |> get("/api/oauth_tokens")
68 json_response(response, 200)
72 assert keys -- ["id", "app_name", "valid_until"] == []
75 test "revoke token", %{token: token} do
78 |> assign(:user, token.user)
79 |> delete("/api/oauth_tokens/#{token.id}")
81 tokens = Token.get_user_tokens(token.user)
84 assert response.status == 201