1 defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
2 use Pleroma.Web.ConnCase
4 alias Pleroma.Notification
6 alias Pleroma.Web.CommonAPI
10 Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
14 describe "POST /api/pleroma/follow_import" do
15 test "it returns HTTP 200", %{conn: conn} do
21 |> assign(:user, user1)
22 |> post("/api/pleroma/follow_import", %{"list" => "#{user2.ap_id}"})
25 assert response == "job started"
28 test "requires 'follow' permission", %{conn: conn} do
29 token1 = insert(:oauth_token, scopes: ["read", "write"])
30 token2 = insert(:oauth_token, scopes: ["follow"])
31 another_user = insert(:user)
33 for token <- [token1, token2] do
36 |> put_req_header("authorization", "Bearer #{token.token}")
37 |> post("/api/pleroma/follow_import", %{"list" => "#{another_user.ap_id}"})
40 assert %{"error" => "Insufficient permissions: follow."} == json_response(conn, 403)
42 assert json_response(conn, 200)
48 describe "POST /api/pleroma/blocks_import" do
49 test "it returns HTTP 200", %{conn: conn} do
55 |> assign(:user, user1)
56 |> post("/api/pleroma/blocks_import", %{"list" => "#{user2.ap_id}"})
59 assert response == "job started"
63 describe "POST /api/pleroma/notifications/read" do
64 test "it marks a single notification as read", %{conn: conn} do
67 {:ok, activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
68 {:ok, activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
69 {:ok, [notification1]} = Notification.create_notifications(activity1)
70 {:ok, [notification2]} = Notification.create_notifications(activity2)
73 |> assign(:user, user1)
74 |> post("/api/pleroma/notifications/read", %{"id" => "#{notification1.id}"})
77 assert Repo.get(Notification, notification1.id).seen
78 refute Repo.get(Notification, notification2.id).seen
82 describe "GET /api/statusnet/config.json" do
83 test "returns the state of safe_dm_mentions flag", %{conn: conn} do
84 option = Pleroma.Config.get([:instance, :safe_dm_mentions])
85 Pleroma.Config.put([:instance, :safe_dm_mentions], true)
89 |> get("/api/statusnet/config.json")
92 assert response["site"]["safeDMMentionsEnabled"] == "1"
94 Pleroma.Config.put([:instance, :safe_dm_mentions], false)
98 |> get("/api/statusnet/config.json")
101 assert response["site"]["safeDMMentionsEnabled"] == "0"
103 Pleroma.Config.put([:instance, :safe_dm_mentions], option)
106 test "it returns the managed config", %{conn: conn} do
107 Pleroma.Config.put([:instance, :managed_config], false)
108 Pleroma.Config.put([:fe], theme: "rei-ayanami-towel")
112 |> get("/api/statusnet/config.json")
113 |> json_response(:ok)
115 refute response["site"]["pleromafe"]
117 Pleroma.Config.put([:instance, :managed_config], true)
121 |> get("/api/statusnet/config.json")
122 |> json_response(:ok)
124 assert response["site"]["pleromafe"]
127 test "if :pleroma, :fe is false, it returns the new style config settings", %{conn: conn} do
128 Pleroma.Config.put([:instance, :managed_config], true)
129 Pleroma.Config.put([:fe, :theme], "rei-ayanami-towel")
130 Pleroma.Config.put([:frontend_configurations, :pleroma_fe], %{theme: "asuka-hospital"})
134 |> get("/api/statusnet/config.json")
135 |> json_response(:ok)
137 assert response["site"]["pleromafe"]["theme"] == "rei-ayanami-towel"
139 Pleroma.Config.put([:fe], false)
143 |> get("/api/statusnet/config.json")
144 |> json_response(:ok)
146 assert response["site"]["pleromafe"]["theme"] == "asuka-hospital"
150 describe "GET /api/pleroma/frontend_configurations" do
151 test "returns everything in :pleroma, :frontend_configurations", %{conn: conn} do
162 Pleroma.Config.put(:frontend_configurations, config)
166 |> get("/api/pleroma/frontend_configurations")
167 |> json_response(:ok)
169 assert response == Jason.encode!(config |> Enum.into(%{})) |> Jason.decode!()
173 describe "/api/pleroma/emoji" do
174 test "returns json with custom emoji with tags", %{conn: conn} do
177 |> get("/api/pleroma/emoji")
178 |> json_response(200)
180 [key] = Map.keys(emoji)
189 assert is_binary(url)
194 describe "GET /ostatus_subscribe?acct=...." do
195 test "adds status to pleroma instance if the `acct` is a status", %{conn: conn} do
199 "/ostatus_subscribe?acct=https://mastodon.social/users/emelie/statuses/101849165031453009"
202 assert redirected_to(conn) =~ "/notice/"
205 test "show follow account page if the `acct` is a account link", %{conn: conn} do
209 "/ostatus_subscribe?acct=https://mastodon.social/users/emelie"
212 assert html_response(response, 200) =~ "Log in to follow"