From 67b4297f4d4010ee1b66452af4cea094d2cab2c4 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Sat, 29 Dec 2018 12:02:37 +0300 Subject: [#483] Refactored blocks and follows import, added tests. --- test/web/twitter_api/util_controller_test.exs | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/web/twitter_api/util_controller_test.exs (limited to 'test/web/twitter_api/util_controller_test.exs') diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs new file mode 100644 index 000000000..73aa70bd5 --- /dev/null +++ b/test/web/twitter_api/util_controller_test.exs @@ -0,0 +1,35 @@ +defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do + use Pleroma.Web.ConnCase + + import Pleroma.Factory + + describe "POST /api/pleroma/follow_import" do + test "it returns HTTP 200", %{conn: conn} do + user1 = insert(:user) + user2 = insert(:user) + + response = + conn + |> assign(:user, user1) + |> post("/api/pleroma/follow_import", %{"list" => "#{user2.ap_id}"}) + |> json_response(:ok) + + assert response == "job started" + end + end + + describe "POST /api/pleroma/blocks_import" do + test "it returns HTTP 200", %{conn: conn} do + user1 = insert(:user) + user2 = insert(:user) + + response = + conn + |> assign(:user, user1) + |> post("/api/pleroma/blocks_import", %{"list" => "#{user2.ap_id}"}) + |> json_response(:ok) + + assert response == "job started" + end + end +end -- cgit v1.2.3 From e221c681dcd387aa445c35957a32fdc0189a0955 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 23 Jan 2019 12:40:57 +0100 Subject: New frontend configuration mechanism. --- test/web/twitter_api/util_controller_test.exs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test/web/twitter_api/util_controller_test.exs') diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs index 73aa70bd5..c099db003 100644 --- a/test/web/twitter_api/util_controller_test.exs +++ b/test/web/twitter_api/util_controller_test.exs @@ -32,4 +32,27 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do assert response == "job started" end end + + describe "GET /api/pleroma/frontent_configurations" do + test "returns everything in :pleroma, :frontend_configurations", %{conn: conn} do + config = [ + frontend_a: %{ + x: 1, + y: 2 + }, + frontend_b: %{ + z: 3 + } + ] + + Pleroma.Config.put(:frontend_configurations, config) + + response = + conn + |> get("/api/pleroma/frontend_configurations") + |> json_response(:ok) + + assert response == Jason.encode!(config |> Enum.into(%{})) |> Jason.decode!() + end + end end -- cgit v1.2.3 From 8e8a1e1ba8a08bc297884fe085b4542a052d6d01 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 28 Jan 2019 13:07:12 +0100 Subject: Return new-style config if old-style config is set to false. This is in preparation for 1.0. We'll be able to switch the config to the new mechanism on PleromaFE then as well. --- test/web/twitter_api/util_controller_test.exs | 46 ++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'test/web/twitter_api/util_controller_test.exs') diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs index c099db003..dc9bad369 100644 --- a/test/web/twitter_api/util_controller_test.exs +++ b/test/web/twitter_api/util_controller_test.exs @@ -33,7 +33,51 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do end end - describe "GET /api/pleroma/frontent_configurations" do + describe "GET /api/statusnet/config.json" do + test "it returns the managed config", %{conn: conn} do + Pleroma.Config.put([:instance, :managed_config], false) + + response = + conn + |> get("/api/statusnet/config.json") + |> json_response(:ok) + + refute response["site"]["pleromafe"] + + Pleroma.Config.put([:instance, :managed_config], true) + + response = + conn + |> get("/api/statusnet/config.json") + |> json_response(:ok) + + assert response["site"]["pleromafe"] + end + + test "if :pleroma, :fe is false, it returns the new style config settings", %{conn: conn} do + Pleroma.Config.put([:instance, :managed_config], true) + Pleroma.Config.put([:fe, :theme], "rei-ayanami-towel") + Pleroma.Config.put([:frontend_configurations, :pleroma_fe], %{theme: "asuka-hospital"}) + + response = + conn + |> get("/api/statusnet/config.json") + |> json_response(:ok) + + assert response["site"]["pleromafe"]["theme"] == "rei-ayanami-towel" + + Pleroma.Config.put([:fe], false) + + response = + conn + |> get("/api/statusnet/config.json") + |> json_response(:ok) + + assert response["site"]["pleromafe"]["theme"] == "asuka-hospital" + end + end + + describe "GET /api/pleroma/frontend_configurations" do test "returns everything in :pleroma, :frontend_configurations", %{conn: conn} do config = [ frontend_a: %{ -- cgit v1.2.3 From c4d317ccb679f7fef11983b9629249e047bec4db Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 5 Feb 2019 18:49:02 +0000 Subject: test: twitterapi: fix the test breakage for real --- test/web/twitter_api/util_controller_test.exs | 1 + 1 file changed, 1 insertion(+) (limited to 'test/web/twitter_api/util_controller_test.exs') diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs index dc9bad369..8e152ecd4 100644 --- a/test/web/twitter_api/util_controller_test.exs +++ b/test/web/twitter_api/util_controller_test.exs @@ -36,6 +36,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do describe "GET /api/statusnet/config.json" do test "it returns the managed config", %{conn: conn} do Pleroma.Config.put([:instance, :managed_config], false) + Pleroma.Config.put([:fe, :theme], "rei-ayanami-towel") response = conn -- cgit v1.2.3 From 73e6a1f1dd9bfe9ebf95308292ecb9a2dd67abe4 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 5 Feb 2019 20:04:39 +0000 Subject: test: twitterapi: fix another possible test failure case --- test/web/twitter_api/util_controller_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/web/twitter_api/util_controller_test.exs') diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs index 8e152ecd4..007d7d8e6 100644 --- a/test/web/twitter_api/util_controller_test.exs +++ b/test/web/twitter_api/util_controller_test.exs @@ -36,7 +36,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do describe "GET /api/statusnet/config.json" do test "it returns the managed config", %{conn: conn} do Pleroma.Config.put([:instance, :managed_config], false) - Pleroma.Config.put([:fe, :theme], "rei-ayanami-towel") + Pleroma.Config.put([:fe], theme: "rei-ayanami-towel") response = conn -- cgit v1.2.3 From 04ee877a20a849db53a307a1736e635229129b7a Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Tue, 19 Feb 2019 22:28:21 +0300 Subject: [#468] Added OAuth scopes-specific tests. --- test/web/twitter_api/util_controller_test.exs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/web/twitter_api/util_controller_test.exs') diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs index 007d7d8e6..fc762ab18 100644 --- a/test/web/twitter_api/util_controller_test.exs +++ b/test/web/twitter_api/util_controller_test.exs @@ -16,6 +16,25 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do assert response == "job started" end + + test "requires 'follow' permission", %{conn: conn} do + token1 = insert(:oauth_token, scopes: ["read", "write"]) + token2 = insert(:oauth_token, scopes: ["follow"]) + another_user = insert(:user) + + for token <- [token1, token2] do + conn = + conn + |> put_req_header("authorization", "Bearer #{token.token}") + |> post("/api/pleroma/follow_import", %{"list" => "#{another_user.ap_id}"}) + + if token == token1 do + assert %{"error" => "Insufficient permissions: follow."} == json_response(conn, 403) + else + assert json_response(conn, 200) + end + end + end end describe "POST /api/pleroma/blocks_import" do -- cgit v1.2.3 From 43fb03be5a8968c1df23938ed4f5a93825ab476c Mon Sep 17 00:00:00 2001 From: eugenijm Date: Fri, 15 Mar 2019 20:06:28 +0300 Subject: Allow to mark a single notification as read --- test/web/twitter_api/util_controller_test.exs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test/web/twitter_api/util_controller_test.exs') diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs index fc762ab18..6e8a25056 100644 --- a/test/web/twitter_api/util_controller_test.exs +++ b/test/web/twitter_api/util_controller_test.exs @@ -1,6 +1,9 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do use Pleroma.Web.ConnCase + alias Pleroma.Notification + alias Pleroma.Repo + alias Pleroma.Web.CommonAPI import Pleroma.Factory describe "POST /api/pleroma/follow_import" do @@ -52,6 +55,25 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do end end + describe "POST /api/pleroma/notifications/read" do + test "it marks a single notification as read", %{conn: conn} do + user1 = insert(:user) + user2 = insert(:user) + {:ok, activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"}) + {:ok, activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"}) + {:ok, [notification1]} = Notification.create_notifications(activity1) + {:ok, [notification2]} = Notification.create_notifications(activity2) + + conn + |> assign(:user, user1) + |> post("/api/pleroma/notifications/read", %{"id" => "#{notification1.id}"}) + |> json_response(:ok) + + assert Repo.get(Notification, notification1.id).seen + refute Repo.get(Notification, notification2.id).seen + end + end + describe "GET /api/statusnet/config.json" do test "it returns the managed config", %{conn: conn} do Pleroma.Config.put([:instance, :managed_config], false) -- cgit v1.2.3 From bf27190f7f0942a05de518f2085a299eb011614c Mon Sep 17 00:00:00 2001 From: lain Date: Thu, 21 Mar 2019 16:16:26 +0100 Subject: UtilController: Return state of safe dm mentions. --- test/web/twitter_api/util_controller_test.exs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test/web/twitter_api/util_controller_test.exs') diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs index 6e8a25056..832fdc096 100644 --- a/test/web/twitter_api/util_controller_test.exs +++ b/test/web/twitter_api/util_controller_test.exs @@ -75,6 +75,29 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do end describe "GET /api/statusnet/config.json" do + test "returns the state of safe_dm_mentions flag", %{conn: conn} do + option = Pleroma.Config.get([:instance, :safe_dm_mentions]) + Pleroma.Config.put([:instance, :safe_dm_mentions], true) + + response = + conn + |> get("/api/statusnet/config.json") + |> json_response(:ok) + + assert response["site"]["safeDMMentionsEnabled"] == "1" + + Pleroma.Config.put([:instance, :safe_dm_mentions], false) + + response = + conn + |> get("/api/statusnet/config.json") + |> json_response(:ok) + + assert response["site"]["safeDMMentionsEnabled"] == "0" + + Pleroma.Config.put([:instance, :safe_dm_mentions], option) + end + test "it returns the managed config", %{conn: conn} do Pleroma.Config.put([:instance, :managed_config], false) Pleroma.Config.put([:fe], theme: "rei-ayanami-towel") -- cgit v1.2.3 From cd90695a349f33b84f287794bae6070e9eec446a Mon Sep 17 00:00:00 2001 From: eugenijm Date: Thu, 28 Mar 2019 14:52:09 +0300 Subject: Add PUT /api/pleroma/notification_settings endpoint --- test/web/twitter_api/util_controller_test.exs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/web/twitter_api/util_controller_test.exs') diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs index 832fdc096..426508353 100644 --- a/test/web/twitter_api/util_controller_test.exs +++ b/test/web/twitter_api/util_controller_test.exs @@ -3,6 +3,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do alias Pleroma.Notification alias Pleroma.Repo + alias Pleroma.User alias Pleroma.Web.CommonAPI import Pleroma.Factory @@ -74,6 +75,26 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do end end + describe "PUT /api/pleroma/notification_settings" do + test "it updates notification settings", %{conn: conn} do + user = insert(:user) + + conn + |> assign(:user, user) + |> put("/api/pleroma/notification_settings", %{ + "remote" => false, + "followers" => false, + "bar" => 1 + }) + |> json_response(:ok) + + user = Repo.get(User, user.id) + + assert %{"remote" => false, "local" => true, "followers" => false, "follows" => true} == + user.info.notification_settings + end + end + describe "GET /api/statusnet/config.json" do test "returns the state of safe_dm_mentions flag", %{conn: conn} do option = Pleroma.Config.get([:instance, :safe_dm_mentions]) -- cgit v1.2.3 From 3601f03147bd104f6acff64e7c8d5d4d3e1f53a2 Mon Sep 17 00:00:00 2001 From: Alex S Date: Mon, 1 Apr 2019 17:17:57 +0700 Subject: Adding tag to emoji ets table changes in apis --- test/web/twitter_api/util_controller_test.exs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/web/twitter_api/util_controller_test.exs') diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs index 832fdc096..1063ad28f 100644 --- a/test/web/twitter_api/util_controller_test.exs +++ b/test/web/twitter_api/util_controller_test.exs @@ -164,4 +164,25 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do assert response == Jason.encode!(config |> Enum.into(%{})) |> Jason.decode!() end end + + describe "/api/pleroma/emoji" do + test "returns json with custom emoji with tags", %{conn: conn} do + [emoji | _body] = + conn + |> get("/api/pleroma/emoji") + |> json_response(200) + + [key] = Map.keys(emoji) + + %{ + ^key => %{ + "image_url" => url, + "tags" => tags + } + } = emoji + + assert is_binary(url) + assert is_list(tags) + end + end end -- cgit v1.2.3 From 1d01e8e656c364b97b9ee36a6173a830d3f5f4fc Mon Sep 17 00:00:00 2001 From: Sachin Joshi Date: Mon, 1 Apr 2019 22:12:02 +0545 Subject: [OStatus] adds status to pleroma instance if the url given is a status --- test/web/twitter_api/util_controller_test.exs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/web/twitter_api/util_controller_test.exs') diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs index 832fdc096..f4a3ce501 100644 --- a/test/web/twitter_api/util_controller_test.exs +++ b/test/web/twitter_api/util_controller_test.exs @@ -6,6 +6,11 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do alias Pleroma.Web.CommonAPI import Pleroma.Factory + setup do + Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end) + :ok + end + describe "POST /api/pleroma/follow_import" do test "it returns HTTP 200", %{conn: conn} do user1 = insert(:user) @@ -164,4 +169,16 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do assert response == Jason.encode!(config |> Enum.into(%{})) |> Jason.decode!() end end + + describe "GET /ostatus_subscribe?acct=...." do + test "adds status to pleroma instance if the `acct` is a status", %{conn: conn} do + conn = + get( + conn, + "/ostatus_subscribe?acct=https://mastodon.social/users/emelie/statuses/101849165031453009" + ) + + assert redirected_to(conn) =~ "/notice/" + end + end end -- cgit v1.2.3 From 6386c1c9c1ff971c784744922a479ae38e5fdbad Mon Sep 17 00:00:00 2001 From: Sachin Joshi Date: Tue, 2 Apr 2019 10:26:09 +0545 Subject: fetch url for OStatus to know if it is a/c or status --- test/web/twitter_api/util_controller_test.exs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test/web/twitter_api/util_controller_test.exs') diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs index f4a3ce501..e4dd97d46 100644 --- a/test/web/twitter_api/util_controller_test.exs +++ b/test/web/twitter_api/util_controller_test.exs @@ -180,5 +180,15 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do assert redirected_to(conn) =~ "/notice/" end + + test "show follow account page if the `acct` is a account link", %{conn: conn} do + response = + get( + conn, + "/ostatus_subscribe?acct=https://mastodon.social/users/emelie" + ) + + assert html_response(response, 200) =~ "Log in to follow" + end end end -- cgit v1.2.3 From b57b43027cf958d3a3a82b95f155ae27b235b543 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 9 Apr 2019 23:20:31 +0300 Subject: Change response format of /api/pleroma/emoji to the one that actually makes sense --- test/web/twitter_api/util_controller_test.exs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'test/web/twitter_api/util_controller_test.exs') diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs index 410f20f87..a1a5e3964 100644 --- a/test/web/twitter_api/util_controller_test.exs +++ b/test/web/twitter_api/util_controller_test.exs @@ -172,22 +172,19 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do describe "/api/pleroma/emoji" do test "returns json with custom emoji with tags", %{conn: conn} do - [emoji | _body] = + emoji = conn |> get("/api/pleroma/emoji") |> json_response(200) - [key] = Map.keys(emoji) - - %{ - ^key => %{ - "image_url" => url, - "tags" => tags - } - } = emoji - - assert is_binary(url) - assert is_list(tags) + assert Enum.all?(emoji, fn + {_key, + %{ + "image_url" => url, + "tags" => tags + }} -> + is_binary(url) and is_list(tags) + end) end end -- cgit v1.2.3 From d4a749cfb2f644dab9b0f414e8f0e41ed4ffd08f Mon Sep 17 00:00:00 2001 From: Normandy Date: Tue, 16 Apr 2019 18:35:38 +0000 Subject: Handle new-style mastodon follow lists Fixes https://git.pleroma.social/pleroma/pleroma/issues/814 --- test/web/twitter_api/util_controller_test.exs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test/web/twitter_api/util_controller_test.exs') diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs index a4b3d651a..c58b49ea4 100644 --- a/test/web/twitter_api/util_controller_test.exs +++ b/test/web/twitter_api/util_controller_test.exs @@ -26,6 +26,21 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do assert response == "job started" end + test "it imports new-style mastodon follow lists", %{conn: conn} do + user1 = insert(:user) + user2 = insert(:user) + + response = + conn + |> assign(:user, user1) + |> post("/api/pleroma/follow_import", %{ + "list" => "Account address,Show boosts\n#{user2.ap_id},true" + }) + |> json_response(:ok) + + assert response == "job started" + end + test "requires 'follow' permission", %{conn: conn} do token1 = insert(:oauth_token, scopes: ["read", "write"]) token2 = insert(:oauth_token, scopes: ["follow"]) -- cgit v1.2.3