diff options
Diffstat (limited to 'test/web')
| -rw-r--r-- | test/web/activity_pub/activity_pub_controller_test.exs | 6 | ||||
| -rw-r--r-- | test/web/activity_pub/activity_pub_test.exs | 15 | ||||
| -rw-r--r-- | test/web/activity_pub/views/user_view_test.exs | 16 | ||||
| -rw-r--r-- | test/web/admin_api/admin_api_controller_test.exs | 4 | ||||
| -rw-r--r-- | test/web/mastodon_api/controllers/notification_controller_test.exs | 299 | ||||
| -rw-r--r-- | test/web/mastodon_api/mastodon_api_controller_test.exs | 310 | ||||
| -rw-r--r-- | test/web/mastodon_api/views/account_view_test.exs | 12 | ||||
| -rw-r--r-- | test/web/oauth/oauth_controller_test.exs | 9 | ||||
| -rw-r--r-- | test/web/ostatus/ostatus_controller_test.exs | 22 | ||||
| -rw-r--r-- | test/web/pleroma_api/emoji_api_controller_test.exs | 26 | 
10 files changed, 382 insertions, 337 deletions
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs index 9e8e420ec..ab52044ae 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -479,7 +479,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do          conn          |> assign(:user, user)          |> put_req_header("accept", "application/activity+json") -        |> get("/users/#{user.nickname}/inbox") +        |> get("/users/#{user.nickname}/inbox?page=true")        assert response(conn, 200) =~ note_object.data["content"]      end @@ -567,7 +567,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do        conn =          conn          |> put_req_header("accept", "application/activity+json") -        |> get("/users/#{user.nickname}/outbox") +        |> get("/users/#{user.nickname}/outbox?page=true")        assert response(conn, 200) =~ note_object.data["content"]      end @@ -579,7 +579,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do        conn =          conn          |> put_req_header("accept", "application/activity+json") -        |> get("/users/#{user.nickname}/outbox") +        |> get("/users/#{user.nickname}/outbox?page=true")        assert response(conn, 200) =~ announce_activity.data["object"]      end diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 4100108a5..f28fd6871 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -647,6 +647,21 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do        assert last == last_expected      end +    test "paginates via offset/limit" do +      _first_activities = ActivityBuilder.insert_list(10) +      activities = ActivityBuilder.insert_list(10) +      _later_activities = ActivityBuilder.insert_list(10) +      first_expected = List.first(activities) + +      activities = +        ActivityPub.fetch_public_activities(%{"page" => "2", "page_size" => "20"}, :offset) + +      first = List.first(activities) + +      assert length(activities) == 20 +      assert first == first_expected +    end +      test "doesn't return reblogs for users for whom reblogs have been muted" do        activity = insert(:note_activity)        user = insert(:user) diff --git a/test/web/activity_pub/views/user_view_test.exs b/test/web/activity_pub/views/user_view_test.exs index 78b0408ee..3155749aa 100644 --- a/test/web/activity_pub/views/user_view_test.exs +++ b/test/web/activity_pub/views/user_view_test.exs @@ -159,7 +159,7 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do      end    end -  test "outbox paginates correctly" do +  test "activity collection page aginates correctly" do      user = insert(:user)      posts = @@ -171,13 +171,21 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do      # outbox sorts chronologically, newest first, with ten per page      posts = Enum.reverse(posts) -    %{"first" => %{"next" => next_url}} = -      UserView.render("outbox.json", %{user: user, max_id: nil}) +    %{"next" => next_url} = +      UserView.render("activity_collection_page.json", %{ +        iri: "#{user.ap_id}/outbox", +        activities: Enum.take(posts, 10) +      })      next_id = Enum.at(posts, 9).id      assert next_url =~ next_id -    %{"next" => next_url} = UserView.render("outbox.json", %{user: user, max_id: next_id}) +    %{"next" => next_url} = +      UserView.render("activity_collection_page.json", %{ +        iri: "#{user.ap_id}/outbox", +        activities: Enum.take(Enum.drop(posts, 10), 10) +      }) +      next_id = Enum.at(posts, 19).id      assert next_url =~ next_id    end diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index f00e02a7a..00e64692a 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -586,7 +586,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do        |> put_req_header("accept", "application/json")        |> get("/api/pleroma/admin/users/#{user.nickname}/password_reset") -    assert conn.status == 200 +    resp = json_response(conn, 200) + +    assert Regex.match?(~r/(http:\/\/|https:\/\/)/, resp["link"])    end    describe "GET /api/pleroma/admin/users" do diff --git a/test/web/mastodon_api/controllers/notification_controller_test.exs b/test/web/mastodon_api/controllers/notification_controller_test.exs new file mode 100644 index 000000000..e4137e92c --- /dev/null +++ b/test/web/mastodon_api/controllers/notification_controller_test.exs @@ -0,0 +1,299 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do +  use Pleroma.Web.ConnCase + +  alias Pleroma.Notification +  alias Pleroma.Repo +  alias Pleroma.User +  alias Pleroma.Web.CommonAPI + +  import Pleroma.Factory + +  test "list of notifications", %{conn: conn} do +    user = insert(:user) +    other_user = insert(:user) + +    {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"}) + +    {:ok, [_notification]} = Notification.create_notifications(activity) + +    conn = +      conn +      |> assign(:user, user) +      |> get("/api/v1/notifications") + +    expected_response = +      "hi <span class=\"h-card\"><a data-user=\"#{user.id}\" class=\"u-url mention\" href=\"#{ +        user.ap_id +      }\" rel=\"ugc\">@<span>#{user.nickname}</span></a></span>" + +    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} = CommonAPI.post(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 <span class=\"h-card\"><a data-user=\"#{user.id}\" class=\"u-url mention\" href=\"#{ +        user.ap_id +      }\" rel=\"ugc\">@<span>#{user.nickname}</span></a></span>" + +    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} = CommonAPI.post(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} = CommonAPI.post(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 + +  test "paginates notifications using min_id, since_id, max_id, and limit", %{conn: conn} do +    user = insert(:user) +    other_user = insert(:user) + +    {:ok, activity1} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"}) +    {:ok, activity2} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"}) +    {:ok, activity3} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"}) +    {:ok, activity4} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"}) + +    notification1_id = get_notification_id_by_activity(activity1) +    notification2_id = get_notification_id_by_activity(activity2) +    notification3_id = get_notification_id_by_activity(activity3) +    notification4_id = get_notification_id_by_activity(activity4) + +    conn = assign(conn, :user, user) + +    # min_id +    result = +      conn +      |> get("/api/v1/notifications?limit=2&min_id=#{notification1_id}") +      |> json_response(:ok) + +    assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result + +    # since_id +    result = +      conn +      |> get("/api/v1/notifications?limit=2&since_id=#{notification1_id}") +      |> json_response(:ok) + +    assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result + +    # max_id +    result = +      conn +      |> get("/api/v1/notifications?limit=2&max_id=#{notification4_id}") +      |> json_response(:ok) + +    assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result +  end + +  test "filters notifications using exclude_types", %{conn: conn} do +    user = insert(:user) +    other_user = insert(:user) + +    {: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, reblog_activity, _} = CommonAPI.repeat(create_activity.id, other_user) +    {:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user) + +    mention_notification_id = get_notification_id_by_activity(mention_activity) +    favorite_notification_id = get_notification_id_by_activity(favorite_activity) +    reblog_notification_id = get_notification_id_by_activity(reblog_activity) +    follow_notification_id = get_notification_id_by_activity(follow_activity) + +    conn = assign(conn, :user, user) + +    conn_res = +      get(conn, "/api/v1/notifications", %{exclude_types: ["mention", "favourite", "reblog"]}) + +    assert [%{"id" => ^follow_notification_id}] = json_response(conn_res, 200) + +    conn_res = +      get(conn, "/api/v1/notifications", %{exclude_types: ["favourite", "reblog", "follow"]}) + +    assert [%{"id" => ^mention_notification_id}] = json_response(conn_res, 200) + +    conn_res = +      get(conn, "/api/v1/notifications", %{exclude_types: ["reblog", "follow", "mention"]}) + +    assert [%{"id" => ^favorite_notification_id}] = json_response(conn_res, 200) + +    conn_res = +      get(conn, "/api/v1/notifications", %{exclude_types: ["follow", "mention", "favourite"]}) + +    assert [%{"id" => ^reblog_notification_id}] = json_response(conn_res, 200) +  end + +  test "destroy multiple", %{conn: conn} do +    user = insert(:user) +    other_user = insert(:user) + +    {:ok, activity1} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"}) +    {:ok, activity2} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"}) +    {:ok, activity3} = CommonAPI.post(user, %{"status" => "hi @#{other_user.nickname}"}) +    {:ok, activity4} = CommonAPI.post(user, %{"status" => "hi @#{other_user.nickname}"}) + +    notification1_id = get_notification_id_by_activity(activity1) +    notification2_id = get_notification_id_by_activity(activity2) +    notification3_id = get_notification_id_by_activity(activity3) +    notification4_id = get_notification_id_by_activity(activity4) + +    conn = assign(conn, :user, user) + +    result = +      conn +      |> get("/api/v1/notifications") +      |> json_response(:ok) + +    assert [%{"id" => ^notification2_id}, %{"id" => ^notification1_id}] = result + +    conn2 = +      conn +      |> assign(:user, other_user) + +    result = +      conn2 +      |> get("/api/v1/notifications") +      |> json_response(:ok) + +    assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result + +    conn_destroy = +      conn +      |> delete("/api/v1/notifications/destroy_multiple", %{ +        "ids" => [notification1_id, notification2_id] +      }) + +    assert json_response(conn_destroy, 200) == %{} + +    result = +      conn2 +      |> get("/api/v1/notifications") +      |> json_response(:ok) + +    assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result +  end + +  test "doesn't see notifications after muting user with notifications", %{conn: conn} do +    user = insert(:user) +    user2 = insert(:user) + +    {:ok, _, _, _} = CommonAPI.follow(user, user2) +    {:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"}) + +    conn = assign(conn, :user, user) + +    conn = get(conn, "/api/v1/notifications") + +    assert length(json_response(conn, 200)) == 1 + +    {:ok, user} = User.mute(user, user2) + +    conn = assign(build_conn(), :user, user) +    conn = get(conn, "/api/v1/notifications") + +    assert json_response(conn, 200) == [] +  end + +  test "see notifications after muting user without notifications", %{conn: conn} do +    user = insert(:user) +    user2 = insert(:user) + +    {:ok, _, _, _} = CommonAPI.follow(user, user2) +    {:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"}) + +    conn = assign(conn, :user, user) + +    conn = get(conn, "/api/v1/notifications") + +    assert length(json_response(conn, 200)) == 1 + +    {:ok, user} = User.mute(user, user2, false) + +    conn = assign(build_conn(), :user, user) +    conn = get(conn, "/api/v1/notifications") + +    assert length(json_response(conn, 200)) == 1 +  end + +  test "see notifications after muting user with notifications and with_muted parameter", %{ +    conn: conn +  } do +    user = insert(:user) +    user2 = insert(:user) + +    {:ok, _, _, _} = CommonAPI.follow(user, user2) +    {:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"}) + +    conn = assign(conn, :user, user) + +    conn = get(conn, "/api/v1/notifications") + +    assert length(json_response(conn, 200)) == 1 + +    {:ok, user} = User.mute(user, user2) + +    conn = assign(build_conn(), :user, user) +    conn = get(conn, "/api/v1/notifications", %{"with_muted" => "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) +    |> Map.get(:id) +    |> to_string() +  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 0bff7e5da..1e9829886 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -999,299 +999,6 @@ 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} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"}) - -      {:ok, [_notification]} = Notification.create_notifications(activity) - -      conn = -        conn -        |> assign(:user, user) -        |> get("/api/v1/notifications") - -      expected_response = -        ~s(hi <span class="h-card"><a data-user="#{user.id}" class="u-url mention" href="#{ -          user.ap_id -        }" rel="ugc">@<span>#{user.nickname}</span></a></span>) - -      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} = CommonAPI.post(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 = -        ~s(hi <span class="h-card"><a data-user="#{user.id}" class="u-url mention" href="#{ -          user.ap_id -        }" rel="ugc">@<span>#{user.nickname}</span></a></span>) - -      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} = CommonAPI.post(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} = CommonAPI.post(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 - -    test "paginates notifications using min_id, since_id, max_id, and limit", %{conn: conn} do -      user = insert(:user) -      other_user = insert(:user) - -      {:ok, activity1} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"}) -      {:ok, activity2} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"}) -      {:ok, activity3} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"}) -      {:ok, activity4} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"}) - -      notification1_id = Repo.get_by(Notification, activity_id: activity1.id).id |> to_string() -      notification2_id = Repo.get_by(Notification, activity_id: activity2.id).id |> to_string() -      notification3_id = Repo.get_by(Notification, activity_id: activity3.id).id |> to_string() -      notification4_id = Repo.get_by(Notification, activity_id: activity4.id).id |> to_string() - -      conn = -        conn -        |> assign(:user, user) - -      # min_id -      conn_res = -        conn -        |> get("/api/v1/notifications?limit=2&min_id=#{notification1_id}") - -      result = json_response(conn_res, 200) -      assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result - -      # since_id -      conn_res = -        conn -        |> get("/api/v1/notifications?limit=2&since_id=#{notification1_id}") - -      result = json_response(conn_res, 200) -      assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result - -      # max_id -      conn_res = -        conn -        |> get("/api/v1/notifications?limit=2&max_id=#{notification4_id}") - -      result = json_response(conn_res, 200) -      assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result -    end - -    test "filters notifications using exclude_types", %{conn: conn} do -      user = insert(:user) -      other_user = insert(:user) - -      {: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, reblog_activity, _} = CommonAPI.repeat(create_activity.id, other_user) -      {:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user) - -      mention_notification_id = -        Repo.get_by(Notification, activity_id: mention_activity.id).id |> to_string() - -      favorite_notification_id = -        Repo.get_by(Notification, activity_id: favorite_activity.id).id |> to_string() - -      reblog_notification_id = -        Repo.get_by(Notification, activity_id: reblog_activity.id).id |> to_string() - -      follow_notification_id = -        Repo.get_by(Notification, activity_id: follow_activity.id).id |> to_string() - -      conn = -        conn -        |> assign(:user, user) - -      conn_res = -        get(conn, "/api/v1/notifications", %{exclude_types: ["mention", "favourite", "reblog"]}) - -      assert [%{"id" => ^follow_notification_id}] = json_response(conn_res, 200) - -      conn_res = -        get(conn, "/api/v1/notifications", %{exclude_types: ["favourite", "reblog", "follow"]}) - -      assert [%{"id" => ^mention_notification_id}] = json_response(conn_res, 200) - -      conn_res = -        get(conn, "/api/v1/notifications", %{exclude_types: ["reblog", "follow", "mention"]}) - -      assert [%{"id" => ^favorite_notification_id}] = json_response(conn_res, 200) - -      conn_res = -        get(conn, "/api/v1/notifications", %{exclude_types: ["follow", "mention", "favourite"]}) - -      assert [%{"id" => ^reblog_notification_id}] = json_response(conn_res, 200) -    end - -    test "destroy multiple", %{conn: conn} do -      user = insert(:user) -      other_user = insert(:user) - -      {:ok, activity1} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"}) -      {:ok, activity2} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"}) -      {:ok, activity3} = CommonAPI.post(user, %{"status" => "hi @#{other_user.nickname}"}) -      {:ok, activity4} = CommonAPI.post(user, %{"status" => "hi @#{other_user.nickname}"}) - -      notification1_id = Repo.get_by(Notification, activity_id: activity1.id).id |> to_string() -      notification2_id = Repo.get_by(Notification, activity_id: activity2.id).id |> to_string() -      notification3_id = Repo.get_by(Notification, activity_id: activity3.id).id |> to_string() -      notification4_id = Repo.get_by(Notification, activity_id: activity4.id).id |> to_string() - -      conn = -        conn -        |> assign(:user, user) - -      conn_res = -        conn -        |> get("/api/v1/notifications") - -      result = json_response(conn_res, 200) -      assert [%{"id" => ^notification2_id}, %{"id" => ^notification1_id}] = result - -      conn2 = -        conn -        |> assign(:user, other_user) - -      conn_res = -        conn2 -        |> get("/api/v1/notifications") - -      result = json_response(conn_res, 200) -      assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result - -      conn_destroy = -        conn -        |> delete("/api/v1/notifications/destroy_multiple", %{ -          "ids" => [notification1_id, notification2_id] -        }) - -      assert json_response(conn_destroy, 200) == %{} - -      conn_res = -        conn2 -        |> get("/api/v1/notifications") - -      result = json_response(conn_res, 200) -      assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result -    end - -    test "doesn't see notifications after muting user with notifications", %{conn: conn} do -      user = insert(:user) -      user2 = insert(:user) - -      {:ok, _, _, _} = CommonAPI.follow(user, user2) -      {:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"}) - -      conn = assign(conn, :user, user) - -      conn = get(conn, "/api/v1/notifications") - -      assert length(json_response(conn, 200)) == 1 - -      {:ok, user} = User.mute(user, user2) - -      conn = assign(build_conn(), :user, user) -      conn = get(conn, "/api/v1/notifications") - -      assert json_response(conn, 200) == [] -    end - -    test "see notifications after muting user without notifications", %{conn: conn} do -      user = insert(:user) -      user2 = insert(:user) - -      {:ok, _, _, _} = CommonAPI.follow(user, user2) -      {:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"}) - -      conn = assign(conn, :user, user) - -      conn = get(conn, "/api/v1/notifications") - -      assert length(json_response(conn, 200)) == 1 - -      {:ok, user} = User.mute(user, user2, false) - -      conn = assign(build_conn(), :user, user) -      conn = get(conn, "/api/v1/notifications") - -      assert length(json_response(conn, 200)) == 1 -    end - -    test "see notifications after muting user with notifications and with_muted parameter", %{ -      conn: conn -    } do -      user = insert(:user) -      user2 = insert(:user) - -      {:ok, _, _, _} = CommonAPI.follow(user, user2) -      {:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"}) - -      conn = assign(conn, :user, user) - -      conn = get(conn, "/api/v1/notifications") - -      assert length(json_response(conn, 200)) == 1 - -      {:ok, user} = User.mute(user, user2) - -      conn = assign(build_conn(), :user, user) -      conn = get(conn, "/api/v1/notifications", %{"with_muted" => "true"}) - -      assert length(json_response(conn, 200)) == 1 -    end -  end -    describe "reblogging" do      test "reblogs and returns the reblogged status", %{conn: conn} do        activity = insert(:note_activity) @@ -2654,14 +2361,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do      {:ok, _} = CommonAPI.post(user, %{"status" => "cofe"})      # Stats should count users with missing or nil `info.deactivated` value -    user = User.get_cached_by_id(user.id) -    info_change = Changeset.change(user.info, %{deactivated: nil})      {:ok, _user} = -      user -      |> Changeset.change() -      |> Changeset.put_embed(:info, info_change) -      |> User.update_and_set_cache() +      user.id +      |> User.get_cached_by_id() +      |> User.update_info(&Changeset.change(&1, %{deactivated: nil}))      Pleroma.Stats.force_update() @@ -4108,13 +3812,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do    describe "POST /api/v1/pleroma/accounts/confirmation_resend" do      setup do -      user = insert(:user) -      info_change = User.Info.confirmation_changeset(user.info, need_confirmation: true) -        {:ok, user} = -        user -        |> Changeset.change() -        |> Changeset.put_embed(:info, info_change) +        insert(:user) +        |> User.change_info(&User.Info.confirmation_changeset(&1, need_confirmation: true))          |> Repo.update()        assert user.info.confirmation_pending diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs index 6206107f7..f2f334992 100644 --- a/test/web/mastodon_api/views/account_view_test.exs +++ b/test/web/mastodon_api/views/account_view_test.exs @@ -67,7 +67,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do        source: %{          note: "valid html",          sensitive: false, -        pleroma: %{}, +        pleroma: %{ +          discoverable: false +        },          fields: []        },        pleroma: %{ @@ -137,7 +139,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do        source: %{          note: user.bio,          sensitive: false, -        pleroma: %{}, +        pleroma: %{ +          discoverable: false +        },          fields: []        },        pleroma: %{ @@ -310,7 +314,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do        source: %{          note: user.bio,          sensitive: false, -        pleroma: %{}, +        pleroma: %{ +          discoverable: false +        },          fields: []        },        pleroma: %{ diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs index 8b88fd784..0cf755806 100644 --- a/test/web/oauth/oauth_controller_test.exs +++ b/test/web/oauth/oauth_controller_test.exs @@ -7,6 +7,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do    import Pleroma.Factory    alias Pleroma.Repo +  alias Pleroma.User    alias Pleroma.Web.OAuth.Authorization    alias Pleroma.Web.OAuth.OAuthController    alias Pleroma.Web.OAuth.Token @@ -775,15 +776,11 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do      test "rejects token exchange for valid credentials belonging to unconfirmed user and confirmation is required" do        Pleroma.Config.put([:instance, :account_activation_required], true) -        password = "testpassword" -      user = insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt(password)) -      info_change = Pleroma.User.Info.confirmation_changeset(user.info, need_confirmation: true)        {:ok, user} = -        user -        |> Ecto.Changeset.change() -        |> Ecto.Changeset.put_embed(:info, info_change) +        insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt(password)) +        |> User.change_info(&User.Info.confirmation_changeset(&1, need_confirmation: true))          |> Repo.update()        refute Pleroma.User.auth_active?(user) diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs index ec96f0012..2b40fb47e 100644 --- a/test/web/ostatus/ostatus_controller_test.exs +++ b/test/web/ostatus/ostatus_controller_test.exs @@ -50,20 +50,16 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do                 assert response(conn, 200)               end) =~ "[error]" -      # Set a wrong magic-key for a user so it has to refetch -      salmon_user = User.get_cached_by_ap_id("http://gs.example.org:4040/index.php/user/1") -        # Wrong key -      info_cng = -        User.Info.remote_user_creation(salmon_user.info, %{ -          magic_key: -            "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwrong1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB" -        }) - -      salmon_user -      |> Ecto.Changeset.change() -      |> Ecto.Changeset.put_embed(:info, info_cng) -      |> User.update_and_set_cache() +      info = %{ +        magic_key: +          "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwrong1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB" +      } + +      # Set a wrong magic-key for a user so it has to refetch +      "http://gs.example.org:4040/index.php/user/1" +      |> User.get_cached_by_ap_id() +      |> User.update_info(&User.Info.remote_user_creation(&1, info))        assert capture_log(fn ->                 conn = diff --git a/test/web/pleroma_api/emoji_api_controller_test.exs b/test/web/pleroma_api/emoji_api_controller_test.exs index c5a553692..93a507a01 100644 --- a/test/web/pleroma_api/emoji_api_controller_test.exs +++ b/test/web/pleroma_api/emoji_api_controller_test.exs @@ -33,6 +33,28 @@ defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do      refute pack["pack"]["can-download"]    end +  test "listing remote packs" do +    admin = insert(:user, info: %{is_admin: true}) +    conn = build_conn() |> assign(:user, admin) + +    resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200) + +    mock(fn +      %{method: :get, url: "https://example.com/.well-known/nodeinfo"} -> +        json(%{links: [%{href: "https://example.com/nodeinfo/2.1.json"}]}) + +      %{method: :get, url: "https://example.com/nodeinfo/2.1.json"} -> +        json(%{metadata: %{features: ["shareable_emoji_packs"]}}) + +      %{method: :get, url: "https://example.com/api/pleroma/emoji/packs"} -> +        json(resp) +    end) + +    assert conn +           |> post(emoji_api_path(conn, :list_from), %{instance_address: "https://example.com"}) +           |> json_response(200) == resp +  end +    test "downloading a shared pack from download_shared" do      conn = build_conn() @@ -55,13 +77,13 @@ defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do      mock(fn        %{method: :get, url: "https://old-instance/.well-known/nodeinfo"} -> -        json([%{href: "https://old-instance/nodeinfo/2.1.json"}]) +        json(%{links: [%{href: "https://old-instance/nodeinfo/2.1.json"}]})        %{method: :get, url: "https://old-instance/nodeinfo/2.1.json"} ->          json(%{metadata: %{features: []}})        %{method: :get, url: "https://example.com/.well-known/nodeinfo"} -> -        json([%{href: "https://example.com/nodeinfo/2.1.json"}]) +        json(%{links: [%{href: "https://example.com/nodeinfo/2.1.json"}]})        %{method: :get, url: "https://example.com/nodeinfo/2.1.json"} ->          json(%{metadata: %{features: ["shareable_emoji_packs"]}})  | 
