mirror of
https://github.com/plausible/analytics.git
synced 2024-12-25 10:33:01 +03:00
0007c0c108
* Remove "Context" namespace level * Change Goal string representation * Alias Schemas in Plugin API Test Case template * Update schema & tests for SharedLink resource * Update Goals interface - make it possible to create revenue goals - extract "for site" query to a standalone function * Fixup typespecs * Alias Errors module in OpenAPI controllers * Add missing goals test * Implement Goals Plugins API resource * Add extra test to confirm changeset error propagation * Mute credo * Fix typos * Handle changeset traversal in `Errors` * Use upserts in `Goals.find_or_create` * Extract touch_site! to Site.Cache, address credo, improve code docs * Apply formatting * Remove unused inner join * Update test/plausible_web/plugins/api/controllers/goals_test.exs Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com> * Update test/plausible_web/plugins/api/controllers/goals_test.exs Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com> * Update test/plausible_web/plugins/api/controllers/goals_test.exs Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com> * Update test/plausible_web/plugins/api/controllers/goals_test.exs Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com> * Update test/plausible_web/plugins/api/controllers/goals_test.exs Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com> * Update error message on revenue goal currency clash * Remove unused code --------- Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com>
53 lines
1.4 KiB
Elixir
53 lines
1.4 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]
|
|
import Plausible.Factory
|
|
|
|
import OpenApiSpex.TestAssertions
|
|
|
|
alias PlausibleWeb.Plugins.API.Router.Helpers, as: Routes
|
|
alias PlausibleWeb.Plugins.API.Schemas
|
|
|
|
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 %{test: test} = tags do
|
|
import Plausible.Factory
|
|
: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()
|
|
|
|
site = insert(:site)
|
|
{:ok, _token, raw_token} = Plausible.Plugins.API.Tokens.create(site, Atom.to_string(test))
|
|
|
|
{:ok, conn: conn, site: site, token: raw_token}
|
|
end
|
|
end
|