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.CommonAPI
11 alias Pleroma.Web.OAuth.Token
13 import Pleroma.Factory
15 describe "POST /api/qvitter/statuses/notifications/read" do
16 test "without valid credentials", %{conn: conn} do
17 conn = post(conn, "/api/qvitter/statuses/notifications/read", %{"latest_id" => 1_234_567})
18 assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
21 test "with credentials, without any params" do
22 %{conn: conn} = oauth_access(["write:notifications"])
24 conn = post(conn, "/api/qvitter/statuses/notifications/read")
26 assert json_response(conn, 400) == %{
27 "error" => "You need to specify latest_id",
28 "request" => "/api/qvitter/statuses/notifications/read"
32 test "with credentials, with params" do
33 %{user: current_user, conn: conn} =
34 oauth_access(["read:notifications", "write:notifications"])
36 other_user = insert(:user)
39 CommonAPI.post(other_user, %{
40 status: "Hey @#{current_user.nickname}"
45 |> get("/api/v1/notifications")
47 [notification] = json_response(response_conn, 200)
49 assert notification["pleroma"]["is_seen"] == false
53 |> post("/api/qvitter/statuses/notifications/read", %{"latest_id" => notification["id"]})
55 [notification] = response = json_response(response_conn, 200)
57 assert length(response) == 1
59 assert notification["pleroma"]["is_seen"] == true
63 describe "GET /api/account/confirm_email/:id/:token" do
67 |> User.confirmation_changeset(set_confirmation: false)
70 refute user.is_confirmed
75 test "it redirects to root url", %{conn: conn, user: user} do
76 conn = get(conn, "/api/account/confirm_email/#{user.id}/#{user.confirmation_token}")
78 assert 302 == conn.status
81 test "it confirms the user account", %{conn: conn, user: user} do
82 get(conn, "/api/account/confirm_email/#{user.id}/#{user.confirmation_token}")
84 user = User.get_cached_by_id(user.id)
86 assert user.is_confirmed
87 refute user.confirmation_token
90 test "it returns 500 if user cannot be found by id", %{conn: conn, user: user} do
91 conn = get(conn, "/api/account/confirm_email/0/#{user.confirmation_token}")
93 assert 500 == conn.status
96 test "it returns 500 if token is invalid", %{conn: conn, user: user} do
97 conn = get(conn, "/api/account/confirm_email/#{user.id}/wrong_token")
99 assert 500 == conn.status
103 describe "GET /api/oauth_tokens" do
105 token = insert(:oauth_token) |> Repo.preload(:user)
110 test "renders list", %{token: token} do
113 |> assign(:user, token.user)
114 |> get("/api/oauth_tokens")
117 json_response(response, 200)
121 assert keys -- ["id", "app_name", "valid_until"] == []
124 test "revoke token", %{token: token} do
127 |> assign(:user, token.user)
128 |> delete("/api/oauth_tokens/#{token.id}")
130 tokens = Token.get_user_tokens(token.user)
133 assert response.status == 201