1 defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
2 use Pleroma.Web.ConnCase
4 alias Pleroma.Notification
7 alias Pleroma.Web.CommonAPI
11 Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
15 describe "POST /api/pleroma/follow_import" do
16 test "it returns HTTP 200", %{conn: conn} do
22 |> assign(:user, user1)
23 |> post("/api/pleroma/follow_import", %{"list" => "#{user2.ap_id}"})
26 assert response == "job started"
29 test "it imports new-style mastodon follow lists", %{conn: conn} do
35 |> assign(:user, user1)
36 |> post("/api/pleroma/follow_import", %{
37 "list" => "Account address,Show boosts\n#{user2.ap_id},true"
41 assert response == "job started"
44 test "requires 'follow' permission", %{conn: conn} do
45 token1 = insert(:oauth_token, scopes: ["read", "write"])
46 token2 = insert(:oauth_token, scopes: ["follow"])
47 another_user = insert(:user)
49 for token <- [token1, token2] do
52 |> put_req_header("authorization", "Bearer #{token.token}")
53 |> post("/api/pleroma/follow_import", %{"list" => "#{another_user.ap_id}"})
56 assert %{"error" => "Insufficient permissions: follow."} == json_response(conn, 403)
58 assert json_response(conn, 200)
64 describe "POST /api/pleroma/blocks_import" do
65 test "it returns HTTP 200", %{conn: conn} do
71 |> assign(:user, user1)
72 |> post("/api/pleroma/blocks_import", %{"list" => "#{user2.ap_id}"})
75 assert response == "job started"
79 describe "POST /api/pleroma/notifications/read" do
80 test "it marks a single notification as read", %{conn: conn} do
83 {:ok, activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
84 {:ok, activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
85 {:ok, [notification1]} = Notification.create_notifications(activity1)
86 {:ok, [notification2]} = Notification.create_notifications(activity2)
89 |> assign(:user, user1)
90 |> post("/api/pleroma/notifications/read", %{"id" => "#{notification1.id}"})
93 assert Repo.get(Notification, notification1.id).seen
94 refute Repo.get(Notification, notification2.id).seen
98 describe "PUT /api/pleroma/notification_settings" do
99 test "it updates notification settings", %{conn: conn} do
103 |> assign(:user, user)
104 |> put("/api/pleroma/notification_settings", %{
106 "followers" => false,
109 |> json_response(:ok)
111 user = Repo.get(User, user.id)
116 "followers" => false,
118 "non_follows" => true,
119 "non_followers" => true
120 } == user.info.notification_settings
124 describe "GET /api/statusnet/config.json" do
125 test "returns the state of safe_dm_mentions flag", %{conn: conn} do
126 option = Pleroma.Config.get([:instance, :safe_dm_mentions])
127 Pleroma.Config.put([:instance, :safe_dm_mentions], true)
131 |> get("/api/statusnet/config.json")
132 |> json_response(:ok)
134 assert response["site"]["safeDMMentionsEnabled"] == "1"
136 Pleroma.Config.put([:instance, :safe_dm_mentions], false)
140 |> get("/api/statusnet/config.json")
141 |> json_response(:ok)
143 assert response["site"]["safeDMMentionsEnabled"] == "0"
145 Pleroma.Config.put([:instance, :safe_dm_mentions], option)
148 test "it returns the managed config", %{conn: conn} do
149 Pleroma.Config.put([:instance, :managed_config], false)
150 Pleroma.Config.put([:frontend_configurations, :pleroma_fe], %{theme: "asuka-hospital"})
154 |> get("/api/statusnet/config.json")
155 |> json_response(:ok)
157 refute response["site"]["pleromafe"]
159 Pleroma.Config.put([:instance, :managed_config], true)
163 |> get("/api/statusnet/config.json")
164 |> json_response(:ok)
166 assert response["site"]["pleromafe"] == %{"theme" => "asuka-hospital"}
170 describe "GET /api/pleroma/frontend_configurations" do
171 test "returns everything in :pleroma, :frontend_configurations", %{conn: conn} do
182 Pleroma.Config.put(:frontend_configurations, config)
186 |> get("/api/pleroma/frontend_configurations")
187 |> json_response(:ok)
189 assert response == Jason.encode!(config |> Enum.into(%{})) |> Jason.decode!()
193 describe "/api/pleroma/emoji" do
194 test "returns json with custom emoji with tags", %{conn: conn} do
197 |> get("/api/pleroma/emoji")
198 |> json_response(200)
200 assert Enum.all?(emoji, fn
206 is_binary(url) and is_list(tags)
211 describe "GET /ostatus_subscribe?acct=...." do
212 test "adds status to pleroma instance if the `acct` is a status", %{conn: conn} do
216 "/ostatus_subscribe?acct=https://mastodon.social/users/emelie/statuses/101849165031453009"
219 assert redirected_to(conn) =~ "/notice/"
222 test "show follow account page if the `acct` is a account link", %{conn: conn} do
226 "/ostatus_subscribe?acct=https://mastodon.social/users/emelie"
229 assert html_response(response, 200) =~ "Log in to follow"
233 test "GET /api/pleroma/healthcheck", %{conn: conn} do
234 conn = get(conn, "/api/pleroma/healthcheck")
236 assert conn.status in [200, 503]
239 describe "POST /api/pleroma/disable_account" do
240 test "it returns HTTP 200", %{conn: conn} do
245 |> assign(:user, user)
246 |> post("/api/pleroma/disable_account", %{"password" => "test"})
247 |> json_response(:ok)
249 assert response == %{"status" => "success"}
251 user = User.get_cached_by_id(user.id)
253 assert user.info.deactivated == true