diff options
Diffstat (limited to 'test/web/mastodon_api')
| -rw-r--r-- | test/web/mastodon_api/account_view_test.exs | 2 | ||||
| -rw-r--r-- | test/web/mastodon_api/mastodon_api_controller_test.exs | 122 | 
2 files changed, 121 insertions, 3 deletions
diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs index aa6a1e960..d7487bed9 100644 --- a/test/web/mastodon_api/account_view_test.exs +++ b/test/web/mastodon_api/account_view_test.exs @@ -156,6 +156,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do        blocking: true,        muting: false,        muting_notifications: false, +      subscribing: false,        requested: false,        domain_blocking: false,        showing_reblogs: true, @@ -212,6 +213,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do            following: false,            followed_by: false,            blocking: true, +          subscribing: false,            muting: false,            muting_notifications: false,            requested: false, diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index e16862a48..292cd46b8 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -944,6 +944,58 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do        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    end    describe "reblogging" do @@ -1421,7 +1473,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do      assert id2 == follower2.id      assert [link_header] = get_resp_header(res_conn, "link") -    assert link_header =~ ~r/since_id=#{follower2.id}/ +    assert link_header =~ ~r/min_id=#{follower2.id}/      assert link_header =~ ~r/max_id=#{follower2.id}/    end @@ -1500,7 +1552,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do      assert id2 == following2.id      assert [link_header] = get_resp_header(res_conn, "link") -    assert link_header =~ ~r/since_id=#{following2.id}/ +    assert link_header =~ ~r/min_id=#{following2.id}/      assert link_header =~ ~r/max_id=#{following2.id}/    end @@ -1556,6 +1608,25 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do      assert %{"id" => _id, "muting" => false} = json_response(conn, 200)    end +  test "subscribing / unsubscribing to a user", %{conn: conn} do +    user = insert(:user) +    subscription_target = insert(:user) + +    conn = +      conn +      |> assign(:user, user) +      |> post("/api/v1/pleroma/accounts/#{subscription_target.id}/subscribe") + +    assert %{"id" => _id, "subscribing" => true} = json_response(conn, 200) + +    conn = +      build_conn() +      |> assign(:user, user) +      |> post("/api/v1/pleroma/accounts/#{subscription_target.id}/unsubscribe") + +    assert %{"id" => _id, "subscribing" => false} = json_response(conn, 200) +  end +    test "getting a list of mutes", %{conn: conn} do      user = insert(:user)      other_user = insert(:user) @@ -2311,7 +2382,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do        assert [link_header] = get_resp_header(conn, "link")        assert link_header =~ ~r/media_only=true/ -      assert link_header =~ ~r/since_id=#{notification2.id}/ +      assert link_header =~ ~r/min_id=#{notification2.id}/        assert link_header =~ ~r/max_id=#{notification1.id}/      end    end @@ -2634,4 +2705,49 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do        assert %{"error" => "Record not found"} = json_response(res_conn, 404)      end    end + +  test "Repeated posts that are replies incorrectly have in_reply_to_id null", %{conn: conn} do +    user1 = insert(:user) +    user2 = insert(:user) +    user3 = insert(:user) + +    {:ok, replied_to} = TwitterAPI.create_status(user1, %{"status" => "cofe"}) + +    # Reply to status from another user +    conn1 = +      conn +      |> assign(:user, user2) +      |> post("/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => replied_to.id}) + +    assert %{"content" => "xD", "id" => id} = json_response(conn1, 200) + +    activity = Activity.get_by_id(id) + +    assert activity.data["object"]["inReplyTo"] == replied_to.data["object"]["id"] +    assert activity.data["object"]["inReplyToStatusId"] == replied_to.id + +    # Reblog from the third user +    conn2 = +      conn +      |> assign(:user, user3) +      |> post("/api/v1/statuses/#{activity.id}/reblog") + +    assert %{"reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 1}} = +             json_response(conn2, 200) + +    assert to_string(activity.id) == id + +    # Getting third user status +    conn3 = +      conn +      |> assign(:user, user3) +      |> get("api/v1/timelines/home") + +    [reblogged_activity] = json_response(conn3, 200) + +    assert reblogged_activity["reblog"]["in_reply_to_id"] == replied_to.id + +    replied_to_user = User.get_by_ap_id(replied_to.data["actor"]) +    assert reblogged_activity["reblog"]["in_reply_to_account_id"] == replied_to_user.id +  end  end  | 
