1 defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
2 use Pleroma.Web.ConnCase
4 alias Pleroma.Notification
6 alias Pleroma.Web.CommonAPI
9 describe "POST /api/pleroma/follow_import" do
10 test "it returns HTTP 200", %{conn: conn} do
16 |> assign(:user, user1)
17 |> post("/api/pleroma/follow_import", %{"list" => "#{user2.ap_id}"})
20 assert response == "job started"
23 test "requires 'follow' permission", %{conn: conn} do
24 token1 = insert(:oauth_token, scopes: ["read", "write"])
25 token2 = insert(:oauth_token, scopes: ["follow"])
26 another_user = insert(:user)
28 for token <- [token1, token2] do
31 |> put_req_header("authorization", "Bearer #{token.token}")
32 |> post("/api/pleroma/follow_import", %{"list" => "#{another_user.ap_id}"})
35 assert %{"error" => "Insufficient permissions: follow."} == json_response(conn, 403)
37 assert json_response(conn, 200)
43 describe "POST /api/pleroma/blocks_import" do
44 test "it returns HTTP 200", %{conn: conn} do
50 |> assign(:user, user1)
51 |> post("/api/pleroma/blocks_import", %{"list" => "#{user2.ap_id}"})
54 assert response == "job started"
58 describe "POST /api/pleroma/notifications/read" do
59 test "it marks a single notification as read", %{conn: conn} do
62 {:ok, activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
63 {:ok, activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
64 {:ok, [notification1]} = Notification.create_notifications(activity1)
65 {:ok, [notification2]} = Notification.create_notifications(activity2)
68 |> assign(:user, user1)
69 |> post("/api/pleroma/notifications/read", %{"id" => "#{notification1.id}"})
72 assert Repo.get(Notification, notification1.id).seen
73 refute Repo.get(Notification, notification2.id).seen
77 describe "GET /api/statusnet/config.json" do
78 test "returns the state of safe_dm_mentions flag", %{conn: conn} do
79 option = Pleroma.Config.get([:instance, :safe_dm_mentions])
80 Pleroma.Config.put([:instance, :safe_dm_mentions], true)
84 |> get("/api/statusnet/config.json")
87 assert response["site"]["safeDMMentionsEnabled"] == "1"
89 Pleroma.Config.put([:instance, :safe_dm_mentions], false)
93 |> get("/api/statusnet/config.json")
96 assert response["site"]["safeDMMentionsEnabled"] == "0"
98 Pleroma.Config.put([:instance, :safe_dm_mentions], option)
101 test "it returns the managed config", %{conn: conn} do
102 Pleroma.Config.put([:instance, :managed_config], false)
103 Pleroma.Config.put([:fe], theme: "rei-ayanami-towel")
107 |> get("/api/statusnet/config.json")
108 |> json_response(:ok)
110 refute response["site"]["pleromafe"]
112 Pleroma.Config.put([:instance, :managed_config], true)
116 |> get("/api/statusnet/config.json")
117 |> json_response(:ok)
119 assert response["site"]["pleromafe"]
122 test "if :pleroma, :fe is false, it returns the new style config settings", %{conn: conn} do
123 Pleroma.Config.put([:instance, :managed_config], true)
124 Pleroma.Config.put([:fe, :theme], "rei-ayanami-towel")
125 Pleroma.Config.put([:frontend_configurations, :pleroma_fe], %{theme: "asuka-hospital"})
129 |> get("/api/statusnet/config.json")
130 |> json_response(:ok)
132 assert response["site"]["pleromafe"]["theme"] == "rei-ayanami-towel"
134 Pleroma.Config.put([:fe], false)
138 |> get("/api/statusnet/config.json")
139 |> json_response(:ok)
141 assert response["site"]["pleromafe"]["theme"] == "asuka-hospital"
145 describe "GET /api/pleroma/frontend_configurations" do
146 test "returns everything in :pleroma, :frontend_configurations", %{conn: conn} do
157 Pleroma.Config.put(:frontend_configurations, config)
161 |> get("/api/pleroma/frontend_configurations")
162 |> json_response(:ok)
164 assert response == Jason.encode!(config |> Enum.into(%{})) |> Jason.decode!()