diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/notification_test.exs | 4 | ||||
-rw-r--r-- | test/web/mastodon_api/account_view_test.exs | 8 | ||||
-rw-r--r-- | test/web/mastodon_api/mastodon_api_controller_test.exs | 18 | ||||
-rw-r--r-- | test/web/mastodon_api/status_view_test.exs | 4 | ||||
-rw-r--r-- | test/web/ostatus/feed_representer_test.exs | 1 | ||||
-rw-r--r-- | test/web/ostatus/ostatus_test.exs | 6 | ||||
-rw-r--r-- | test/web/ostatus/user_representer_test.exs | 1 | ||||
-rw-r--r-- | test/web/twitter_api/twitter_api_controller_test.exs | 32 | ||||
-rw-r--r-- | test/web/twitter_api/twitter_api_test.exs | 6 | ||||
-rw-r--r-- | test/web/twitter_api/views/user_view_test.exs | 39 |
10 files changed, 87 insertions, 32 deletions
diff --git a/test/notification_test.exs b/test/notification_test.exs index eee1c9fa3..0a4462241 100644 --- a/test/notification_test.exs +++ b/test/notification_test.exs @@ -14,9 +14,9 @@ defmodule Pleroma.NotificationTest do {:ok, [notification, other_notification]} = Notification.create_notifications(activity) - assert notification.user_id == other_user.id + notified_ids = Enum.sort([notification.user_id, other_notification.user_id]) + assert notified_ids == [other_user.id, third_user.id] assert notification.activity_id == activity.id - assert other_notification.user_id == third_user.id assert other_notification.activity_id == activity.id end end diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs index eccfe0b36..5eefa61e1 100644 --- a/test/web/mastodon_api/account_view_test.exs +++ b/test/web/mastodon_api/account_view_test.exs @@ -19,10 +19,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do statuses_count: 5, note: user.bio, url: user.ap_id, - avatar: "https://placehold.it/48x48", - avatar_static: "https://placehold.it/48x48", - header: "https://placehold.it/700x335", - header_static: "https://placehold.it/700x335", + avatar: "http://localhost:4001/images/avi.png", + avatar_static: "http://localhost:4001/images/avi.png", + header: "http://localhost:4001/images/banner.png", + header_static: "http://localhost:4001/images/banner.png", source: %{ note: "", privacy: "public", diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index fc0010569..93b29dfae 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -35,7 +35,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do {:ok, [_activity]} = OStatus.fetch_activity_from_url("https://shitposter.club/notice/2827873") conn = conn - |> get("/api/v1/timelines/public") + |> get("/api/v1/timelines/public", %{"local" => "False"}) assert length(json_response(conn, 200)) == 2 @@ -43,6 +43,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> get("/api/v1/timelines/public", %{"local" => "True"}) assert [%{"content" => "test"}] = json_response(conn, 200) + + conn = build_conn() + |> get("/api/v1/timelines/public", %{"local" => "1"}) + + assert [%{"content" => "test"}] = json_response(conn, 200) end test "posting a status", %{conn: conn} do @@ -50,9 +55,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do conn = conn |> assign(:user, user) - |> post("/api/v1/statuses", %{"status" => "cofe", "spoiler_text" => "2hu"}) + |> post("/api/v1/statuses", %{"status" => "cofe", "spoiler_text" => "2hu", "sensitive" => "false"}) - assert %{"content" => "cofe", "id" => id, "spoiler_text" => "2hu"} = json_response(conn, 200) + assert %{"content" => "cofe", "id" => id, "spoiler_text" => "2hu", "sensitive" => false} = json_response(conn, 200) assert Repo.get(Activity, id) end @@ -145,7 +150,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> assign(:user, user) |> get("/api/v1/notifications") - expected_response = "hi <a href=\"#{user.ap_id}\">@#{user.nickname}</a>" + expected_response = "hi <span><a href=\"#{user.ap_id}\">@<span>#{user.nickname}</span></a></span>" assert [%{"status" => %{"content" => response}} | _rest] = json_response(conn, 200) assert response == expected_response end @@ -161,7 +166,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> assign(:user, user) |> get("/api/v1/notifications/#{notification.id}") - expected_response = "hi <a href=\"#{user.ap_id}\">@#{user.nickname}</a>" + expected_response = "hi <span><a href=\"#{user.ap_id}\">@<span>#{user.nickname}</span></a></span>" assert %{"status" => %{"content" => response}} = json_response(conn, 200) assert response == expected_response end @@ -581,11 +586,14 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do {:ok, _} = TwitterAPI.create_status(user, %{"status" => "cofe"}) + Pleroma.Stats.update_stats() + conn = conn |> get("/api/v1/instance") assert result = json_response(conn, 200) assert result["stats"]["user_count"] == 2 + assert result["stats"]["status_count"] == 1 end end diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs index 93c0b7236..0d396f3b8 100644 --- a/test/web/mastodon_api/status_view_test.exs +++ b/test/web/mastodon_api/status_view_test.exs @@ -56,7 +56,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do test "contains mentions" do incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml") - user = insert(:user, %{ap_id: "https://pleroma.soykaf.com/users/lain"}) + # a user with this ap id might be in the cache. + recipient = "https://pleroma.soykaf.com/users/lain" + user = User.get_cached_by_ap_id(recipient) || insert(:user, %{ap_id: recipient}) {:ok, [activity]} = OStatus.handle_incoming(incoming) diff --git a/test/web/ostatus/feed_representer_test.exs b/test/web/ostatus/feed_representer_test.exs index df5a964e2..e10936366 100644 --- a/test/web/ostatus/feed_representer_test.exs +++ b/test/web/ostatus/feed_representer_test.exs @@ -26,6 +26,7 @@ defmodule Pleroma.Web.OStatus.FeedRepresenterTest do <id>#{OStatus.feed_path(user)}</id> <title>#{user.nickname}'s timeline</title> <updated>#{most_recent_update}</updated> + <logo>#{User.avatar_url(user)}</logo> <link rel="hub" href="#{OStatus.pubsub_path(user)}" /> <link rel="salmon" href="#{OStatus.salmon_path(user)}" /> <link rel="self" href="#{OStatus.feed_path(user)}" type="application/atom+xml" /> diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs index de01612b3..b27f8cb55 100644 --- a/test/web/ostatus/ostatus_test.exs +++ b/test/web/ostatus/ostatus_test.exs @@ -302,7 +302,8 @@ defmodule Pleroma.Web.OStatusTest do "host" => "social.heldscal.la", "fqn" => user, "bio" => "cofe", - "avatar" => %{"type" => "Image", "url" => [%{"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg", "mediaType" => "image/jpeg", "type" => "Link"}]} + "avatar" => %{"type" => "Image", "url" => [%{"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg", "mediaType" => "image/jpeg", "type" => "Link"}]}, + "subscribe_address" => "https://social.heldscal.la/main/ostatussub?profile={uri}" } assert data == expected end @@ -325,7 +326,8 @@ defmodule Pleroma.Web.OStatusTest do "host" => "social.heldscal.la", "fqn" => user, "bio" => "cofe", - "avatar" => %{"type" => "Image", "url" => [%{"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg", "mediaType" => "image/jpeg", "type" => "Link"}]} + "avatar" => %{"type" => "Image", "url" => [%{"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg", "mediaType" => "image/jpeg", "type" => "Link"}]}, + "subscribe_address" => "https://social.heldscal.la/main/ostatussub?profile={uri}" } assert data == expected end diff --git a/test/web/ostatus/user_representer_test.exs b/test/web/ostatus/user_representer_test.exs index d5d70f5c6..b22420379 100644 --- a/test/web/ostatus/user_representer_test.exs +++ b/test/web/ostatus/user_representer_test.exs @@ -21,6 +21,7 @@ defmodule Pleroma.Web.OStatus.UserRepresenterTest do <summary>#{user.bio}</summary> <name>#{user.nickname}</name> <link rel="avatar" href="#{User.avatar_url(user)}" /> + <link rel="header" href="#{User.banner_url(user)}" /> """ assert clean(res) == clean(expected) diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 90d0fa654..39f1cdd4c 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -518,7 +518,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do end describe "GET /api/statuses/friends" do - test "it returns a user's friends", %{conn: conn} do + test "it returns the logged in user's friends", %{conn: conn} do user = insert(:user) followed_one = insert(:user) followed_two = insert(:user) @@ -533,6 +533,36 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do assert MapSet.equal?(MapSet.new(json_response(conn, 200)), MapSet.new(UserView.render("index.json", %{users: [followed_one, followed_two], for: user}))) end + + test "it returns a given user's friends with user_id", %{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 + |> get("/api/statuses/friends", %{"user_id" => user.id}) + + assert MapSet.equal?(MapSet.new(json_response(conn, 200)), MapSet.new(UserView.render("index.json", %{users: [followed_one, followed_two], for: user}))) + end + + test "it returns a given user's friends with screen_name", %{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 + |> get("/api/statuses/friends", %{"screen_name" => user.nickname}) + + assert MapSet.equal?(MapSet.new(json_response(conn, 200)), MapSet.new(UserView.render("index.json", %{users: [followed_one, followed_two], for: user}))) + end end describe "GET /friends/ids" do diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index 96552f97e..ac62880d5 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, <a href='shp'>@shp</a>.<script></script><br>This is on another :moominmamma: line. #2hu #epic #phantasmagoric<br><a href=\"http://example.org/image.jpg\" class='attachment'>image.jpg</a>" + assert get_in(activity.data, ["object", "content"]) == "Hello again, <span><a href='shp'>@<span>shp</span></a></span>.<script></script><br>This is on another :moominmamma: line. #2hu #epic #phantasmagoric<br><a href=\"http://example.org/image.jpg\" class='attachment'>image.jpg</a>" 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 @@ -291,7 +291,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"}) mentions = Pleroma.Formatter.parse_mentions(text) - expected_text = "<a href='#{gsimg.ap_id}'>@gsimg</a> According to <a href='#{archaeme.ap_id}'>@archaeme</a>, that is @daggsy. Also hello <a href='#{archaeme_remote.ap_id}'>@archaeme</a>" + expected_text = "<span><a href='#{gsimg.ap_id}'>@<span>gsimg</span></a></span> According to <span><a href='#{archaeme.ap_id}'>@<span>archaeme</span></a></span>, that is @daggsy. Also hello <span><a href='#{archaeme_remote.ap_id}'>@<span>archaeme</span></a></span>" assert Utils.add_user_links(text, mentions) == expected_text end @@ -404,7 +404,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do 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") + # assert Activity.get_create_activity_by_object_ap_id("tag:mastodon.social,2017-04-05:objectId=1641750:objectType=Status") end end end diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs index 18a19ef70..d5d2f0adc 100644 --- a/test/web/twitter_api/views/user_view_test.exs +++ b/test/web/twitter_api/views/user_view_test.exs @@ -30,10 +30,11 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do User.follow(follower, user) User.follow(second_follower, user) User.follow(user, follower) + {:ok, user} = User.update_follower_count(user) + Cachex.set(:user_cache, "user_info:#{user.id}", User.user_info(Repo.get!(User, user.id))) - user = Repo.get!(User, user.id) - - image = "https://placehold.it/48x48" + image = "http://localhost:4001/images/avi.png" + banner = "http://localhost:4001/images/banner.png" represented = %{ "id" => user.id, @@ -54,8 +55,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "statusnet_blocking" => false, "rights" => %{}, "statusnet_profile_url" => user.ap_id, - "cover_photo" => nil, - "background_image" => nil + "cover_photo" => banner, + "background_image" => nil, + "is_local" => true } assert represented == UserView.render("show.json", %{user: user}) @@ -64,7 +66,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do test "A user for a given other follower", %{user: user} do {:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]}) {:ok, user} = User.update_follower_count(user) - image = "https://placehold.it/48x48" + image = "http://localhost:4001/images/avi.png" + banner = "http://localhost:4001/images/banner.png" + represented = %{ "id" => user.id, "name" => user.name, @@ -84,8 +88,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "statusnet_blocking" => false, "rights" => %{}, "statusnet_profile_url" => user.ap_id, - "cover_photo" => nil, - "background_image" => nil + "cover_photo" => banner, + "background_image" => nil, + "is_local" => true } assert represented == UserView.render("show.json", %{user: user, for: follower}) @@ -95,7 +100,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do follower = insert(:user) {:ok, follower} = User.follow(follower, user) {:ok, user} = User.update_follower_count(user) - image = "https://placehold.it/48x48" + image = "http://localhost:4001/images/avi.png" + banner = "http://localhost:4001/images/banner.png" + represented = %{ "id" => follower.id, "name" => follower.name, @@ -115,8 +122,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "statusnet_blocking" => false, "rights" => %{}, "statusnet_profile_url" => follower.ap_id, - "cover_photo" => nil, - "background_image" => nil + "cover_photo" => banner, + "background_image" => nil, + "is_local" => true } assert represented == UserView.render("show.json", %{user: follower, for: user}) @@ -126,7 +134,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do user = insert(:user) blocker = insert(:user) User.block(blocker, user) - image = "https://placehold.it/48x48" + image = "http://localhost:4001/images/avi.png" + banner = "http://localhost:4001/images/banner.png" + represented = %{ "id" => user.id, "name" => user.name, @@ -146,8 +156,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "statusnet_blocking" => true, "rights" => %{}, "statusnet_profile_url" => user.ap_id, - "cover_photo" => nil, - "background_image" => nil + "cover_photo" => banner, + "background_image" => nil, + "is_local" => true } blocker = Repo.get(User, blocker.id) |