defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do
use Pleroma.Web.ConnCase
- alias Pleroma.Web.ApiSpec
import Pleroma.Factory
- import OpenApiSpex.TestAssertions
describe "GET /api/v1/markers" do
test "gets markers with correct scopes", %{conn: conn} do
|> assign(:user, user)
|> assign(:token, token)
|> get("/api/v1/markers?timeline[]=notifications")
- |> json_response(200)
+ |> json_response_and_validate_schema(200)
assert response == %{
"notifications" => %{
"version" => 0
}
}
-
- assert_schema(response, "MarkersResponse", ApiSpec.spec())
end
test "gets markers with missed scopes", %{conn: conn} do
|> assign(:user, user)
|> assign(:token, token)
|> get("/api/v1/markers", %{timeline: ["notifications"]})
- |> json_response(403)
+ |> json_response_and_validate_schema(403)
assert response == %{"error" => "Insufficient permissions: read:statuses."}
end
home: %{last_read_id: "777"},
notifications: %{"last_read_id" => "69420"}
})
- |> json_response(200)
+ |> json_response_and_validate_schema(200)
assert %{
"notifications" => %{
"version" => 0
}
} = response
-
- assert_schema(response, "MarkersResponse", ApiSpec.spec())
end
test "updates exist marker", %{conn: conn} do
home: %{last_read_id: "777"},
notifications: %{"last_read_id" => "69888"}
})
- |> json_response(200)
+ |> json_response_and_validate_schema(200)
assert response == %{
"notifications" => %{
"version" => 0
}
}
-
- assert_schema(response, "MarkersResponse", ApiSpec.spec())
end
test "creates a marker with missed scopes", %{conn: conn} do
conn
|> assign(:user, user)
|> assign(:token, token)
+ |> put_req_header("content-type", "application/json")
|> post("/api/v1/markers", %{
home: %{last_read_id: "777"},
notifications: %{"last_read_id" => "69420"}
})
- |> json_response(403)
+ |> json_response_and_validate_schema(403)
assert response == %{"error" => "Insufficient permissions: write:statuses."}
end