d25c28f49a85e0c533f77d051cdc84d9be1b93ea
[akkoma] / test / support / conn_case.ex
1 defmodule Pleroma.Web.ConnCase do
2 @moduledoc """
3 This module defines the test case to be used by
4 tests that require setting up a connection.
5
6 Such tests rely on `Phoenix.ConnTest` and also
7 import other functionality to make it easier
8 to build common datastructures and query the data layer.
9
10 Finally, if the test case interacts with the database,
11 it cannot be async. For this reason, every test runs
12 inside a transaction which is reset at the beginning
13 of the test unless the test case is marked as async.
14 """
15
16 use ExUnit.CaseTemplate
17
18 using do
19 quote do
20 # Import conveniences for testing with connections
21 use Phoenix.ConnTest
22 use Pleroma.Tests.Helpers
23 import Pleroma.Web.Router.Helpers
24
25 # The default endpoint for testing
26 @endpoint Pleroma.Web.Endpoint
27 end
28 end
29
30 setup tags do
31 Cachex.clear(:user_cache)
32 :ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo)
33
34 unless tags[:async] do
35 Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()})
36 end
37
38 {:ok, conn: Phoenix.ConnTest.build_conn()}
39 end
40 end