diff options
| author | Maksim Pechnikov <parallel588@gmail.com> | 2019-12-08 19:52:46 +0300 | 
|---|---|---|
| committer | Maksim Pechnikov <parallel588@gmail.com> | 2019-12-08 19:52:46 +0300 | 
| commit | 5876a9cb79e53f932d63e457610852031669a222 (patch) | |
| tree | 6ff7335e9ddd5cfbce1e33ca075265c6f31b8b61 /test/web/mastodon_api | |
| parent | 3c3bba0b7c65187b3270ef3402442cf870a55198 (diff) | |
| parent | af5fef1f228a1781d7d9cad490d3b3a783389f5e (diff) | |
| download | pleroma-5876a9cb79e53f932d63e457610852031669a222.tar.gz pleroma-5876a9cb79e53f932d63e457610852031669a222.zip  | |
Merge branch 'develop' into issue/1383
Diffstat (limited to 'test/web/mastodon_api')
7 files changed, 90 insertions, 20 deletions
diff --git a/test/web/mastodon_api/controllers/account_controller_test.exs b/test/web/mastodon_api/controllers/account_controller_test.exs index 585cb8a9e..fa08ae4df 100644 --- a/test/web/mastodon_api/controllers/account_controller_test.exs +++ b/test/web/mastodon_api/controllers/account_controller_test.exs @@ -144,6 +144,50 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do    end    describe "user timelines" do +    test "respects blocks", %{conn: conn} do +      user_one = insert(:user) +      user_two = insert(:user) +      user_three = insert(:user) + +      User.block(user_one, user_two) + +      {:ok, activity} = CommonAPI.post(user_two, %{"status" => "User one sux0rz"}) +      {:ok, repeat, _} = CommonAPI.repeat(activity.id, user_three) + +      resp = +        conn +        |> get("/api/v1/accounts/#{user_two.id}/statuses") + +      assert [%{"id" => id}] = json_response(resp, 200) +      assert id == activity.id + +      # Even a blocked user will deliver the full user timeline, there would be +      # no point in looking at a blocked users timeline otherwise +      resp = +        conn +        |> assign(:user, user_one) +        |> get("/api/v1/accounts/#{user_two.id}/statuses") + +      assert [%{"id" => id}] = json_response(resp, 200) +      assert id == activity.id + +      resp = +        conn +        |> get("/api/v1/accounts/#{user_three.id}/statuses") + +      assert [%{"id" => id}] = json_response(resp, 200) +      assert id == repeat.id + +      # When viewing a third user's timeline, the blocked users will NOT be +      # shown. +      resp = +        conn +        |> assign(:user, user_one) +        |> get("/api/v1/accounts/#{user_three.id}/statuses") + +      assert [] = json_response(resp, 200) +    end +      test "gets a users statuses", %{conn: conn} do        user_one = insert(:user)        user_two = insert(:user) @@ -891,7 +935,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do      user = insert(:user)      other_user = insert(:user) -    {:ok, user} = User.mute(user, other_user) +    {:ok, _user_relationships} = User.mute(user, other_user)      conn =        conn @@ -906,7 +950,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do      user = insert(:user)      other_user = insert(:user) -    {:ok, user} = User.block(user, other_user) +    {:ok, _user_relationship} = User.block(user, other_user)      conn =        conn diff --git a/test/web/mastodon_api/controllers/notification_controller_test.exs b/test/web/mastodon_api/controllers/notification_controller_test.exs index fa55a7cf9..f6d4ab9f0 100644 --- a/test/web/mastodon_api/controllers/notification_controller_test.exs +++ b/test/web/mastodon_api/controllers/notification_controller_test.exs @@ -289,7 +289,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do      assert length(json_response(conn, 200)) == 1 -    {:ok, user} = User.mute(user, user2) +    {:ok, _user_relationships} = User.mute(user, user2)      conn = assign(build_conn(), :user, user)      conn = get(conn, "/api/v1/notifications") @@ -310,7 +310,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do      assert length(json_response(conn, 200)) == 1 -    {:ok, user} = User.mute(user, user2, false) +    {:ok, _user_relationships} = User.mute(user, user2, false)      conn = assign(build_conn(), :user, user)      conn = get(conn, "/api/v1/notifications") @@ -333,7 +333,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do      assert length(json_response(conn, 200)) == 1 -    {:ok, user} = User.mute(user, user2) +    {:ok, _user_relationships} = User.mute(user, user2)      conn = assign(build_conn(), :user, user)      conn = get(conn, "/api/v1/notifications", %{"with_muted" => "true"}) @@ -341,6 +341,32 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do      assert length(json_response(conn, 200)) == 1    end +  test "see move notifications with `with_move` parameter", %{ +    conn: conn +  } do +    old_user = insert(:user) +    new_user = insert(:user, also_known_as: [old_user.ap_id]) +    follower = insert(:user) + +    User.follow(follower, old_user) +    Pleroma.Web.ActivityPub.ActivityPub.move(old_user, new_user) +    Pleroma.Tests.ObanHelpers.perform_all() + +    conn = +      conn +      |> assign(:user, follower) +      |> get("/api/v1/notifications") + +    assert json_response(conn, 200) == [] + +    conn = +      build_conn() +      |> assign(:user, follower) +      |> get("/api/v1/notifications", %{"with_move" => "true"}) + +    assert length(json_response(conn, 200)) == 1 +  end +    defp get_notification_id_by_activity(%{id: id}) do      Notification      |> Repo.get_by(activity_id: id) diff --git a/test/web/mastodon_api/controllers/status_controller_test.exs b/test/web/mastodon_api/controllers/status_controller_test.exs index a96fd860b..5fbe947ba 100644 --- a/test/web/mastodon_api/controllers/status_controller_test.exs +++ b/test/web/mastodon_api/controllers/status_controller_test.exs @@ -1108,7 +1108,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        activity: activity      } do        other_user = insert(:user) -      {:ok, user} = User.block(user, other_user) +      {:ok, _user_relationship} = User.block(user, other_user)        {:ok, _, _} = CommonAPI.favorite(activity.id, other_user) @@ -1205,7 +1205,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        activity: activity      } do        other_user = insert(:user) -      {:ok, user} = User.block(user, other_user) +      {:ok, _user_relationship} = User.block(user, other_user)        {:ok, _, _} = CommonAPI.repeat(activity.id, other_user) diff --git a/test/web/mastodon_api/controllers/timeline_controller_test.exs b/test/web/mastodon_api/controllers/timeline_controller_test.exs index 61b6cea75..dc17cc963 100644 --- a/test/web/mastodon_api/controllers/timeline_controller_test.exs +++ b/test/web/mastodon_api/controllers/timeline_controller_test.exs @@ -194,7 +194,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do        blocker = insert(:user)        blocked = insert(:user)        user = insert(:user) -      {:ok, blocker} = User.block(blocker, blocked) +      {:ok, _user_relationship} = User.block(blocker, blocked)        {:ok, _blocked_direct} =          CommonAPI.post(blocked, %{ diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs index 35aefb7dc..ed6f2ecbd 100644 --- a/test/web/mastodon_api/views/account_view_test.exs +++ b/test/web/mastodon_api/views/account_view_test.exs @@ -190,9 +190,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do        {:ok, user} = User.follow(user, other_user)        {:ok, other_user} = User.follow(other_user, user) -      {:ok, other_user} = User.subscribe(user, other_user) -      {:ok, user} = User.mute(user, other_user, true) -      {:ok, user} = CommonAPI.hide_reblogs(user, other_user) +      {:ok, _subscription} = User.subscribe(user, other_user) +      {:ok, _user_relationships} = User.mute(user, other_user, true) +      {:ok, _reblog_mute} = CommonAPI.hide_reblogs(user, other_user)        expected = %{          id: to_string(other_user.id), @@ -218,9 +218,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do        other_user = insert(:user)        {:ok, user} = User.follow(user, other_user) -      {:ok, other_user} = User.subscribe(user, other_user) -      {:ok, user} = User.block(user, other_user) -      {:ok, other_user} = User.block(other_user, user) +      {:ok, _subscription} = User.subscribe(user, other_user) +      {:ok, _user_relationship} = User.block(user, other_user) +      {:ok, _user_relationship} = User.block(other_user, user)        expected = %{          id: to_string(other_user.id), @@ -291,7 +291,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do      other_user = insert(:user)      {:ok, other_user} = User.follow(other_user, user) -    {:ok, other_user} = User.block(other_user, user) +    {:ok, _user_relationship} = User.block(other_user, user)      {:ok, _} = User.follow(insert(:user), user)      expected = %{ diff --git a/test/web/mastodon_api/views/notification_view_test.exs b/test/web/mastodon_api/views/notification_view_test.exs index 26e1afc85..ba1721e06 100644 --- a/test/web/mastodon_api/views/notification_view_test.exs +++ b/test/web/mastodon_api/views/notification_view_test.exs @@ -109,8 +109,8 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do    end    test "Move notification" do -    %{ap_id: old_ap_id} = old_user = insert(:user) -    %{ap_id: _new_ap_id} = new_user = insert(:user, also_known_as: [old_ap_id]) +    old_user = insert(:user) +    new_user = insert(:user, also_known_as: [old_user.ap_id])      follower = insert(:user)      User.follow(follower, old_user) @@ -120,7 +120,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do      old_user = refresh_record(old_user)      new_user = refresh_record(new_user) -    [notification] = Notification.for_user(follower) +    [notification] = Notification.for_user(follower, %{with_move: true})      expected = %{        id: to_string(notification.id), diff --git a/test/web/mastodon_api/views/status_view_test.exs b/test/web/mastodon_api/views/status_view_test.exs index d46ecc646..bdd87a79e 100644 --- a/test/web/mastodon_api/views/status_view_test.exs +++ b/test/web/mastodon_api/views/status_view_test.exs @@ -183,7 +183,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      user = insert(:user)      other_user = insert(:user) -    {:ok, user} = User.mute(user, other_user) +    {:ok, _user_relationships} = User.mute(user, other_user)      {:ok, activity} = CommonAPI.post(other_user, %{"status" => "test"})      status = StatusView.render("show.json", %{activity: activity}) @@ -199,7 +199,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      user = insert(:user)      other_user = insert(:user) -    {:ok, user} = User.mute(user, other_user) +    {:ok, _user_relationships} = User.mute(user, other_user)      {:ok, activity} = CommonAPI.post(other_user, %{"status" => "test"})      status = StatusView.render("show.json", %{activity: activity, for: user})  | 
