diff options
Diffstat (limited to 'test/web/mastodon_api/controllers')
10 files changed, 560 insertions, 404 deletions
diff --git a/test/web/mastodon_api/controllers/account_controller_test.exs b/test/web/mastodon_api/controllers/account_controller_test.exs index 256a8b304..280bd6aca 100644 --- a/test/web/mastodon_api/controllers/account_controller_test.exs +++ b/test/web/mastodon_api/controllers/account_controller_test.exs @@ -222,13 +222,40 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do    describe "user timelines" do      setup do: oauth_access(["read:statuses"]) +    test "works with announces that are just addressed to public", %{conn: conn} do +      user = insert(:user, ap_id: "https://honktest/u/test", local: false) +      other_user = insert(:user) + +      {:ok, post} = CommonAPI.post(other_user, %{status: "bonkeronk"}) + +      {:ok, announce, _} = +        %{ +          "@context" => "https://www.w3.org/ns/activitystreams", +          "actor" => "https://honktest/u/test", +          "id" => "https://honktest/u/test/bonk/1793M7B9MQ48847vdx", +          "object" => post.data["object"], +          "published" => "2019-06-25T19:33:58Z", +          "to" => ["https://www.w3.org/ns/activitystreams#Public"], +          "type" => "Announce" +        } +        |> ActivityPub.persist(local: false) + +      assert resp = +               conn +               |> get("/api/v1/accounts/#{user.id}/statuses") +               |> json_response_and_validate_schema(200) + +      assert [%{"id" => id}] = resp +      assert id == announce.id +    end +      test "respects blocks", %{user: user_one, conn: conn} do        user_two = insert(:user)        user_three = insert(:user)        User.block(user_one, user_two) -      {:ok, activity} = CommonAPI.post(user_two, %{"status" => "User one sux0rz"}) +      {:ok, activity} = CommonAPI.post(user_two, %{status: "User one sux0rz"})        {:ok, repeat, _} = CommonAPI.repeat(activity.id, user_three)        assert resp = @@ -271,16 +298,16 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do        {:ok, _user_three} = User.follow(user_three, user_one) -      {:ok, activity} = CommonAPI.post(user_one, %{"status" => "HI!!!"}) +      {:ok, activity} = CommonAPI.post(user_one, %{status: "HI!!!"})        {:ok, direct_activity} =          CommonAPI.post(user_one, %{ -          "status" => "Hi, @#{user_two.nickname}.", -          "visibility" => "direct" +          status: "Hi, @#{user_two.nickname}.", +          visibility: "direct"          })        {:ok, private_activity} = -        CommonAPI.post(user_one, %{"status" => "private", "visibility" => "private"}) +        CommonAPI.post(user_one, %{status: "private", visibility: "private"})        # TODO!!!        resp = @@ -335,8 +362,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do        {:ok, %{id: media_id}} = ActivityPub.upload(file, actor: user.ap_id) -      {:ok, %{id: image_post_id}} = -        CommonAPI.post(user, %{"status" => "cofe", "media_ids" => [media_id]}) +      {:ok, %{id: image_post_id}} = CommonAPI.post(user, %{status: "cofe", media_ids: [media_id]})        conn = get(conn, "/api/v1/accounts/#{user.id}/statuses?only_media=true") @@ -348,7 +374,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do      end      test "gets a user's statuses without reblogs", %{user: user, conn: conn} do -      {:ok, %{id: post_id}} = CommonAPI.post(user, %{"status" => "HI!!!"}) +      {:ok, %{id: post_id}} = CommonAPI.post(user, %{status: "HI!!!"})        {:ok, _, _} = CommonAPI.repeat(post_id, user)        conn = get(conn, "/api/v1/accounts/#{user.id}/statuses?exclude_reblogs=true") @@ -359,8 +385,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do      end      test "filters user's statuses by a hashtag", %{user: user, conn: conn} do -      {:ok, %{id: post_id}} = CommonAPI.post(user, %{"status" => "#hashtag"}) -      {:ok, _post} = CommonAPI.post(user, %{"status" => "hashtag"}) +      {:ok, %{id: post_id}} = CommonAPI.post(user, %{status: "#hashtag"}) +      {:ok, _post} = CommonAPI.post(user, %{status: "hashtag"})        conn = get(conn, "/api/v1/accounts/#{user.id}/statuses?tagged=hashtag")        assert [%{"id" => ^post_id}] = json_response_and_validate_schema(conn, 200) @@ -371,9 +397,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do        conn: conn      } do        {:ok, %{id: public_activity_id}} = -        CommonAPI.post(user, %{"status" => ".", "visibility" => "public"}) +        CommonAPI.post(user, %{status: ".", visibility: "public"}) -      {:ok, _direct_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"}) +      {:ok, _direct_activity} = CommonAPI.post(user, %{status: ".", visibility: "direct"})        conn = get(conn, "/api/v1/accounts/#{user.id}/statuses?exclude_visibilities[]=direct")        assert [%{"id" => ^public_activity_id}] = json_response_and_validate_schema(conn, 200) @@ -651,7 +677,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do        assert %{"showing_reblogs" => false} = json_response_and_validate_schema(ret_conn, 200) -      {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hey"}) +      {:ok, activity} = CommonAPI.post(other_user, %{status: "hey"})        {:ok, %{id: reblog_id}, _} = CommonAPI.repeat(activity.id, followed)        assert [] == @@ -750,7 +776,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do    describe "pinned statuses" do      setup do        user = insert(:user) -      {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"}) +      {:ok, activity} = CommonAPI.post(user, %{status: "HI!!!"})        %{conn: conn} = oauth_access(["read:statuses"], user: user)        [conn: conn, user: user, activity: activity] diff --git a/test/web/mastodon_api/controllers/conversation_controller_test.exs b/test/web/mastodon_api/controllers/conversation_controller_test.exs index 04695572e..693ba51e5 100644 --- a/test/web/mastodon_api/controllers/conversation_controller_test.exs +++ b/test/web/mastodon_api/controllers/conversation_controller_test.exs @@ -22,16 +22,16 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do      {:ok, direct} =        CommonAPI.post(user_one, %{ -        "status" => "Hi @#{user_two.nickname}, @#{user_three.nickname}!", -        "visibility" => "direct" +        status: "Hi @#{user_two.nickname}, @#{user_three.nickname}!", +        visibility: "direct"        })      assert User.get_cached_by_id(user_two.id).unread_conversation_count == 1      {:ok, _follower_only} =        CommonAPI.post(user_one, %{ -        "status" => "Hi @#{user_two.nickname}!", -        "visibility" => "private" +        status: "Hi @#{user_two.nickname}!", +        visibility: "private"        })      res_conn = get(conn, "/api/v1/conversations") @@ -63,32 +63,32 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do      {:ok, direct1} =        CommonAPI.post(user_one, %{ -        "status" => "Hi @#{user_two.nickname}!", -        "visibility" => "direct" +        status: "Hi @#{user_two.nickname}!", +        visibility: "direct"        })      {:ok, _direct2} =        CommonAPI.post(user_one, %{ -        "status" => "Hi @#{user_three.nickname}!", -        "visibility" => "direct" +        status: "Hi @#{user_three.nickname}!", +        visibility: "direct"        })      {:ok, direct3} =        CommonAPI.post(user_one, %{ -        "status" => "Hi @#{user_two.nickname}, @#{user_three.nickname}!", -        "visibility" => "direct" +        status: "Hi @#{user_two.nickname}, @#{user_three.nickname}!", +        visibility: "direct"        })      {:ok, _direct4} =        CommonAPI.post(user_two, %{ -        "status" => "Hi @#{user_three.nickname}!", -        "visibility" => "direct" +        status: "Hi @#{user_three.nickname}!", +        visibility: "direct"        })      {:ok, direct5} =        CommonAPI.post(user_two, %{ -        "status" => "Hi @#{user_one.nickname}!", -        "visibility" => "direct" +        status: "Hi @#{user_one.nickname}!", +        visibility: "direct"        })      assert [conversation1, conversation2] = @@ -112,15 +112,15 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do      {:ok, direct} =        CommonAPI.post(user_one, %{ -        "status" => "Hi @#{user_two.nickname}", -        "visibility" => "direct" +        status: "Hi @#{user_two.nickname}", +        visibility: "direct"        })      {:ok, direct_reply} =        CommonAPI.post(user_two, %{ -        "status" => "reply", -        "visibility" => "direct", -        "in_reply_to_status_id" => direct.id +        status: "reply", +        visibility: "direct", +        in_reply_to_status_id: direct.id        })      [%{"last_status" => res_last_status}] = @@ -136,8 +136,8 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do      {:ok, direct} =        CommonAPI.post(user_one, %{ -        "status" => "Hi @#{user_two.nickname}", -        "visibility" => "direct" +        status: "Hi @#{user_two.nickname}", +        visibility: "direct"        })      assert User.get_cached_by_id(user_one.id).unread_conversation_count == 0 @@ -167,9 +167,9 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do      # The conversation is marked as unread on reply      {:ok, _} =        CommonAPI.post(user_two, %{ -        "status" => "reply", -        "visibility" => "direct", -        "in_reply_to_status_id" => direct.id +        status: "reply", +        visibility: "direct", +        in_reply_to_status_id: direct.id        })      [%{"unread" => true}] = @@ -183,9 +183,9 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do      # A reply doesn't increment the user's unread_conversation_count if the conversation is unread      {:ok, _} =        CommonAPI.post(user_two, %{ -        "status" => "reply", -        "visibility" => "direct", -        "in_reply_to_status_id" => direct.id +        status: "reply", +        visibility: "direct", +        in_reply_to_status_id: direct.id        })      assert User.get_cached_by_id(user_one.id).unread_conversation_count == 1 @@ -197,8 +197,8 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do      {:ok, direct} =        CommonAPI.post(user_one, %{ -        "status" => "Hi @#{user_two.nickname}!", -        "visibility" => "direct" +        status: "Hi @#{user_two.nickname}!", +        visibility: "direct"        })      res_conn = get(conn, "/api/v1/statuses/#{direct.id}/context") diff --git a/test/web/mastodon_api/controllers/instance_controller_test.exs b/test/web/mastodon_api/controllers/instance_controller_test.exs index 90840d5ab..2c61dc5ba 100644 --- a/test/web/mastodon_api/controllers/instance_controller_test.exs +++ b/test/web/mastodon_api/controllers/instance_controller_test.exs @@ -50,7 +50,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do      insert(:user, %{local: false, nickname: "u@peer1.com"})      insert(:user, %{local: false, nickname: "u@peer2.com"}) -    {:ok, _} = Pleroma.Web.CommonAPI.post(user, %{"status" => "cofe"}) +    {:ok, _} = Pleroma.Web.CommonAPI.post(user, %{status: "cofe"})      Pleroma.Stats.force_update() diff --git a/test/web/mastodon_api/controllers/notification_controller_test.exs b/test/web/mastodon_api/controllers/notification_controller_test.exs index db380f76a..d9356a844 100644 --- a/test/web/mastodon_api/controllers/notification_controller_test.exs +++ b/test/web/mastodon_api/controllers/notification_controller_test.exs @@ -18,7 +18,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do      %{user: user, conn: conn} = oauth_access(["read:notifications"])      other_user = insert(:user) -    {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"}) +    {:ok, activity} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})      {:ok, [_notification]} = Notification.create_notifications(activity)      response = @@ -36,7 +36,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do      %{user: user, conn: conn} = oauth_access(["read:notifications"])      other_user = insert(:user) -    {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"}) +    {:ok, activity} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})      {:ok, [_notification]} = Notification.create_notifications(activity) @@ -60,7 +60,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do      %{user: user, conn: conn} = oauth_access(["read:notifications"])      other_user = insert(:user) -    {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"}) +    {:ok, activity} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})      {:ok, [notification]} = Notification.create_notifications(activity) @@ -79,7 +79,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do      %{user: user, conn: conn} = oauth_access(["write:notifications"])      other_user = insert(:user) -    {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"}) +    {:ok, activity} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})      {:ok, [notification]} = Notification.create_notifications(activity) @@ -96,7 +96,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do      %{user: user, conn: conn} = oauth_access(["write:notifications"])      other_user = insert(:user) -    {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"}) +    {:ok, activity} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})      {:ok, [notification]} = Notification.create_notifications(activity) @@ -112,7 +112,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do      %{user: user, conn: conn} = oauth_access(["write:notifications", "read:notifications"])      other_user = insert(:user) -    {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"}) +    {:ok, activity} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})      {:ok, [_notification]} = Notification.create_notifications(activity) @@ -130,10 +130,10 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do      %{user: user, conn: conn} = oauth_access(["read:notifications"])      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}"}) +    {: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) @@ -173,16 +173,16 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do        other_user = insert(:user)        {:ok, public_activity} = -        CommonAPI.post(other_user, %{"status" => "@#{user.nickname}", "visibility" => "public"}) +        CommonAPI.post(other_user, %{status: "@#{user.nickname}", visibility: "public"})        {:ok, direct_activity} = -        CommonAPI.post(other_user, %{"status" => "@#{user.nickname}", "visibility" => "direct"}) +        CommonAPI.post(other_user, %{status: "@#{user.nickname}", visibility: "direct"})        {:ok, unlisted_activity} = -        CommonAPI.post(other_user, %{"status" => "@#{user.nickname}", "visibility" => "unlisted"}) +        CommonAPI.post(other_user, %{status: "@#{user.nickname}", visibility: "unlisted"})        {:ok, private_activity} = -        CommonAPI.post(other_user, %{"status" => "@#{user.nickname}", "visibility" => "private"}) +        CommonAPI.post(other_user, %{status: "@#{user.nickname}", visibility: "private"})        query = params_to_query(%{exclude_visibilities: ["public", "unlisted", "private"]})        conn_res = get(conn, "/api/v1/notifications?" <> query) @@ -213,17 +213,15 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do        user = insert(:user)        %{user: other_user, conn: conn} = oauth_access(["read:notifications"]) -      {:ok, public_activity} = -        CommonAPI.post(other_user, %{"status" => ".", "visibility" => "public"}) +      {:ok, public_activity} = CommonAPI.post(other_user, %{status: ".", visibility: "public"})        {:ok, direct_activity} = -        CommonAPI.post(other_user, %{"status" => "@#{user.nickname}", "visibility" => "direct"}) +        CommonAPI.post(other_user, %{status: "@#{user.nickname}", visibility: "direct"})        {:ok, unlisted_activity} = -        CommonAPI.post(other_user, %{"status" => ".", "visibility" => "unlisted"}) +        CommonAPI.post(other_user, %{status: ".", visibility: "unlisted"}) -      {:ok, private_activity} = -        CommonAPI.post(other_user, %{"status" => ".", "visibility" => "private"}) +      {:ok, private_activity} = CommonAPI.post(other_user, %{status: ".", visibility: "private"})        {:ok, _} = CommonAPI.favorite(user, public_activity.id)        {:ok, _} = CommonAPI.favorite(user, direct_activity.id) @@ -279,11 +277,10 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do        user = insert(:user)        %{user: other_user, conn: conn} = oauth_access(["read:notifications"]) -      {:ok, public_activity} = -        CommonAPI.post(other_user, %{"status" => ".", "visibility" => "public"}) +      {:ok, public_activity} = CommonAPI.post(other_user, %{status: ".", visibility: "public"})        {:ok, unlisted_activity} = -        CommonAPI.post(other_user, %{"status" => ".", "visibility" => "unlisted"}) +        CommonAPI.post(other_user, %{status: ".", visibility: "unlisted"})        {:ok, _, _} = CommonAPI.repeat(public_activity.id, user)        {:ok, _, _} = CommonAPI.repeat(unlisted_activity.id, user) @@ -303,8 +300,8 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do      %{user: user, conn: conn} = oauth_access(["read:notifications"])      other_user = insert(:user) -    {:ok, mention_activity} = CommonAPI.post(other_user, %{"status" => "hey @#{user.nickname}"}) -    {:ok, create_activity} = CommonAPI.post(user, %{"status" => "hey"}) +    {:ok, mention_activity} = CommonAPI.post(other_user, %{status: "hey @#{user.nickname}"}) +    {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"})      {: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) @@ -341,8 +338,8 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do      %{user: user, conn: conn} = oauth_access(["read:notifications"])      other_user = insert(:user) -    {:ok, mention_activity} = CommonAPI.post(other_user, %{"status" => "hey @#{user.nickname}"}) -    {:ok, create_activity} = CommonAPI.post(user, %{"status" => "hey"}) +    {:ok, mention_activity} = CommonAPI.post(other_user, %{status: "hey @#{user.nickname}"}) +    {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"})      {: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) @@ -388,10 +385,10 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do      %{user: user, conn: conn} = oauth_access(["read:notifications", "write:notifications"])      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}"}) +    {: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) @@ -435,7 +432,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do      user2 = insert(:user)      {:ok, _, _, _} = CommonAPI.follow(user, user2) -    {:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"}) +    {:ok, _} = CommonAPI.post(user2, %{status: "hey @#{user.nickname}"})      ret_conn = get(conn, "/api/v1/notifications") @@ -453,7 +450,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do      user2 = insert(:user)      {:ok, _, _, _} = CommonAPI.follow(user, user2) -    {:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"}) +    {:ok, _} = CommonAPI.post(user2, %{status: "hey @#{user.nickname}"})      ret_conn = get(conn, "/api/v1/notifications") @@ -471,7 +468,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do      user2 = insert(:user)      {:ok, _, _, _} = CommonAPI.follow(user, user2) -    {:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"}) +    {:ok, _} = CommonAPI.post(user2, %{status: "hey @#{user.nickname}"})      ret_conn = get(conn, "/api/v1/notifications") @@ -518,14 +515,14 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do        {:ok, activity1} =          CommonAPI.post(other_user, %{ -          "status" => "hi @#{user.nickname}", -          "visibility" => "public" +          status: "hi @#{user.nickname}", +          visibility: "public"          })        {:ok, activity2} =          CommonAPI.post(other_user, %{ -          "status" => "hi @#{user.nickname}", -          "visibility" => "public" +          status: "hi @#{user.nickname}", +          visibility: "public"          })        notification1 = Repo.get_by(Notification, activity_id: activity1.id) @@ -550,8 +547,8 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do        %{id: account_id} = other_user1 = insert(:user)        other_user2 = insert(:user) -      {:ok, _activity} = CommonAPI.post(other_user1, %{"status" => "hi @#{user.nickname}"}) -      {:ok, _activity} = CommonAPI.post(other_user2, %{"status" => "bye @#{user.nickname}"}) +      {:ok, _activity} = CommonAPI.post(other_user1, %{status: "hi @#{user.nickname}"}) +      {:ok, _activity} = CommonAPI.post(other_user2, %{status: "bye @#{user.nickname}"})        assert [%{"account" => %{"id" => ^account_id}}] =                 conn diff --git a/test/web/mastodon_api/controllers/poll_controller_test.exs b/test/web/mastodon_api/controllers/poll_controller_test.exs index d8f34aa86..f41de6448 100644 --- a/test/web/mastodon_api/controllers/poll_controller_test.exs +++ b/test/web/mastodon_api/controllers/poll_controller_test.exs @@ -16,8 +16,8 @@ defmodule Pleroma.Web.MastodonAPI.PollControllerTest do      test "returns poll entity for object id", %{user: user, conn: conn} do        {:ok, activity} =          CommonAPI.post(user, %{ -          "status" => "Pleroma does", -          "poll" => %{"options" => ["what Mastodon't", "n't what Mastodoes"], "expires_in" => 20} +          status: "Pleroma does", +          poll: %{options: ["what Mastodon't", "n't what Mastodoes"], expires_in: 20}          })        object = Object.normalize(activity) @@ -34,9 +34,9 @@ defmodule Pleroma.Web.MastodonAPI.PollControllerTest do        {:ok, activity} =          CommonAPI.post(other_user, %{ -          "status" => "Pleroma does", -          "poll" => %{"options" => ["what Mastodon't", "n't what Mastodoes"], "expires_in" => 20}, -          "visibility" => "private" +          status: "Pleroma does", +          poll: %{options: ["what Mastodon't", "n't what Mastodoes"], expires_in: 20}, +          visibility: "private"          })        object = Object.normalize(activity) @@ -55,11 +55,11 @@ defmodule Pleroma.Web.MastodonAPI.PollControllerTest do        {:ok, activity} =          CommonAPI.post(other_user, %{ -          "status" => "A very delicious sandwich", -          "poll" => %{ -            "options" => ["Lettuce", "Grilled Bacon", "Tomato"], -            "expires_in" => 20, -            "multiple" => true +          status: "A very delicious sandwich", +          poll: %{ +            options: ["Lettuce", "Grilled Bacon", "Tomato"], +            expires_in: 20, +            multiple: true            }          }) @@ -81,8 +81,8 @@ defmodule Pleroma.Web.MastodonAPI.PollControllerTest do      test "author can't vote", %{user: user, conn: conn} do        {:ok, activity} =          CommonAPI.post(user, %{ -          "status" => "Am I cute?", -          "poll" => %{"options" => ["Yes", "No"], "expires_in" => 20} +          status: "Am I cute?", +          poll: %{options: ["Yes", "No"], expires_in: 20}          })        object = Object.normalize(activity) @@ -102,8 +102,8 @@ defmodule Pleroma.Web.MastodonAPI.PollControllerTest do        {:ok, activity} =          CommonAPI.post(other_user, %{ -          "status" => "The glass is", -          "poll" => %{"options" => ["half empty", "half full"], "expires_in" => 20} +          status: "The glass is", +          poll: %{options: ["half empty", "half full"], expires_in: 20}          })        object = Object.normalize(activity) @@ -125,8 +125,8 @@ defmodule Pleroma.Web.MastodonAPI.PollControllerTest do        {:ok, activity} =          CommonAPI.post(other_user, %{ -          "status" => "Am I cute?", -          "poll" => %{"options" => ["Yes", "No"], "expires_in" => 20} +          status: "Am I cute?", +          poll: %{options: ["Yes", "No"], expires_in: 20}          })        object = Object.normalize(activity) @@ -153,9 +153,9 @@ defmodule Pleroma.Web.MastodonAPI.PollControllerTest do        {:ok, activity} =          CommonAPI.post(other_user, %{ -          "status" => "Am I cute?", -          "poll" => %{"options" => ["Yes", "No"], "expires_in" => 20}, -          "visibility" => "private" +          status: "Am I cute?", +          poll: %{options: ["Yes", "No"], expires_in: 20}, +          visibility: "private"          })        object = Object.normalize(activity) diff --git a/test/web/mastodon_api/controllers/report_controller_test.exs b/test/web/mastodon_api/controllers/report_controller_test.exs index 21b037237..6636cff96 100644 --- a/test/web/mastodon_api/controllers/report_controller_test.exs +++ b/test/web/mastodon_api/controllers/report_controller_test.exs @@ -14,7 +14,7 @@ defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do    setup do      target_user = insert(:user) -    {:ok, activity} = CommonAPI.post(target_user, %{"status" => "foobar"}) +    {:ok, activity} = CommonAPI.post(target_user, %{status: "foobar"})      [target_user: target_user, activity: activity]    end diff --git a/test/web/mastodon_api/controllers/search_controller_test.exs b/test/web/mastodon_api/controllers/search_controller_test.exs index 02476acb6..7d0cafccc 100644 --- a/test/web/mastodon_api/controllers/search_controller_test.exs +++ b/test/web/mastodon_api/controllers/search_controller_test.exs @@ -13,7 +13,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do    import Tesla.Mock    import Mock -  setup do +  setup_all do      mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)      :ok    end @@ -42,15 +42,15 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do        user_two = insert(:user, %{nickname: "shp@shitposter.club"})        user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"}) -      {:ok, activity} = CommonAPI.post(user, %{"status" => "This is about 2hu private 天子"}) +      {:ok, activity} = CommonAPI.post(user, %{status: "This is about 2hu private 天子"})        {:ok, _activity} =          CommonAPI.post(user, %{ -          "status" => "This is about 2hu, but private", -          "visibility" => "private" +          status: "This is about 2hu, but private", +          visibility: "private"          }) -      {:ok, _} = CommonAPI.post(user_two, %{"status" => "This isn't"}) +      {:ok, _} = CommonAPI.post(user_two, %{status: "This isn't"})        results =          conn @@ -80,9 +80,9 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do        user_smith = insert(:user, %{nickname: "Agent", name: "I love 2hu"})        user_neo = insert(:user, %{nickname: "Agent Neo", name: "Agent"}) -      {:ok, act1} = CommonAPI.post(user, %{"status" => "This is about 2hu private 天子"}) -      {:ok, act2} = CommonAPI.post(user_smith, %{"status" => "Agent Smith"}) -      {:ok, act3} = CommonAPI.post(user_neo, %{"status" => "Agent Smith"}) +      {:ok, act1} = CommonAPI.post(user, %{status: "This is about 2hu private 天子"}) +      {:ok, act2} = CommonAPI.post(user_smith, %{status: "Agent Smith"}) +      {:ok, act3} = CommonAPI.post(user_neo, %{status: "Agent Smith"})        Pleroma.User.block(user, user_smith)        results = @@ -161,15 +161,15 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do        user_two = insert(:user, %{nickname: "shp@shitposter.club"})        user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"}) -      {:ok, activity} = CommonAPI.post(user, %{"status" => "This is about 2hu"}) +      {:ok, activity} = CommonAPI.post(user, %{status: "This is about 2hu"})        {:ok, _activity} =          CommonAPI.post(user, %{ -          "status" => "This is about 2hu, but private", -          "visibility" => "private" +          status: "This is about 2hu, but private", +          visibility: "private"          }) -      {:ok, _} = CommonAPI.post(user_two, %{"status" => "This isn't"}) +      {:ok, _} = CommonAPI.post(user_two, %{status: "This isn't"})        results =          conn @@ -189,7 +189,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do        capture_log(fn ->          {:ok, %{id: activity_id}} =            CommonAPI.post(insert(:user), %{ -            "status" => "check out https://shitposter.club/notice/2827873" +            status: "check out https://shitposter.club/notice/2827873"            })          results = @@ -207,8 +207,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do      test "search doesn't show statuses that it shouldn't", %{conn: conn} do        {:ok, activity} =          CommonAPI.post(insert(:user), %{ -          "status" => "This is about 2hu, but private", -          "visibility" => "private" +          status: "This is about 2hu, but private", +          visibility: "private"          })        capture_log(fn -> @@ -251,8 +251,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do        _user_two = insert(:user, %{nickname: "shp@shitposter.club"})        _user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"}) -      {:ok, _activity1} = CommonAPI.post(user, %{"status" => "This is about 2hu"}) -      {:ok, _activity2} = CommonAPI.post(user, %{"status" => "This is also about 2hu"}) +      {:ok, _activity1} = CommonAPI.post(user, %{status: "This is about 2hu"}) +      {:ok, _activity2} = CommonAPI.post(user, %{status: "This is also about 2hu"})        result =          conn @@ -277,7 +277,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do        user = insert(:user)        _user_two = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"}) -      {:ok, _activity} = CommonAPI.post(user, %{"status" => "This is about 2hu"}) +      {:ok, _activity} = CommonAPI.post(user, %{status: "This is about 2hu"})        assert %{"statuses" => [_activity], "accounts" => [], "hashtags" => []} =                 conn @@ -294,8 +294,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do        user = insert(:user, %{nickname: "shp@shitposter.club"})        user_two = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"}) -      {:ok, activity1} = CommonAPI.post(user, %{"status" => "This is about 2hu"}) -      {:ok, activity2} = CommonAPI.post(user_two, %{"status" => "This is also about 2hu"}) +      {:ok, activity1} = CommonAPI.post(user, %{status: "This is about 2hu"}) +      {:ok, activity2} = CommonAPI.post(user_two, %{status: "This is also about 2hu"})        results =          conn diff --git a/test/web/mastodon_api/controllers/status_controller_test.exs b/test/web/mastodon_api/controllers/status_controller_test.exs index 85068edd0..a4403132c 100644 --- a/test/web/mastodon_api/controllers/status_controller_test.exs +++ b/test/web/mastodon_api/controllers/status_controller_test.exs @@ -32,13 +32,14 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        response =          conn +        |> put_req_header("content-type", "application/json")          |> post("api/v1/statuses", %{            "content_type" => "text/plain",            "source" => "Pleroma FE",            "status" => "Hello world",            "visibility" => "public"          }) -        |> json_response(200) +        |> json_response_and_validate_schema(200)        assert response["reblogs_count"] == 0        ObanHelpers.perform_all() @@ -46,7 +47,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        response =          conn          |> get("api/v1/statuses/#{response["id"]}", %{}) -        |> json_response(200) +        |> json_response_and_validate_schema(200)        assert response["reblogs_count"] == 0      end @@ -56,6 +57,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        conn_one =          conn +        |> put_req_header("content-type", "application/json")          |> put_req_header("idempotency-key", idempotency_key)          |> post("/api/v1/statuses", %{            "status" => "cofe", @@ -68,12 +70,13 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        assert ttl > :timer.seconds(6 * 60 * 60 - 1)        assert %{"content" => "cofe", "id" => id, "spoiler_text" => "2hu", "sensitive" => false} = -               json_response(conn_one, 200) +               json_response_and_validate_schema(conn_one, 200)        assert Activity.get_by_id(id)        conn_two =          conn +        |> put_req_header("content-type", "application/json")          |> put_req_header("idempotency-key", idempotency_key)          |> post("/api/v1/statuses", %{            "status" => "cofe", @@ -86,13 +89,14 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        conn_three =          conn +        |> put_req_header("content-type", "application/json")          |> post("/api/v1/statuses", %{            "status" => "cofe",            "spoiler_text" => "2hu",            "sensitive" => "false"          }) -      assert %{"id" => third_id} = json_response(conn_three, 200) +      assert %{"id" => third_id} = json_response_and_validate_schema(conn_three, 200)        refute id == third_id        # An activity that will expire: @@ -101,12 +105,15 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        conn_four =          conn +        |> put_req_header("content-type", "application/json")          |> post("api/v1/statuses", %{            "status" => "oolong",            "expires_in" => expires_in          }) -      assert fourth_response = %{"id" => fourth_id} = json_response(conn_four, 200) +      assert fourth_response = +               %{"id" => fourth_id} = json_response_and_validate_schema(conn_four, 200) +        assert activity = Activity.get_by_id(fourth_id)        assert expiration = ActivityExpiration.get_by_activity_id(fourth_id) @@ -130,22 +137,24 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        assert %{"error" => "Expiry date is too soon"} =                 conn +               |> put_req_header("content-type", "application/json")                 |> post("api/v1/statuses", %{                   "status" => "oolong",                   "expires_in" => expires_in                 }) -               |> json_response(422) +               |> json_response_and_validate_schema(422)        # 30 minutes        expires_in = 30 * 60        assert %{"error" => "Expiry date is too soon"} =                 conn +               |> put_req_header("content-type", "application/json")                 |> post("api/v1/statuses", %{                   "status" => "oolong",                   "expires_in" => expires_in                 }) -               |> json_response(422) +               |> json_response_and_validate_schema(422)      end      test "posting an undefined status with an attachment", %{user: user, conn: conn} do @@ -158,21 +167,24 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        {:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)        conn = -        post(conn, "/api/v1/statuses", %{ +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/statuses", %{            "media_ids" => [to_string(upload.id)]          }) -      assert json_response(conn, 200) +      assert json_response_and_validate_schema(conn, 200)      end      test "replying to a status", %{user: user, conn: conn} do -      {:ok, replied_to} = CommonAPI.post(user, %{"status" => "cofe"}) +      {:ok, replied_to} = CommonAPI.post(user, %{status: "cofe"})        conn =          conn +        |> put_req_header("content-type", "application/json")          |> post("/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => replied_to.id}) -      assert %{"content" => "xD", "id" => id} = json_response(conn, 200) +      assert %{"content" => "xD", "id" => id} = json_response_and_validate_schema(conn, 200)        activity = Activity.get_by_id(id) @@ -184,43 +196,56 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        user: user,        conn: conn      } do -      {:ok, replied_to} = CommonAPI.post(user, %{"status" => "suya..", "visibility" => "direct"}) +      {:ok, replied_to} = CommonAPI.post(user, %{status: "suya..", visibility: "direct"})        Enum.each(["public", "private", "unlisted"], fn visibility ->          conn =            conn +          |> put_req_header("content-type", "application/json")            |> post("/api/v1/statuses", %{              "status" => "@#{user.nickname} hey",              "in_reply_to_id" => replied_to.id,              "visibility" => visibility            }) -        assert json_response(conn, 422) == %{"error" => "The message visibility must be direct"} +        assert json_response_and_validate_schema(conn, 422) == %{ +                 "error" => "The message visibility must be direct" +               }        end)      end      test "posting a status with an invalid in_reply_to_id", %{conn: conn} do -      conn = post(conn, "/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => ""}) +      conn = +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => ""}) -      assert %{"content" => "xD", "id" => id} = json_response(conn, 200) +      assert %{"content" => "xD", "id" => id} = json_response_and_validate_schema(conn, 200)        assert Activity.get_by_id(id)      end      test "posting a sensitive status", %{conn: conn} do -      conn = post(conn, "/api/v1/statuses", %{"status" => "cofe", "sensitive" => true}) +      conn = +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/statuses", %{"status" => "cofe", "sensitive" => true}) + +      assert %{"content" => "cofe", "id" => id, "sensitive" => true} = +               json_response_and_validate_schema(conn, 200) -      assert %{"content" => "cofe", "id" => id, "sensitive" => true} = json_response(conn, 200)        assert Activity.get_by_id(id)      end      test "posting a fake status", %{conn: conn} do        real_conn = -        post(conn, "/api/v1/statuses", %{ +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/statuses", %{            "status" =>              "\"Tenshi Eating a Corndog\" is a much discussed concept on /jp/. The significance of it is disputed, so I will focus on one core concept: the symbolism behind it"          }) -      real_status = json_response(real_conn, 200) +      real_status = json_response_and_validate_schema(real_conn, 200)        assert real_status        assert Object.get_by_ap_id(real_status["uri"]) @@ -234,13 +259,15 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do          |> Kernel.put_in(["pleroma", "conversation_id"], nil)        fake_conn = -        post(conn, "/api/v1/statuses", %{ +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/statuses", %{            "status" =>              "\"Tenshi Eating a Corndog\" is a much discussed concept on /jp/. The significance of it is disputed, so I will focus on one core concept: the symbolism behind it",            "preview" => true          }) -      fake_status = json_response(fake_conn, 200) +      fake_status = json_response_and_validate_schema(fake_conn, 200)        assert fake_status        refute Object.get_by_ap_id(fake_status["uri"]) @@ -261,11 +288,15 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        Config.put([:rich_media, :enabled], true)        conn = -        post(conn, "/api/v1/statuses", %{ +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/statuses", %{            "status" => "https://example.com/ogp"          }) -      assert %{"id" => id, "card" => %{"title" => "The Rock"}} = json_response(conn, 200) +      assert %{"id" => id, "card" => %{"title" => "The Rock"}} = +               json_response_and_validate_schema(conn, 200) +        assert Activity.get_by_id(id)      end @@ -273,9 +304,12 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        user2 = insert(:user)        content = "direct cofe @#{user2.nickname}" -      conn = post(conn, "api/v1/statuses", %{"status" => content, "visibility" => "direct"}) +      conn = +        conn +        |> put_req_header("content-type", "application/json") +        |> post("api/v1/statuses", %{"status" => content, "visibility" => "direct"}) -      assert %{"id" => id} = response = json_response(conn, 200) +      assert %{"id" => id} = response = json_response_and_validate_schema(conn, 200)        assert response["visibility"] == "direct"        assert response["pleroma"]["direct_conversation_id"]        assert activity = Activity.get_by_id(id) @@ -289,32 +323,45 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      setup do: oauth_access(["write:statuses"])      test "creates a scheduled activity", %{conn: conn} do -      scheduled_at = NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(120), :millisecond) +      scheduled_at = +        NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(120), :millisecond) +        |> NaiveDateTime.to_iso8601() +        |> Kernel.<>("Z")        conn = -        post(conn, "/api/v1/statuses", %{ +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/statuses", %{            "status" => "scheduled",            "scheduled_at" => scheduled_at          }) -      assert %{"scheduled_at" => expected_scheduled_at} = json_response(conn, 200) +      assert %{"scheduled_at" => expected_scheduled_at} = +               json_response_and_validate_schema(conn, 200) +        assert expected_scheduled_at == CommonAPI.Utils.to_masto_date(scheduled_at)        assert [] == Repo.all(Activity)      end      test "ignores nil values", %{conn: conn} do        conn = -        post(conn, "/api/v1/statuses", %{ +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/statuses", %{            "status" => "not scheduled",            "scheduled_at" => nil          }) -      assert result = json_response(conn, 200) +      assert result = json_response_and_validate_schema(conn, 200)        assert Activity.get_by_id(result["id"])      end      test "creates a scheduled activity with a media attachment", %{user: user, conn: conn} do -      scheduled_at = NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(120), :millisecond) +      scheduled_at = +        NaiveDateTime.utc_now() +        |> NaiveDateTime.add(:timer.minutes(120), :millisecond) +        |> NaiveDateTime.to_iso8601() +        |> Kernel.<>("Z")        file = %Plug.Upload{          content_type: "image/jpg", @@ -325,13 +372,17 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        {:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)        conn = -        post(conn, "/api/v1/statuses", %{ +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/statuses", %{            "media_ids" => [to_string(upload.id)],            "status" => "scheduled",            "scheduled_at" => scheduled_at          }) -      assert %{"media_attachments" => [media_attachment]} = json_response(conn, 200) +      assert %{"media_attachments" => [media_attachment]} = +               json_response_and_validate_schema(conn, 200) +        assert %{"type" => "image"} = media_attachment      end @@ -339,14 +390,18 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do           %{conn: conn} do        scheduled_at =          NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(5) - 1, :millisecond) +        |> NaiveDateTime.to_iso8601() +        |> Kernel.<>("Z")        conn = -        post(conn, "/api/v1/statuses", %{ +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/statuses", %{            "status" => "not scheduled",            "scheduled_at" => scheduled_at          }) -      assert %{"content" => "not scheduled"} = json_response(conn, 200) +      assert %{"content" => "not scheduled"} = json_response_and_validate_schema(conn, 200)        assert [] == Repo.all(ScheduledActivity)      end @@ -355,14 +410,19 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do          NaiveDateTime.utc_now()          |> NaiveDateTime.add(:timer.minutes(6), :millisecond)          |> NaiveDateTime.to_iso8601() +        # TODO +        |> Kernel.<>("Z")        attrs = %{params: %{}, scheduled_at: today}        {:ok, _} = ScheduledActivity.create(user, attrs)        {:ok, _} = ScheduledActivity.create(user, attrs) -      conn = post(conn, "/api/v1/statuses", %{"status" => "scheduled", "scheduled_at" => today}) +      conn = +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/statuses", %{"status" => "scheduled", "scheduled_at" => today}) -      assert %{"error" => "daily limit exceeded"} == json_response(conn, 422) +      assert %{"error" => "daily limit exceeded"} == json_response_and_validate_schema(conn, 422)      end      test "returns error when total user limit is exceeded", %{user: user, conn: conn} do @@ -370,11 +430,13 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do          NaiveDateTime.utc_now()          |> NaiveDateTime.add(:timer.minutes(6), :millisecond)          |> NaiveDateTime.to_iso8601() +        |> Kernel.<>("Z")        tomorrow =          NaiveDateTime.utc_now()          |> NaiveDateTime.add(:timer.hours(36), :millisecond)          |> NaiveDateTime.to_iso8601() +        |> Kernel.<>("Z")        attrs = %{params: %{}, scheduled_at: today}        {:ok, _} = ScheduledActivity.create(user, attrs) @@ -382,9 +444,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        {:ok, _} = ScheduledActivity.create(user, %{params: %{}, scheduled_at: tomorrow})        conn = -        post(conn, "/api/v1/statuses", %{"status" => "scheduled", "scheduled_at" => tomorrow}) +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/statuses", %{"status" => "scheduled", "scheduled_at" => tomorrow}) -      assert %{"error" => "total limit exceeded"} == json_response(conn, 422) +      assert %{"error" => "total limit exceeded"} == json_response_and_validate_schema(conn, 422)      end    end @@ -395,12 +459,17 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        time = NaiveDateTime.utc_now()        conn = -        post(conn, "/api/v1/statuses", %{ +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/statuses", %{            "status" => "Who is the #bestgrill?", -          "poll" => %{"options" => ["Rei", "Asuka", "Misato"], "expires_in" => 420} +          "poll" => %{ +            "options" => ["Rei", "Asuka", "Misato"], +            "expires_in" => 420 +          }          }) -      response = json_response(conn, 200) +      response = json_response_and_validate_schema(conn, 200)        assert Enum.all?(response["poll"]["options"], fn %{"title" => title} ->                 title in ["Rei", "Asuka", "Misato"] @@ -419,12 +488,14 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        limit = Config.get([:instance, :poll_limits, :max_options])        conn = -        post(conn, "/api/v1/statuses", %{ +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/statuses", %{            "status" => "desu~",            "poll" => %{"options" => Enum.map(0..limit, fn _ -> "desu" end), "expires_in" => 1}          }) -      %{"error" => error} = json_response(conn, 422) +      %{"error" => error} = json_response_and_validate_schema(conn, 422)        assert error == "Poll can't contain more than #{limit} options"      end @@ -432,7 +503,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        limit = Config.get([:instance, :poll_limits, :max_option_chars])        conn = -        post(conn, "/api/v1/statuses", %{ +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/statuses", %{            "status" => "...",            "poll" => %{              "options" => [Enum.reduce(0..limit, "", fn _, acc -> acc <> "." end)], @@ -440,7 +513,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do            }          }) -      %{"error" => error} = json_response(conn, 422) +      %{"error" => error} = json_response_and_validate_schema(conn, 422)        assert error == "Poll options cannot be longer than #{limit} characters each"      end @@ -448,7 +521,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        limit = Config.get([:instance, :poll_limits, :min_expiration])        conn = -        post(conn, "/api/v1/statuses", %{ +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/statuses", %{            "status" => "imagine arbitrary limits",            "poll" => %{              "options" => ["this post was made by pleroma gang"], @@ -456,7 +531,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do            }          }) -      %{"error" => error} = json_response(conn, 422) +      %{"error" => error} = json_response_and_validate_schema(conn, 422)        assert error == "Expiration date is too soon"      end @@ -464,7 +539,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        limit = Config.get([:instance, :poll_limits, :max_expiration])        conn = -        post(conn, "/api/v1/statuses", %{ +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/statuses", %{            "status" => "imagine arbitrary limits",            "poll" => %{              "options" => ["this post was made by pleroma gang"], @@ -472,7 +549,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do            }          }) -      %{"error" => error} = json_response(conn, 422) +      %{"error" => error} = json_response_and_validate_schema(conn, 422)        assert error == "Expiration date is too far in the future"      end    end @@ -483,7 +560,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      conn = get(conn, "/api/v1/statuses/#{activity.id}") -    assert %{"id" => id} = json_response(conn, 200) +    assert %{"id" => id} = json_response_and_validate_schema(conn, 200)      assert id == to_string(activity.id)    end @@ -503,13 +580,13 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do        res_conn = get(conn, "/api/v1/statuses/#{local.id}") -      assert json_response(res_conn, :not_found) == %{ +      assert json_response_and_validate_schema(res_conn, :not_found) == %{                 "error" => "Record not found"               }        res_conn = get(conn, "/api/v1/statuses/#{remote.id}") -      assert json_response(res_conn, :not_found) == %{ +      assert json_response_and_validate_schema(res_conn, :not_found) == %{                 "error" => "Record not found"               }      end @@ -517,10 +594,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      test "if user is authenticated", %{local: local, remote: remote} do        %{conn: conn} = oauth_access(["read"])        res_conn = get(conn, "/api/v1/statuses/#{local.id}") -      assert %{"id" => _} = json_response(res_conn, 200) +      assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)        res_conn = get(conn, "/api/v1/statuses/#{remote.id}") -      assert %{"id" => _} = json_response(res_conn, 200) +      assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)      end    end @@ -532,21 +609,21 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do        res_conn = get(conn, "/api/v1/statuses/#{local.id}") -      assert json_response(res_conn, :not_found) == %{ +      assert json_response_and_validate_schema(res_conn, :not_found) == %{                 "error" => "Record not found"               }        res_conn = get(conn, "/api/v1/statuses/#{remote.id}") -      assert %{"id" => _} = json_response(res_conn, 200) +      assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)      end      test "if user is authenticated", %{local: local, remote: remote} do        %{conn: conn} = oauth_access(["read"])        res_conn = get(conn, "/api/v1/statuses/#{local.id}") -      assert %{"id" => _} = json_response(res_conn, 200) +      assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)        res_conn = get(conn, "/api/v1/statuses/#{remote.id}") -      assert %{"id" => _} = json_response(res_conn, 200) +      assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)      end    end @@ -557,11 +634,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do        res_conn = get(conn, "/api/v1/statuses/#{local.id}") -      assert %{"id" => _} = json_response(res_conn, 200) +      assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)        res_conn = get(conn, "/api/v1/statuses/#{remote.id}") -      assert json_response(res_conn, :not_found) == %{ +      assert json_response_and_validate_schema(res_conn, :not_found) == %{                 "error" => "Record not found"               }      end @@ -569,10 +646,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      test "if user is authenticated", %{local: local, remote: remote} do        %{conn: conn} = oauth_access(["read"])        res_conn = get(conn, "/api/v1/statuses/#{local.id}") -      assert %{"id" => _} = json_response(res_conn, 200) +      assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)        res_conn = get(conn, "/api/v1/statuses/#{remote.id}") -      assert %{"id" => _} = json_response(res_conn, 200) +      assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)      end    end @@ -582,7 +659,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      conn = get(conn, "/api/v1/statuses/#{String.downcase(activity.id)}") -    assert json_response(conn, 404) == %{"error" => "Record not found"} +    assert json_response_and_validate_schema(conn, 404) == %{"error" => "Record not found"}    end    test "get a direct status" do @@ -590,7 +667,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      other_user = insert(:user)      {:ok, activity} = -      CommonAPI.post(user, %{"status" => "@#{other_user.nickname}", "visibility" => "direct"}) +      CommonAPI.post(user, %{status: "@#{other_user.nickname}", visibility: "direct"})      conn =        conn @@ -599,7 +676,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      [participation] = Participation.for_user(user) -    res = json_response(conn, 200) +    res = json_response_and_validate_schema(conn, 200)      assert res["pleroma"]["direct_conversation_id"] == participation.id    end @@ -611,7 +688,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      query_string = "ids[]=#{id1}&ids[]=#{id2}"      conn = get(conn, "/api/v1/statuses/?#{query_string}") -    assert [%{"id" => ^id1}, %{"id" => ^id2}] = Enum.sort_by(json_response(conn, :ok), & &1["id"]) +    assert [%{"id" => ^id1}, %{"id" => ^id2}] = +             Enum.sort_by(json_response_and_validate_schema(conn, :ok), & &1["id"])    end    describe "getting statuses by ids with restricted unauthenticated for local and remote" do @@ -622,17 +700,17 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)      test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do -      res_conn = get(conn, "/api/v1/statuses", %{ids: [local.id, remote.id]}) +      res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}") -      assert json_response(res_conn, 200) == [] +      assert json_response_and_validate_schema(res_conn, 200) == []      end      test "if user is authenticated", %{local: local, remote: remote} do        %{conn: conn} = oauth_access(["read"]) -      res_conn = get(conn, "/api/v1/statuses", %{ids: [local.id, remote.id]}) +      res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}") -      assert length(json_response(res_conn, 200)) == 2 +      assert length(json_response_and_validate_schema(res_conn, 200)) == 2      end    end @@ -642,18 +720,18 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      setup do: clear_config([:restrict_unauthenticated, :activities, :local], true)      test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do -      res_conn = get(conn, "/api/v1/statuses", %{ids: [local.id, remote.id]}) +      res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}")        remote_id = remote.id -      assert [%{"id" => ^remote_id}] = json_response(res_conn, 200) +      assert [%{"id" => ^remote_id}] = json_response_and_validate_schema(res_conn, 200)      end      test "if user is authenticated", %{local: local, remote: remote} do        %{conn: conn} = oauth_access(["read"]) -      res_conn = get(conn, "/api/v1/statuses", %{ids: [local.id, remote.id]}) +      res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}") -      assert length(json_response(res_conn, 200)) == 2 +      assert length(json_response_and_validate_schema(res_conn, 200)) == 2      end    end @@ -663,18 +741,18 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)      test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do -      res_conn = get(conn, "/api/v1/statuses", %{ids: [local.id, remote.id]}) +      res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}")        local_id = local.id -      assert [%{"id" => ^local_id}] = json_response(res_conn, 200) +      assert [%{"id" => ^local_id}] = json_response_and_validate_schema(res_conn, 200)      end      test "if user is authenticated", %{local: local, remote: remote} do        %{conn: conn} = oauth_access(["read"]) -      res_conn = get(conn, "/api/v1/statuses", %{ids: [local.id, remote.id]}) +      res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}") -      assert length(json_response(res_conn, 200)) == 2 +      assert length(json_response_and_validate_schema(res_conn, 200)) == 2      end    end @@ -688,7 +766,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do          |> assign(:user, author)          |> delete("/api/v1/statuses/#{activity.id}") -      assert %{} = json_response(conn, 200) +      assert %{} = json_response_and_validate_schema(conn, 200)        refute Activity.get_by_id(activity.id)      end @@ -702,7 +780,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do          |> assign(:user, author)          |> delete("/api/v1/statuses/#{String.downcase(activity.id)}") -      assert %{"error" => "Record not found"} == json_response(conn, 404) +      assert %{"error" => "Record not found"} == json_response_and_validate_schema(conn, 404)      end      test "when you didn't create it" do @@ -711,7 +789,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        conn = delete(conn, "/api/v1/statuses/#{activity.id}") -      assert %{"error" => _} = json_response(conn, 403) +      assert %{"error" => _} = json_response_and_validate_schema(conn, 403)        assert Activity.get_by_id(activity.id) == activity      end @@ -728,7 +806,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do          |> assign(:token, insert(:oauth_token, user: admin, scopes: ["write:statuses"]))          |> delete("/api/v1/statuses/#{activity1.id}") -      assert %{} = json_response(res_conn, 200) +      assert %{} = json_response_and_validate_schema(res_conn, 200)        res_conn =          conn @@ -736,7 +814,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do          |> assign(:token, insert(:oauth_token, user: moderator, scopes: ["write:statuses"]))          |> delete("/api/v1/statuses/#{activity2.id}") -      assert %{} = json_response(res_conn, 200) +      assert %{} = json_response_and_validate_schema(res_conn, 200)        refute Activity.get_by_id(activity1.id)        refute Activity.get_by_id(activity2.id) @@ -749,12 +827,15 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      test "reblogs and returns the reblogged status", %{conn: conn} do        activity = insert(:note_activity) -      conn = post(conn, "/api/v1/statuses/#{activity.id}/reblog") +      conn = +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/statuses/#{activity.id}/reblog")        assert %{                 "reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 1},                 "reblogged" => true -             } = json_response(conn, 200) +             } = json_response_and_validate_schema(conn, 200)        assert to_string(activity.id) == id      end @@ -762,21 +843,30 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      test "returns 404 if the reblogged status doesn't exist", %{conn: conn} do        activity = insert(:note_activity) -      conn = post(conn, "/api/v1/statuses/#{String.downcase(activity.id)}/reblog") +      conn = +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/statuses/#{String.downcase(activity.id)}/reblog") -      assert %{"error" => "Record not found"} = json_response(conn, 404) +      assert %{"error" => "Record not found"} = json_response_and_validate_schema(conn, 404)      end      test "reblogs privately and returns the reblogged status", %{conn: conn} do        activity = insert(:note_activity) -      conn = post(conn, "/api/v1/statuses/#{activity.id}/reblog", %{"visibility" => "private"}) +      conn = +        conn +        |> put_req_header("content-type", "application/json") +        |> post( +          "/api/v1/statuses/#{activity.id}/reblog", +          %{"visibility" => "private"} +        )        assert %{                 "reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 1},                 "reblogged" => true,                 "visibility" => "private" -             } = json_response(conn, 200) +             } = json_response_and_validate_schema(conn, 200)        assert to_string(activity.id) == id      end @@ -802,7 +892,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do                 "reblogged" => false,                 "favourited" => false,                 "bookmarked" => false -             } = json_response(conn_res, 200) +             } = json_response_and_validate_schema(conn_res, 200)        conn_res =          build_conn() @@ -815,7 +905,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do                 "reblogged" => true,                 "favourited" => true,                 "bookmarked" => true -             } = json_response(conn_res, 200) +             } = json_response_and_validate_schema(conn_res, 200)        assert to_string(activity.id) == id      end @@ -829,17 +919,24 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        {:ok, _, _} = CommonAPI.repeat(activity.id, user) -      conn = post(conn, "/api/v1/statuses/#{activity.id}/unreblog") +      conn = +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/statuses/#{activity.id}/unreblog") -      assert %{"id" => id, "reblogged" => false, "reblogs_count" => 0} = json_response(conn, 200) +      assert %{"id" => id, "reblogged" => false, "reblogs_count" => 0} = +               json_response_and_validate_schema(conn, 200)        assert to_string(activity.id) == id      end      test "returns 404 error when activity does not exist", %{conn: conn} do -      conn = post(conn, "/api/v1/statuses/foo/unreblog") +      conn = +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/statuses/foo/unreblog") -      assert json_response(conn, 404) == %{"error" => "Record not found"} +      assert json_response_and_validate_schema(conn, 404) == %{"error" => "Record not found"}      end    end @@ -849,10 +946,13 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      test "favs a status and returns it", %{conn: conn} do        activity = insert(:note_activity) -      conn = post(conn, "/api/v1/statuses/#{activity.id}/favourite") +      conn = +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/statuses/#{activity.id}/favourite")        assert %{"id" => id, "favourites_count" => 1, "favourited" => true} = -               json_response(conn, 200) +               json_response_and_validate_schema(conn, 200)        assert to_string(activity.id) == id      end @@ -860,18 +960,23 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      test "favoriting twice will just return 200", %{conn: conn} do        activity = insert(:note_activity) -      post(conn, "/api/v1/statuses/#{activity.id}/favourite") +      conn +      |> put_req_header("content-type", "application/json") +      |> post("/api/v1/statuses/#{activity.id}/favourite") -      assert post(conn, "/api/v1/statuses/#{activity.id}/favourite") -             |> json_response(200) +      assert conn +             |> put_req_header("content-type", "application/json") +             |> post("/api/v1/statuses/#{activity.id}/favourite") +             |> json_response_and_validate_schema(200)      end      test "returns 404 error for a wrong id", %{conn: conn} do        conn =          conn +        |> put_req_header("content-type", "application/json")          |> post("/api/v1/statuses/1/favourite") -      assert json_response(conn, 404) == %{"error" => "Record not found"} +      assert json_response_and_validate_schema(conn, 404) == %{"error" => "Record not found"}      end    end @@ -883,18 +988,24 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        {:ok, _} = CommonAPI.favorite(user, activity.id) -      conn = post(conn, "/api/v1/statuses/#{activity.id}/unfavourite") +      conn = +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/statuses/#{activity.id}/unfavourite")        assert %{"id" => id, "favourites_count" => 0, "favourited" => false} = -               json_response(conn, 200) +               json_response_and_validate_schema(conn, 200)        assert to_string(activity.id) == id      end      test "returns 404 error for a wrong id", %{conn: conn} do -      conn = post(conn, "/api/v1/statuses/1/unfavourite") +      conn = +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/statuses/1/unfavourite") -      assert json_response(conn, 404) == %{"error" => "Record not found"} +      assert json_response_and_validate_schema(conn, 404) == %{"error" => "Record not found"}      end    end @@ -902,7 +1013,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      setup do: oauth_access(["write:accounts"])      setup %{user: user} do -      {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"}) +      {:ok, activity} = CommonAPI.post(user, %{status: "HI!!!"})        %{activity: activity}      end @@ -914,21 +1025,25 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        assert %{"id" => ^id_str, "pinned" => true} =                 conn +               |> put_req_header("content-type", "application/json")                 |> post("/api/v1/statuses/#{activity.id}/pin") -               |> json_response(200) +               |> json_response_and_validate_schema(200)        assert [%{"id" => ^id_str, "pinned" => true}] =                 conn                 |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true") -               |> json_response(200) +               |> json_response_and_validate_schema(200)      end      test "/pin: returns 400 error when activity is not public", %{conn: conn, user: user} do -      {:ok, dm} = CommonAPI.post(user, %{"status" => "test", "visibility" => "direct"}) +      {:ok, dm} = CommonAPI.post(user, %{status: "test", visibility: "direct"}) -      conn = post(conn, "/api/v1/statuses/#{dm.id}/pin") +      conn = +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/statuses/#{dm.id}/pin") -      assert json_response(conn, 400) == %{"error" => "Could not pin"} +      assert json_response_and_validate_schema(conn, 400) == %{"error" => "Could not pin"}      end      test "unpin status", %{conn: conn, user: user, activity: activity} do @@ -941,29 +1056,33 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do                 conn                 |> assign(:user, user)                 |> post("/api/v1/statuses/#{activity.id}/unpin") -               |> json_response(200) +               |> json_response_and_validate_schema(200)        assert [] =                 conn                 |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true") -               |> json_response(200) +               |> json_response_and_validate_schema(200)      end      test "/unpin: returns 400 error when activity is not exist", %{conn: conn} do -      conn = post(conn, "/api/v1/statuses/1/unpin") +      conn = +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/statuses/1/unpin") -      assert json_response(conn, 400) == %{"error" => "Could not unpin"} +      assert json_response_and_validate_schema(conn, 400) == %{"error" => "Could not unpin"}      end      test "max pinned statuses", %{conn: conn, user: user, activity: activity_one} do -      {:ok, activity_two} = CommonAPI.post(user, %{"status" => "HI!!!"}) +      {:ok, activity_two} = CommonAPI.post(user, %{status: "HI!!!"})        id_str_one = to_string(activity_one.id)        assert %{"id" => ^id_str_one, "pinned" => true} =                 conn +               |> put_req_header("content-type", "application/json")                 |> post("/api/v1/statuses/#{id_str_one}/pin") -               |> json_response(200) +               |> json_response_and_validate_schema(200)        user = refresh_record(user) @@ -971,7 +1090,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do                 conn                 |> assign(:user, user)                 |> post("/api/v1/statuses/#{activity_two.id}/pin") -               |> json_response(400) +               |> json_response_and_validate_schema(400)      end    end @@ -985,7 +1104,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      test "returns rich-media card", %{conn: conn, user: user} do        Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end) -      {:ok, activity} = CommonAPI.post(user, %{"status" => "https://example.com/ogp"}) +      {:ok, activity} = CommonAPI.post(user, %{status: "https://example.com/ogp"})        card_data = %{          "image" => "http://ia.media-imdb.com/images/rock.jpg", @@ -1011,18 +1130,18 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        response =          conn          |> get("/api/v1/statuses/#{activity.id}/card") -        |> json_response(200) +        |> json_response_and_validate_schema(200)        assert response == card_data        # works with private posts        {:ok, activity} = -        CommonAPI.post(user, %{"status" => "https://example.com/ogp", "visibility" => "direct"}) +        CommonAPI.post(user, %{status: "https://example.com/ogp", visibility: "direct"})        response_two =          conn          |> get("/api/v1/statuses/#{activity.id}/card") -        |> json_response(200) +        |> json_response_and_validate_schema(200)        assert response_two == card_data      end @@ -1030,13 +1149,12 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      test "replaces missing description with an empty string", %{conn: conn, user: user} do        Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end) -      {:ok, activity} = -        CommonAPI.post(user, %{"status" => "https://example.com/ogp-missing-data"}) +      {:ok, activity} = CommonAPI.post(user, %{status: "https://example.com/ogp-missing-data"})        response =          conn          |> get("/api/v1/statuses/#{activity.id}/card") -        |> json_response(:ok) +        |> json_response_and_validate_schema(:ok)        assert response == %{                 "type" => "link", @@ -1063,36 +1181,42 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      %{conn: conn} = oauth_access(["write:bookmarks", "read:bookmarks"])      author = insert(:user) -    {:ok, activity1} = -      CommonAPI.post(author, %{ -        "status" => "heweoo?" -      }) +    {:ok, activity1} = CommonAPI.post(author, %{status: "heweoo?"}) +    {:ok, activity2} = CommonAPI.post(author, %{status: "heweoo!"}) -    {:ok, activity2} = -      CommonAPI.post(author, %{ -        "status" => "heweoo!" -      }) - -    response1 = post(conn, "/api/v1/statuses/#{activity1.id}/bookmark") +    response1 = +      conn +      |> put_req_header("content-type", "application/json") +      |> post("/api/v1/statuses/#{activity1.id}/bookmark") -    assert json_response(response1, 200)["bookmarked"] == true +    assert json_response_and_validate_schema(response1, 200)["bookmarked"] == true -    response2 = post(conn, "/api/v1/statuses/#{activity2.id}/bookmark") +    response2 = +      conn +      |> put_req_header("content-type", "application/json") +      |> post("/api/v1/statuses/#{activity2.id}/bookmark") -    assert json_response(response2, 200)["bookmarked"] == true +    assert json_response_and_validate_schema(response2, 200)["bookmarked"] == true      bookmarks = get(conn, bookmarks_uri) -    assert [json_response(response2, 200), json_response(response1, 200)] == -             json_response(bookmarks, 200) +    assert [ +             json_response_and_validate_schema(response2, 200), +             json_response_and_validate_schema(response1, 200) +           ] == +             json_response_and_validate_schema(bookmarks, 200) -    response1 = post(conn, "/api/v1/statuses/#{activity1.id}/unbookmark") +    response1 = +      conn +      |> put_req_header("content-type", "application/json") +      |> post("/api/v1/statuses/#{activity1.id}/unbookmark") -    assert json_response(response1, 200)["bookmarked"] == false +    assert json_response_and_validate_schema(response1, 200)["bookmarked"] == false      bookmarks = get(conn, bookmarks_uri) -    assert [json_response(response2, 200)] == json_response(bookmarks, 200) +    assert [json_response_and_validate_schema(response2, 200)] == +             json_response_and_validate_schema(bookmarks, 200)    end    describe "conversation muting" do @@ -1100,7 +1224,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      setup do        post_user = insert(:user) -      {:ok, activity} = CommonAPI.post(post_user, %{"status" => "HIE"}) +      {:ok, activity} = CommonAPI.post(post_user, %{status: "HIE"})        %{activity: activity}      end @@ -1109,16 +1233,22 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        assert %{"id" => ^id_str, "muted" => true} =                 conn +               |> put_req_header("content-type", "application/json")                 |> post("/api/v1/statuses/#{activity.id}/mute") -               |> json_response(200) +               |> json_response_and_validate_schema(200)      end      test "cannot mute already muted conversation", %{conn: conn, user: user, activity: activity} do        {:ok, _} = CommonAPI.add_mute(user, activity) -      conn = post(conn, "/api/v1/statuses/#{activity.id}/mute") +      conn = +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/statuses/#{activity.id}/mute") -      assert json_response(conn, 400) == %{"error" => "conversation is already muted"} +      assert json_response_and_validate_schema(conn, 400) == %{ +               "error" => "conversation is already muted" +             }      end      test "unmute conversation", %{conn: conn, user: user, activity: activity} do @@ -1130,7 +1260,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do                 conn                 # |> assign(:user, user)                 |> post("/api/v1/statuses/#{activity.id}/unmute") -               |> json_response(200) +               |> json_response_and_validate_schema(200)      end    end @@ -1139,16 +1269,17 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      user2 = insert(:user)      user3 = insert(:user) -    {:ok, replied_to} = CommonAPI.post(user1, %{"status" => "cofe"}) +    {:ok, replied_to} = CommonAPI.post(user1, %{status: "cofe"})      # Reply to status from another user      conn1 =        conn        |> assign(:user, user2)        |> assign(:token, insert(:oauth_token, user: user2, scopes: ["write:statuses"])) +      |> put_req_header("content-type", "application/json")        |> post("/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => replied_to.id}) -    assert %{"content" => "xD", "id" => id} = json_response(conn1, 200) +    assert %{"content" => "xD", "id" => id} = json_response_and_validate_schema(conn1, 200)      activity = Activity.get_by_id_with_object(id) @@ -1160,10 +1291,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        conn        |> assign(:user, user3)        |> assign(:token, insert(:oauth_token, user: user3, scopes: ["write:statuses"])) +      |> put_req_header("content-type", "application/json")        |> post("/api/v1/statuses/#{activity.id}/reblog")      assert %{"reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 1}} = -             json_response(conn2, 200) +             json_response_and_validate_schema(conn2, 200)      assert to_string(activity.id) == id @@ -1186,7 +1318,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      setup do: oauth_access(["read:accounts"])      setup %{user: user} do -      {:ok, activity} = CommonAPI.post(user, %{"status" => "test"}) +      {:ok, activity} = CommonAPI.post(user, %{status: "test"})        %{activity: activity}      end @@ -1198,7 +1330,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        response =          conn          |> get("/api/v1/statuses/#{activity.id}/favourited_by") -        |> json_response(:ok) +        |> json_response_and_validate_schema(:ok)        [%{"id" => id}] = response @@ -1212,7 +1344,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        response =          conn          |> get("/api/v1/statuses/#{activity.id}/favourited_by") -        |> json_response(:ok) +        |> json_response_and_validate_schema(:ok)        assert Enum.empty?(response)      end @@ -1229,7 +1361,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        response =          conn          |> get("/api/v1/statuses/#{activity.id}/favourited_by") -        |> json_response(:ok) +        |> json_response_and_validate_schema(:ok)        assert Enum.empty?(response)      end @@ -1241,7 +1373,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        response =          build_conn()          |> get("/api/v1/statuses/#{activity.id}/favourited_by") -        |> json_response(:ok) +        |> json_response_and_validate_schema(:ok)        [%{"id" => id}] = response        assert id == other_user.id @@ -1252,8 +1384,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        {:ok, activity} =          CommonAPI.post(user, %{ -          "status" => "@#{other_user.nickname} wanna get some #cofe together?", -          "visibility" => "direct" +          status: "@#{other_user.nickname} wanna get some #cofe together?", +          visibility: "direct"          })        {:ok, _} = CommonAPI.favorite(other_user, activity.id) @@ -1262,7 +1394,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        build_conn()        |> get(favourited_by_url) -      |> json_response(404) +      |> json_response_and_validate_schema(404)        conn =          build_conn() @@ -1272,12 +1404,12 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        conn        |> assign(:token, nil)        |> get(favourited_by_url) -      |> json_response(404) +      |> json_response_and_validate_schema(404)        response =          conn          |> get(favourited_by_url) -        |> json_response(200) +        |> json_response_and_validate_schema(200)        [%{"id" => id}] = response        assert id == other_user.id @@ -1288,7 +1420,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      setup do: oauth_access(["read:accounts"])      setup %{user: user} do -      {:ok, activity} = CommonAPI.post(user, %{"status" => "test"}) +      {:ok, activity} = CommonAPI.post(user, %{status: "test"})        %{activity: activity}      end @@ -1300,7 +1432,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        response =          conn          |> get("/api/v1/statuses/#{activity.id}/reblogged_by") -        |> json_response(:ok) +        |> json_response_and_validate_schema(:ok)        [%{"id" => id}] = response @@ -1314,7 +1446,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        response =          conn          |> get("/api/v1/statuses/#{activity.id}/reblogged_by") -        |> json_response(:ok) +        |> json_response_and_validate_schema(:ok)        assert Enum.empty?(response)      end @@ -1331,7 +1463,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        response =          conn          |> get("/api/v1/statuses/#{activity.id}/reblogged_by") -        |> json_response(:ok) +        |> json_response_and_validate_schema(:ok)        assert Enum.empty?(response)      end @@ -1342,12 +1474,12 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      } do        other_user = insert(:user) -      {:ok, _, _} = CommonAPI.repeat(activity.id, other_user, %{"visibility" => "private"}) +      {:ok, _, _} = CommonAPI.repeat(activity.id, other_user, %{visibility: "private"})        response =          conn          |> get("/api/v1/statuses/#{activity.id}/reblogged_by") -        |> json_response(:ok) +        |> json_response_and_validate_schema(:ok)        assert Enum.empty?(response)      end @@ -1359,7 +1491,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        response =          build_conn()          |> get("/api/v1/statuses/#{activity.id}/reblogged_by") -        |> json_response(:ok) +        |> json_response_and_validate_schema(:ok)        [%{"id" => id}] = response        assert id == other_user.id @@ -1370,20 +1502,20 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        {:ok, activity} =          CommonAPI.post(user, %{ -          "status" => "@#{other_user.nickname} wanna get some #cofe together?", -          "visibility" => "direct" +          status: "@#{other_user.nickname} wanna get some #cofe together?", +          visibility: "direct"          })        build_conn()        |> get("/api/v1/statuses/#{activity.id}/reblogged_by") -      |> json_response(404) +      |> json_response_and_validate_schema(404)        response =          build_conn()          |> assign(:user, other_user)          |> assign(:token, insert(:oauth_token, user: other_user, scopes: ["read:accounts"]))          |> get("/api/v1/statuses/#{activity.id}/reblogged_by") -        |> json_response(200) +        |> json_response_and_validate_schema(200)        assert [] == response      end @@ -1392,16 +1524,16 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do    test "context" do      user = insert(:user) -    {:ok, %{id: id1}} = CommonAPI.post(user, %{"status" => "1"}) -    {:ok, %{id: id2}} = CommonAPI.post(user, %{"status" => "2", "in_reply_to_status_id" => id1}) -    {:ok, %{id: id3}} = CommonAPI.post(user, %{"status" => "3", "in_reply_to_status_id" => id2}) -    {:ok, %{id: id4}} = CommonAPI.post(user, %{"status" => "4", "in_reply_to_status_id" => id3}) -    {:ok, %{id: id5}} = CommonAPI.post(user, %{"status" => "5", "in_reply_to_status_id" => id4}) +    {:ok, %{id: id1}} = CommonAPI.post(user, %{status: "1"}) +    {:ok, %{id: id2}} = CommonAPI.post(user, %{status: "2", in_reply_to_status_id: id1}) +    {:ok, %{id: id3}} = CommonAPI.post(user, %{status: "3", in_reply_to_status_id: id2}) +    {:ok, %{id: id4}} = CommonAPI.post(user, %{status: "4", in_reply_to_status_id: id3}) +    {:ok, %{id: id5}} = CommonAPI.post(user, %{status: "5", in_reply_to_status_id: id4})      response =        build_conn()        |> get("/api/v1/statuses/#{id3}/context") -      |> json_response(:ok) +      |> json_response_and_validate_schema(:ok)      assert %{               "ancestors" => [%{"id" => ^id1}, %{"id" => ^id2}], @@ -1413,14 +1545,14 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      %{user: user, conn: conn} = oauth_access(["read:favourites"])      other_user = insert(:user) -    {:ok, _} = CommonAPI.post(other_user, %{"status" => "bla"}) -    {:ok, activity} = CommonAPI.post(other_user, %{"status" => "traps are happy"}) +    {:ok, _} = CommonAPI.post(other_user, %{status: "bla"}) +    {:ok, activity} = CommonAPI.post(other_user, %{status: "traps are happy"})      {:ok, _} = CommonAPI.favorite(user, activity.id)      first_conn = get(conn, "/api/v1/favourites") -    assert [status] = json_response(first_conn, 200) +    assert [status] = json_response_and_validate_schema(first_conn, 200)      assert status["id"] == to_string(activity.id)      assert [{"link", _link_header}] = @@ -1429,8 +1561,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      # Honours query params      {:ok, second_activity} =        CommonAPI.post(other_user, %{ -        "status" => -          "Trees Are Never Sad Look At Them Every Once In Awhile They're Quite Beautiful." +        status: "Trees Are Never Sad Look At Them Every Once In Awhile They're Quite Beautiful."        })      {:ok, _} = CommonAPI.favorite(user, second_activity.id) @@ -1439,17 +1570,17 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      second_conn = get(conn, "/api/v1/favourites?since_id=#{last_like}") -    assert [second_status] = json_response(second_conn, 200) +    assert [second_status] = json_response_and_validate_schema(second_conn, 200)      assert second_status["id"] == to_string(second_activity.id)      third_conn = get(conn, "/api/v1/favourites?limit=0") -    assert [] = json_response(third_conn, 200) +    assert [] = json_response_and_validate_schema(third_conn, 200)    end    test "expires_at is nil for another user" do      %{conn: conn, user: user} = oauth_access(["read:statuses"]) -    {:ok, activity} = CommonAPI.post(user, %{"status" => "foobar", "expires_in" => 1_000_000}) +    {:ok, activity} = CommonAPI.post(user, %{status: "foobar", expires_in: 1_000_000})      expires_at =        activity.id @@ -1458,11 +1589,15 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        |> NaiveDateTime.to_iso8601()      assert %{"pleroma" => %{"expires_at" => ^expires_at}} = -             conn |> get("/api/v1/statuses/#{activity.id}") |> json_response(:ok) +             conn +             |> get("/api/v1/statuses/#{activity.id}") +             |> json_response_and_validate_schema(:ok)      %{conn: conn} = oauth_access(["read:statuses"])      assert %{"pleroma" => %{"expires_at" => nil}} = -             conn |> get("/api/v1/statuses/#{activity.id}") |> json_response(:ok) +             conn +             |> get("/api/v1/statuses/#{activity.id}") +             |> json_response_and_validate_schema(:ok)    end  end diff --git a/test/web/mastodon_api/controllers/suggestion_controller_test.exs b/test/web/mastodon_api/controllers/suggestion_controller_test.exs index f120bd0cd..7f08e187c 100644 --- a/test/web/mastodon_api/controllers/suggestion_controller_test.exs +++ b/test/web/mastodon_api/controllers/suggestion_controller_test.exs @@ -11,7 +11,7 @@ defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do      res =        conn        |> get("/api/v1/suggestions") -      |> json_response(200) +      |> json_response_and_validate_schema(200)      assert res == []    end diff --git a/test/web/mastodon_api/controllers/timeline_controller_test.exs b/test/web/mastodon_api/controllers/timeline_controller_test.exs index 06efdc901..f8b9289f3 100644 --- a/test/web/mastodon_api/controllers/timeline_controller_test.exs +++ b/test/web/mastodon_api/controllers/timeline_controller_test.exs @@ -28,13 +28,13 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do        other_user = insert(:user) -      {:ok, _} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"}) +      {:ok, _} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})        response =          conn          |> assign(:user, user)          |> get("/api/v1/timelines/home") -        |> json_response(200) +        |> json_response_and_validate_schema(200)        assert Enum.all?(response, fn n ->                 get_in(n, ["account", "pleroma", "relationship"]) == %{} @@ -42,18 +42,18 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do      end      test "the home timeline", %{user: user, conn: conn} do -      uri = "/api/v1/timelines/home?with_relationships=true" +      uri = "/api/v1/timelines/home?with_relationships=1"        following = insert(:user, nickname: "followed")        third_user = insert(:user, nickname: "repeated") -      {:ok, _activity} = CommonAPI.post(following, %{"status" => "post"}) -      {:ok, activity} = CommonAPI.post(third_user, %{"status" => "repeated post"}) +      {:ok, _activity} = CommonAPI.post(following, %{status: "post"}) +      {:ok, activity} = CommonAPI.post(third_user, %{status: "repeated post"})        {:ok, _, _} = CommonAPI.repeat(activity.id, following)        ret_conn = get(conn, uri) -      assert Enum.empty?(json_response(ret_conn, :ok)) +      assert Enum.empty?(json_response_and_validate_schema(ret_conn, :ok))        {:ok, _user} = User.follow(user, following) @@ -78,7 +78,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do                     "pleroma" => %{"relationship" => %{"following" => true}}                   }                 } -             ] = json_response(ret_conn, :ok) +             ] = json_response_and_validate_schema(ret_conn, :ok)        {:ok, _user} = User.follow(third_user, user) @@ -104,22 +104,20 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do                     "pleroma" => %{"relationship" => %{"following" => true}}                   }                 } -             ] = json_response(ret_conn, :ok) +             ] = json_response_and_validate_schema(ret_conn, :ok)      end      test "the home timeline when the direct messages are excluded", %{user: user, conn: conn} do -      {:ok, public_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "public"}) -      {:ok, direct_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"}) +      {:ok, public_activity} = CommonAPI.post(user, %{status: ".", visibility: "public"}) +      {:ok, direct_activity} = CommonAPI.post(user, %{status: ".", visibility: "direct"}) -      {:ok, unlisted_activity} = -        CommonAPI.post(user, %{"status" => ".", "visibility" => "unlisted"}) +      {:ok, unlisted_activity} = CommonAPI.post(user, %{status: ".", visibility: "unlisted"}) -      {:ok, private_activity} = -        CommonAPI.post(user, %{"status" => ".", "visibility" => "private"}) +      {:ok, private_activity} = CommonAPI.post(user, %{status: ".", visibility: "private"}) -      conn = get(conn, "/api/v1/timelines/home", %{"exclude_visibilities" => ["direct"]}) +      conn = get(conn, "/api/v1/timelines/home?exclude_visibilities[]=direct") -      assert status_ids = json_response(conn, :ok) |> Enum.map(& &1["id"]) +      assert status_ids = json_response_and_validate_schema(conn, :ok) |> Enum.map(& &1["id"])        assert public_activity.id in status_ids        assert unlisted_activity.id in status_ids        assert private_activity.id in status_ids @@ -132,33 +130,33 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do      test "the public timeline", %{conn: conn} do        following = insert(:user) -      {:ok, _activity} = CommonAPI.post(following, %{"status" => "test"}) +      {:ok, _activity} = CommonAPI.post(following, %{status: "test"})        _activity = insert(:note_activity, local: false) -      conn = get(conn, "/api/v1/timelines/public", %{"local" => "False"}) +      conn = get(conn, "/api/v1/timelines/public?local=False") -      assert length(json_response(conn, :ok)) == 2 +      assert length(json_response_and_validate_schema(conn, :ok)) == 2 -      conn = get(build_conn(), "/api/v1/timelines/public", %{"local" => "True"}) +      conn = get(build_conn(), "/api/v1/timelines/public?local=True") -      assert [%{"content" => "test"}] = json_response(conn, :ok) +      assert [%{"content" => "test"}] = json_response_and_validate_schema(conn, :ok) -      conn = get(build_conn(), "/api/v1/timelines/public", %{"local" => "1"}) +      conn = get(build_conn(), "/api/v1/timelines/public?local=1") -      assert [%{"content" => "test"}] = json_response(conn, :ok) +      assert [%{"content" => "test"}] = json_response_and_validate_schema(conn, :ok)      end      test "the public timeline includes only public statuses for an authenticated user" do        %{user: user, conn: conn} = oauth_access(["read:statuses"]) -      {:ok, _activity} = CommonAPI.post(user, %{"status" => "test"}) -      {:ok, _activity} = CommonAPI.post(user, %{"status" => "test", "visibility" => "private"}) -      {:ok, _activity} = CommonAPI.post(user, %{"status" => "test", "visibility" => "unlisted"}) -      {:ok, _activity} = CommonAPI.post(user, %{"status" => "test", "visibility" => "direct"}) +      {:ok, _activity} = CommonAPI.post(user, %{status: "test"}) +      {:ok, _activity} = CommonAPI.post(user, %{status: "test", visibility: "private"}) +      {:ok, _activity} = CommonAPI.post(user, %{status: "test", visibility: "unlisted"}) +      {:ok, _activity} = CommonAPI.post(user, %{status: "test", visibility: "direct"})        res_conn = get(conn, "/api/v1/timelines/public") -      assert length(json_response(res_conn, 200)) == 1 +      assert length(json_response_and_validate_schema(res_conn, 200)) == 1      end    end @@ -176,15 +174,15 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do      setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], true)      test "if user is unauthenticated", %{conn: conn} do -      res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "true"}) +      res_conn = get(conn, "/api/v1/timelines/public?local=true") -      assert json_response(res_conn, :unauthorized) == %{ +      assert json_response_and_validate_schema(res_conn, :unauthorized) == %{                 "error" => "authorization required for timeline view"               } -      res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "false"}) +      res_conn = get(conn, "/api/v1/timelines/public?local=false") -      assert json_response(res_conn, :unauthorized) == %{ +      assert json_response_and_validate_schema(res_conn, :unauthorized) == %{                 "error" => "authorization required for timeline view"               }      end @@ -192,11 +190,11 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do      test "if user is authenticated" do        %{conn: conn} = oauth_access(["read:statuses"]) -      res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "true"}) -      assert length(json_response(res_conn, 200)) == 1 +      res_conn = get(conn, "/api/v1/timelines/public?local=true") +      assert length(json_response_and_validate_schema(res_conn, 200)) == 1 -      res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "false"}) -      assert length(json_response(res_conn, 200)) == 2 +      res_conn = get(conn, "/api/v1/timelines/public?local=false") +      assert length(json_response_and_validate_schema(res_conn, 200)) == 2      end    end @@ -206,24 +204,24 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do      setup do: clear_config([:restrict_unauthenticated, :timelines, :local], true)      test "if user is unauthenticated", %{conn: conn} do -      res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "true"}) +      res_conn = get(conn, "/api/v1/timelines/public?local=true") -      assert json_response(res_conn, :unauthorized) == %{ +      assert json_response_and_validate_schema(res_conn, :unauthorized) == %{                 "error" => "authorization required for timeline view"               } -      res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "false"}) -      assert length(json_response(res_conn, 200)) == 2 +      res_conn = get(conn, "/api/v1/timelines/public?local=false") +      assert length(json_response_and_validate_schema(res_conn, 200)) == 2      end      test "if user is authenticated", %{conn: _conn} do        %{conn: conn} = oauth_access(["read:statuses"]) -      res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "true"}) -      assert length(json_response(res_conn, 200)) == 1 +      res_conn = get(conn, "/api/v1/timelines/public?local=true") +      assert length(json_response_and_validate_schema(res_conn, 200)) == 1 -      res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "false"}) -      assert length(json_response(res_conn, 200)) == 2 +      res_conn = get(conn, "/api/v1/timelines/public?local=false") +      assert length(json_response_and_validate_schema(res_conn, 200)) == 2      end    end @@ -233,12 +231,12 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do      setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], true)      test "if user is unauthenticated", %{conn: conn} do -      res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "true"}) -      assert length(json_response(res_conn, 200)) == 1 +      res_conn = get(conn, "/api/v1/timelines/public?local=true") +      assert length(json_response_and_validate_schema(res_conn, 200)) == 1 -      res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "false"}) +      res_conn = get(conn, "/api/v1/timelines/public?local=false") -      assert json_response(res_conn, :unauthorized) == %{ +      assert json_response_and_validate_schema(res_conn, :unauthorized) == %{                 "error" => "authorization required for timeline view"               }      end @@ -246,11 +244,11 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do      test "if user is authenticated", %{conn: _conn} do        %{conn: conn} = oauth_access(["read:statuses"]) -      res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "true"}) -      assert length(json_response(res_conn, 200)) == 1 +      res_conn = get(conn, "/api/v1/timelines/public?local=true") +      assert length(json_response_and_validate_schema(res_conn, 200)) == 1 -      res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "false"}) -      assert length(json_response(res_conn, 200)) == 2 +      res_conn = get(conn, "/api/v1/timelines/public?local=false") +      assert length(json_response_and_validate_schema(res_conn, 200)) == 2      end    end @@ -263,14 +261,14 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do        {:ok, direct} =          CommonAPI.post(user_one, %{ -          "status" => "Hi @#{user_two.nickname}!", -          "visibility" => "direct" +          status: "Hi @#{user_two.nickname}!", +          visibility: "direct"          })        {:ok, _follower_only} =          CommonAPI.post(user_one, %{ -          "status" => "Hi @#{user_two.nickname}!", -          "visibility" => "private" +          status: "Hi @#{user_two.nickname}!", +          visibility: "private"          })        conn_user_two = @@ -281,7 +279,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do        # Only direct should be visible here        res_conn = get(conn_user_two, "api/v1/timelines/direct") -      [status] = json_response(res_conn, :ok) +      assert [status] = json_response_and_validate_schema(res_conn, :ok)        assert %{"visibility" => "direct"} = status        assert status["url"] != direct.data["id"] @@ -293,33 +291,34 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do          |> assign(:token, insert(:oauth_token, user: user_one, scopes: ["read:statuses"]))          |> get("api/v1/timelines/direct") -      [status] = json_response(res_conn, :ok) +      [status] = json_response_and_validate_schema(res_conn, :ok)        assert %{"visibility" => "direct"} = status        # Both should be visible here        res_conn = get(conn_user_two, "api/v1/timelines/home") -      [_s1, _s2] = json_response(res_conn, :ok) +      [_s1, _s2] = json_response_and_validate_schema(res_conn, :ok)        # Test pagination        Enum.each(1..20, fn _ ->          {:ok, _} =            CommonAPI.post(user_one, %{ -            "status" => "Hi @#{user_two.nickname}!", -            "visibility" => "direct" +            status: "Hi @#{user_two.nickname}!", +            visibility: "direct"            })        end)        res_conn = get(conn_user_two, "api/v1/timelines/direct") -      statuses = json_response(res_conn, :ok) +      statuses = json_response_and_validate_schema(res_conn, :ok)        assert length(statuses) == 20 -      res_conn = -        get(conn_user_two, "api/v1/timelines/direct", %{max_id: List.last(statuses)["id"]}) +      max_id = List.last(statuses)["id"] + +      res_conn = get(conn_user_two, "api/v1/timelines/direct?max_id=#{max_id}") -      [status] = json_response(res_conn, :ok) +      assert [status] = json_response_and_validate_schema(res_conn, :ok)        assert status["url"] != direct.data["id"]      end @@ -332,19 +331,19 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do        {:ok, _blocked_direct} =          CommonAPI.post(blocked, %{ -          "status" => "Hi @#{blocker.nickname}!", -          "visibility" => "direct" +          status: "Hi @#{blocker.nickname}!", +          visibility: "direct"          })        {:ok, direct} =          CommonAPI.post(other_user, %{ -          "status" => "Hi @#{blocker.nickname}!", -          "visibility" => "direct" +          status: "Hi @#{blocker.nickname}!", +          visibility: "direct"          })        res_conn = get(conn, "api/v1/timelines/direct") -      [status] = json_response(res_conn, :ok) +      [status] = json_response_and_validate_schema(res_conn, :ok)        assert status["id"] == direct.id      end    end @@ -354,14 +353,14 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do      test "list timeline", %{user: user, conn: conn} do        other_user = insert(:user) -      {:ok, _activity_one} = CommonAPI.post(user, %{"status" => "Marisa is cute."}) -      {:ok, activity_two} = CommonAPI.post(other_user, %{"status" => "Marisa is cute."}) +      {:ok, _activity_one} = CommonAPI.post(user, %{status: "Marisa is cute."}) +      {:ok, activity_two} = CommonAPI.post(other_user, %{status: "Marisa is cute."})        {:ok, list} = Pleroma.List.create("name", user)        {:ok, list} = Pleroma.List.follow(list, other_user)        conn = get(conn, "/api/v1/timelines/list/#{list.id}") -      assert [%{"id" => id}] = json_response(conn, :ok) +      assert [%{"id" => id}] = json_response_and_validate_schema(conn, :ok)        assert id == to_string(activity_two.id)      end @@ -371,12 +370,12 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do        conn: conn      } do        other_user = insert(:user) -      {:ok, activity_one} = CommonAPI.post(other_user, %{"status" => "Marisa is cute."}) +      {:ok, activity_one} = CommonAPI.post(other_user, %{status: "Marisa is cute."})        {:ok, _activity_two} =          CommonAPI.post(other_user, %{ -          "status" => "Marisa is cute.", -          "visibility" => "private" +          status: "Marisa is cute.", +          visibility: "private"          })        {:ok, list} = Pleroma.List.create("name", user) @@ -384,7 +383,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do        conn = get(conn, "/api/v1/timelines/list/#{list.id}") -      assert [%{"id" => id}] = json_response(conn, :ok) +      assert [%{"id" => id}] = json_response_and_validate_schema(conn, :ok)        assert id == to_string(activity_one.id)      end @@ -397,18 +396,18 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do      test "hashtag timeline", %{conn: conn} do        following = insert(:user) -      {:ok, activity} = CommonAPI.post(following, %{"status" => "test #2hu"}) +      {:ok, activity} = CommonAPI.post(following, %{status: "test #2hu"})        nconn = get(conn, "/api/v1/timelines/tag/2hu") -      assert [%{"id" => id}] = json_response(nconn, :ok) +      assert [%{"id" => id}] = json_response_and_validate_schema(nconn, :ok)        assert id == to_string(activity.id)        # works for different capitalization too        nconn = get(conn, "/api/v1/timelines/tag/2HU") -      assert [%{"id" => id}] = json_response(nconn, :ok) +      assert [%{"id" => id}] = json_response_and_validate_schema(nconn, :ok)        assert id == to_string(activity.id)      end @@ -416,26 +415,25 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do      test "multi-hashtag timeline", %{conn: conn} do        user = insert(:user) -      {:ok, activity_test} = CommonAPI.post(user, %{"status" => "#test"}) -      {:ok, activity_test1} = CommonAPI.post(user, %{"status" => "#test #test1"}) -      {:ok, activity_none} = CommonAPI.post(user, %{"status" => "#test #none"}) +      {:ok, activity_test} = CommonAPI.post(user, %{status: "#test"}) +      {:ok, activity_test1} = CommonAPI.post(user, %{status: "#test #test1"}) +      {:ok, activity_none} = CommonAPI.post(user, %{status: "#test #none"}) -      any_test = get(conn, "/api/v1/timelines/tag/test", %{"any" => ["test1"]}) +      any_test = get(conn, "/api/v1/timelines/tag/test?any[]=test1") -      [status_none, status_test1, status_test] = json_response(any_test, :ok) +      [status_none, status_test1, status_test] = json_response_and_validate_schema(any_test, :ok)        assert to_string(activity_test.id) == status_test["id"]        assert to_string(activity_test1.id) == status_test1["id"]        assert to_string(activity_none.id) == status_none["id"] -      restricted_test = -        get(conn, "/api/v1/timelines/tag/test", %{"all" => ["test1"], "none" => ["none"]}) +      restricted_test = get(conn, "/api/v1/timelines/tag/test?all[]=test1&none[]=none") -      assert [status_test1] == json_response(restricted_test, :ok) +      assert [status_test1] == json_response_and_validate_schema(restricted_test, :ok) -      all_test = get(conn, "/api/v1/timelines/tag/test", %{"all" => ["none"]}) +      all_test = get(conn, "/api/v1/timelines/tag/test?all[]=none") -      assert [status_none] == json_response(all_test, :ok) +      assert [status_none] == json_response_and_validate_schema(all_test, :ok)      end    end  end  | 
