diff options
| author | rinpatch <rinpatch@sdf.org> | 2020-04-16 21:28:52 +0300 | 
|---|---|---|
| committer | rinpatch <rinpatch@sdf.org> | 2020-04-16 21:28:52 +0300 | 
| commit | 942d7467ca28c898f914539ae85ea3044c36ebbc (patch) | |
| tree | 03d909dfcf5974838919076c6ae994515b0c1f84 /test/web | |
| parent | e89078ac2a27bb0a833c982dbb5eef63ddea3cc0 (diff) | |
| parent | 252528a4b9ca3a5d92f1676c44989ad7d8777de1 (diff) | |
| download | pleroma-942d7467ca28c898f914539ae85ea3044c36ebbc.tar.gz pleroma-942d7467ca28c898f914539ae85ea3044c36ebbc.zip  | |
Merge branch 'develop' into features/remove-user-source_data
Diffstat (limited to 'test/web')
12 files changed, 148 insertions, 53 deletions
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs index 573853afa..fbacb3993 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -1239,16 +1239,56 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do          filename: "an_image.jpg"        } -      conn = +      object =          conn          |> assign(:user, user)          |> post("/api/ap/upload_media", %{"file" => image, "description" => desc}) +        |> json_response(:created) -      assert object = json_response(conn, :created)        assert object["name"] == desc        assert object["type"] == "Document"        assert object["actor"] == user.ap_id +      assert [%{"href" => object_href, "mediaType" => object_mediatype}] = object["url"] +      assert is_binary(object_href) +      assert object_mediatype == "image/jpeg" + +      activity_request = %{ +        "@context" => "https://www.w3.org/ns/activitystreams", +        "type" => "Create", +        "object" => %{ +          "type" => "Note", +          "content" => "AP C2S test, attachment", +          "attachment" => [object] +        }, +        "to" => "https://www.w3.org/ns/activitystreams#Public", +        "cc" => [] +      } + +      activity_response = +        conn +        |> assign(:user, user) +        |> post("/users/#{user.nickname}/outbox", activity_request) +        |> json_response(:created) + +      assert activity_response["id"] +      assert activity_response["object"] +      assert activity_response["actor"] == user.ap_id + +      assert %Object{data: %{"attachment" => [attachment]}} = +               Object.normalize(activity_response["object"]) + +      assert attachment["type"] == "Document" +      assert attachment["name"] == desc + +      assert [ +               %{ +                 "href" => ^object_href, +                 "type" => "Link", +                 "mediaType" => ^object_mediatype +               } +             ] = attachment["url"] +      # Fails if unauthenticated        conn        |> post("/api/ap/upload_media", %{"file" => image, "description" => desc})        |> json_response(403) diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 8ddc75669..6057e360a 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -1230,19 +1230,13 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        attachment = %{          "type" => "Link",          "mediaType" => "video/mp4", -        "href" => -          "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4", -        "mimeType" => "video/mp4", -        "size" => 5_015_880,          "url" => [            %{              "href" =>                "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4", -            "mediaType" => "video/mp4", -            "type" => "Link" +            "mediaType" => "video/mp4"            } -        ], -        "width" => 480 +        ]        }        assert object.data["url"] == @@ -1624,7 +1618,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do          })        user_two = insert(:user) -      Pleroma.FollowingRelationship.follow(user_two, user, "accept") +      Pleroma.FollowingRelationship.follow(user_two, user, :follow_accept)        {:ok, activity} = CommonAPI.post(user, %{"status" => "test"})        {:ok, unrelated_activity} = CommonAPI.post(user_two, %{"status" => "test"}) @@ -2063,11 +2057,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do                   %{                     "mediaType" => "video/mp4",                     "url" => [ -                     %{ -                       "href" => "https://peertube.moe/stat-480.mp4", -                       "mediaType" => "video/mp4", -                       "type" => "Link" -                     } +                     %{"href" => "https://peertube.moe/stat-480.mp4", "mediaType" => "video/mp4"}                     ]                   }                 ] @@ -2085,23 +2075,13 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do                   %{                     "mediaType" => "video/mp4",                     "url" => [ -                     %{ -                       "href" => "https://pe.er/stat-480.mp4", -                       "mediaType" => "video/mp4", -                       "type" => "Link" -                     } +                     %{"href" => "https://pe.er/stat-480.mp4", "mediaType" => "video/mp4"}                     ]                   },                   %{ -                   "href" => "https://pe.er/stat-480.mp4",                     "mediaType" => "video/mp4", -                   "mimeType" => "video/mp4",                     "url" => [ -                     %{ -                       "href" => "https://pe.er/stat-480.mp4", -                       "mediaType" => "video/mp4", -                       "type" => "Link" -                     } +                     %{"href" => "https://pe.er/stat-480.mp4", "mediaType" => "video/mp4"}                     ]                   }                 ] diff --git a/test/web/activity_pub/views/user_view_test.exs b/test/web/activity_pub/views/user_view_test.exs index 20578161b..8d00893a5 100644 --- a/test/web/activity_pub/views/user_view_test.exs +++ b/test/web/activity_pub/views/user_view_test.exs @@ -29,7 +29,7 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do      {:ok, user} =        insert(:user) -      |> User.upgrade_changeset(%{fields: fields}) +      |> User.update_changeset(%{fields: fields})        |> User.update_and_set_cache()      assert %{ diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index f02f6ae7a..60ec895f5 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -2273,13 +2273,17 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do            value: :erlang.term_to_binary([])          ) +      Pleroma.Config.TransferTask.load_and_update_env([], false) + +      assert Application.get_env(:logger, :backends) == [] +        conn =          post(conn, "/api/pleroma/admin/config", %{            configs: [              %{                group: config.group,                key: config.key, -              value: [":console", %{"tuple" => ["ExSyslogger", ":ex_syslogger"]}] +              value: [":console"]              }            ]          }) @@ -2290,8 +2294,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do                     "group" => ":logger",                     "key" => ":backends",                     "value" => [ -                     ":console", -                     %{"tuple" => ["ExSyslogger", ":ex_syslogger"]} +                     ":console"                     ],                     "db" => [":backends"]                   } @@ -2299,14 +2302,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do               }        assert Application.get_env(:logger, :backends) == [ -               :console, -               {ExSyslogger, :ex_syslogger} +               :console               ] - -      capture_log(fn -> -        require Logger -        Logger.warn("Ooops...") -      end) =~ "Ooops..."      end      test "saving full setting if value is not keyword", %{conn: conn} do diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs index 5e78c5758..e130736ec 100644 --- a/test/web/common_api/common_api_test.exs +++ b/test/web/common_api/common_api_test.exs @@ -553,7 +553,7 @@ defmodule Pleroma.Web.CommonAPITest do        assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} =                 CommonAPI.follow(follower, followed) -      assert User.get_follow_state(follower, followed) == "pending" +      assert User.get_follow_state(follower, followed) == :follow_pending        assert {:ok, follower} = CommonAPI.unfollow(follower, followed)        assert User.get_follow_state(follower, followed) == nil @@ -575,7 +575,7 @@ defmodule Pleroma.Web.CommonAPITest do        assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} =                 CommonAPI.follow(follower, followed) -      assert User.get_follow_state(follower, followed) == "pending" +      assert User.get_follow_state(follower, followed) == :follow_pending        assert {:ok, follower} = CommonAPI.unfollow(follower, followed)        assert User.get_follow_state(follower, followed) == nil diff --git a/test/web/mastodon_api/controllers/domain_block_controller_test.exs b/test/web/mastodon_api/controllers/domain_block_controller_test.exs index 8d24b3b88..d66190c90 100644 --- a/test/web/mastodon_api/controllers/domain_block_controller_test.exs +++ b/test/web/mastodon_api/controllers/domain_block_controller_test.exs @@ -6,20 +6,29 @@ defmodule Pleroma.Web.MastodonAPI.DomainBlockControllerTest do    use Pleroma.Web.ConnCase    alias Pleroma.User +  alias Pleroma.Web.ApiSpec +  alias Pleroma.Web.ApiSpec.Schemas.DomainBlocksResponse    import Pleroma.Factory +  import OpenApiSpex.TestAssertions    test "blocking / unblocking a domain" do      %{user: user, conn: conn} = oauth_access(["write:blocks"])      other_user = insert(:user, %{ap_id: "https://dogwhistle.zone/@pundit"}) -    ret_conn = post(conn, "/api/v1/domain_blocks", %{"domain" => "dogwhistle.zone"}) +    ret_conn = +      conn +      |> put_req_header("content-type", "application/json") +      |> post("/api/v1/domain_blocks", %{"domain" => "dogwhistle.zone"})      assert %{} = json_response(ret_conn, 200)      user = User.get_cached_by_ap_id(user.ap_id)      assert User.blocks?(user, other_user) -    ret_conn = delete(conn, "/api/v1/domain_blocks", %{"domain" => "dogwhistle.zone"}) +    ret_conn = +      conn +      |> put_req_header("content-type", "application/json") +      |> delete("/api/v1/domain_blocks", %{"domain" => "dogwhistle.zone"})      assert %{} = json_response(ret_conn, 200)      user = User.get_cached_by_ap_id(user.ap_id) @@ -41,5 +50,12 @@ defmodule Pleroma.Web.MastodonAPI.DomainBlockControllerTest do      assert "bad.site" in domain_blocks      assert "even.worse.site" in domain_blocks +    assert_schema(domain_blocks, "DomainBlocksResponse", ApiSpec.spec()) +  end + +  test "DomainBlocksResponse example matches schema" do +    api_spec = ApiSpec.spec() +    schema = DomainBlocksResponse.schema() +    assert_schema(schema.example, "DomainBlocksResponse", api_spec)    end  end diff --git a/test/web/mastodon_api/controllers/follow_request_controller_test.exs b/test/web/mastodon_api/controllers/follow_request_controller_test.exs index dd848821a..d8dbe4800 100644 --- a/test/web/mastodon_api/controllers/follow_request_controller_test.exs +++ b/test/web/mastodon_api/controllers/follow_request_controller_test.exs @@ -21,7 +21,7 @@ defmodule Pleroma.Web.MastodonAPI.FollowRequestControllerTest do        other_user = insert(:user)        {:ok, _activity} = ActivityPub.follow(other_user, user) -      {:ok, other_user} = User.follow(other_user, user, "pending") +      {:ok, other_user} = User.follow(other_user, user, :follow_pending)        assert User.following?(other_user, user) == false @@ -35,7 +35,7 @@ defmodule Pleroma.Web.MastodonAPI.FollowRequestControllerTest do        other_user = insert(:user)        {:ok, _activity} = ActivityPub.follow(other_user, user) -      {:ok, other_user} = User.follow(other_user, user, "pending") +      {:ok, other_user} = User.follow(other_user, user, :follow_pending)        user = User.get_cached_by_id(user.id)        other_user = User.get_cached_by_id(other_user.id) diff --git a/test/web/mastodon_api/controllers/notification_controller_test.exs b/test/web/mastodon_api/controllers/notification_controller_test.exs index 1557937d8..8c815b415 100644 --- a/test/web/mastodon_api/controllers/notification_controller_test.exs +++ b/test/web/mastodon_api/controllers/notification_controller_test.exs @@ -12,6 +12,26 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do    import Pleroma.Factory +  test "does NOT render account/pleroma/relationship if this is disabled by default" do +    clear_config([:extensions, :output_relationships_in_statuses_by_default], false) + +    %{user: user, conn: conn} = oauth_access(["read:notifications"]) +    other_user = insert(:user) + +    {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"}) +    {:ok, [_notification]} = Notification.create_notifications(activity) + +    response = +      conn +      |> assign(:user, user) +      |> get("/api/v1/notifications") +      |> json_response(200) + +    assert Enum.all?(response, fn n -> +             get_in(n, ["account", "pleroma", "relationship"]) == %{} +           end) +  end +    test "list of notifications" do      %{user: user, conn: conn} = oauth_access(["read:notifications"])      other_user = insert(:user) diff --git a/test/web/mastodon_api/controllers/status_controller_test.exs b/test/web/mastodon_api/controllers/status_controller_test.exs index cd9ca4973..162f7b1b2 100644 --- a/test/web/mastodon_api/controllers/status_controller_test.exs +++ b/test/web/mastodon_api/controllers/status_controller_test.exs @@ -1047,6 +1047,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do    end    test "bookmarks" do +    bookmarks_uri = "/api/v1/bookmarks?with_relationships=true" +      %{conn: conn} = oauth_access(["write:bookmarks", "read:bookmarks"])      author = insert(:user) @@ -1068,7 +1070,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      assert json_response(response2, 200)["bookmarked"] == true -    bookmarks = get(conn, "/api/v1/bookmarks") +    bookmarks = get(conn, bookmarks_uri)      assert [json_response(response2, 200), json_response(response1, 200)] ==               json_response(bookmarks, 200) @@ -1077,7 +1079,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      assert json_response(response1, 200)["bookmarked"] == false -    bookmarks = get(conn, "/api/v1/bookmarks") +    bookmarks = get(conn, bookmarks_uri)      assert [json_response(response2, 200)] == json_response(bookmarks, 200)    end diff --git a/test/web/mastodon_api/controllers/timeline_controller_test.exs b/test/web/mastodon_api/controllers/timeline_controller_test.exs index 97b1c3e66..06efdc901 100644 --- a/test/web/mastodon_api/controllers/timeline_controller_test.exs +++ b/test/web/mastodon_api/controllers/timeline_controller_test.exs @@ -20,7 +20,30 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do    describe "home" do      setup do: oauth_access(["read:statuses"]) +    test "does NOT render account/pleroma/relationship if this is disabled by default", %{ +      user: user, +      conn: conn +    } do +      clear_config([:extensions, :output_relationships_in_statuses_by_default], false) + +      other_user = insert(:user) + +      {:ok, _} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"}) + +      response = +        conn +        |> assign(:user, user) +        |> get("/api/v1/timelines/home") +        |> json_response(200) + +      assert Enum.all?(response, fn n -> +               get_in(n, ["account", "pleroma", "relationship"]) == %{} +             end) +    end +      test "the home timeline", %{user: user, conn: conn} do +      uri = "/api/v1/timelines/home?with_relationships=true" +        following = insert(:user, nickname: "followed")        third_user = insert(:user, nickname: "repeated") @@ -28,13 +51,13 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do        {:ok, activity} = CommonAPI.post(third_user, %{"status" => "repeated post"})        {:ok, _, _} = CommonAPI.repeat(activity.id, following) -      ret_conn = get(conn, "/api/v1/timelines/home") +      ret_conn = get(conn, uri)        assert Enum.empty?(json_response(ret_conn, :ok))        {:ok, _user} = User.follow(user, following) -      ret_conn = get(conn, "/api/v1/timelines/home") +      ret_conn = get(conn, uri)        assert [                 %{ @@ -59,7 +82,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do        {:ok, _user} = User.follow(third_user, user) -      ret_conn = get(conn, "/api/v1/timelines/home") +      ret_conn = get(conn, uri)        assert [                 %{ diff --git a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs index 32250f06f..8bf7eb3be 100644 --- a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs +++ b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs @@ -169,6 +169,23 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do      id_one = activity.id      id_two = activity_two.id      assert [%{"id" => ^id_one}, %{"id" => ^id_two}] = result + +    {:ok, %{id: id_three}} = +      CommonAPI.post(other_user, %{ +        "status" => "Bye!", +        "in_reply_to_status_id" => activity.id, +        "in_reply_to_conversation_id" => participation.id +      }) + +    assert [%{"id" => ^id_two}, %{"id" => ^id_three}] = +             conn +             |> get("/api/v1/pleroma/conversations/#{participation.id}/statuses?limit=2") +             |> json_response(:ok) + +    assert [%{"id" => ^id_three}] = +             conn +             |> get("/api/v1/pleroma/conversations/#{participation.id}/statuses?min_id=#{id_two}") +             |> json_response(:ok)    end    test "PATCH /api/v1/pleroma/conversations/:id" do diff --git a/test/web/streamer/streamer_test.exs b/test/web/streamer/streamer_test.exs index b3fe22920..eb082b79f 100644 --- a/test/web/streamer/streamer_test.exs +++ b/test/web/streamer/streamer_test.exs @@ -209,7 +209,7 @@ defmodule Pleroma.Web.StreamerTest do        Pleroma.Config.put([:instance, :skip_thread_containment], false)        author = insert(:user)        user = insert(:user) -      User.follow(user, author, "accept") +      User.follow(user, author, :follow_accept)        activity =          insert(:note_activity, @@ -232,7 +232,7 @@ defmodule Pleroma.Web.StreamerTest do        Pleroma.Config.put([:instance, :skip_thread_containment], true)        author = insert(:user)        user = insert(:user) -      User.follow(user, author, "accept") +      User.follow(user, author, :follow_accept)        activity =          insert(:note_activity, @@ -255,7 +255,7 @@ defmodule Pleroma.Web.StreamerTest do        Pleroma.Config.put([:instance, :skip_thread_containment], false)        author = insert(:user)        user = insert(:user, skip_thread_containment: true) -      User.follow(user, author, "accept") +      User.follow(user, author, :follow_accept)        activity =          insert(:note_activity,  | 
