From 82b57ebad1b5de0fc4614441e8838cbdb4fe32b3 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Thu, 27 Sep 2018 20:17:44 +0200 Subject: [Pleroma.Web.TwitterAPI.UserView]: Add mastodon-fields in "fields" --- test/web/twitter_api/views/user_view_test.exs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs index 50687f450..383d7d34c 100644 --- a/test/web/twitter_api/views/user_view_test.exs +++ b/test/web/twitter_api/views/user_view_test.exs @@ -88,7 +88,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "is_local" => true, "locked" => false, "default_scope" => "public", - "no_rich_text" => false + "no_rich_text" => false, + "fields" => [] } assert represented == UserView.render("show.json", %{user: user}) @@ -128,7 +129,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "is_local" => true, "locked" => false, "default_scope" => "public", - "no_rich_text" => false + "no_rich_text" => false, + "fields" => [] } assert represented == UserView.render("show.json", %{user: user, for: follower}) @@ -169,7 +171,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "is_local" => true, "locked" => false, "default_scope" => "public", - "no_rich_text" => false + "no_rich_text" => false, + "fields" => [] } assert represented == UserView.render("show.json", %{user: follower, for: user}) @@ -217,7 +220,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "is_local" => true, "locked" => false, "default_scope" => "public", - "no_rich_text" => false + "no_rich_text" => false, + "fields" => [] } blocker = Repo.get(User, blocker.id) -- cgit v1.2.3 From a74daabfae5ed149942b5afc64982d3e2ca95b11 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Fri, 28 Sep 2018 11:17:33 +0200 Subject: [Pleroma.Web.TwitterAPI.UserViewTest]: Add test for mastodon-fields --- test/web/twitter_api/views/user_view_test.exs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs index 383d7d34c..2deb22fb1 100644 --- a/test/web/twitter_api/views/user_view_test.exs +++ b/test/web/twitter_api/views/user_view_test.exs @@ -227,4 +227,30 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do blocker = Repo.get(User, blocker.id) assert represented == UserView.render("show.json", %{user: user, for: blocker}) end + + test "a user with mastodon fields" do + fields = [ + %{ + "name" => "Pronouns", + "value" => "she/her" + }, + %{ + "name" => "Website", + "value" => "https://example.org/" + } + ] + + user = + insert(:user, %{ + info: %{ + "source_data" => %{ + "attachment" => + Enum.map(fields, fn field -> Map.put(field, "type", "PropertyValue") end) + } + } + }) + + userview = UserView.render("show.json", %{user: user}) + assert userview["fields"] == fields + end end -- cgit v1.2.3 From 9563f3766d45e6c95fe50e371bc0048d9f4a2452 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 25 Oct 2018 03:03:44 +0000 Subject: tests: update for new in_reply_to_screen_name field --- test/web/twitter_api/representers/activity_representer_test.exs | 1 + test/web/twitter_api/views/activity_view_test.exs | 1 + 2 files changed, 2 insertions(+) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs index 894d20049..ae6f62ed0 100644 --- a/test/web/twitter_api/representers/activity_representer_test.exs +++ b/test/web/twitter_api/representers/activity_representer_test.exs @@ -139,6 +139,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do "is_post_verb" => true, "created_at" => "Tue May 24 13:26:08 +0000 2016", "in_reply_to_status_id" => 213_123, + "in_reply_to_screen_name" => nil, "statusnet_conversation_id" => convo_object.id, "attachments" => [ ObjectRepresenter.to_map(object) diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index b9a8efdad..3ab87d6fa 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -36,6 +36,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do "favorited" => false, "id" => activity.id, "in_reply_to_status_id" => nil, + "in_reply_to_screen_name" => nil, "is_local" => true, "is_post_verb" => true, "possibly_sensitive" => false, -- cgit v1.2.3 From 6cfba7db8de1cdb409243885724101500fa21e6d Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 25 Oct 2018 04:06:42 +0000 Subject: tests: twitterapi: add additional fields --- test/web/twitter_api/representers/activity_representer_test.exs | 3 +++ test/web/twitter_api/views/activity_view_test.exs | 3 +++ 2 files changed, 6 insertions(+) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs index ae6f62ed0..291fd5237 100644 --- a/test/web/twitter_api/representers/activity_representer_test.exs +++ b/test/web/twitter_api/representers/activity_representer_test.exs @@ -140,6 +140,9 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do "created_at" => "Tue May 24 13:26:08 +0000 2016", "in_reply_to_status_id" => 213_123, "in_reply_to_screen_name" => nil, + "in_reply_to_user_id" => nil, + "in_reply_to_profileurl" => nil, + "in_reply_to_ostatus_uri" => nil, "statusnet_conversation_id" => convo_object.id, "attachments" => [ ObjectRepresenter.to_map(object) diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index 3ab87d6fa..5cef06f88 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -37,6 +37,9 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do "id" => activity.id, "in_reply_to_status_id" => nil, "in_reply_to_screen_name" => nil, + "in_reply_to_user_id" => nil, + "in_reply_to_profileurl" => nil, + "in_reply_to_ostatus_uri" => nil, "is_local" => true, "is_post_verb" => true, "possibly_sensitive" => false, -- cgit v1.2.3 From 013f7ba8c1c4e6519cf30d192e3a41c6c96f8a63 Mon Sep 17 00:00:00 2001 From: href Date: Tue, 6 Nov 2018 14:44:00 +0100 Subject: Add federating plug & public tests --- .../twitter_api/twitter_api_controller_test.exs | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 87bcdaf71..b64f416e3 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -100,6 +100,56 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do assert length(response) == 10 end + + test "returns 403 to unauthenticated request when the instance is not public" do + instance = + Application.get_env(:pleroma, :instance) + |> Keyword.put(:public, false) + + Application.put_env(:pleroma, :instance, instance) + + conn + |> get("/api/statuses/public_timeline.json") + |> json_response(403) + + instance = + Application.get_env(:pleroma, :instance) + |> Keyword.put(:public, true) + + Application.put_env(:pleroma, :instance, instance) + end + + test "returns 200 to unauthenticated request when the instance is public" do + conn + |> get("/api/statuses/public_timeline.json") + |> json_response(200) + end + end + + describe "GET /statuses/public_and_external_timeline.json" do + test "returns 403 to unauthenticated request when the instance is not public" do + instance = + Application.get_env(:pleroma, :instance) + |> Keyword.put(:public, false) + + Application.put_env(:pleroma, :instance, instance) + + conn + |> get("/api/statuses/public_and_external_timeline.json") + |> json_response(403) + + instance = + Application.get_env(:pleroma, :instance) + |> Keyword.put(:public, true) + + Application.put_env(:pleroma, :instance, instance) + end + + test "returns 200 to unauthenticated request when the instance is public" do + conn + |> get("/api/statuses/public_and_external_timeline.json") + |> json_response(200) + end end describe "GET /statuses/show/:id.json" do -- cgit v1.2.3 From d675b8a16f84728134b09340a78db9e77f87839c Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 6 Nov 2018 23:25:16 +0000 Subject: tests: add tests for twitterapi endpoint --- .../twitter_api/twitter_api_controller_test.exs | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index b64f416e3..13480c21b 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -331,6 +331,56 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do end end + describe "POST /api/qvitter/statuses/notifications/read" do + setup [:valid_user] + + test "without valid credentials", %{conn: conn} do + conn = post(conn, "/api/qvitter/statuses/notifications/read", %{"latest_id" => 1_234_567}) + assert json_response(conn, 403) == %{"error" => "Invalid credentials."} + end + + test "with credentials, without any params", %{conn: conn, user: current_user} do + conn = + conn + |> with_credentials(current_user.nickname, "test") + |> post("/api/qvitter/statuses/notifications/read") + + assert json_response(conn, 400) == %{ + "error" => "You need to specify latest_id", + "request" => "/api/qvitter/statuses/notifications/read" + } + end + + test "with credentials, with params", %{conn: conn, user: current_user} do + other_user = insert(:user) + + {:ok, _activity} = + ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: other_user}) + + response_conn = + conn + |> with_credentials(current_user.nickname, "test") + |> get("/api/qvitter/statuses/notifications.json") + + [notification] = response = json_response(response_conn, 200) + + assert length(response) == 1 + + assert notification["is_seen"] == 0 + + response_conn = + conn + |> with_credentials(current_user.nickname, "test") + |> post("/api/qvitter/statuses/notifications/read", %{"latest_id" => notification["id"]}) + + [notification] = response = json_response(response_conn, 200) + + assert length(response) == 1 + + assert notification["is_seen"] == 1 + end + end + describe "GET /statuses/user_timeline.json" do setup [:valid_user] -- cgit v1.2.3 From 719a8a1f826972a43b80f100d3cbe65e75891366 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 8 Nov 2018 19:17:15 +0000 Subject: tests: flip testing to/cc for mentions --- test/web/twitter_api/twitter_api_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index 6486540f8..8b9920bd9 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -48,7 +48,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do "https://www.w3.org/ns/activitystreams#Public" ) - assert Enum.member?(get_in(activity.data, ["cc"]), "shp") + assert Enum.member?(get_in(activity.data, ["to"]), "shp") assert activity.local == true assert %{"moominmamma" => "http://localhost:4001/finmoji/128px/moominmamma-128.png"} = -- cgit v1.2.3 From db78c72868358eed6c07ee43a5f1427d545c45ed Mon Sep 17 00:00:00 2001 From: scarlett Date: Mon, 12 Nov 2018 16:40:34 +0000 Subject: Twitter API: Add tests for nil names. --- test/web/twitter_api/views/user_view_test.exs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs index 2deb22fb1..2c583c0d3 100644 --- a/test/web/twitter_api/views/user_view_test.exs +++ b/test/web/twitter_api/views/user_view_test.exs @@ -13,6 +13,13 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do [user: user] end + test "A user with only a nickname", %{user: user} do + user = %{user | name: nil, nickname: "scarlett@catgirl.science"} + represented = UserView.render("show.json", %{user: user}) + assert represented["name"] == user.nickname + assert represented["name_html"] == user.nickname + end + test "A user with an avatar object", %{user: user} do image = "image" user = %{user | avatar: %{"url" => [%{"href" => image}]}} -- cgit v1.2.3 From ea9a776d7beb32b157269652759b85cdc17fec32 Mon Sep 17 00:00:00 2001 From: lain Date: Tue, 13 Nov 2018 20:08:50 +0100 Subject: TwitterApi: Add direct message endpoint --- .../twitter_api/twitter_api_controller_test.exs | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 13480c21b..788e3a6eb 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -271,6 +271,36 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do end end + describe "GET /statuses/dm_timeline.json" do + test "it show direct messages", %{conn: conn} do + user_one = insert(:user) + user_two = insert(:user) + + {:ok, user_two} = User.follow(user_two, user_one) + + {:ok, direct} = + CommonAPI.post(user_one, %{ + "status" => "Hi @#{user_two.nickname}!", + "visibility" => "direct" + }) + + {:ok, _follower_only} = + CommonAPI.post(user_one, %{ + "status" => "Hi @#{user_two.nickname}!", + "visibility" => "private" + }) + + # Only direct should be visible here + res_conn = + conn + |> assign(:user, user_two) + |> get("/api/statuses/dm_timeline.json") + + [status] = json_response(res_conn, 200) + assert status["id"] == direct.id + end + end + describe "GET /statuses/mentions.json" do setup [:valid_user] -- cgit v1.2.3 From 7b170cd6161166e153ad54856d5f1cf189f4e3ae Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 14 Nov 2018 20:33:23 +0100 Subject: Add Pleroma user search api for PleromaFE. --- test/web/twitter_api/twitter_api_controller_test.exs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 788e3a6eb..07f9c7814 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -1211,4 +1211,19 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do assert relationship["follows_you"] == false end end + + describe "GET /api/pleroma/search_user" do + test "it returns users, ordered by similarity", %{conn: conn} do + user = insert(:user, %{name: "eal"}) + user_two = insert(:user, %{name: "ean"}) + user_three = insert(:user, %{name: "ebn"}) + + resp = conn + |> get(twitter_api_search__path(conn, :search_user), query: "eal") + |> json_response(200) + + assert length(resp) == 3 + assert [user.id, user_two.id, user_three.id] == Enum.map(resp, fn (%{"id" => id}) -> id end) + end + end end -- cgit v1.2.3 From 27aa136aacb43084089234df59649bc81e53d63c Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 14 Nov 2018 20:41:12 +0100 Subject: Format. --- test/web/twitter_api/twitter_api_controller_test.exs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 07f9c7814..1d45d9437 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -1218,12 +1218,13 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do user_two = insert(:user, %{name: "ean"}) user_three = insert(:user, %{name: "ebn"}) - resp = conn - |> get(twitter_api_search__path(conn, :search_user), query: "eal") - |> json_response(200) + resp = + conn + |> get(twitter_api_search__path(conn, :search_user), query: "eal") + |> json_response(200) assert length(resp) == 3 - assert [user.id, user_two.id, user_three.id] == Enum.map(resp, fn (%{"id" => id}) -> id end) + assert [user.id, user_two.id, user_three.id] == Enum.map(resp, fn %{"id" => id} -> id end) end end end -- cgit v1.2.3 From f87b315618cf55f5c0794ab0dfc5523bdce348ef Mon Sep 17 00:00:00 2001 From: lain Date: Fri, 16 Nov 2018 19:47:36 +0100 Subject: TwitterAPI: Fix dm_timeline displaying only half of the conversation. --- test/web/twitter_api/twitter_api_controller_test.exs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 1d45d9437..6bdcb4fd8 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -284,6 +284,12 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do "visibility" => "direct" }) + {:ok, direct_two} = + CommonAPI.post(user_two, %{ + "status" => "Hi @#{user_one.nickname}!", + "visibility" => "direct" + }) + {:ok, _follower_only} = CommonAPI.post(user_one, %{ "status" => "Hi @#{user_two.nickname}!", @@ -296,8 +302,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do |> assign(:user, user_two) |> get("/api/statuses/dm_timeline.json") - [status] = json_response(res_conn, 200) - assert status["id"] == direct.id + [status, status_two] = json_response(res_conn, 200) + assert status["id"] == direct_two.id + assert status_two["id"] == direct.id end end -- cgit v1.2.3