Merge branch 'remove-todo-txt' into 'develop'
[akkoma] / test / web / twitter_api / util_controller_test.exs
1 defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
2 use Pleroma.Web.ConnCase
3
4 import Pleroma.Factory
5
6 describe "POST /api/pleroma/follow_import" do
7 test "it returns HTTP 200", %{conn: conn} do
8 user1 = insert(:user)
9 user2 = insert(:user)
10
11 response =
12 conn
13 |> assign(:user, user1)
14 |> post("/api/pleroma/follow_import", %{"list" => "#{user2.ap_id}"})
15 |> json_response(:ok)
16
17 assert response == "job started"
18 end
19
20 test "requires 'follow' permission", %{conn: conn} do
21 token1 = insert(:oauth_token, scopes: ["read", "write"])
22 token2 = insert(:oauth_token, scopes: ["follow"])
23 another_user = insert(:user)
24
25 for token <- [token1, token2] do
26 conn =
27 conn
28 |> put_req_header("authorization", "Bearer #{token.token}")
29 |> post("/api/pleroma/follow_import", %{"list" => "#{another_user.ap_id}"})
30
31 if token == token1 do
32 assert %{"error" => "Insufficient permissions: follow."} == json_response(conn, 403)
33 else
34 assert json_response(conn, 200)
35 end
36 end
37 end
38 end
39
40 describe "POST /api/pleroma/blocks_import" do
41 test "it returns HTTP 200", %{conn: conn} do
42 user1 = insert(:user)
43 user2 = insert(:user)
44
45 response =
46 conn
47 |> assign(:user, user1)
48 |> post("/api/pleroma/blocks_import", %{"list" => "#{user2.ap_id}"})
49 |> json_response(:ok)
50
51 assert response == "job started"
52 end
53 end
54
55 describe "GET /api/statusnet/config.json" do
56 test "it returns the managed config", %{conn: conn} do
57 Pleroma.Config.put([:instance, :managed_config], false)
58 Pleroma.Config.put([:fe], theme: "rei-ayanami-towel")
59
60 response =
61 conn
62 |> get("/api/statusnet/config.json")
63 |> json_response(:ok)
64
65 refute response["site"]["pleromafe"]
66
67 Pleroma.Config.put([:instance, :managed_config], true)
68
69 response =
70 conn
71 |> get("/api/statusnet/config.json")
72 |> json_response(:ok)
73
74 assert response["site"]["pleromafe"]
75 end
76
77 test "if :pleroma, :fe is false, it returns the new style config settings", %{conn: conn} do
78 Pleroma.Config.put([:instance, :managed_config], true)
79 Pleroma.Config.put([:fe, :theme], "rei-ayanami-towel")
80 Pleroma.Config.put([:frontend_configurations, :pleroma_fe], %{theme: "asuka-hospital"})
81
82 response =
83 conn
84 |> get("/api/statusnet/config.json")
85 |> json_response(:ok)
86
87 assert response["site"]["pleromafe"]["theme"] == "rei-ayanami-towel"
88
89 Pleroma.Config.put([:fe], false)
90
91 response =
92 conn
93 |> get("/api/statusnet/config.json")
94 |> json_response(:ok)
95
96 assert response["site"]["pleromafe"]["theme"] == "asuka-hospital"
97 end
98 end
99
100 describe "GET /api/pleroma/frontend_configurations" do
101 test "returns everything in :pleroma, :frontend_configurations", %{conn: conn} do
102 config = [
103 frontend_a: %{
104 x: 1,
105 y: 2
106 },
107 frontend_b: %{
108 z: 3
109 }
110 ]
111
112 Pleroma.Config.put(:frontend_configurations, config)
113
114 response =
115 conn
116 |> get("/api/pleroma/frontend_configurations")
117 |> json_response(:ok)
118
119 assert response == Jason.encode!(config |> Enum.into(%{})) |> Jason.decode!()
120 end
121 end
122 end