From aed0f902871524ecc1db0d8c088ce5939e7c685a Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Tue, 18 Dec 2018 14:07:05 +0300 Subject: [#114] Added `pleroma.confirmation_pending` to user views, adjusted view tests. --- test/web/twitter_api/views/user_view_test.exs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'test/web/twitter_api/views') diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs index 34e6d4e27..0adc69ff9 100644 --- a/test/web/twitter_api/views/user_view_test.exs +++ b/test/web/twitter_api/views/user_view_test.exs @@ -96,7 +96,10 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "default_scope" => "public", "no_rich_text" => false, "fields" => [], - "pleroma" => %{"tags" => []} + "pleroma" => %{ + "confirmation_pending" => false, + "tags" => [] + } } assert represented == UserView.render("show.json", %{user: user}) @@ -138,7 +141,10 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "default_scope" => "public", "no_rich_text" => false, "fields" => [], - "pleroma" => %{"tags" => []} + "pleroma" => %{ + "confirmation_pending" => false, + "tags" => [] + } } assert represented == UserView.render("show.json", %{user: user, for: follower}) @@ -181,7 +187,10 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "default_scope" => "public", "no_rich_text" => false, "fields" => [], - "pleroma" => %{"tags" => []} + "pleroma" => %{ + "confirmation_pending" => false, + "tags" => [] + } } assert represented == UserView.render("show.json", %{user: follower, for: user}) @@ -231,7 +240,10 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "default_scope" => "public", "no_rich_text" => false, "fields" => [], - "pleroma" => %{"tags" => []} + "pleroma" => %{ + "confirmation_pending" => false, + "tags" => [] + } } blocker = Repo.get(User, blocker.id) -- cgit v1.2.3 From 873938d223949f647a196b7f2a4140d323fbab1c Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 23 Dec 2018 13:55:08 +0000 Subject: tests: twitter api: activity view test: enable tesla mock --- test/web/twitter_api/views/activity_view_test.exs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/web/twitter_api/views') diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index 8aa9e3130..09d7a18d4 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -12,6 +12,13 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do alias Pleroma.Web.ActivityPub.ActivityPub import Pleroma.Factory + import Tesla.Mock + + setup do + mock(fn env -> apply(HttpRequestMock, :request, [env]) end) + :ok + end + import Mock test "a create activity with a html status" do -- cgit v1.2.3 From a2bceaf688608f61151e298e6025ccbecc9de227 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 23 Dec 2018 13:59:06 +0000 Subject: tests: twitter api: add test proving that peertube videos are correctly handled --- test/web/twitter_api/views/activity_view_test.exs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/web/twitter_api/views') diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index 09d7a18d4..fd511b546 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -265,4 +265,18 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do assert result == expected end + + test "a peertube video" do + {:ok, object} = + ActivityPub.fetch_object_from_id( + "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3" + ) + + %Activity{} = activity = Activity.get_create_activity_by_object_ap_id(object.data["id"]) + + result = ActivityView.render("activity.json", activity: activity) + + assert length(result["attachments"]) == 1 + assert result["summary"] == "Friday Night" + end end -- cgit v1.2.3 From 3c08d229db423052d0dd88b8a36fb39b0ae81ead Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 23 Dec 2018 20:11:29 +0000 Subject: tests: add legal boilerplate --- test/web/twitter_api/views/activity_view_test.exs | 4 ++++ test/web/twitter_api/views/notification_view_test.exs | 4 ++++ test/web/twitter_api/views/user_view_test.exs | 4 ++++ 3 files changed, 12 insertions(+) (limited to 'test/web/twitter_api/views') diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index fd511b546..013245033 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do use Pleroma.DataCase diff --git a/test/web/twitter_api/views/notification_view_test.exs b/test/web/twitter_api/views/notification_view_test.exs index fcf2b3d90..8367fc6c7 100644 --- a/test/web/twitter_api/views/notification_view_test.exs +++ b/test/web/twitter_api/views/notification_view_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do use Pleroma.DataCase diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs index 0adc69ff9..32e9466e1 100644 --- a/test/web/twitter_api/views/user_view_test.exs +++ b/test/web/twitter_api/views/user_view_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.TwitterAPI.UserViewTest do use Pleroma.DataCase -- cgit v1.2.3 From b43d630f307110b5fa552c28c9fa0ebae09e85f2 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sun, 23 Dec 2018 18:31:37 +0100 Subject: Web.TwitterAPI.UserView: Add rights.admin --- test/web/twitter_api/views/user_view_test.exs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'test/web/twitter_api/views') diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs index 32e9466e1..5f7481eb6 100644 --- a/test/web/twitter_api/views/user_view_test.exs +++ b/test/web/twitter_api/views/user_view_test.exs @@ -90,7 +90,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "follows_you" => false, "statusnet_blocking" => false, "rights" => %{ - "delete_others_notice" => false + "delete_others_notice" => false, + "admin" => false }, "statusnet_profile_url" => user.ap_id, "cover_photo" => banner, @@ -135,7 +136,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "follows_you" => false, "statusnet_blocking" => false, "rights" => %{ - "delete_others_notice" => false + "delete_others_notice" => false, + "admin" => false }, "statusnet_profile_url" => user.ap_id, "cover_photo" => banner, @@ -181,7 +183,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "follows_you" => true, "statusnet_blocking" => false, "rights" => %{ - "delete_others_notice" => false + "delete_others_notice" => false, + "admin" => false }, "statusnet_profile_url" => follower.ap_id, "cover_photo" => banner, @@ -207,6 +210,13 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do assert represented["rights"]["delete_others_notice"] end + test "a user that is a admin" do + user = insert(:user, %{info: %{is_admin: true}}) + represented = UserView.render("show.json", %{user: user, for: user}) + + assert represented["rights"]["admin"] + end + test "A blocked user for the blocker" do user = insert(:user) blocker = insert(:user) @@ -234,7 +244,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "follows_you" => false, "statusnet_blocking" => true, "rights" => %{ - "delete_others_notice" => false + "delete_others_notice" => false, + "admin" => false }, "statusnet_profile_url" => user.ap_id, "cover_photo" => banner, -- cgit v1.2.3 From 6556be344de981272b9c14faf5fb9837c1ea0da6 Mon Sep 17 00:00:00 2001 From: scarlett Date: Sat, 5 Jan 2019 18:20:42 +0000 Subject: Resolve some test failures. --- test/web/twitter_api/views/activity_view_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/web/twitter_api/views') diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index 013245033..40c4abc39 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -73,6 +73,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do "repeat_num" => 0, "repeated" => false, "statusnet_conversation_id" => convo_id, + "summary" => "", "statusnet_html" => "Hey @shp!", "tags" => [], @@ -80,7 +81,6 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do "uri" => activity.data["object"]["id"], "user" => UserView.render("show.json", %{user: user}), "visibility" => "direct", - "summary" => nil } assert result == expected -- cgit v1.2.3 From 096e121879f5e9aad694f1b57438f0545ecd73b3 Mon Sep 17 00:00:00 2001 From: scarlett Date: Sat, 5 Jan 2019 18:25:36 +0000 Subject: Remove redundant comma. --- test/web/twitter_api/views/activity_view_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/web/twitter_api/views') diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index 40c4abc39..32a08dbc9 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -80,7 +80,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do "text" => "Hey @shp!", "uri" => activity.data["object"]["id"], "user" => UserView.render("show.json", %{user: user}), - "visibility" => "direct", + "visibility" => "direct" } assert result == expected -- cgit v1.2.3 From 57df7d6e1da1a94a3866afc9b6d353aea602d4d3 Mon Sep 17 00:00:00 2001 From: scarlett Date: Sat, 5 Jan 2019 21:46:42 +0000 Subject: Add tests for emoji and lack of HTML in summaries. --- test/web/twitter_api/views/activity_view_test.exs | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'test/web/twitter_api/views') diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index 32a08dbc9..05780a54a 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -41,6 +41,35 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do "#Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg" end + test "a create activity with a summary containing emoji" do + {:ok, activity} = + CommonAPI.post(insert(:user), %{ + "spoiler_text" => ":woollysocks: meow", + "status" => "." + }) + + result = ActivityView.render("activity.json", activity: activity) + + expected = + "\"woollysocks\" meow" + + assert result["summary"] == expected + end + + test "a create activity with a summary containing invalid HTML" do + {:ok, activity} = + CommonAPI.post(insert(:user), %{ + "spoiler_text" => "meow", + "status" => "." + }) + + result = ActivityView.render("activity.json", activity: activity) + + expected = "meow" + + assert result["summary"] == expected + end + test "a create activity with a note" do user = insert(:user) other_user = insert(:user, %{nickname: "shp"}) -- cgit v1.2.3 From 52493467ac314ec58ed6123d3581428a82ec170c Mon Sep 17 00:00:00 2001 From: scarlett Date: Sun, 6 Jan 2019 10:16:40 +0000 Subject: Twitter API: Add a summary_html field. The intention here is to allow proper subject copying when it contains emoji, obviously this will require minor frontend changes, though. --- test/web/twitter_api/views/activity_view_test.exs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'test/web/twitter_api/views') diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index 05780a54a..a03f48b61 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -50,10 +50,13 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do result = ActivityView.render("activity.json", activity: activity) - expected = + expected = ":woollysocks: meow" + + expected_html = "\"woollysocks\" meow" assert result["summary"] == expected + assert result["summary_html"] == expected_html end test "a create activity with a summary containing invalid HTML" do @@ -68,6 +71,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do expected = "meow" assert result["summary"] == expected + assert result["summary_html"] == expected end test "a create activity with a note" do @@ -103,6 +107,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do "repeated" => false, "statusnet_conversation_id" => convo_id, "summary" => "", + "summary_html" => "", "statusnet_html" => "Hey @shp!", "tags" => [], -- cgit v1.2.3 From 7382adf407301945e30ee38aa4efe28a819fcf44 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 7 Jan 2019 12:41:31 +0100 Subject: Make TwAPI UserView more resilient to issues. Will work for missing users and badly migrated users. --- test/web/twitter_api/views/activity_view_test.exs | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test/web/twitter_api/views') diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index 05780a54a..7f003c214 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -25,6 +25,34 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do import Mock + test "returns an error user for activities missing users" do + user = insert(:user) + + {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"}) + + Repo.delete(user) + Cachex.clear(:user_cache) + + result = ActivityView.render("activity.json", activity: activity) + assert result + end + + test "tries to get a user by nickname if fetching by ap_id doesn't work" do + user = insert(:user) + + {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"}) + + {:ok, user} = + user + |> Ecto.Changeset.change(%{ap_id: "#{user.ap_id}/extension/#{user.nickname}"}) + |> Repo.update() + + Cachex.clear(:user_cache) + + result = ActivityView.render("activity.json", activity: activity) + assert result["user"]["id"] == user.id + end + test "a create activity with a html status" do text = """ #Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg -- cgit v1.2.3 From a16b17cc61a57d1adbc6f10f16fc36e8238c6c2a Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 7 Jan 2019 20:59:30 +0100 Subject: Actually put some onformation in the error user, make it actually properly parse in conversations. --- test/web/twitter_api/views/activity_view_test.exs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'test/web/twitter_api/views') diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index 7f003c214..bd4878e98 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -25,7 +25,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do import Mock - test "returns an error user for activities missing users" do + test "returns a temporary ap_id based user for activities missing db users" do user = insert(:user) {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"}) @@ -33,8 +33,11 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do Repo.delete(user) Cachex.clear(:user_cache) - result = ActivityView.render("activity.json", activity: activity) - assert result + %{"user" => tw_user} = ActivityView.render("activity.json", activity: activity) + + assert tw_user["screen_name"] == "erroruser@example.com" + assert tw_user["name"] == user.ap_id + assert tw_user["statusnet_profile_url"] == user.ap_id end test "tries to get a user by nickname if fetching by ap_id doesn't work" do -- cgit v1.2.3 From 44a1e6948488d9a96ed684f0a7855fe2fce02ed4 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Wed, 9 Jan 2019 19:54:19 +0700 Subject: Add Twitter API for the pinned statuses ``` # Only return statuses that have been pinned GET /api/statuses/user_timeline.json?pinned=true # Pin POST /api/statuses/pin/:id # Unpin POST /api/statuses/unpin/:id ``` --- test/web/twitter_api/views/activity_view_test.exs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/web/twitter_api/views') diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index bd4878e98..374440300 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do @@ -132,6 +132,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do "possibly_sensitive" => false, "repeat_num" => 0, "repeated" => false, + "pinned" => false, "statusnet_conversation_id" => convo_id, "summary" => "", "statusnet_html" => -- cgit v1.2.3