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 "requires 'follow' permission", %{conn: conn} do
30 token1 = insert(:oauth_token, scopes: ["read", "write"])
31 token2 = insert(:oauth_token, scopes: ["follow"])
32 another_user = insert(:user)
34 for token <- [token1, token2] do
37 |> put_req_header("authorization", "Bearer #{token.token}")
38 |> post("/api/pleroma/follow_import", %{"list" => "#{another_user.ap_id}"})
41 assert %{"error" => "Insufficient permissions: follow."} == json_response(conn, 403)
43 assert json_response(conn, 200)
49 describe "POST /api/pleroma/blocks_import" do
50 test "it returns HTTP 200", %{conn: conn} do
56 |> assign(:user, user1)
57 |> post("/api/pleroma/blocks_import", %{"list" => "#{user2.ap_id}"})
60 assert response == "job started"
64 describe "POST /api/pleroma/notifications/read" do
65 test "it marks a single notification as read", %{conn: conn} do
68 {:ok, activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
69 {:ok, activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
70 {:ok, [notification1]} = Notification.create_notifications(activity1)
71 {:ok, [notification2]} = Notification.create_notifications(activity2)
74 |> assign(:user, user1)
75 |> post("/api/pleroma/notifications/read", %{"id" => "#{notification1.id}"})
78 assert Repo.get(Notification, notification1.id).seen
79 refute Repo.get(Notification, notification2.id).seen
83 describe "PUT /api/pleroma/notification_settings" do
84 test "it updates notification settings", %{conn: conn} do
88 |> assign(:user, user)
89 |> put("/api/pleroma/notification_settings", %{
96 user = Repo.get(User, user.id)
98 assert %{"remote" => false, "local" => true, "followers" => false, "follows" => true} ==
99 user.info.notification_settings
103 describe "GET /api/statusnet/config.json" do
104 test "returns the state of safe_dm_mentions flag", %{conn: conn} do
105 option = Pleroma.Config.get([:instance, :safe_dm_mentions])
106 Pleroma.Config.put([:instance, :safe_dm_mentions], true)
110 |> get("/api/statusnet/config.json")
111 |> json_response(:ok)
113 assert response["site"]["safeDMMentionsEnabled"] == "1"
115 Pleroma.Config.put([:instance, :safe_dm_mentions], false)
119 |> get("/api/statusnet/config.json")
120 |> json_response(:ok)
122 assert response["site"]["safeDMMentionsEnabled"] == "0"
124 Pleroma.Config.put([:instance, :safe_dm_mentions], option)
127 test "it returns the managed config", %{conn: conn} do
128 Pleroma.Config.put([:instance, :managed_config], false)
129 Pleroma.Config.put([:fe], theme: "rei-ayanami-towel")
133 |> get("/api/statusnet/config.json")
134 |> json_response(:ok)
136 refute response["site"]["pleromafe"]
138 Pleroma.Config.put([:instance, :managed_config], true)
142 |> get("/api/statusnet/config.json")
143 |> json_response(:ok)
145 assert response["site"]["pleromafe"]
148 test "if :pleroma, :fe is false, it returns the new style config settings", %{conn: conn} do
149 Pleroma.Config.put([:instance, :managed_config], true)
150 Pleroma.Config.put([:fe, :theme], "rei-ayanami-towel")
151 Pleroma.Config.put([:frontend_configurations, :pleroma_fe], %{theme: "asuka-hospital"})
155 |> get("/api/statusnet/config.json")
156 |> json_response(:ok)
158 assert response["site"]["pleromafe"]["theme"] == "rei-ayanami-towel"
160 Pleroma.Config.put([:fe], false)
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"