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 %{user: current_user, conn: conn} =
23 oauth_access(["read:notifications", "write:notifications"])
27 |> assign(:user, current_user)
28 |> post("/api/qvitter/statuses/notifications/read")
30 assert json_response(conn, 400) == %{
31 "error" => "You need to specify latest_id",
32 "request" => "/api/qvitter/statuses/notifications/read"
36 test "with credentials, with params" do
37 %{user: current_user, conn: conn} =
38 oauth_access(["read:notifications", "write:notifications"])
40 other_user = insert(:user)
43 ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: other_user})
47 |> assign(:user, current_user)
48 |> get("/api/v1/notifications")
50 [notification] = response = json_response(response_conn, 200)
52 assert length(response) == 1
54 assert notification["pleroma"]["is_seen"] == false
58 |> assign(:user, current_user)
59 |> post("/api/qvitter/statuses/notifications/read", %{"latest_id" => notification["id"]})
61 [notification] = response = json_response(response_conn, 200)
63 assert length(response) == 1
65 assert notification["pleroma"]["is_seen"] == true
69 describe "GET /api/account/confirm_email/:id/:token" do
73 |> User.confirmation_changeset(need_confirmation: true)
76 assert user.confirmation_pending
81 test "it redirects to root url", %{conn: conn, user: user} do
82 conn = get(conn, "/api/account/confirm_email/#{user.id}/#{user.confirmation_token}")
84 assert 302 == conn.status
87 test "it confirms the user account", %{conn: conn, user: user} do
88 get(conn, "/api/account/confirm_email/#{user.id}/#{user.confirmation_token}")
90 user = User.get_cached_by_id(user.id)
92 refute user.confirmation_pending
93 refute user.confirmation_token
96 test "it returns 500 if user cannot be found by id", %{conn: conn, user: user} do
97 conn = get(conn, "/api/account/confirm_email/0/#{user.confirmation_token}")
99 assert 500 == conn.status
102 test "it returns 500 if token is invalid", %{conn: conn, user: user} do
103 conn = get(conn, "/api/account/confirm_email/#{user.id}/wrong_token")
105 assert 500 == conn.status
109 describe "GET /api/oauth_tokens" do
111 token = insert(:oauth_token) |> Repo.preload(:user)
116 test "renders list", %{token: token} do
119 |> assign(:user, token.user)
120 |> get("/api/oauth_tokens")
123 json_response(response, 200)
127 assert keys -- ["id", "app_name", "valid_until"] == []
130 test "revoke token", %{token: token} do
133 |> assign(:user, token.user)
134 |> delete("/api/oauth_tokens/#{token.id}")
136 tokens = Token.get_user_tokens(token.user)
139 assert response.status == 201