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') 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/support/factory.ex | 5 ++++- test/web/mastodon_api/status_view_test.exs | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/support/factory.ex b/test/support/factory.ex index f499024a2..33bacd40c 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -26,7 +26,10 @@ defmodule Pleroma.Factory do "likes" => [], "like_count" => 0, "context" => "2hu", - "tag" => ["2hu"] + "tag" => ["2hu"], + "emoji" => %{ + "2hu" => "corndog.png" + } } %Pleroma.Object{ 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') 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') 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') 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') 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') 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') 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') 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 4dcbb64f19723334a9ef66b4ce71856d30e32796 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Tue, 31 Oct 2017 16:37:11 +0100 Subject: Avoid potentially slow count queries for user note count. For a variety of reasons, posgresql won't use the available actor, type index to do an index only scan. We now just increase the user note count, which will lead to slightly wrong counts in some cases, but it's better than the potentially very slow count query. --- test/user_test.exs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index 097d7d98e..ae9a48e74 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -246,6 +246,21 @@ defmodule Pleroma.UserTest do assert user.info["note_count"] == 1 end + test "it increases the info->note_count property" do + note = insert(:note) + user = User.get_by_ap_id(note.data["actor"]) + + assert user.info["note_count"] == nil + + {:ok, user} = User.increase_note_count(user) + + assert user.info["note_count"] == 1 + + {:ok, user} = User.increase_note_count(user) + + assert user.info["note_count"] == 2 + end + test "it sets the info->follower_count property" do user = insert(:user) follower = insert(:user) -- 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') 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') 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/support/factory.ex | 1 + test/web/mastodon_api/status_view_test.exs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/support/factory.ex b/test/support/factory.ex index 33bacd40c..dabb95141 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -26,6 +26,7 @@ defmodule Pleroma.Factory do "likes" => [], "like_count" => 0, "context" => "2hu", + "summary" => "2hu", "tag" => ["2hu"], "emoji" => %{ "2hu" => "corndog.png" 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') 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') 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') 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 9be286a9004ae60f8ea48bb0c8871d70223f082b Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Wed, 1 Nov 2017 09:33:29 +0100 Subject: Handle empty terms / tags. --- test/fixtures/ostatus_incoming_post_tag.xml | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/fixtures/ostatus_incoming_post_tag.xml b/test/fixtures/ostatus_incoming_post_tag.xml index 5febb80d1..0f99c4126 100644 --- a/test/fixtures/ostatus_incoming_post_tag.xml +++ b/test/fixtures/ostatus_incoming_post_tag.xml @@ -43,6 +43,7 @@ New note by lambadalambda Will it blend? + http://activitystrea.ms/schema/1.0/post -- cgit v1.2.3 From 345ad870f710ef8e8da8bc49878317696362c5c0 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Thu, 2 Nov 2017 21:57:21 +0100 Subject: Clean up user_test.exs. --- test/user_test.exs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index ae9a48e74..36ac27656 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -9,11 +9,6 @@ defmodule Pleroma.UserTest do import Ecto.Query test "ap_id returns the activity pub id for the user" do - host = - Application.get_env(:pleroma, Pleroma.Web.Endpoint) - |> Keyword.fetch!(:url) - |> Keyword.fetch!(:host) - user = UserBuilder.build expected_ap_id = "#{Pleroma.Web.base_url}/users/#{user.nickname}" @@ -213,7 +208,9 @@ defmodule Pleroma.UserTest do {:ok, res} = User.get_followers(user) - assert res == [follower_one, follower_two] + assert Enum.member?(res, follower_one) + assert Enum.member?(res, follower_two) + refute Enum.member?(res, not_follower) end test "gets all friends (followed users) for a given user" do @@ -229,7 +226,9 @@ defmodule Pleroma.UserTest do followed_one = User.get_by_ap_id(followed_one.ap_id) followed_two = User.get_by_ap_id(followed_two.ap_id) - assert res == [followed_one, followed_two] + assert Enum.member?(res, followed_one) + assert Enum.member?(res, followed_two) + refute Enum.member?(res, not_followed) end end -- cgit v1.2.3 From 6a5f0871745316b50742ea9ebf3ff7c69881e105 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Thu, 2 Nov 2017 21:57:37 +0100 Subject: Add blocks to User. --- test/user_test.exs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index 36ac27656..151b9afc0 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -273,5 +273,28 @@ defmodule Pleroma.UserTest do assert user.info["follower_count"] == 1 end end + + describe "blocks" do + test "it blocks people" do + user = insert(:user) + blocked_user = insert(:user) + + refute User.blocks?(user, blocked_user) + + {:ok, user} = User.block(user, blocked_user) + + assert User.blocks?(user, blocked_user) + end + + test "it unblocks users" do + user = insert(:user) + blocked_user = insert(:user) + + {:ok, user} = User.block(user, blocked_user) + {:ok, user} = User.unblock(user, blocked_user) + + refute User.blocks?(user, blocked_user) + end + end end -- cgit v1.2.3 From 632da6c9273b55984bdd67b8a10672733df7fae5 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Thu, 2 Nov 2017 22:08:22 +0100 Subject: Don't create notifications if the user is blocked. --- test/notification_test.exs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'test') diff --git a/test/notification_test.exs b/test/notification_test.exs index f50b3cb24..77fdb532f 100644 --- a/test/notification_test.exs +++ b/test/notification_test.exs @@ -20,4 +20,15 @@ defmodule Pleroma.NotificationTest do assert other_notification.activity_id == activity.id end end + + describe "create_notification" do + test "it doesn't create a notification for user if the user blocks the activity author" do + activity = insert(:note_activity) + author = User.get_by_ap_id(activity.data["actor"]) + user = insert(:user) + {:ok, user} = User.block(user, author) + + assert nil == Notification.create_notification(activity, user) + end + end end -- 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') 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') 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') 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') 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') 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') 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') 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') 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 7da978f3f54a8981c082625a8ad2fea48c918675 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Tue, 7 Nov 2017 12:06:37 +0100 Subject: Linkify fixes. --- test/formatter_test.exs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/formatter_test.exs b/test/formatter_test.exs index d96f433f9..f91973881 100644 --- a/test/formatter_test.exs +++ b/test/formatter_test.exs @@ -7,10 +7,24 @@ defmodule Pleroma.FormatterTest do describe ".linkify" do test "turning urls into links" do text = "Hey, check out https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla." - expected = "Hey, check out https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla." assert Formatter.linkify(text) == expected + + text = "https://mastodon.social/@lambadalambda" + expected = "https://mastodon.social/@lambadalambda" + + assert Formatter.linkify(text) == expected + + text = "@lambadalambda" + expected = "@lambadalambda" + + assert Formatter.linkify(text) == expected + + text = "http://www.cs.vu.nl/~ast/intel/" + expected = "http://www.cs.vu.nl/~ast/intel/" + + assert Formatter.linkify(text) == expected 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') 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') 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') 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') 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/support/factory.ex | 3 ++- test/web/activity_pub/activity_pub_test.exs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/support/factory.ex b/test/support/factory.ex index dabb95141..9bbf11f08 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -51,7 +51,8 @@ defmodule Pleroma.Factory do } %Pleroma.Activity{ - data: data + data: data, + actor: data["actor"] } end 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 e942e1e5528f587d2d5411f235d17599965f0f85 Mon Sep 17 00:00:00 2001 From: eal Date: Thu, 9 Nov 2017 14:11:37 +0200 Subject: Correct mimetype on bad uploads. --- test/upload_test.exs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test') diff --git a/test/upload_test.exs b/test/upload_test.exs index 71041e83c..f90c4d713 100644 --- a/test/upload_test.exs +++ b/test/upload_test.exs @@ -9,5 +9,17 @@ defmodule Pleroma.UploadTest do assert data["name"] == "an [image.jpg" assert List.first(data["url"])["href"] == "http://localhost:4001/media/#{data["uuid"]}/an%20%5Bimage.jpg" end + + test "fixes an incorrect content type" do + file = %Plug.Upload{content_type: "application/octet-stream", path: Path.absname("test/fixtures/image.jpg"), filename: "an [image.jpg"} + data = Upload.store(file) + assert hd(data["url"])["mediaType"] == "image/jpeg" + end + + test "does not modify a valid content type" do + file = %Plug.Upload{content_type: "image/png", path: Path.absname("test/fixtures/image.jpg"), filename: "an [image.jpg"} + data = Upload.store(file) + assert hd(data["url"])["mediaType"] == "image/png" + end 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') 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. --- test/notification_test.exs | 61 +++++++++++++++++++ .../mastodon_api/mastodon_api_controller_test.exs | 71 +++++++++++++++++++++- 2 files changed, 131 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/notification_test.exs b/test/notification_test.exs index 77fdb532f..eee1c9fa3 100644 --- a/test/notification_test.exs +++ b/test/notification_test.exs @@ -31,4 +31,65 @@ defmodule Pleroma.NotificationTest do assert nil == Notification.create_notification(activity, user) end end + + describe "get notification" do + test "it gets a notification that belongs to the user" do + user = insert(:user) + other_user = insert(:user) + + {:ok, activity} = TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"}) + {:ok, [notification]} = Notification.create_notifications(activity) + {:ok, notification} = Notification.get(other_user, notification.id) + + assert notification.user_id == other_user.id + end + + test "it returns error if the notification doesn't belong to the user" do + user = insert(:user) + other_user = insert(:user) + + {:ok, activity} = TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"}) + {:ok, [notification]} = Notification.create_notifications(activity) + {:error, notification} = Notification.get(user, notification.id) + end + end + + describe "dismiss notification" do + test "it dismisses a notification that belongs to the user" do + user = insert(:user) + other_user = insert(:user) + + {:ok, activity} = TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"}) + {:ok, [notification]} = Notification.create_notifications(activity) + {:ok, notification} = Notification.dismiss(other_user, notification.id) + + assert notification.user_id == other_user.id + end + + test "it returns error if the notification doesn't belong to the user" do + user = insert(:user) + other_user = insert(:user) + + {:ok, activity} = TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"}) + {:ok, [notification]} = Notification.create_notifications(activity) + {:error, notification} = Notification.dismiss(user, notification.id) + end + end + + describe "clear notification" do + test "it clears all notifications belonging to the user" do + user = insert(:user) + other_user = insert(:user) + third_user = insert(:user) + + {:ok, activity} = TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname} and @#{third_user.nickname} !"}) + {:ok, _notifs} = Notification.create_notifications(activity) + {:ok, activity} = TwitterAPI.create_status(user, %{"status" => "hey again @#{other_user.nickname} and @#{third_user.nickname} !"}) + {:ok, _notifs} = Notification.create_notifications(activity) + Notification.clear(other_user) + + assert Notification.for_user(other_user) == [] + assert Notification.for_user(third_user) != [] + end + end end 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') 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') 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') 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') 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') 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') 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') 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') 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') 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 a743940463a7d0a7346f77792310dff6a98e7f31 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Thu, 16 Nov 2017 16:49:51 +0100 Subject: MastoAPI: Implement all streaming functions. --- test/user_test.exs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index 151b9afc0..430f56846 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -3,6 +3,7 @@ defmodule Pleroma.UserTest do alias Pleroma.{User, Repo} alias Pleroma.Web.OStatus alias Pleroma.Web.Websub.WebsubClientSubscription + alias Pleroma.Web.CommonAPI use Pleroma.DataCase import Pleroma.Factory @@ -296,5 +297,22 @@ defmodule Pleroma.UserTest do refute User.blocks?(user, blocked_user) end end + + test "get recipients from activity" do + actor = insert(:user) + user = insert(:user, local: true) + user_two = insert(:user, local: false) + addressed = insert(:user, local: true) + addressed_remote = insert(:user, local: false) + {:ok, activity} = CommonAPI.post(actor, %{"status" => "hey @#{addressed.nickname} @#{addressed_remote.nickname}"}) + + assert [addressed] == User.get_recipients_from_activity(activity) + + {:ok, user} = User.follow(user, actor) + recipients = User.get_recipients_from_activity(activity) + assert length(recipients) == 2 + assert user in recipients + assert addressed in recipients + end end -- 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') 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') 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') 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') 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 4db5954786b60df84b833feb360fd8c81be956d9 Mon Sep 17 00:00:00 2001 From: eal Date: Mon, 20 Nov 2017 01:21:53 +0200 Subject: Don't let the user unfollow their own account. --- test/user_test.exs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index 430f56846..e9f7a8666 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -66,6 +66,15 @@ defmodule Pleroma.UserTest do assert user.following == [] end + test "unfollow doesn't unfollow yourself" do + user = insert(:user) + + {:error, _} = User.unfollow(user, user) + + assert user.following == [user.ap_id] + end + + test "test if a user is following another user" do followed = insert(:user) user = insert(:user, %{following: [User.ap_followers(followed)]}) -- 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/support/factory.ex | 2 +- test/user_test.exs | 4 ++-- 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 ++- 5 files changed, 10 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/support/factory.ex b/test/support/factory.ex index 9bbf11f08..7f378915e 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -9,7 +9,7 @@ defmodule Pleroma.Factory do password_hash: Comeonin.Pbkdf2.hashpwsalt("test"), bio: sequence(:bio, &"Tester Number #{&1}") } - %{ user | ap_id: Pleroma.User.ap_id(user), follower_address: Pleroma.User.ap_followers(user) } + %{ user | ap_id: Pleroma.User.ap_id(user), follower_address: Pleroma.User.ap_followers(user), following: [Pleroma.User.ap_id(user)] } end def note_factory do diff --git a/test/user_test.exs b/test/user_test.exs index e9f7a8666..c06663ed7 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -36,7 +36,7 @@ defmodule Pleroma.UserTest do followed = User.get_by_ap_id(followed.ap_id) assert followed.info["follower_count"] == 1 - assert user.following == [User.ap_followers(followed)] + assert User.ap_followers(followed) in user.following end test "following a remote user will ensure a websub subscription is present" do @@ -46,7 +46,7 @@ defmodule Pleroma.UserTest do assert followed.local == false {:ok, user} = User.follow(user, followed) - assert user.following == [User.ap_followers(followed)] + assert User.ap_followers(followed) in user.following query = from w in WebsubClientSubscription, where: w.topic == ^followed.info["topic"] 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 bd921ca5d7830efc9dde68b763412fdc03725adc Mon Sep 17 00:00:00 2001 From: eal Date: Mon, 20 Nov 2017 07:58:43 +0200 Subject: Fix posts being streamed to non-local websocket channels. --- test/user_test.exs | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index c06663ed7..8ec23c751 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -318,6 +318,7 @@ defmodule Pleroma.UserTest do assert [addressed] == User.get_recipients_from_activity(activity) {:ok, user} = User.follow(user, actor) + {:ok, user_two} = User.follow(user_two, actor) recipients = User.get_recipients_from_activity(activity) assert length(recipients) == 2 assert user in recipients -- cgit v1.2.3 From 8d4e7b32c9adc2b16eaec93f4e6d754a2ace45b3 Mon Sep 17 00:00:00 2001 From: eal Date: Mon, 20 Nov 2017 09:26:31 +0200 Subject: Ensure correct state in self-unfollow. --- test/user_test.exs | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index 8ec23c751..31c5962e2 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -71,6 +71,7 @@ defmodule Pleroma.UserTest do {:error, _} = User.unfollow(user, user) + user = Repo.get(User, user.id) assert user.following == [user.ap_id] end -- 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') 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') 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') 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') 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') 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') 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') 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 From 0ec5aeb8a76653935caefa0de92861269f98f343 Mon Sep 17 00:00:00 2001 From: Lain Iwakura Date: Thu, 7 Dec 2017 17:41:34 +0100 Subject: Don't log in deactivated users. --- test/plugs/authentication_plug_test.exs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'test') diff --git a/test/plugs/authentication_plug_test.exs b/test/plugs/authentication_plug_test.exs index 9d6c2cd70..5480dab43 100644 --- a/test/plugs/authentication_plug_test.exs +++ b/test/plugs/authentication_plug_test.exs @@ -14,6 +14,13 @@ defmodule Pleroma.Plugs.AuthenticationPlugTest do password_hash: Comeonin.Pbkdf2.hashpwsalt("guy") } + @deactivated %User{ + id: 1, + name: "dude", + password_hash: Comeonin.Pbkdf2.hashpwsalt("guy"), + info: %{"deactivated" => true} + } + @session_opts [ store: :cookie, key: "_test", @@ -131,6 +138,26 @@ defmodule Pleroma.Plugs.AuthenticationPlugTest do end end + describe "with a correct authorization header for an deactiviated user" do + test "it halts the appication", %{conn: conn} do + opts = %{ + optional: false, + fetcher: fn _ -> @deactivated end + } + + header = basic_auth_enc("dude", "guy") + + conn = conn + |> Plug.Session.call(Plug.Session.init(@session_opts)) + |> fetch_session + |> put_req_header("authorization", header) + |> AuthenticationPlug.call(opts) + + assert conn.status == 403 + assert conn.halted == true + end + end + describe "with a user_id in the session for an existing user" do test "it assigns the user", %{conn: conn} do opts = %{ -- cgit v1.2.3 From b727ecc5e75388e2b2d67c76cab6df1a7e6719b3 Mon Sep 17 00:00:00 2001 From: Lain Iwakura Date: Thu, 7 Dec 2017 17:47:23 +0100 Subject: Add function to deactivate users. --- test/user_test.exs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index 31c5962e2..6daf1ecb7 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -325,5 +325,11 @@ defmodule Pleroma.UserTest do assert user in recipients assert addressed in recipients end -end + test ".deactivate deactivates a user" do + user = insert(:user) + assert false == !!user.info["deactivated"] + {:ok, user} = User.deactivate(user) + assert true == user.info["deactivated"] + end +end -- cgit v1.2.3 From a78ae2a685769cbf7459eb347aca581d389018ad Mon Sep 17 00:00:00 2001 From: Lain Iwakura Date: Thu, 7 Dec 2017 17:51:55 +0100 Subject: Don't follow deactivated users. --- test/user_test.exs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index 6daf1ecb7..486998907 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -39,6 +39,13 @@ defmodule Pleroma.UserTest do assert User.ap_followers(followed) in user.following end + test "can't follow a deactivated users" do + user = insert(:user) + followed = insert(:user, info: %{"deactivated" => true}) + + {:error, _} = User.follow(user, followed) + end + test "following a remote user will ensure a websub subscription is present" do user = insert(:user) {:ok, followed} = OStatus.make_user("shp@social.heldscal.la") -- cgit v1.2.3 From 6df6ad0b429150b00b065d95890bd62cd2778fad Mon Sep 17 00:00:00 2001 From: Lain Iwakura Date: Thu, 7 Dec 2017 18:13:05 +0100 Subject: User deletion: Remove relationships. --- test/user_test.exs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index 486998907..0dd5afb18 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -339,4 +339,33 @@ defmodule Pleroma.UserTest do {:ok, user} = User.deactivate(user) assert true == user.info["deactivated"] end + + test ".delete deactivates a user, all follow relationships and all create activities" do + user = insert(:user) + followed = insert(:user) + follower = insert(:user) + + {:ok, user} = User.follow(user, followed) + {:ok, follower} = User.follow(follower, user) + + {:ok, activity} = CommonAPI.post(user, %{"status" => "2hu"}) + {:ok, activity_two} = CommonAPI.post(follower, %{"status" => "3hu"}) + + {:ok, _, _} = CommonAPI.favorite(activity_two.id, user) + {:ok, _, _} = CommonAPI.favorite(activity.id, follower) + {:ok, _, _} = CommonAPI.repeat(activity.id, follower) + + :ok = User.delete(user) + + followed = Repo.get(User, followed.id) + follower = Repo.get(User, follower.id) + user = Repo.get(User, user.id) + + assert user.info["deactivated"] + + refute User.following?(user, followed) + refute User.following?(followed, follower) + + # TODO: check for activities. + end end -- cgit v1.2.3 From a3e68f02330a3c38f1d3f568ad507e5111b82600 Mon Sep 17 00:00:00 2001 From: eal Date: Thu, 7 Dec 2017 21:38:31 +0200 Subject: Allow parentheses in links. --- test/formatter_test.exs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test') diff --git a/test/formatter_test.exs b/test/formatter_test.exs index f91973881..cb7695e8e 100644 --- a/test/formatter_test.exs +++ b/test/formatter_test.exs @@ -25,6 +25,16 @@ defmodule Pleroma.FormatterTest do expected = "http://www.cs.vu.nl/~ast/intel/" assert Formatter.linkify(text) == expected + + text = "https://forum.zdoom.org/viewtopic.php?f=44&t=57087" + expected = "https://forum.zdoom.org/viewtopic.php?f=44&t=57087" + + assert Formatter.linkify(text) == expected + + text = "https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul" + expected = "https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul" + + assert Formatter.linkify(text) == expected end end -- cgit v1.2.3 From bad499b3fd95d1643890feaedea07123c004be57 Mon Sep 17 00:00:00 2001 From: Lain Iwakura Date: Fri, 8 Dec 2017 17:50:11 +0100 Subject: Basic user deletion. --- test/user_test.exs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index 0dd5afb18..16d43e619 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -1,6 +1,6 @@ defmodule Pleroma.UserTest do alias Pleroma.Builders.UserBuilder - alias Pleroma.{User, Repo} + alias Pleroma.{User, Repo, Activity} alias Pleroma.Web.OStatus alias Pleroma.Web.Websub.WebsubClientSubscription alias Pleroma.Web.CommonAPI @@ -366,6 +366,8 @@ defmodule Pleroma.UserTest do refute User.following?(user, followed) refute User.following?(followed, follower) - # TODO: check for activities. + # TODO: Remove favorites, repeats, delete activities. + + refute Repo.get(Activity, activity.id) end end -- cgit v1.2.3