1 defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
2 use Pleroma.Web.ConnCase
4 alias Pleroma.Notification
7 alias Pleroma.Web.CommonAPI
10 describe "POST /api/pleroma/follow_import" do
11 test "it returns HTTP 200", %{conn: conn} do
17 |> assign(:user, user1)
18 |> post("/api/pleroma/follow_import", %{"list" => "#{user2.ap_id}"})
21 assert response == "job started"
24 test "requires 'follow' permission", %{conn: conn} do
25 token1 = insert(:oauth_token, scopes: ["read", "write"])
26 token2 = insert(:oauth_token, scopes: ["follow"])
27 another_user = insert(:user)
29 for token <- [token1, token2] do
32 |> put_req_header("authorization", "Bearer #{token.token}")
33 |> post("/api/pleroma/follow_import", %{"list" => "#{another_user.ap_id}"})
36 assert %{"error" => "Insufficient permissions: follow."} == json_response(conn, 403)
38 assert json_response(conn, 200)
44 describe "POST /api/pleroma/blocks_import" do
45 test "it returns HTTP 200", %{conn: conn} do
51 |> assign(:user, user1)
52 |> post("/api/pleroma/blocks_import", %{"list" => "#{user2.ap_id}"})
55 assert response == "job started"
59 describe "POST /api/pleroma/notifications/read" do
60 test "it marks a single notification as read", %{conn: conn} do
63 {:ok, activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
64 {:ok, activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
65 {:ok, [notification1]} = Notification.create_notifications(activity1)
66 {:ok, [notification2]} = Notification.create_notifications(activity2)
69 |> assign(:user, user1)
70 |> post("/api/pleroma/notifications/read", %{"id" => "#{notification1.id}"})
73 assert Repo.get(Notification, notification1.id).seen
74 refute Repo.get(Notification, notification2.id).seen
78 describe "PUT /api/pleroma/notification_settings" do
79 test "it updates notification settings", %{conn: conn} do
83 |> assign(:user, user)
84 |> put("/api/pleroma/notification_settings", %{
91 user = Repo.get(User, user.id)
93 assert %{"remote" => false, "local" => true, "followers" => false, "follows" => true} ==
94 user.info.notification_settings
98 describe "GET /api/statusnet/config.json" do
99 test "returns the state of safe_dm_mentions flag", %{conn: conn} do
100 option = Pleroma.Config.get([:instance, :safe_dm_mentions])
101 Pleroma.Config.put([:instance, :safe_dm_mentions], true)
105 |> get("/api/statusnet/config.json")
106 |> json_response(:ok)
108 assert response["site"]["safeDMMentionsEnabled"] == "1"
110 Pleroma.Config.put([:instance, :safe_dm_mentions], false)
114 |> get("/api/statusnet/config.json")
115 |> json_response(:ok)
117 assert response["site"]["safeDMMentionsEnabled"] == "0"
119 Pleroma.Config.put([:instance, :safe_dm_mentions], option)
122 test "it returns the managed config", %{conn: conn} do
123 Pleroma.Config.put([:instance, :managed_config], false)
124 Pleroma.Config.put([:fe], theme: "rei-ayanami-towel")
128 |> get("/api/statusnet/config.json")
129 |> json_response(:ok)
131 refute response["site"]["pleromafe"]
133 Pleroma.Config.put([:instance, :managed_config], true)
137 |> get("/api/statusnet/config.json")
138 |> json_response(:ok)
140 assert response["site"]["pleromafe"]
143 test "if :pleroma, :fe is false, it returns the new style config settings", %{conn: conn} do
144 Pleroma.Config.put([:instance, :managed_config], true)
145 Pleroma.Config.put([:fe, :theme], "rei-ayanami-towel")
146 Pleroma.Config.put([:frontend_configurations, :pleroma_fe], %{theme: "asuka-hospital"})
150 |> get("/api/statusnet/config.json")
151 |> json_response(:ok)
153 assert response["site"]["pleromafe"]["theme"] == "rei-ayanami-towel"
155 Pleroma.Config.put([:fe], false)
159 |> get("/api/statusnet/config.json")
160 |> json_response(:ok)
162 assert response["site"]["pleromafe"]["theme"] == "asuka-hospital"
166 describe "GET /api/pleroma/frontend_configurations" do
167 test "returns everything in :pleroma, :frontend_configurations", %{conn: conn} do
178 Pleroma.Config.put(:frontend_configurations, config)
182 |> get("/api/pleroma/frontend_configurations")
183 |> json_response(:ok)
185 assert response == Jason.encode!(config |> Enum.into(%{})) |> Jason.decode!()