diff options
Diffstat (limited to 'test/web/twitter_api')
3 files changed, 143 insertions, 8 deletions
| diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs index 2ac32aeb2..ef0294140 100644 --- a/test/web/twitter_api/representers/activity_representer_test.exs +++ b/test/web/twitter_api/representers/activity_representer_test.exs @@ -1,5 +1,5 @@  # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>  # SPDX-License-Identifier: AGPL-3.0-only  defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do @@ -107,7 +107,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do            "published" => date,            "type" => "Note",            "content" => content_html, -          "summary" => "2hu", +          "summary" => "2hu :2hu:",            "inReplyToStatusId" => 213_123,            "attachment" => [              object @@ -129,7 +129,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do      }      expected_html = -      "<p>2hu</p>alert('YAY')Some <img height=\"32px\" width=\"32px\" alt=\"2hu\" title=\"2hu\" src=\"corndog.png\" /> content mentioning <a href=\"#{ +      "<p>2hu <img height=\"32px\" width=\"32px\" alt=\"2hu\" title=\"2hu\" src=\"corndog.png\" /></p>alert('YAY')Some <img height=\"32px\" width=\"32px\" alt=\"2hu\" title=\"2hu\" src=\"corndog.png\" /> content mentioning <a href=\"#{          mentioned_user.ap_id        }\">@shp</a>" @@ -138,7 +138,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do        "user" => UserView.render("show.json", %{user: user, for: follower}),        "is_local" => false,        "statusnet_html" => expected_html, -      "text" => "2hu" <> content, +      "text" => "2hu :2hu:" <> content,        "is_post_verb" => true,        "created_at" => "Tue May 24 13:26:08 +0000 2016",        "in_reply_to_status_id" => 213_123, @@ -157,13 +157,16 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do        "repeat_num" => 3,        "favorited" => false,        "repeated" => false, +      "pinned" => false,        "external_url" => "some url",        "tags" => ["nsfw", "content", "mentioning"],        "activity_type" => "post",        "possibly_sensitive" => true,        "uri" => activity.data["object"]["id"],        "visibility" => "direct", -      "summary" => "2hu" +      "summary" => "2hu :2hu:", +      "summary_html" => +        "2hu <img height=\"32px\" width=\"32px\" alt=\"2hu\" title=\"2hu\" src=\"corndog.png\" />"      }      assert ActivityRepresenter.to_map(activity, %{ diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index c41f615ac..5f13e7959 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -1,5 +1,5 @@  # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>  # SPDX-License-Identifier: AGPL-3.0-only  defmodule Pleroma.Web.TwitterAPI.ControllerTest do @@ -1082,6 +1082,31 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do        assert Enum.sort(expected) == Enum.sort(result)      end +    test "it returns 20 followers per page", %{conn: conn} do +      user = insert(:user) +      followers = insert_list(21, :user) + +      Enum.each(followers, fn follower -> +        User.follow(follower, user) +      end) + +      res_conn = +        conn +        |> assign(:user, user) +        |> get("/api/statuses/followers") + +      result = json_response(res_conn, 200) +      assert length(result) == 20 + +      res_conn = +        conn +        |> assign(:user, user) +        |> get("/api/statuses/followers?page=2") + +      result = json_response(res_conn, 200) +      assert length(result) == 1 +    end +      test "it returns a given user's followers with user_id", %{conn: conn} do        user = insert(:user)        follower_one = insert(:user) @@ -1183,6 +1208,32 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do        assert Enum.sort(expected) == Enum.sort(result)      end +    test "it returns 20 friends per page", %{conn: conn} do +      user = insert(:user) +      followeds = insert_list(21, :user) + +      {:ok, user} = +        Enum.reduce(followeds, {:ok, user}, fn followed, {:ok, user} -> +          User.follow(user, followed) +        end) + +      res_conn = +        conn +        |> assign(:user, user) +        |> get("/api/statuses/friends") + +      result = json_response(res_conn, 200) +      assert length(result) == 20 + +      res_conn = +        conn +        |> assign(:user, user) +        |> get("/api/statuses/friends", %{page: 2}) + +      result = json_response(res_conn, 200) +      assert length(result) == 1 +    end +      test "it returns a given user's friends with user_id", %{conn: conn} do        user = insert(:user)        followed_one = insert(:user) @@ -1694,4 +1745,79 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do        assert object.data["name"] == description      end    end + +  describe "POST /api/statuses/user_timeline.json?user_id=:user_id&pinned=true" do +    test "it returns a list of pinned statuses", %{conn: conn} do +      Pleroma.Config.put([:instance, :max_pinned_statuses], 1) + +      user = insert(:user, %{name: "egor"}) +      {:ok, %{id: activity_id}} = CommonAPI.post(user, %{"status" => "HI!!!"}) +      {:ok, _} = CommonAPI.pin(activity_id, user) + +      resp = +        conn +        |> get("/api/statuses/user_timeline.json", %{user_id: user.id, pinned: true}) +        |> json_response(200) + +      assert length(resp) == 1 +      assert [%{"id" => ^activity_id, "pinned" => true}] = resp +    end +  end + +  describe "POST /api/statuses/pin/:id" do +    setup do +      Pleroma.Config.put([:instance, :max_pinned_statuses], 1) +      [user: insert(:user)] +    end + +    test "without valid credentials", %{conn: conn} do +      note_activity = insert(:note_activity) +      conn = post(conn, "/api/statuses/pin/#{note_activity.id}.json") +      assert json_response(conn, 403) == %{"error" => "Invalid credentials."} +    end + +    test "with credentials", %{conn: conn, user: user} do +      {:ok, activity} = CommonAPI.post(user, %{"status" => "test!"}) + +      request_path = "/api/statuses/pin/#{activity.id}.json" + +      response = +        conn +        |> with_credentials(user.nickname, "test") +        |> post(request_path) + +      user = refresh_record(user) + +      assert json_response(response, 200) == ActivityRepresenter.to_map(activity, %{user: user}) +    end +  end + +  describe "POST /api/statuses/unpin/:id" do +    setup do +      Pleroma.Config.put([:instance, :max_pinned_statuses], 1) +      [user: insert(:user)] +    end + +    test "without valid credentials", %{conn: conn} do +      note_activity = insert(:note_activity) +      conn = post(conn, "/api/statuses/unpin/#{note_activity.id}.json") +      assert json_response(conn, 403) == %{"error" => "Invalid credentials."} +    end + +    test "with credentials", %{conn: conn, user: user} do +      {:ok, activity} = CommonAPI.post(user, %{"status" => "test!"}) +      {:ok, activity} = CommonAPI.pin(activity.id, user) + +      request_path = "/api/statuses/unpin/#{activity.id}.json" + +      response = +        conn +        |> with_credentials(user.nickname, "test") +        |> post(request_path) + +      user = refresh_record(user) + +      assert json_response(response, 200) == ActivityRepresenter.to_map(activity, %{user: user}) +    end +  end  end diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index bd4878e98..8b5a16add 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -1,5 +1,5 @@  # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>  # SPDX-License-Identifier: AGPL-3.0-only  defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do @@ -81,10 +81,13 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do      result = ActivityView.render("activity.json", activity: activity) -    expected = +    expected = ":woollysocks: meow" + +    expected_html =        "<img height=\"32px\" width=\"32px\" alt=\"woollysocks\" title=\"woollysocks\" src=\"http://localhost:4001/finmoji/128px/woollysocks-128.png\" /> meow"      assert result["summary"] == expected +    assert result["summary_html"] == expected_html    end    test "a create activity with a summary containing invalid HTML" do @@ -99,6 +102,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do      expected = "meow"      assert result["summary"] == expected +    assert result["summary_html"] == expected    end    test "a create activity with a note" do @@ -132,8 +136,10 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do        "possibly_sensitive" => false,        "repeat_num" => 0,        "repeated" => false, +      "pinned" => false,        "statusnet_conversation_id" => convo_id,        "summary" => "", +      "summary_html" => "",        "statusnet_html" =>          "Hey <span><a data-user=\"#{other_user.id}\" href=\"#{other_user.ap_id}\">@<span>shp</span></a></span>!",        "tags" => [], | 
