mirror of
https://github.com/plausible/analytics.git
synced 2024-11-23 11:12:15 +03:00
0fa6b688af
* Make TestUtils module available in all tests * Add macros patching the application env in tests Unfortunately a lot of existing functionality relies on certain application env setup. This isn't ideal because the app config is a shared state that prevents us from running the tests in parallel. Those macros encapsulate setting up new env for test purposes and make sure the changes are reverted when the test finishes. * Allow passing request opts to HTTPClient.post/4 We need this to swap custom request building in Google Analytics import. * Unify errors when listing sites * React: propagate backend error messages if available * React: catch API errors in Search Terms component * Propagate google API errors on referrer drilldown * Handle verified properties errors in SC settings * Add missing tests for SC settings controller * Unify errors for fetching search analytics queries (list stats) * Unify errors refreshing Google Auth Token * Test fetch_stats/3 errors and replace Double with Mox * Fixup makrup * s/class/className * Simplify Search Terms display in case of errors * Fix warnings
42 lines
1.1 KiB
Elixir
42 lines
1.1 KiB
Elixir
defmodule PlausibleWeb.ConnCase do
|
|
@moduledoc """
|
|
This module defines the test case to be used by
|
|
tests that require setting up a connection.
|
|
|
|
Such tests rely on `Phoenix.ConnTest` and also
|
|
import other functionality to make it easier
|
|
to build common data structures and query the data layer.
|
|
|
|
Finally, if the test case interacts with the database,
|
|
it cannot be async. For this reason, every test runs
|
|
inside a transaction which is reset at the beginning
|
|
of the test unless the test case is marked as async.
|
|
"""
|
|
|
|
use ExUnit.CaseTemplate
|
|
|
|
using do
|
|
quote do
|
|
# Import conveniences for testing with connections
|
|
use Plausible.TestUtils
|
|
import Plug.Conn
|
|
import Phoenix.ConnTest
|
|
alias PlausibleWeb.Router.Helpers, as: Routes
|
|
import Plausible.Factory
|
|
|
|
# The default endpoint for testing
|
|
@endpoint PlausibleWeb.Endpoint
|
|
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
|
|
|
|
{:ok, conn: Phoenix.ConnTest.build_conn()}
|
|
end
|
|
end
|