diff options
Diffstat (limited to 'test/web/mastodon_api')
5 files changed, 86 insertions, 19 deletions
diff --git a/test/web/mastodon_api/controllers/notification_controller_test.exs b/test/web/mastodon_api/controllers/notification_controller_test.exs index 7a0011646..344eabb4a 100644 --- a/test/web/mastodon_api/controllers/notification_controller_test.exs +++ b/test/web/mastodon_api/controllers/notification_controller_test.exs @@ -194,10 +194,10 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do        {:ok, private_activity} =          CommonAPI.post(other_user, %{"status" => ".", "visibility" => "private"}) -      {:ok, _, _} = CommonAPI.favorite(public_activity.id, user) -      {:ok, _, _} = CommonAPI.favorite(direct_activity.id, user) -      {:ok, _, _} = CommonAPI.favorite(unlisted_activity.id, user) -      {:ok, _, _} = CommonAPI.favorite(private_activity.id, user) +      {:ok, _} = CommonAPI.favorite(user, public_activity.id) +      {:ok, _} = CommonAPI.favorite(user, direct_activity.id) +      {:ok, _} = CommonAPI.favorite(user, unlisted_activity.id) +      {:ok, _} = CommonAPI.favorite(user, private_activity.id)        activity_ids =          conn @@ -274,7 +274,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do      {:ok, mention_activity} = CommonAPI.post(other_user, %{"status" => "hey @#{user.nickname}"})      {:ok, create_activity} = CommonAPI.post(user, %{"status" => "hey"}) -    {:ok, favorite_activity, _} = CommonAPI.favorite(create_activity.id, other_user) +    {:ok, favorite_activity} = CommonAPI.favorite(other_user, create_activity.id)      {:ok, reblog_activity, _} = CommonAPI.repeat(create_activity.id, other_user)      {:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user) @@ -310,7 +310,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do      {:ok, mention_activity} = CommonAPI.post(other_user, %{"status" => "hey @#{user.nickname}"})      {:ok, create_activity} = CommonAPI.post(user, %{"status" => "hey"}) -    {:ok, favorite_activity, _} = CommonAPI.favorite(create_activity.id, other_user) +    {:ok, favorite_activity} = CommonAPI.favorite(other_user, create_activity.id)      {:ok, reblog_activity, _} = CommonAPI.repeat(create_activity.id, other_user)      {:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user) @@ -452,11 +452,24 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do      assert length(json_response(conn, 200)) == 1    end +  @tag capture_log: true    test "see move notifications" do      old_user = insert(:user)      new_user = insert(:user, also_known_as: [old_user.ap_id])      %{user: follower, conn: conn} = oauth_access(["read:notifications"]) +    old_user_url = old_user.ap_id + +    body = +      File.read!("test/fixtures/users_mock/localhost.json") +      |> String.replace("{{nickname}}", old_user.nickname) +      |> Jason.encode!() + +    Tesla.Mock.mock(fn +      %{method: :get, url: ^old_user_url} -> +        %Tesla.Env{status: 200, body: body} +    end) +      User.follow(follower, old_user)      Pleroma.Web.ActivityPub.ActivityPub.move(old_user, new_user)      Pleroma.Tests.ObanHelpers.perform_all() diff --git a/test/web/mastodon_api/controllers/status_controller_test.exs b/test/web/mastodon_api/controllers/status_controller_test.exs index d59974d50..cd9ca4973 100644 --- a/test/web/mastodon_api/controllers/status_controller_test.exs +++ b/test/web/mastodon_api/controllers/status_controller_test.exs @@ -775,7 +775,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        user1 = insert(:user)        user2 = insert(:user)        user3 = insert(:user) -      CommonAPI.favorite(activity.id, user2) +      {:ok, _} = CommonAPI.favorite(user2, activity.id)        {:ok, _bookmark} = Pleroma.Bookmark.create(user2.id, activity.id)        {:ok, reblog_activity1, _object} = CommonAPI.repeat(activity.id, user1)        {:ok, _, _object} = CommonAPI.repeat(activity.id, user2) @@ -850,11 +850,15 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        activity = insert(:note_activity)        post(conn, "/api/v1/statuses/#{activity.id}/favourite") -      assert post(conn, "/api/v1/statuses/#{activity.id}/favourite") |> json_response(200) + +      assert post(conn, "/api/v1/statuses/#{activity.id}/favourite") +             |> json_response(200)      end      test "returns 404 error for a wrong id", %{conn: conn} do -      conn = post(conn, "/api/v1/statuses/1/favourite") +      conn = +        conn +        |> post("/api/v1/statuses/1/favourite")        assert json_response(conn, 404) == %{"error" => "Record not found"}      end @@ -866,7 +870,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      test "unfavorites a status and returns it", %{user: user, conn: conn} do        activity = insert(:note_activity) -      {:ok, _, _} = CommonAPI.favorite(activity.id, user) +      {:ok, _} = CommonAPI.favorite(user, activity.id)        conn = post(conn, "/api/v1/statuses/#{activity.id}/unfavourite") @@ -1176,7 +1180,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      test "returns users who have favorited the status", %{conn: conn, activity: activity} do        other_user = insert(:user) -      {:ok, _, _} = CommonAPI.favorite(activity.id, other_user) +      {:ok, _} = CommonAPI.favorite(other_user, activity.id)        response =          conn @@ -1207,7 +1211,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        other_user = insert(:user)        {:ok, _user_relationship} = User.block(user, other_user) -      {:ok, _, _} = CommonAPI.favorite(activity.id, other_user) +      {:ok, _} = CommonAPI.favorite(other_user, activity.id)        response =          conn @@ -1219,7 +1223,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      test "does not fail on an unauthenticated request", %{activity: activity} do        other_user = insert(:user) -      {:ok, _, _} = CommonAPI.favorite(activity.id, other_user) +      {:ok, _} = CommonAPI.favorite(other_user, activity.id)        response =          build_conn() @@ -1239,7 +1243,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do            "visibility" => "direct"          }) -      {:ok, _, _} = CommonAPI.favorite(activity.id, other_user) +      {:ok, _} = CommonAPI.favorite(other_user, activity.id)        favourited_by_url = "/api/v1/statuses/#{activity.id}/favourited_by" @@ -1399,7 +1403,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      {:ok, _} = CommonAPI.post(other_user, %{"status" => "bla"})      {:ok, activity} = CommonAPI.post(other_user, %{"status" => "traps are happy"}) -    {:ok, _, _} = CommonAPI.favorite(activity.id, user) +    {:ok, _} = CommonAPI.favorite(user, activity.id)      first_conn = get(conn, "/api/v1/favourites") @@ -1416,7 +1420,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do            "Trees Are Never Sad Look At Them Every Once In Awhile They're Quite Beautiful."        }) -    {:ok, _, _} = CommonAPI.favorite(second_activity.id, user) +    {:ok, _} = CommonAPI.favorite(user, second_activity.id)      last_like = status["id"] diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs index 0d1c3ecb3..4435f69ff 100644 --- a/test/web/mastodon_api/views/account_view_test.exs +++ b/test/web/mastodon_api/views/account_view_test.exs @@ -5,13 +5,19 @@  defmodule Pleroma.Web.MastodonAPI.AccountViewTest do    use Pleroma.DataCase -  import Pleroma.Factory -    alias Pleroma.User    alias Pleroma.UserRelationship    alias Pleroma.Web.CommonAPI    alias Pleroma.Web.MastodonAPI.AccountView +  import Pleroma.Factory +  import Tesla.Mock + +  setup do +    mock(fn env -> apply(HttpRequestMock, :request, [env]) end) +    :ok +  end +    test "Represent a user account" do      source_data = %{        "tag" => [ @@ -164,6 +170,17 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do      assert expected == AccountView.render("show.json", %{user: user})    end +  test "Represent a Funkwhale channel" do +    {:ok, user} = +      User.get_or_fetch_by_ap_id( +        "https://channels.tests.funkwhale.audio/federation/actors/compositions" +      ) + +    assert represented = AccountView.render("show.json", %{user: user}) +    assert represented.acct == "compositions@channels.tests.funkwhale.audio" +    assert represented.url == "https://channels.tests.funkwhale.audio/channels/compositions" +  end +    test "Represent a deactivated user for an admin" do      admin = insert(:user, is_admin: true)      deactivated_user = insert(:user, deactivated: true) @@ -192,6 +209,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do        relationships_opt = UserRelationship.view_relationships_option(user, [other_user])        opts = Map.put(opts, :relationships, relationships_opt)        assert expected_result == AccountView.render("relationship.json", opts) + +      assert [expected_result] == +               AccountView.render("relationships.json", %{user: user, targets: [other_user]})      end      @blank_response %{ diff --git a/test/web/mastodon_api/views/notification_view_test.exs b/test/web/mastodon_api/views/notification_view_test.exs index 7965af00a..c3ec9dfec 100644 --- a/test/web/mastodon_api/views/notification_view_test.exs +++ b/test/web/mastodon_api/views/notification_view_test.exs @@ -54,7 +54,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do      user = insert(:user)      another_user = insert(:user)      {:ok, create_activity} = CommonAPI.post(user, %{"status" => "hey"}) -    {:ok, favorite_activity, _object} = CommonAPI.favorite(create_activity.id, another_user) +    {:ok, favorite_activity} = CommonAPI.favorite(another_user, create_activity.id)      {:ok, [notification]} = Notification.create_notifications(favorite_activity)      create_activity = Activity.get_by_id(create_activity.id) @@ -112,11 +112,24 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do      test_notifications_rendering([notification], followed, [])    end +  @tag capture_log: true    test "Move notification" do      old_user = insert(:user)      new_user = insert(:user, also_known_as: [old_user.ap_id])      follower = insert(:user) +    old_user_url = old_user.ap_id + +    body = +      File.read!("test/fixtures/users_mock/localhost.json") +      |> String.replace("{{nickname}}", old_user.nickname) +      |> Jason.encode!() + +    Tesla.Mock.mock(fn +      %{method: :get, url: ^old_user_url} -> +        %Tesla.Env{status: 200, body: body} +    end) +      User.follow(follower, old_user)      Pleroma.Web.ActivityPub.ActivityPub.move(old_user, new_user)      Pleroma.Tests.ObanHelpers.perform_all() diff --git a/test/web/mastodon_api/views/status_view_test.exs b/test/web/mastodon_api/views/status_view_test.exs index 3b6571706..6791c2fb0 100644 --- a/test/web/mastodon_api/views/status_view_test.exs +++ b/test/web/mastodon_api/views/status_view_test.exs @@ -94,6 +94,23 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      Repo.delete(user)      Cachex.clear(:user_cache) +    finger_url = +      "https://localhost/.well-known/webfinger?resource=acct:#{user.nickname}@localhost" + +    Tesla.Mock.mock_global(fn +      %{method: :get, url: "http://localhost/.well-known/host-meta"} -> +        %Tesla.Env{status: 404, body: ""} + +      %{method: :get, url: "https://localhost/.well-known/host-meta"} -> +        %Tesla.Env{status: 404, body: ""} + +      %{ +        method: :get, +        url: ^finger_url +      } -> +        %Tesla.Env{status: 404, body: ""} +    end) +      %{account: ms_user} = StatusView.render("show.json", activity: activity)      assert ms_user.acct == "erroruser@example.com"  | 
