From b4f055b60416986220d905bbf688f8417cd8a270 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Thu, 5 Oct 2017 12:53:16 +0200 Subject: Don't reject already accepted subscriptions. --- test/web/websub/websub_test.exs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/web') diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs index 1ca573d66..6b2c612ad 100644 --- a/test/web/websub/websub_test.exs +++ b/test/web/websub/websub_test.exs @@ -46,7 +46,8 @@ defmodule Pleroma.Web.WebsubTest do end {:error, sub} = Websub.verify(sub, getter) - assert sub.state == "rejected" + # Keep the current state. + assert sub.state == "requested" end test "an incoming subscription request" do -- cgit v1.2.3 From 64bc38e009208fa4f4409f6930d5117dc291c2f5 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Mon, 23 Oct 2017 16:27:51 +0200 Subject: MastoAPI: Add emoji output. --- test/web/mastodon_api/status_view_test.exs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'test/web') diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs index 1575b1d6e..dc5cdfe9a 100644 --- a/test/web/mastodon_api/status_view_test.exs +++ b/test/web/mastodon_api/status_view_test.exs @@ -41,7 +41,14 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do name: "Web", website: nil }, - language: nil + language: nil, + emojis: [ + %{ + shortcode: "2hu", + url: "corndog.png", + static_url: "corndog.png" + } + ] } assert status == expected -- cgit v1.2.3 From 8e94936553c978e5f0d3bb802a1932a6b505f86e Mon Sep 17 00:00:00 2001 From: eal Date: Fri, 27 Oct 2017 13:55:36 +0300 Subject: Add tests. --- test/web/mastodon_api/mastodon_api_controller_test.exs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/web') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 56888140d..af2351706 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -281,6 +281,13 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> post("/api/v1/accounts/#{other_user.id}/unfollow") assert %{"id" => id, "following" => false} = json_response(conn, 200) + + user = Repo.get(User, user.id) + conn = build_conn() + |> assign(:user, user) + |> post("/api/v1/follows", %{"uri" => other_user.nickname}) + + assert %{"id" => id, "following" => true} = json_response(conn, 200) end test "unimplemented block/mute endpoints" do -- cgit v1.2.3 From c56d28f96c343d445ec8d06baf351423691036f3 Mon Sep 17 00:00:00 2001 From: eal Date: Sun, 29 Oct 2017 00:07:38 +0300 Subject: Fix return type of /api/v1/follows --- test/web/mastodon_api/mastodon_api_controller_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/web') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index af2351706..4e5dc963f 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -287,7 +287,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> assign(:user, user) |> post("/api/v1/follows", %{"uri" => other_user.nickname}) - assert %{"id" => id, "following" => true} = json_response(conn, 200) + assert other_user = json_response(conn, 200) end test "unimplemented block/mute endpoints" do -- cgit v1.2.3 From 71f66bd4589faddc35137ed3197f685555b77aaf Mon Sep 17 00:00:00 2001 From: eal Date: Sun, 29 Oct 2017 14:25:11 +0200 Subject: Fix follow test semantics. --- test/web/mastodon_api/mastodon_api_controller_test.exs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/web') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 4e5dc963f..acdb08ac2 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -287,7 +287,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> assign(:user, user) |> post("/api/v1/follows", %{"uri" => other_user.nickname}) - assert other_user = json_response(conn, 200) + assert %{"id" => id} = json_response(conn, 200) + assert id == other_user.id end test "unimplemented block/mute endpoints" do -- cgit v1.2.3 From 502cb38cd69f9f8c15a0ee597584364f9d36bdf1 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Mon, 30 Oct 2017 19:23:16 +0100 Subject: Move user search to User module. --- test/web/mastodon_api/mastodon_api_controller_test.exs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/web') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index acdb08ac2..485a0d029 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -319,6 +319,19 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do end) end + test "account seach", %{conn: conn} do + user = insert(:user) + user_two = insert(:user, %{nickname: "shp@shitposter.club"}) + user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"}) + + conn = conn + |> assign(:user, user) + |> get("/api/v1/accounts/search", %{"q" => "2hu"}) + + assert [account] = json_response(conn, 200) + assert account["id"] == user_three.id + end + test "search", %{conn: conn} do user = insert(:user) user_two = insert(:user, %{nickname: "shp@shitposter.club"}) -- cgit v1.2.3 From ce7f9f527c55b282a56c86a68c358a6272d01aee Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Tue, 31 Oct 2017 14:40:12 +0100 Subject: MastoAPI: Always return an url for statuses. External url if available, id if not. --- test/web/mastodon_api/status_view_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/web') diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs index dc5cdfe9a..caa2c9d83 100644 --- a/test/web/mastodon_api/status_view_test.exs +++ b/test/web/mastodon_api/status_view_test.exs @@ -19,7 +19,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do expected = %{ id: note.id, uri: note.data["object"]["id"], - url: note.data["object"]["external_id"], + url: note.data["object"]["id"], account: AccountView.render("account.json", %{user: user}), in_reply_to_id: nil, in_reply_to_account_id: nil, -- cgit v1.2.3 From 2f39bb6b432ad993b86146d3e0284dc30653c6b4 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Tue, 31 Oct 2017 14:46:01 +0100 Subject: Typo. --- test/web/mastodon_api/mastodon_api_controller_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/web') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 485a0d029..b97ca06e8 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -319,7 +319,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do end) end - test "account seach", %{conn: conn} do + test "account search", %{conn: conn} do user = insert(:user) user_two = insert(:user, %{nickname: "shp@shitposter.club"}) user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"}) -- cgit v1.2.3 From 968a546d4ac7d6b50af84aea71b3b37af8f2f669 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Tue, 31 Oct 2017 14:51:41 +0100 Subject: MastoAPI: Return id as string instead of integer. --- test/web/mastodon_api/status_view_test.exs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/web') diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs index caa2c9d83..5aeee98c4 100644 --- a/test/web/mastodon_api/status_view_test.exs +++ b/test/web/mastodon_api/status_view_test.exs @@ -17,7 +17,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do |> String.replace(~r/\.\d+Z/, ".000Z") expected = %{ - id: note.id, + id: to_string(note.id), uri: note.data["object"]["id"], url: note.data["object"]["id"], account: AccountView.render("account.json", %{user: user}), @@ -101,7 +101,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do represented = StatusView.render("status.json", %{for: user, activity: reblog}) - assert represented[:id] == reblog.id - assert represented[:reblog][:id] == activity.id + assert represented[:id] == to_string(reblog.id) + assert represented[:reblog][:id] == to_string(activity.id) end end -- cgit v1.2.3 From 4cbf17dac6c9501e9fc711d04540da9afbcad717 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Tue, 31 Oct 2017 17:30:46 +0100 Subject: Save cws in the activitypub data. --- test/web/ostatus/ostatus_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/web') diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs index 95038b73c..de01612b3 100644 --- a/test/web/ostatus/ostatus_test.exs +++ b/test/web/ostatus/ostatus_test.exs @@ -85,7 +85,7 @@ defmodule Pleroma.Web.OStatusTest do assert activity.data["type"] == "Create" assert activity.data["object"]["type"] == "Note" assert activity.data["object"]["actor"] == "https://mastodon.social/users/lambadalambda" - assert String.contains?(activity.data["object"]["content"], "technologic") + assert activity.data["object"]["summary"] == "technologic" assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"] end @@ -93,7 +93,7 @@ defmodule Pleroma.Web.OStatusTest do incoming = File.read!("test/fixtures/cw_retweet.xml") {:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming) - assert String.contains?(retweeted_activity.data["object"]["content"], "Hey.") + assert retweeted_activity.data["object"]["summary"] == "Hey." end test "handle incoming notes - GS, subscription, reply" do -- cgit v1.2.3 From 04217f52c92d5a287b317e10be4b42bf74b30e07 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Tue, 31 Oct 2017 17:43:37 +0100 Subject: TwitterAPI: Display cws. --- test/web/twitter_api/representers/activity_representer_test.exs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'test/web') diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs index f08644611..7e2ea630c 100644 --- a/test/web/twitter_api/representers/activity_representer_test.exs +++ b/test/web/twitter_api/representers/activity_representer_test.exs @@ -91,6 +91,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do "published" => date, "type" => "Note", "content" => content_html, + "summary" => "2hu", "inReplyToStatusId" => 213123, "attachment" => [ object @@ -110,14 +111,14 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do local: false } - expected_html = "alert('YAY')Some 2hu content mentioning @shp" + expected_html = "2hu
alert('YAY')Some 2hu content mentioning @shp" expected_status = %{ "id" => activity.id, "user" => UserView.render("show.json", %{user: user, for: follower}), "is_local" => false, "statusnet_html" => expected_html, - "text" => content, + "text" => "2hu" <> content, "is_post_verb" => true, "created_at" => "Tue May 24 13:26:08 +0000 2016", "in_reply_to_status_id" => 213123, -- cgit v1.2.3 From 44295dd49ad004b8c7a289387e913b1234ad1e61 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Tue, 31 Oct 2017 17:49:47 +0100 Subject: MastoAPI: Include CW. --- test/web/mastodon_api/status_view_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/web') diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs index 5aeee98c4..69d86ea82 100644 --- a/test/web/mastodon_api/status_view_test.exs +++ b/test/web/mastodon_api/status_view_test.exs @@ -32,7 +32,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do favourited: false, muted: false, sensitive: false, - spoiler_text: "", + spoiler_text: note.data["object"]["summary"], visibility: "public", media_attachments: [], mentions: [], -- cgit v1.2.3 From 0c871e5c6eb35d9d8c78cfdc83af869f312389b8 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Tue, 31 Oct 2017 17:57:26 +0100 Subject: Fix specs. --- test/web/mastodon_api/mastodon_api_controller_test.exs | 16 ++++++++-------- test/web/twitter_api/twitter_api_test.exs | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'test/web') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index b97ca06e8..6569b8c45 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -91,7 +91,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> get("/api/v1/statuses/#{activity.id}") assert %{"id" => id} = json_response(conn, 200) - assert id == activity.id + assert id == to_string(activity.id) end describe "deleting a status" do @@ -132,7 +132,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> post("/api/v1/statuses/#{activity.id}/reblog") assert %{"id" => id, "reblogged" => true, "reblogs_count" => 1} = json_response(conn, 200) - assert activity.id == id + assert to_string(activity.id) == id end end @@ -146,7 +146,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> post("/api/v1/statuses/#{activity.id}/favourite") assert %{"id" => id, "favourites_count" => 1, "favourited" => true} = json_response(conn, 200) - assert activity.id == id + assert to_string(activity.id) == id end end @@ -162,7 +162,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> post("/api/v1/statuses/#{activity.id}/unfavourite") assert %{"id" => id, "favourites_count" => 0, "favourited" => false} = json_response(conn, 200) - assert activity.id == id + assert to_string(activity.id) == id end end @@ -178,7 +178,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do assert [%{"id" => id}] = json_response(conn, 200) - assert id == note_two.id + assert id == to_string(note_two.id) end end @@ -238,7 +238,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do assert [%{"id" => id}] = json_response(conn, 200) - assert id == activity.id + assert id == to_string(activity.id) end test "getting followers", %{conn: conn} do @@ -351,7 +351,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do assert results["hashtags"] == [] [status] = results["statuses"] - assert status["id"] == activity.id + assert status["id"] == to_string(activity.id) end test "search fetches remote accounts", %{conn: conn} do @@ -377,6 +377,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> get("/api/v1/favourites") assert [status] = json_response(conn, 200) - assert status["id"] == activity.id + assert status["id"] == to_string(activity.id) end end diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index 1cf48dd4b..1ec9ef388 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -365,7 +365,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do {:ok, represented} = TwitterAPI.get_external_profile(user, id) remote = User.get_by_ap_id(id) - assert represented == UserView.render("show.json", %{user: remote, for: user}) + assert represented["id"] == UserView.render("show.json", %{user: remote, for: user})["id"] # Also fetches the feed. assert Activity.get_create_activity_by_object_ap_id("tag:mastodon.social,2017-04-05:objectId=1641750:objectType=Status") -- cgit v1.2.3 From e014cc6ed8f98e20f5d64f1e666582c62de6321d Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Tue, 31 Oct 2017 19:44:36 +0100 Subject: Allow using cws in mastodon api. --- test/web/mastodon_api/mastodon_api_controller_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/web') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 6569b8c45..cf09bc4b8 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -50,9 +50,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do conn = conn |> assign(:user, user) - |> post("/api/v1/statuses", %{"status" => "cofe"}) + |> post("/api/v1/statuses", %{"status" => "cofe", "spoiler_text" => "2hu"}) - assert %{"content" => "cofe", "id" => id} = json_response(conn, 200) + assert %{"content" => "cofe", "id" => id, "spoiler_text" => "2hu"} = json_response(conn, 200) assert Repo.get(Activity, id) end -- cgit v1.2.3 From 6f05367325e7d773ca7199948fd5b49409f6d78d Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Tue, 31 Oct 2017 19:51:58 +0100 Subject: Federate out content warnings. --- test/web/ostatus/activity_representer_test.exs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/web') diff --git a/test/web/ostatus/activity_representer_test.exs b/test/web/ostatus/activity_representer_test.exs index 8a0121b37..0d83ad964 100644 --- a/test/web/ostatus/activity_representer_test.exs +++ b/test/web/ostatus/activity_representer_test.exs @@ -36,6 +36,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do #{note_activity.data["object"]["published"]} #{note_activity.data["context"]} + #{note_activity.data["object"]["summary"]} @@ -74,6 +75,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do #{answer.data["object"]["published"]} #{answer.data["context"]} + 2hu -- cgit v1.2.3 From a47727adde426ab1e80299f5b5bdb23edabd0cd8 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Thu, 2 Nov 2017 22:37:26 +0100 Subject: Don't return activities from blocked users. --- test/web/activity_pub/activity_pub_test.exs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/web') diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index a088e97be..4c73c0b8a 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -80,6 +80,25 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do end end + test "doesn't return blocked activities" do + activity_one = insert(:note_activity) + activity_two = insert(:note_activity) + user = insert(:user) + {:ok, user} = User.block(user, %{ap_id: activity_one.data["actor"]}) + + activities = ActivityPub.fetch_activities([], %{"blocking_user" => user}) + + assert Enum.member?(activities, activity_two) + refute Enum.member?(activities, activity_one) + + {:ok, user} = User.unblock(user, %{ap_id: activity_one.data["actor"]}) + + activities = ActivityPub.fetch_activities([], %{"blocking_user" => user}) + + assert Enum.member?(activities, activity_two) + assert Enum.member?(activities, activity_one) + end + describe "public fetch activities" do test "retrieves public activities" do %{public: public} = ActivityBuilder.public_and_non_public -- cgit v1.2.3 From 8ef58a266b6c73ac2ec49873d48fda82315c63fd Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Thu, 2 Nov 2017 22:44:36 +0100 Subject: Don't return blocked users' activities in contexts. --- test/web/activity_pub/activity_pub_test.exs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'test/web') diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 4c73c0b8a..2644ad5de 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -73,9 +73,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do {:ok, activity_two} = ActivityBuilder.insert(%{"type" => "Create", "context" => "2hu"}) {:ok, _activity_three} = ActivityBuilder.insert(%{"type" => "Create", "context" => "3hu"}) {:ok, _activity_four} = ActivityBuilder.insert(%{"type" => "Announce", "context" => "2hu"}) + activity_five = insert(:note_activity) + user = insert(:user) - activities = ActivityPub.fetch_activities_for_context("2hu") + {:ok, user} = User.block(user, %{ap_id: activity_five.data["actor"]}) + activities = ActivityPub.fetch_activities_for_context("2hu", %{"blocking_user" => user}) assert activities == [activity_two, activity] end end -- cgit v1.2.3 From 867ac1e4f5b1a5b994b57a73bed36710100f9cf8 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Thu, 2 Nov 2017 22:47:11 +0100 Subject: Handle nil cases. --- test/web/activity_pub/activity_pub_test.exs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/web') diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 2644ad5de..a02740d5d 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -100,6 +100,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do assert Enum.member?(activities, activity_two) assert Enum.member?(activities, activity_one) + + activities = ActivityPub.fetch_activities([], %{"blocking_user" => nil}) + + assert Enum.member?(activities, activity_two) + assert Enum.member?(activities, activity_one) end describe "public fetch activities" do -- cgit v1.2.3 From 33beb51da423f5f80311453ad9025aa66984eb12 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Fri, 3 Nov 2017 08:23:31 +0100 Subject: MastoAPI: Add blocking to AccountView. --- test/web/mastodon_api/account_view_test.exs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/web') diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs index aa74ed966..c62cb4f36 100644 --- a/test/web/mastodon_api/account_view_test.exs +++ b/test/web/mastodon_api/account_view_test.exs @@ -51,12 +51,13 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do other_user = insert(:user) {:ok, user} = User.follow(user, other_user) + {:ok, user} = User.block(user, other_user) expected = %{ id: other_user.id, following: true, followed_by: false, - blocking: false, + blocking: true, muting: false, requested: false, domain_blocking: false -- cgit v1.2.3 From 5bf92e50be76b9dc2fa682b9f2ae252c0faad64e Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Fri, 3 Nov 2017 08:38:05 +0100 Subject: MastoAPI: Add blocking. --- .../mastodon_api/mastodon_api_controller_test.exs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'test/web') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index cf09bc4b8..c91f96f38 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -291,11 +291,29 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do assert id == other_user.id end - test "unimplemented block/mute endpoints" do + test "blocking / unblocking a user", %{conn: conn} do user = insert(:user) other_user = insert(:user) - ["block", "unblock", "mute", "unmute"] + conn = conn + |> assign(:user, user) + |> post("/api/v1/accounts/#{other_user.id}/block") + + assert %{"id" => id, "blocking" => true} = json_response(conn, 200) + + user = Repo.get(User, user.id) + conn = build_conn() + |> assign(:user, user) + |> post("/api/v1/accounts/#{other_user.id}/unblock") + + assert %{"id" => id, "blocking" => false} = json_response(conn, 200) + end + + test "unimplemented mute endpoints" do + user = insert(:user) + other_user = insert(:user) + + ["mute", "unmute"] |> Enum.each(fn(endpoint) -> conn = build_conn() |> assign(:user, user) -- cgit v1.2.3 From c6b9b777dacef2fce51e43a25e3af9c9fac9a87e Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Fri, 3 Nov 2017 08:51:17 +0100 Subject: MastoAPI: Add list of blocked users. --- test/web/mastodon_api/mastodon_api_controller_test.exs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/web') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index c91f96f38..d118026eb 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -309,6 +309,20 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do assert %{"id" => id, "blocking" => false} = json_response(conn, 200) end + test "getting a list of blocks", %{conn: conn} do + user = insert(:user) + other_user = insert(:user) + + {:ok, user} = User.block(user, other_user) + + conn = conn + |> assign(:user, user) + |> get("/api/v1/blocks") + + other_user_id = other_user.id + assert [%{"id" => ^other_user_id}] = json_response(conn, 200) + end + test "unimplemented mute endpoints" do user = insert(:user) other_user = insert(:user) -- cgit v1.2.3 From 046bee34d3b19c046dba59c1d6cb08548f978859 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sun, 5 Nov 2017 12:05:25 +0100 Subject: Fix bug when no posts are in the db. --- test/web/activity_pub/activity_pub_test.exs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/web') diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index a088e97be..48597f5fb 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -82,6 +82,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do describe "public fetch activities" do test "retrieves public activities" do + activities = ActivityPub.fetch_public_activities + %{public: public} = ActivityBuilder.public_and_non_public activities = ActivityPub.fetch_public_activities -- cgit v1.2.3 From f85566324ec7cf20f070850d0cd5bd3fec25445d Mon Sep 17 00:00:00 2001 From: eal Date: Tue, 7 Nov 2017 00:33:44 +0200 Subject: Allow profile fetching for authenticated users only. --- test/web/twitter_api/twitter_api_controller_test.exs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'test/web') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index a62947018..798309f7d 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -405,11 +405,13 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do describe "GET /api/externalprofile/show" do test "it returns the user", %{conn: conn} do user = insert(:user) + other_user = insert(:user) conn = conn - |> get("/api/externalprofile/show", %{profileurl: user.ap_id}) + |> assign(:user, user) + |> get("/api/externalprofile/show", %{profileurl: other_user.ap_id}) - assert json_response(conn, 200) == UserView.render("show.json", %{user: user}) + assert json_response(conn, 200) == UserView.render("show.json", %{user: other_user}) end end -- cgit v1.2.3 From 6c0758e041e63d9a8792d2fe7760813f074bc06e Mon Sep 17 00:00:00 2001 From: eal Date: Wed, 8 Nov 2017 00:04:53 +0200 Subject: TwitterAPI: Add blocks. --- .../twitter_api/twitter_api_controller_test.exs | 43 ++++++++++++++++++++++ test/web/twitter_api/twitter_api_test.exs | 34 +++++++++++++++++ 2 files changed, 77 insertions(+) (limited to 'test/web') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 798309f7d..6bdf29a13 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -277,6 +277,49 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do end end + describe "POST /blocks/create.json" do + setup [:valid_user] + test "without valid credentials", %{conn: conn} do + conn = post conn, "/api/blocks/create.json" + assert json_response(conn, 403) == %{"error" => "Invalid credentials."} + end + + test "with credentials", %{conn: conn, user: current_user} do + blocked = insert(:user) + + conn = conn + |> with_credentials(current_user.nickname, "test") + |> post("/api/blocks/create.json", %{user_id: blocked.id}) + + current_user = Repo.get(User, current_user.id) + assert User.blocks?(current_user, blocked) + assert json_response(conn, 200) == UserView.render("show.json", %{user: blocked, for: current_user}) + end + end + + describe "POST /blocks/destroy.json" do + setup [:valid_user] + test "without valid credentials", %{conn: conn} do + conn = post conn, "/api/blocks/destroy.json" + assert json_response(conn, 403) == %{"error" => "Invalid credentials."} + end + + test "with credentials", %{conn: conn, user: current_user} do + blocked = insert(:user) + + {:ok, current_user} = User.block(current_user, blocked) + assert User.blocks?(current_user, blocked) + + conn = conn + |> with_credentials(current_user.nickname, "test") + |> post("/api/blocks/destroy.json", %{user_id: blocked.id}) + + current_user = Repo.get(User, current_user.id) + assert current_user.info["blocks"] == [] + assert json_response(conn, 200) == UserView.render("show.json", %{user: blocked, for: current_user}) + end + end + describe "GET /help/test.json" do test "returns \"ok\"", %{conn: conn} do conn = get conn, "/api/help/test.json" diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index 1ec9ef388..994cc8f90 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -224,6 +224,40 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do assert msg == "Not subscribed!" end + test "Block another user using user_id" do + user = insert(:user) + blocked = insert(:user) + + {:ok, user, blocked} = TwitterAPI.block(user, %{"user_id" => blocked.id}) + assert User.blocks?(user, blocked) + end + + test "Block another user using screen_name" do + user = insert(:user) + blocked = insert(:user) + + {:ok, user, blocked} = TwitterAPI.block(user, %{"screen_name" => blocked.nickname}) + assert User.blocks?(user, blocked) + end + + test "Unblock another user using user_id" do + unblocked = insert(:user) + user = insert(:user) + User.block(user, unblocked) + + {:ok, user, unblocked} = TwitterAPI.unblock(user, %{"user_id" => unblocked.id}) + assert user.info["blocks"] == [] + end + + test "Unblock another user using screen_name" do + unblocked = insert(:user) + user = insert(:user) + User.block(user, unblocked) + + {:ok, user, unblocked} = TwitterAPI.unblock(user, %{"screen_name" => unblocked.nickname}) + assert user.info["blocks"] == [] + end + test "fetch statuses in a context using the conversation id" do {:ok, user} = UserBuilder.insert() {:ok, activity} = ActivityBuilder.insert(%{"type" => "Create", "context" => "2hu"}) -- cgit v1.2.3 From 4656cb9b996169714e6a25c6025e96df81a34b62 Mon Sep 17 00:00:00 2001 From: eal Date: Wed, 8 Nov 2017 13:02:00 +0200 Subject: TwitterAPI user view: add blocks. --- test/web/twitter_api/views/user_view_test.exs | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'test/web') diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs index 886af6b66..a942729c6 100644 --- a/test/web/twitter_api/views/user_view_test.exs +++ b/test/web/twitter_api/views/user_view_test.exs @@ -50,6 +50,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "profile_image_url_profile_size" => image, "profile_image_url_original" => image, "following" => false, + "statusnet_blocking" => false, "rights" => %{}, "statusnet_profile_url" => user.ap_id, "cover_photo" => nil, @@ -78,6 +79,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "profile_image_url_profile_size" => image, "profile_image_url_original" => image, "following" => true, + "statusnet_blocking" => false, "rights" => %{}, "statusnet_profile_url" => user.ap_id, "cover_photo" => nil, @@ -86,4 +88,35 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do assert represented == UserView.render("show.json", %{user: user, for: follower}) end + + test "A blocked user for the blocker", %{user: user} do + user = insert(:user) + blocker = insert(:user) + User.block(blocker, user) + image = "https://placehold.it/48x48" + represented = %{ + "id" => user.id, + "name" => user.name, + "screen_name" => user.nickname, + "description" => HtmlSanitizeEx.strip_tags(user.bio), + "created_at" => user.inserted_at |> Utils.format_naive_asctime, + "favourites_count" => 0, + "statuses_count" => 0, + "friends_count" => 0, + "followers_count" => 0, + "profile_image_url" => image, + "profile_image_url_https" => image, + "profile_image_url_profile_size" => image, + "profile_image_url_original" => image, + "following" => false, + "statusnet_blocking" => true, + "rights" => %{}, + "statusnet_profile_url" => user.ap_id, + "cover_photo" => nil, + "background_image" => nil + } + + blocker = Repo.get(User, blocker.id) + assert represented == UserView.render("show.json", %{user: user, for: blocker}) + end end -- cgit v1.2.3 From f7fc048aeb42ffbfce9f278b362c3d4766a4e9a2 Mon Sep 17 00:00:00 2001 From: eal Date: Wed, 8 Nov 2017 19:13:03 +0200 Subject: TwitterAPI user view: add follows_you. --- test/web/twitter_api/views/user_view_test.exs | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'test/web') diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs index a942729c6..9f8e15574 100644 --- a/test/web/twitter_api/views/user_view_test.exs +++ b/test/web/twitter_api/views/user_view_test.exs @@ -50,6 +50,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "profile_image_url_profile_size" => image, "profile_image_url_original" => image, "following" => false, + "follows_you" => false, "statusnet_blocking" => false, "rights" => %{}, "statusnet_profile_url" => user.ap_id, @@ -79,6 +80,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "profile_image_url_profile_size" => image, "profile_image_url_original" => image, "following" => true, + "follows_you" => false, "statusnet_blocking" => false, "rights" => %{}, "statusnet_profile_url" => user.ap_id, @@ -89,6 +91,36 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do assert represented == UserView.render("show.json", %{user: user, for: follower}) end + test "A user that follows you", %{user: user} do + {:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]}) + {:ok, user} = User.update_follower_count(user) + image = "https://placehold.it/48x48" + represented = %{ + "id" => follower.id, + "name" => follower.name, + "screen_name" => follower.nickname, + "description" => HtmlSanitizeEx.strip_tags(follower.bio), + "created_at" => follower.inserted_at |> Utils.format_naive_asctime, + "favourites_count" => 0, + "statuses_count" => 0, + "friends_count" => 1, + "followers_count" => 0, + "profile_image_url" => image, + "profile_image_url_https" => image, + "profile_image_url_profile_size" => image, + "profile_image_url_original" => image, + "following" => false, + "follows_you" => true, + "statusnet_blocking" => false, + "rights" => %{}, + "statusnet_profile_url" => follower.ap_id, + "cover_photo" => nil, + "background_image" => nil + } + + assert represented == UserView.render("show.json", %{user: follower, for: user}) + end + test "A blocked user for the blocker", %{user: user} do user = insert(:user) blocker = insert(:user) @@ -109,6 +141,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "profile_image_url_profile_size" => image, "profile_image_url_original" => image, "following" => false, + "follows_you" => false, "statusnet_blocking" => true, "rights" => %{}, "statusnet_profile_url" => user.ap_id, -- cgit v1.2.3 From 41b8a76e969e97aef68e7be1f1cdadcb31ea9b1d Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Thu, 9 Nov 2017 08:32:54 +0100 Subject: Re-fetch user data on salmon decode error. --- test/web/ostatus/ostatus_controller_test.exs | 41 +++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'test/web') diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs index 77bc202fe..20d17d41f 100644 --- a/test/web/ostatus/ostatus_controller_test.exs +++ b/test/web/ostatus/ostatus_controller_test.exs @@ -1,9 +1,41 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do use Pleroma.Web.ConnCase import Pleroma.Factory - alias Pleroma.User + alias Pleroma.{User, Repo} alias Pleroma.Web.OStatus.ActivityRepresenter + test "decodes a salmon", %{conn: conn} do + user = insert(:user) + salmon = File.read!("test/fixtures/salmon.xml") + conn = conn + |> put_req_header("content-type", "application/atom+xml") + |> post("/users/#{user.nickname}/salmon", salmon) + + assert response(conn, 200) + end + + test "decodes a salmon with a changed magic key", %{conn: conn} do + user = insert(:user) + salmon = File.read!("test/fixtures/salmon.xml") + conn = conn + |> put_req_header("content-type", "application/atom+xml") + |> post("/users/#{user.nickname}/salmon", salmon) + + assert response(conn, 200) + + # Set a wrong magic-key for a user so it has to refetch + salmon_user = User.get_by_ap_id("http://gs.example.org:4040/index.php/user/1") + info = salmon_user.info + |> Map.put("magic_key", "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwrong1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB") # Wrong key + Repo.update(User.info_changeset(salmon_user, %{info: info})) + + conn = build_conn() + |> put_req_header("content-type", "application/atom+xml") + |> post("/users/#{user.nickname}/salmon", salmon) + + assert response(conn, 200) + end + test "gets a feed", %{conn: conn} do note_activity = insert(:note_activity) user = User.get_cached_by_ap_id(note_activity.data["actor"]) @@ -42,3 +74,10 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do assert response(conn, 200) end end + +defmodule Pleroma.Web.OStatusMock do + import Pleroma.Factory + def handle_incoming(_doc) do + insert(:note_activity) + end +end -- cgit v1.2.3 From f1d27a5fbbe547a78f835bd65b43a652004d708e Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Thu, 9 Nov 2017 10:41:19 +0100 Subject: Add actor column to activities. --- test/web/activity_pub/activity_pub_test.exs | 1 + 1 file changed, 1 insertion(+) (limited to 'test/web') diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 2cd33d623..f50509b63 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -52,6 +52,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do test "removes doubled 'to' recipients" do {:ok, activity} = ActivityPub.create(["user1", "user1", "user2"], %User{ap_id: "1"}, "", %{}) assert activity.data["to"] == ["user1", "user2"] + assert activity.actor == "1" end end -- cgit v1.2.3 From 266d9c008d2a85395bb7ab773d5d548c89e7ed97 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Thu, 9 Nov 2017 16:48:45 +0100 Subject: MastoAPI: Fetch statuses in search. --- test/web/mastodon_api/mastodon_api_controller_test.exs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test/web') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index d118026eb..8bbdecaa8 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -386,6 +386,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do assert status["id"] == to_string(activity.id) end + test "search fetches remote statuses", %{conn: conn} do + conn = conn + |> get("/api/v1/search", %{"q" => "https://shitposter.club/notice/2827873"}) + assert results = json_response(conn, 200) + + [status] = results["statuses"] + assert status["uri"] == "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment" + end + test "search fetches remote accounts", %{conn: conn} do conn = conn |> get("/api/v1/search", %{"q" => "shp@social.heldscal.la", "resolve" => "true"}) -- cgit v1.2.3 From e6a78c6ed0925c27ea4d194c0e52ab07542c444e Mon Sep 17 00:00:00 2001 From: eal Date: Fri, 10 Nov 2017 15:24:39 +0200 Subject: MastoAPI: Add notification get, clear and dismiss. --- .../mastodon_api/mastodon_api_controller_test.exs | 71 +++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) (limited to 'test/web') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index d118026eb..e876b0af4 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -2,7 +2,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do use Pleroma.Web.ConnCase alias Pleroma.Web.TwitterAPI.TwitterAPI - alias Pleroma.{Repo, User, Activity} + alias Pleroma.{Repo, User, Activity, Notification} alias Pleroma.Web.{OStatus, CommonAPI} import Pleroma.Factory @@ -122,6 +122,75 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do end end + describe "notifications" do + test "list of notifications", %{conn: conn} do + user = insert(:user) + other_user = insert(:user) + + {:ok, activity} = TwitterAPI.create_status(other_user, %{"status" => "hi @#{user.nickname}"}) + {:ok, [notification]} = Notification.create_notifications(activity) + + conn = conn + |> assign(:user, user) + |> get("/api/v1/notifications") + + expected_response = "hi @#{user.nickname}" + assert [%{"status" => %{"content" => response}} | _rest] = json_response(conn, 200) + assert response == expected_response + end + + test "getting a single notification", %{conn: conn} do + user = insert(:user) + other_user = insert(:user) + + {:ok, activity} = TwitterAPI.create_status(other_user, %{"status" => "hi @#{user.nickname}"}) + {:ok, [notification]} = Notification.create_notifications(activity) + + conn = conn + |> assign(:user, user) + |> get("/api/v1/notifications/#{notification.id}") + + expected_response = "hi @#{user.nickname}" + assert %{"status" => %{"content" => response}} = json_response(conn, 200) + assert response == expected_response + end + + test "dismissing a single notification", %{conn: conn} do + user = insert(:user) + other_user = insert(:user) + + {:ok, activity} = TwitterAPI.create_status(other_user, %{"status" => "hi @#{user.nickname}"}) + {:ok, [notification]} = Notification.create_notifications(activity) + + conn = conn + |> assign(:user, user) + |> post("/api/v1/notifications/dismiss", %{"id" => notification.id}) + + assert %{} = json_response(conn, 200) + end + + test "clearing all notifications", %{conn: conn} do + user = insert(:user) + other_user = insert(:user) + + {:ok, activity} = TwitterAPI.create_status(other_user, %{"status" => "hi @#{user.nickname}"}) + {:ok, [notification]} = Notification.create_notifications(activity) + + conn = conn + |> assign(:user, user) + |> post("/api/v1/notifications/clear") + + assert %{} = json_response(conn, 200) + + conn = build_conn() + |> assign(:user, user) + |> get("/api/v1/notifications") + + assert all = json_response(conn, 200) + assert all == [] + end + end + describe "reblogging" do test "reblogs and returns the reblogged status", %{conn: conn} do activity = insert(:note_activity) -- cgit v1.2.3 From 6e9c22c0afaa67f0b94f602eceef5c57b7c9192f Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Fri, 10 Nov 2017 17:18:19 +0100 Subject: MastoAPI: Use string ids everywhere. --- test/web/mastodon_api/account_view_test.exs | 6 +++--- .../mastodon_api/mastodon_api_controller_test.exs | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'test/web') diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs index c62cb4f36..eccfe0b36 100644 --- a/test/web/mastodon_api/account_view_test.exs +++ b/test/web/mastodon_api/account_view_test.exs @@ -8,7 +8,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do user = insert(:user, %{info: %{"note_count" => 5, "follower_count" => 3}, nickname: "shp@shitposter.club", inserted_at: ~N[2017-08-15 15:47:06.597036]}) expected = %{ - id: user.id, + id: to_string(user.id), username: "shp", acct: user.nickname, display_name: user.name, @@ -37,7 +37,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do user = insert(:user) expected = %{ - id: user.id, + id: to_string(user.id), acct: user.nickname, username: user.nickname, url: user.ap_id @@ -54,7 +54,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do {:ok, user} = User.block(user, other_user) expected = %{ - id: other_user.id, + id: to_string(other_user.id), following: true, followed_by: false, blocking: true, diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index d118026eb..72ce77c81 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -81,7 +81,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> get("/api/v1/accounts/verify_credentials") assert %{"id" => id} = json_response(conn, 200) - assert id == user.id + assert id == to_string(user.id) end test "get a status", %{conn: conn} do @@ -194,7 +194,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do assert [relationship] = json_response(conn, 200) - assert other_user.id == relationship["id"] + assert to_string(other_user.id) == relationship["id"] end end @@ -205,7 +205,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> get("/api/v1/accounts/#{user.id}") assert %{"id" => id} = json_response(conn, 200) - assert id == user.id + assert id == to_string(user.id) conn = build_conn() |> get("/api/v1/accounts/-1") @@ -250,7 +250,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> get("/api/v1/accounts/#{other_user.id}/followers") assert [%{"id" => id}] = json_response(conn, 200) - assert id = user.id + assert id == to_string(user.id) end test "getting following", %{conn: conn} do @@ -262,7 +262,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> get("/api/v1/accounts/#{user.id}/following") assert [%{"id" => id}] = json_response(conn, 200) - assert id = other_user.id + assert id == to_string(other_user.id) end test "following / unfollowing a user", %{conn: conn} do @@ -288,7 +288,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> post("/api/v1/follows", %{"uri" => other_user.nickname}) assert %{"id" => id} = json_response(conn, 200) - assert id == other_user.id + assert id == to_string(other_user.id) end test "blocking / unblocking a user", %{conn: conn} do @@ -319,7 +319,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> assign(:user, user) |> get("/api/v1/blocks") - other_user_id = other_user.id + other_user_id = to_string(other_user.id) assert [%{"id" => ^other_user_id}] = json_response(conn, 200) end @@ -334,7 +334,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> post("/api/v1/accounts/#{other_user.id}/#{endpoint}") assert %{"id" => id} = json_response(conn, 200) - assert id == other_user.id + assert id == to_string(other_user.id) end) end @@ -361,7 +361,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> get("/api/v1/accounts/search", %{"q" => "2hu"}) assert [account] = json_response(conn, 200) - assert account["id"] == user_three.id + assert account["id"] == to_string(user_three.id) end test "search", %{conn: conn} do @@ -378,7 +378,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do assert results = json_response(conn, 200) [account] = results["accounts"] - assert account["id"] == user_three.id + assert account["id"] == to_string(user_three.id) assert results["hashtags"] == [] -- cgit v1.2.3 From a1923d20e850c6b4f187928dd739314df84047b6 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sat, 11 Nov 2017 11:18:05 +0100 Subject: MastoAPI: Fix reblog emojis. --- test/web/mastodon_api/status_view_test.exs | 1 + 1 file changed, 1 insertion(+) (limited to 'test/web') diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs index 69d86ea82..601e551a9 100644 --- a/test/web/mastodon_api/status_view_test.exs +++ b/test/web/mastodon_api/status_view_test.exs @@ -103,5 +103,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do assert represented[:id] == to_string(reblog.id) assert represented[:reblog][:id] == to_string(activity.id) + assert represented[:emojis] == [] end end -- cgit v1.2.3 From fc7483cb3c679040d40ea86f90384b097dcda2ca Mon Sep 17 00:00:00 2001 From: eal Date: Sun, 12 Nov 2017 00:27:09 +0200 Subject: MastoAPI: Add update credentials endpoint. --- .../mastodon_api/mastodon_api_controller_test.exs | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'test/web') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 47a613837..cf60b4a51 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -420,4 +420,54 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do assert [status] = json_response(conn, 200) assert status["id"] == to_string(activity.id) end + + describe "updating credentials" do + test "updates the user's bio" do + user = insert(:user) + + conn = conn + |> assign(:user, user) + |> patch("/api/v1/accounts/update_credentials", %{"note" => "I drink #cofe"}) + + assert user = json_response(conn, 200) + assert user["note"] == "I drink #cofe" + end + + test "updates the user's name" do + user = insert(:user) + + conn = conn + |> assign(:user, user) + |> patch("/api/v1/accounts/update_credentials", %{"display_name" => "markorepairs"}) + + assert user = json_response(conn, 200) + assert user["display_name"] == "markorepairs" + end + + test "updates the user's avatar" do + user = insert(:user) + + new_avatar = %Plug.Upload{content_type: "image/jpg", path: Path.absname("test/fixtures/image.jpg"), filename: "an_image.jpg"} + + conn = conn + |> assign(:user, user) + |> patch("/api/v1/accounts/update_credentials", %{"avatar" => new_avatar}) + + assert user = json_response(conn, 200) + assert user["avatar"] != "https://placehold.it/48x48" + end + + test "updates the user's banner" do + user = insert(:user) + + new_header = %Plug.Upload{content_type: "image/jpg", path: Path.absname("test/fixtures/image.jpg"), filename: "an_image.jpg"} + + conn = conn + |> assign(:user, user) + |> patch("/api/v1/accounts/update_credentials", %{"header" => new_header}) + + assert user = json_response(conn, 200) + assert user["header"] != "https://placehold.it/700x335" + end + end end -- cgit v1.2.3 From 083cd169d21b0f20332eac80b4481adb41810a64 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Mon, 13 Nov 2017 09:48:56 +0100 Subject: MastoAPI: Fix repeat api bug. Documentation was wrong, reblogging actually returns the reblog, not the reblogged status. --- test/web/mastodon_api/mastodon_api_controller_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/web') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index f506d56a1..25d92d010 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -200,7 +200,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> assign(:user, user) |> post("/api/v1/statuses/#{activity.id}/reblog") - assert %{"id" => id, "reblogged" => true, "reblogs_count" => 1} = json_response(conn, 200) + assert %{"reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 1}} = json_response(conn, 200) assert to_string(activity.id) == id end end -- cgit v1.2.3 From c84723b67956f731801c98a1335128d8cdbf9291 Mon Sep 17 00:00:00 2001 From: eal Date: Tue, 14 Nov 2017 15:41:16 +0200 Subject: MastoAPI: Add media timelines. --- test/web/mastodon_api/mastodon_api_controller_test.exs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/web') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 25d92d010..1b8709941 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -249,6 +249,23 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do assert id == to_string(note_two.id) end + + test "gets an users media", %{conn: conn} do + note = insert(:note_activity) + user = User.get_by_ap_id(note.data["actor"]) + + file = %Plug.Upload{content_type: "image/jpg", path: Path.absname("test/fixtures/image.jpg"), filename: "an_image.jpg"} + media = TwitterAPI.upload(file, "json") + |> Poison.decode! + + {:ok, image_post} = TwitterAPI.create_status(user, %{"status" => "cofe", "media_ids" => [media["media_id"]]}) + + conn = conn + |> get("/api/v1/accounts/#{user.id}/statuses", %{"only_media" => true}) + + assert [%{"id" => id}] = json_response(conn, 200) + assert id == to_string(image_post.id) + end end describe "user relationships" do -- cgit v1.2.3 From 06c3ee3bac9abe5a369364743143618c473eb7a9 Mon Sep 17 00:00:00 2001 From: eal Date: Tue, 14 Nov 2017 15:50:23 +0200 Subject: Accept 1 as true. --- test/web/mastodon_api/mastodon_api_controller_test.exs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'test/web') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 1b8709941..a00a11f8b 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -261,7 +261,13 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do {:ok, image_post} = TwitterAPI.create_status(user, %{"status" => "cofe", "media_ids" => [media["media_id"]]}) conn = conn - |> get("/api/v1/accounts/#{user.id}/statuses", %{"only_media" => true}) + |> get("/api/v1/accounts/#{user.id}/statuses", %{"only_media" => "true"}) + + assert [%{"id" => id}] = json_response(conn, 200) + assert id == to_string(image_post.id) + + conn = build_conn() + |> get("/api/v1/accounts/#{user.id}/statuses", %{"only_media" => "1"}) assert [%{"id" => id}] = json_response(conn, 200) assert id == to_string(image_post.id) -- cgit v1.2.3 From 3533bf7eacaceb493bd4bef4ae5625f7c99021b9 Mon Sep 17 00:00:00 2001 From: eal Date: Tue, 14 Nov 2017 16:04:58 +0200 Subject: TwitterAPI: Add /friends/ids. --- test/web/twitter_api/twitter_api_controller_test.exs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/web') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 6bdf29a13..d0c9a1b6d 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -494,6 +494,25 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do end end + describe "GET /friends/ids" do + test "it returns a user's friends", %{conn: conn} do + user = insert(:user) + followed_one = insert(:user) + followed_two = insert(:user) + not_followed = insert(:user) + + {:ok, user} = User.follow(user, followed_one) + {:ok, user} = User.follow(user, followed_two) + + conn = conn + |> assign(:user, user) + |> get("/api/friends/ids") + + expected = Poison.encode!([followed_one.id, followed_two.id]) + assert json_response(conn, 200) == expected + end + end + describe "POST /api/account/update_profile.json" do test "it updates a user's profile" do user = insert(:user) -- cgit v1.2.3 From f9828e578cf4c193fb35cbcc55133cd8e615755d Mon Sep 17 00:00:00 2001 From: eal Date: Tue, 14 Nov 2017 17:34:48 +0200 Subject: TwitterAPI: Add /users/show. --- .../twitter_api/twitter_api_controller_test.exs | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'test/web') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 6bdf29a13..b886536d6 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -6,6 +6,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.TwitterAPI.UserView alias Pleroma.Web.CommonAPI + alias Pleroma.Web.TwitterAPI.TwitterAPI import Pleroma.Factory @@ -101,6 +102,45 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do end end + describe "GET /users/show.json" do + test "gets user with screen_name", %{conn: conn} do + user = insert(:user) + + conn = conn + |> get("/api/users/show.json", %{"screen_name" => user.nickname}) + + response = json_response(conn, 200) + + assert response["id"] == user.id + end + + test "gets user with user_id", %{conn: conn} do + user = insert(:user) + + conn = conn + |> get("/api/users/show.json", %{"user_id" => user.id}) + + response = json_response(conn, 200) + + assert response["id"] == user.id + end + + test "gets a user for a logged in user", %{conn: conn} do + user = insert(:user) + logged_in = insert(:user) + + {:ok, logged_in, user, _activity} = TwitterAPI.follow(logged_in, %{"user_id" => user.id}) + + conn = conn + |> with_credentials(logged_in.nickname, "test") + |> get("/api/users/show.json", %{"user_id" => user.id}) + + response = json_response(conn, 200) + + assert response["following"] == true + end + end + describe "GET /statusnet/conversation/:id.json" do test "returns the statuses in the conversation", %{conn: conn} do {:ok, _user} = UserBuilder.insert -- cgit v1.2.3 From ced0d64d75831c68851d4deef9875343d9114eaa Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Wed, 15 Nov 2017 18:58:13 +0100 Subject: MastoAPI: Make attachment ids strings. --- test/web/mastodon_api/status_view_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/web') diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs index 601e551a9..93c0b7236 100644 --- a/test/web/mastodon_api/status_view_test.exs +++ b/test/web/mastodon_api/status_view_test.exs @@ -78,7 +78,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do } expected = %{ - id: 1638338801, + id: "1638338801", type: "image", url: "someurl", remote_url: "someurl", @@ -90,7 +90,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do # If theres a "id", use that instead of the generated one object = Map.put(object, "id", 2) - assert %{id: 2} = StatusView.render("attachment.json", %{attachment: object}) + assert %{id: "2"} = StatusView.render("attachment.json", %{attachment: object}) end test "a reblog" do -- cgit v1.2.3 From 66e78c3ec4e524a31a4c12f4dbe682ccbbc0025d Mon Sep 17 00:00:00 2001 From: eal Date: Sat, 18 Nov 2017 14:43:41 +0200 Subject: Escape HTML instead of discarding it. --- test/web/twitter_api/twitter_api_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/web') diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index 994cc8f90..8698686ad 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -34,7 +34,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do { :ok, activity = %Activity{} } = TwitterAPI.create_status(user, input) - assert get_in(activity.data, ["object", "content"]) == "Hello again, @shp.
\nThis is on another line. #2hu #epic #phantasmagoric
\nimage.jpg" + assert get_in(activity.data, ["object", "content"]) == "Hello again, @shp.<script></script>
\nThis is on another line. #2hu #epic #phantasmagoric
\nimage.jpg" assert get_in(activity.data, ["object", "type"]) == "Note" assert get_in(activity.data, ["object", "actor"]) == user.ap_id assert get_in(activity.data, ["actor"]) == user.ap_id -- cgit v1.2.3 From fb118b2978686a44a15534b638ab7887fb38c03d Mon Sep 17 00:00:00 2001 From: eal Date: Sat, 18 Nov 2017 14:46:54 +0200 Subject: Don't insert newlines to generated HTML. MastoFE doesn't like them. --- test/web/common_api/common_api_utils_test.exs | 2 +- test/web/twitter_api/twitter_api_test.exs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'test/web') diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs index a159c0835..f6a7da9ed 100644 --- a/test/web/common_api/common_api_utils_test.exs +++ b/test/web/common_api/common_api_utils_test.exs @@ -11,6 +11,6 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do res = Utils.add_attachments("", [attachment]) - assert res == "
\nSakura Mana – Turned on by a Se…" + assert res == "
Sakura Mana – Turned on by a Se…" end end diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index 8698686ad..06ecd9e75 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -34,7 +34,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do { :ok, activity = %Activity{} } = TwitterAPI.create_status(user, input) - assert get_in(activity.data, ["object", "content"]) == "Hello again, @shp.<script></script>
\nThis is on another line. #2hu #epic #phantasmagoric
\nimage.jpg" + assert get_in(activity.data, ["object", "content"]) == "Hello again, @shp.<script></script>
This is on another line. #2hu #epic #phantasmagoric
image.jpg" assert get_in(activity.data, ["object", "type"]) == "Note" assert get_in(activity.data, ["object", "actor"]) == user.ap_id assert get_in(activity.data, ["actor"]) == user.ap_id -- cgit v1.2.3 From f53cdabcdf5e64c862e0532e6d5ad26666e9c83f Mon Sep 17 00:00:00 2001 From: eal Date: Sat, 18 Nov 2017 16:30:18 +0200 Subject: Add #nsfw tag if sensitive content bit is set --- test/web/mastodon_api/mastodon_api_controller_test.exs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'test/web') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index a00a11f8b..c8b929501 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -56,6 +56,17 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do assert Repo.get(Activity, id) end + test "posting a sensitive status", %{conn: conn} do + user = insert(:user) + + conn = conn + |> assign(:user, user) + |> post("/api/v1/statuses", %{"status" => "cofe", "sensitive" => true}) + + assert %{"content" => "cofe", "id" => id, "sensitive" => true} = json_response(conn, 200) + assert Repo.get(Activity, id) + end + test "replying to a status", %{conn: conn} do user = insert(:user) -- cgit v1.2.3 From 40ca3793578fc505200a1c975cafce15a3b265c7 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sun, 19 Nov 2017 13:07:29 +0100 Subject: Fix flakey test. --- test/web/twitter_api/twitter_api_controller_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/web') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 6f56b8424..4ab18721d 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -530,7 +530,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do |> assign(:user, user) |> get("/api/statuses/friends") - assert json_response(conn, 200) == UserView.render("index.json", %{users: [followed_one, followed_two], for: user}) + assert MapSet.equal?(MapSet.new(json_response(conn, 200)), MapSet.new(UserView.render("index.json", %{users: [followed_one, followed_two], for: user}))) end end -- cgit v1.2.3 From edc3e5bc3014b1ca395038736dd8fd6b6aeed560 Mon Sep 17 00:00:00 2001 From: eal Date: Mon, 20 Nov 2017 07:52:02 +0200 Subject: Make users in tests follow themselves by default. Also fix the semantics of all tests to match. --- test/web/twitter_api/twitter_api_controller_test.exs | 6 +++--- test/web/twitter_api/twitter_api_test.exs | 4 ++-- test/web/twitter_api/views/user_view_test.exs | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'test/web') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 4ab18721d..4b8fa85a5 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -288,7 +288,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do |> post("/api/friendships/create.json", %{user_id: followed.id}) current_user = Repo.get(User, current_user.id) - assert current_user.following == [User.ap_followers(followed)] + assert User.ap_followers(followed) in current_user.following assert json_response(conn, 200) == UserView.render("show.json", %{user: followed, for: current_user}) end end @@ -304,7 +304,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do followed = insert(:user) {:ok, current_user} = User.follow(current_user, followed) - assert current_user.following == [User.ap_followers(followed)] + assert User.ap_followers(followed) in current_user.following ActivityPub.follow(current_user, followed) conn = conn @@ -312,7 +312,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do |> post("/api/friendships/destroy.json", %{user_id: followed.id}) current_user = Repo.get(User, current_user.id) - assert current_user.following == [] + assert current_user.following == [current_user.ap_id] assert json_response(conn, 200) == UserView.render("show.json", %{user: followed, for: current_user}) end end diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index 06ecd9e75..60daeec70 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -179,7 +179,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do followed = insert(:user) {:ok, user, followed, _activity } = TwitterAPI.follow(user, %{"user_id" => followed.id}) - assert user.following == [User.ap_followers(followed)] + assert User.ap_followers(followed) in user.following { :error, msg } = TwitterAPI.follow(user, %{"user_id" => followed.id}) assert msg == "Could not follow user: #{followed.nickname} is already on your list." @@ -190,7 +190,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do followed = insert(:user) {:ok, user, followed, _activity } = TwitterAPI.follow(user, %{"screen_name" => followed.nickname}) - assert user.following == [User.ap_followers(followed)] + assert User.ap_followers(followed) in user.following followed = User.get_by_ap_id(followed.ap_id) assert followed.info["follower_count"] == 1 diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs index 9f8e15574..18a19ef70 100644 --- a/test/web/twitter_api/views/user_view_test.exs +++ b/test/web/twitter_api/views/user_view_test.exs @@ -92,7 +92,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do end test "A user that follows you", %{user: user} do - {:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]}) + follower = insert(:user) + {:ok, follower} = User.follow(follower, user) {:ok, user} = User.update_follower_count(user) image = "https://placehold.it/48x48" represented = %{ -- cgit v1.2.3 From 747a68a075d90f14ce764208c0a409c3a8ec3393 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Mon, 20 Nov 2017 17:53:21 +0100 Subject: Treat internal emoji like external. --- test/web/ostatus/activity_representer_test.exs | 4 ++-- test/web/twitter_api/twitter_api_test.exs | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'test/web') diff --git a/test/web/ostatus/activity_representer_test.exs b/test/web/ostatus/activity_representer_test.exs index 0d83ad964..ed7fdc432 100644 --- a/test/web/ostatus/activity_representer_test.exs +++ b/test/web/ostatus/activity_representer_test.exs @@ -41,7 +41,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do - + """ tuple = ActivityRepresenter.to_simple_form(note_activity, user) @@ -81,7 +81,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do - + """ tuple = ActivityRepresenter.to_simple_form(answer, user) diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index 60daeec70..96552f97e 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -28,13 +28,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do object = Repo.insert!(%Object{data: object_data}) input = %{ - "status" => "Hello again, @shp.\nThis is on another line. #2hu #epic #phantasmagoric", + "status" => "Hello again, @shp.\nThis is on another :moominmamma: line. #2hu #epic #phantasmagoric", "media_ids" => [object.id] } { :ok, activity = %Activity{} } = TwitterAPI.create_status(user, input) - assert get_in(activity.data, ["object", "content"]) == "Hello again, @shp.<script></script>
This is on another line. #2hu #epic #phantasmagoric
image.jpg" + assert get_in(activity.data, ["object", "content"]) == "Hello again, @shp.<script></script>
This is on another :moominmamma: line. #2hu #epic #phantasmagoric
image.jpg" assert get_in(activity.data, ["object", "type"]) == "Note" assert get_in(activity.data, ["object", "actor"]) == user.ap_id assert get_in(activity.data, ["actor"]) == user.ap_id @@ -43,6 +43,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do assert Enum.member?(get_in(activity.data, ["to"]), "shp") assert activity.local == true + assert %{"moominmamma" => "http://localhost:4001/finmoji/128px/moominmamma-128.png"} = activity.data["object"]["emoji"] + # hashtags assert activity.data["object"]["tag"] == ["2hu", "epic", "phantasmagoric"] -- cgit v1.2.3 From 3d29fc5462e4b6bd9f0ee1f343ce971ef8606381 Mon Sep 17 00:00:00 2001 From: eal Date: Mon, 20 Nov 2017 19:16:43 +0200 Subject: Make /api/friends/ids test deterministic. --- test/web/twitter_api/twitter_api_controller_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/web') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 4b8fa85a5..d12ade132 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -548,8 +548,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do |> assign(:user, user) |> get("/api/friends/ids") - expected = Poison.encode!([followed_one.id, followed_two.id]) - assert json_response(conn, 200) == expected + expected = [followed_one.id, followed_two.id] + assert MapSet.equal?(MapSet.new(Poison.decode!(json_response(conn, 200))), MapSet.new(expected)) end end -- cgit v1.2.3 From c680ae581d028144ebea414b4137433ac7ca8e6a Mon Sep 17 00:00:00 2001 From: Lain Iwakura Date: Mon, 27 Nov 2017 17:24:52 +0100 Subject: Return xml notice at /notice path. --- test/web/ostatus/ostatus_controller_test.exs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test/web') diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs index 20d17d41f..9c945e35b 100644 --- a/test/web/ostatus/ostatus_controller_test.exs +++ b/test/web/ostatus/ostatus_controller_test.exs @@ -73,6 +73,16 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do assert response(conn, 200) end + + test "gets a notice", %{conn: conn} do + note_activity = insert(:note_activity) + url = "/notice/#{note_activity.id}" + + conn = conn + |> get(url) + + assert response(conn, 200) + end end defmodule Pleroma.Web.OStatusMock do -- cgit v1.2.3 From 5637d163e6eb365c69f0e79e43306156241f6494 Mon Sep 17 00:00:00 2001 From: Lain Iwakura Date: Thu, 30 Nov 2017 14:59:44 +0100 Subject: MastodonAPI: Add proper user count. --- test/web/mastodon_api/mastodon_api_controller_test.exs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test/web') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index c8b929501..fc0010569 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -573,4 +573,19 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do assert user["header"] != "https://placehold.it/700x335" end end + + test "get instance information" do + insert(:user, %{local: true}) + user = insert(:user, %{local: true}) + insert(:user, %{local: false}) + + {:ok, _} = TwitterAPI.create_status(user, %{"status" => "cofe"}) + + conn = conn + |> get("/api/v1/instance") + + assert result = json_response(conn, 200) + + assert result["stats"]["user_count"] == 2 + end end -- cgit v1.2.3 From d08a34e88b0d42f403755e1bdbaf015784ebbe74 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sun, 3 Dec 2017 13:34:17 +0100 Subject: OStatus: Add user bio as summary field Fixes problem with bio federation. --- test/web/ostatus/user_representer_test.exs | 1 + 1 file changed, 1 insertion(+) (limited to 'test/web') diff --git a/test/web/ostatus/user_representer_test.exs b/test/web/ostatus/user_representer_test.exs index a4afc2cf7..d5d70f5c6 100644 --- a/test/web/ostatus/user_representer_test.exs +++ b/test/web/ostatus/user_representer_test.exs @@ -18,6 +18,7 @@ defmodule Pleroma.Web.OStatus.UserRepresenterTest do #{user.nickname} #{user.name} #{user.bio} + #{user.bio} #{user.nickname} """ -- cgit v1.2.3 From e7c2472abd470b3b0ba8e9321a378e5a77412e26 Mon Sep 17 00:00:00 2001 From: Lain Iwakura Date: Tue, 5 Dec 2017 12:18:04 +0100 Subject: Fix tests. --- test/web/twitter_api/twitter_api_controller_test.exs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/web') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index d12ade132..90d0fa654 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -22,7 +22,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do |> with_credentials(user.nickname, "test") |> post("/api/account/verify_credentials.json") - assert json_response(conn, 200) == UserView.render("show.json", %{user: user}) + assert response = json_response(conn, 200) + assert response == UserView.render("show.json", %{user: user, token: response["token"]}) end end -- cgit v1.2.3 From 66c3813ea6388e9933af2b15e903f1cf6254cd3a Mon Sep 17 00:00:00 2001 From: Lain Iwakura Date: Tue, 5 Dec 2017 18:21:30 +0100 Subject: Add basic queue prioritization. --- test/web/federator_test.exs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test/web/federator_test.exs (limited to 'test/web') diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs new file mode 100644 index 000000000..09533362a --- /dev/null +++ b/test/web/federator_test.exs @@ -0,0 +1,20 @@ +defmodule Pleroma.Web.FederatorTest do + alias Pleroma.Web.Federator + use Pleroma.DataCase + + test "enqueues an element according to priority" do + queue = [%{item: 1, priority: 2}] + + new_queue = Federator.enqueue_sorted(queue, 2, 1) + assert new_queue == [%{item: 2, priority: 1}, %{item: 1, priority: 2}] + + new_queue = Federator.enqueue_sorted(queue, 2, 3) + assert new_queue == [%{item: 1, priority: 2}, %{item: 2, priority: 3}] + end + + test "pop first item" do + queue = [%{item: 2, priority: 1}, %{item: 1, priority: 2}] + + assert {2, [%{item: 1, priority: 2}]} = Federator.queue_pop(queue) + end +end -- cgit v1.2.3