1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
6 use Pleroma.Web.ConnCase
8 alias Pleroma.Notification
11 alias Pleroma.Web.CommonAPI
12 import Pleroma.Factory
15 Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
19 describe "POST /api/pleroma/follow_import" do
20 test "it returns HTTP 200", %{conn: conn} do
26 |> assign(:user, user1)
27 |> post("/api/pleroma/follow_import", %{"list" => "#{user2.ap_id}"})
30 assert response == "job started"
33 test "it imports new-style mastodon follow lists", %{conn: conn} do
39 |> assign(:user, user1)
40 |> post("/api/pleroma/follow_import", %{
41 "list" => "Account address,Show boosts\n#{user2.ap_id},true"
45 assert response == "job started"
48 test "requires 'follow' permission", %{conn: conn} do
49 token1 = insert(:oauth_token, scopes: ["read", "write"])
50 token2 = insert(:oauth_token, scopes: ["follow"])
51 another_user = insert(:user)
53 for token <- [token1, token2] do
56 |> put_req_header("authorization", "Bearer #{token.token}")
57 |> post("/api/pleroma/follow_import", %{"list" => "#{another_user.ap_id}"})
60 assert %{"error" => "Insufficient permissions: follow."} == json_response(conn, 403)
62 assert json_response(conn, 200)
68 describe "POST /api/pleroma/blocks_import" do
69 test "it returns HTTP 200", %{conn: conn} do
75 |> assign(:user, user1)
76 |> post("/api/pleroma/blocks_import", %{"list" => "#{user2.ap_id}"})
79 assert response == "job started"
83 describe "POST /api/pleroma/notifications/read" do
84 test "it marks a single notification as read", %{conn: conn} do
87 {:ok, activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
88 {:ok, activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
89 {:ok, [notification1]} = Notification.create_notifications(activity1)
90 {:ok, [notification2]} = Notification.create_notifications(activity2)
93 |> assign(:user, user1)
94 |> post("/api/pleroma/notifications/read", %{"id" => "#{notification1.id}"})
97 assert Repo.get(Notification, notification1.id).seen
98 refute Repo.get(Notification, notification2.id).seen
102 describe "PUT /api/pleroma/notification_settings" do
103 test "it updates notification settings", %{conn: conn} do
107 |> assign(:user, user)
108 |> put("/api/pleroma/notification_settings", %{
109 "followers" => false,
112 |> json_response(:ok)
114 user = Repo.get(User, user.id)
117 "followers" => false,
119 "non_follows" => true,
120 "non_followers" => true
121 } == user.info.notification_settings
125 describe "GET /api/statusnet/config.json" do
126 test "returns the state of safe_dm_mentions flag", %{conn: conn} do
127 option = Pleroma.Config.get([:instance, :safe_dm_mentions])
128 Pleroma.Config.put([:instance, :safe_dm_mentions], true)
132 |> get("/api/statusnet/config.json")
133 |> json_response(:ok)
135 assert response["site"]["safeDMMentionsEnabled"] == "1"
137 Pleroma.Config.put([:instance, :safe_dm_mentions], false)
141 |> get("/api/statusnet/config.json")
142 |> json_response(:ok)
144 assert response["site"]["safeDMMentionsEnabled"] == "0"
146 Pleroma.Config.put([:instance, :safe_dm_mentions], option)
149 test "it returns the managed config", %{conn: conn} do
150 Pleroma.Config.put([:instance, :managed_config], false)
151 Pleroma.Config.put([:frontend_configurations, :pleroma_fe], %{theme: "asuka-hospital"})
155 |> get("/api/statusnet/config.json")
156 |> json_response(:ok)
158 refute response["site"]["pleromafe"]
160 Pleroma.Config.put([:instance, :managed_config], true)
164 |> get("/api/statusnet/config.json")
165 |> json_response(:ok)
167 assert response["site"]["pleromafe"] == %{"theme" => "asuka-hospital"}
171 describe "GET /api/pleroma/frontend_configurations" do
172 test "returns everything in :pleroma, :frontend_configurations", %{conn: conn} do
183 Pleroma.Config.put(:frontend_configurations, config)
187 |> get("/api/pleroma/frontend_configurations")
188 |> json_response(:ok)
190 assert response == Jason.encode!(config |> Enum.into(%{})) |> Jason.decode!()
194 describe "/api/pleroma/emoji" do
195 test "returns json with custom emoji with tags", %{conn: conn} do
198 |> get("/api/pleroma/emoji")
199 |> json_response(200)
201 assert Enum.all?(emoji, fn
207 is_binary(url) and is_list(tags)
212 describe "GET /ostatus_subscribe?acct=...." do
213 test "adds status to pleroma instance if the `acct` is a status", %{conn: conn} do
217 "/ostatus_subscribe?acct=https://mastodon.social/users/emelie/statuses/101849165031453009"
220 assert redirected_to(conn) =~ "/notice/"
223 test "show follow account page if the `acct` is a account link", %{conn: conn} do
227 "/ostatus_subscribe?acct=https://mastodon.social/users/emelie"
230 assert html_response(response, 200) =~ "Log in to follow"
234 test "GET /api/pleroma/healthcheck", %{conn: conn} do
235 conn = get(conn, "/api/pleroma/healthcheck")
237 assert conn.status in [200, 503]
240 describe "POST /api/pleroma/disable_account" do
241 test "it returns HTTP 200", %{conn: conn} do
246 |> assign(:user, user)
247 |> post("/api/pleroma/disable_account", %{"password" => "test"})
248 |> json_response(:ok)
250 assert response == %{"status" => "success"}
252 user = User.get_cached_by_id(user.id)
254 assert user.info.deactivated == true