1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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
8 alias Pleroma.Builders.ActivityBuilder
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 ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: other_user})
43 |> assign(:user, current_user)
44 |> get("/api/v1/notifications")
46 [notification] = response = json_response(response_conn, 200)
48 assert length(response) == 1
50 assert notification["pleroma"]["is_seen"] == false
54 |> assign(:user, current_user)
55 |> post("/api/qvitter/statuses/notifications/read", %{"latest_id" => notification["id"]})
57 [notification] = response = json_response(response_conn, 200)
59 assert length(response) == 1
61 assert notification["pleroma"]["is_seen"] == true
65 describe "GET /api/account/confirm_email/:id/:token" do
69 |> User.confirmation_changeset(need_confirmation: true)
72 assert user.confirmation_pending
77 test "it redirects to root url", %{conn: conn, user: user} do
78 conn = get(conn, "/api/account/confirm_email/#{user.id}/#{user.confirmation_token}")
80 assert 302 == conn.status
83 test "it confirms the user account", %{conn: conn, user: user} do
84 get(conn, "/api/account/confirm_email/#{user.id}/#{user.confirmation_token}")
86 user = User.get_cached_by_id(user.id)
88 refute user.confirmation_pending
89 refute user.confirmation_token
92 test "it returns 500 if user cannot be found by id", %{conn: conn, user: user} do
93 conn = get(conn, "/api/account/confirm_email/0/#{user.confirmation_token}")
95 assert 500 == conn.status
98 test "it returns 500 if token is invalid", %{conn: conn, user: user} do
99 conn = get(conn, "/api/account/confirm_email/#{user.id}/wrong_token")
101 assert 500 == conn.status
105 describe "GET /api/oauth_tokens" do
107 token = insert(:oauth_token) |> Repo.preload(:user)
112 test "renders list", %{token: token} do
115 |> assign(:user, token.user)
116 |> get("/api/oauth_tokens")
119 json_response(response, 200)
123 assert keys -- ["id", "app_name", "valid_until"] == []
126 test "revoke token", %{token: token} do
129 |> assign(:user, token.user)
130 |> delete("/api/oauth_tokens/#{token.id}")
132 tokens = Token.get_user_tokens(token.user)
135 assert response.status == 201