diff options
| author | lain <lain@soykaf.club> | 2020-08-28 12:17:19 +0000 | 
|---|---|---|
| committer | lain <lain@soykaf.club> | 2020-08-28 12:17:19 +0000 | 
| commit | 73dd5bdb7dcdf804bdbabcf632671d4de5042ebc (patch) | |
| tree | efcb0b8e68f86d067de98a23f40a24c7dab79d2f /test/web/mastodon_api/controllers/poll_controller_test.exs | |
| parent | f891e2b2f1d1daa122b9856e4b660be394d31e34 (diff) | |
| parent | b141e35d641e733dffe7bd6a45a5bbcafe586c56 (diff) | |
| download | pleroma-73dd5bdb7dcdf804bdbabcf632671d4de5042ebc.tar.gz pleroma-73dd5bdb7dcdf804bdbabcf632671d4de5042ebc.zip | |
Merge branch 'release/2.1.0' into 'stable'
Release/2.1.0
See merge request pleroma/pleroma!2927
Diffstat (limited to 'test/web/mastodon_api/controllers/poll_controller_test.exs')
| -rw-r--r-- | test/web/mastodon_api/controllers/poll_controller_test.exs | 76 | 
1 files changed, 45 insertions, 31 deletions
| diff --git a/test/web/mastodon_api/controllers/poll_controller_test.exs b/test/web/mastodon_api/controllers/poll_controller_test.exs index 88b13a25a..f41de6448 100644 --- a/test/web/mastodon_api/controllers/poll_controller_test.exs +++ b/test/web/mastodon_api/controllers/poll_controller_test.exs @@ -16,15 +16,15 @@ 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)        conn = get(conn, "/api/v1/polls/#{object.id}") -      response = json_response(conn, 200) +      response = json_response_and_validate_schema(conn, 200)        id = to_string(object.id)        assert %{"id" => ^id, "expired" => false, "multiple" => false} = response      end @@ -34,16 +34,16 @@ 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)        conn = get(conn, "/api/v1/polls/#{object.id}") -      assert json_response(conn, 404) +      assert json_response_and_validate_schema(conn, 404)      end    end @@ -55,19 +55,22 @@ 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            }          })        object = Object.normalize(activity) -      conn = post(conn, "/api/v1/polls/#{object.id}/votes", %{"choices" => [0, 1, 2]}) +      conn = +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [0, 1, 2]}) -      assert json_response(conn, 200) +      assert json_response_and_validate_schema(conn, 200)        object = Object.get_by_id(object.id)        assert Enum.all?(object.data["anyOf"], fn %{"replies" => %{"totalItems" => total_items}} -> @@ -78,15 +81,16 @@ 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)        assert conn +             |> put_req_header("content-type", "application/json")               |> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [1]}) -             |> json_response(422) == %{"error" => "Poll's author can't vote"} +             |> json_response_and_validate_schema(422) == %{"error" => "Poll's author can't vote"}        object = Object.get_by_id(object.id) @@ -98,15 +102,16 @@ 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)        assert conn +             |> put_req_header("content-type", "application/json")               |> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [0, 1]}) -             |> json_response(422) == %{"error" => "Too many choices"} +             |> json_response_and_validate_schema(422) == %{"error" => "Too many choices"}        object = Object.get_by_id(object.id) @@ -120,21 +125,27 @@ 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) -      conn = post(conn, "/api/v1/polls/#{object.id}/votes", %{"choices" => [2]}) +      conn = +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [2]}) -      assert json_response(conn, 422) == %{"error" => "Invalid indices"} +      assert json_response_and_validate_schema(conn, 422) == %{"error" => "Invalid indices"}      end      test "returns 404 error when object is not exist", %{conn: conn} do -      conn = post(conn, "/api/v1/polls/1/votes", %{"choices" => [0]}) +      conn = +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/polls/1/votes", %{"choices" => [0]}) -      assert json_response(conn, 404) == %{"error" => "Record not found"} +      assert json_response_and_validate_schema(conn, 404) == %{"error" => "Record not found"}      end      test "returns 404 when poll is private and not available for user", %{conn: conn} do @@ -142,16 +153,19 @@ 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) -      conn = post(conn, "/api/v1/polls/#{object.id}/votes", %{"choices" => [0]}) +      conn = +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [0]}) -      assert json_response(conn, 404) == %{"error" => "Record not found"} +      assert json_response_and_validate_schema(conn, 404) == %{"error" => "Record not found"}      end    end  end | 
