analytics/test/support/plugins_api_case.ex
hq1 082ec91c63
OpenAPI: first pass on Plugins API - Shared Links (#3378)
* 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>
2023-10-02 11:18:49 +02:00

47 lines
1.2 KiB
Elixir

defmodule PlausibleWeb.PluginsAPICase do
@moduledoc """
This module defines the test case to be used by
tests that require setting up a Plugins API connection.
"""
use ExUnit.CaseTemplate
using do
quote do
# The default endpoint for testing
@endpoint PlausibleWeb.Endpoint
# Import conveniences for testing with connections
use Plausible.TestUtils
import Plug.Conn
import Phoenix.ConnTest
import PlausibleWeb.Plugins.API, only: [base_uri: 0]
import PlausibleWeb.Plugins.API.Spec, only: [spec: 0]
alias PlausibleWeb.Plugins.API.Router.Helpers, as: Routes
import Plausible.Factory
import OpenApiSpex.TestAssertions
def authenticate(conn, domain, raw_token) do
conn
|> Plug.Conn.put_req_header(
"authorization",
Plug.BasicAuth.encode_basic_auth(domain, raw_token)
)
end
end
end
setup tags do
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Plausible.Repo)
unless tags[:async] do
Ecto.Adapters.SQL.Sandbox.mode(Plausible.Repo, {:shared, self()})
end
conn = Phoenix.ConnTest.build_conn()
{:ok, conn: conn}
end
end