mirror of
https://github.com/plausible/analytics.git
synced 2024-12-23 17:44:43 +03:00
082ec91c63
* Update depenedencies: OpenAPISpex + cursor based pagination * Update formatter config * Add internal server error implementation * Test errors * Implement pagination interface * Implement Plugins API module macros * Implement Public API base URI (to be used with path helpers once called from within forwarded router's scope) * Implement OpenAPI specs + schemas * Implement Shared Links context module * Add pagination and error views * Add Shared Link view * Implement Shared Link controller * Expose SharedLink.t() spec * Implement separate router for the Plugins API * Update moduledocs * Always wrap resource objects with `data` * Update moduledoc * Use https://github.com/open-api-spex/open_api_spex/pull/425 due to https://github.com/open-api-spex/open_api_spex/issues/92 * Rely on BASE_URL for swagger-ui server definition * Fixup goals migration * Migrate broken goals before deleting dupes * Remove bypassing test rate limiting for which there's none anyway * Move the context module under `Plausible.` namespace * Bring back conn assignment to PluginsAPICase template * Update test/plausible_web/plugins/api/controllers/shared_links_test.exs Co-authored-by: Uku Taht <Uku.taht@gmail.com> * Update renamed aliases * Seed static token for development purposes * Delegate Plugins API 500s to a familiar shape * Simplify with statement --------- Co-authored-by: Uku Taht <Uku.taht@gmail.com>
42 lines
1.0 KiB
Elixir
42 lines
1.0 KiB
Elixir
defmodule PlausibleWeb.Plugins.API.ErrorsTest do
|
|
use ExUnit.Case, async: true
|
|
|
|
import Phoenix.ConnTest, only: [json_response: 2]
|
|
|
|
alias PlausibleWeb.Plugins.API.Errors
|
|
|
|
describe "unauthorized/1" do
|
|
test "sends an 401 response with the `www-authenticate` header set" do
|
|
conn =
|
|
Plug.Test.conn(:get, "/")
|
|
|> Errors.unauthorized()
|
|
|
|
assert conn.halted
|
|
|
|
assert json_response(conn, 401) == %{
|
|
"errors" => [%{"detail" => "Plugins API: unauthorized"}]
|
|
}
|
|
|
|
assert Plug.Conn.get_resp_header(conn, "www-authenticate") == [
|
|
~s[Basic realm="Plugins API Access"]
|
|
]
|
|
end
|
|
end
|
|
|
|
describe "error/3" do
|
|
test "formats the given error message" do
|
|
message = "Some message"
|
|
|
|
conn =
|
|
Plug.Test.conn(:get, "/")
|
|
|> Errors.error(:forbidden, message)
|
|
|
|
assert conn.halted
|
|
|
|
assert json_response(conn, 403) == %{
|
|
"errors" => [%{"detail" => "Some message"}]
|
|
}
|
|
end
|
|
end
|
|
end
|