Created
May 12, 2017 02:13
-
-
Save nmerouze/4897e509f4c4b577dc2fb8addd5b3ef9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Dd.Web.ConnCase do | |
use ExUnit.CaseTemplate | |
using do | |
quote do | |
use Phoenix.ConnTest | |
import Dd.Web.Router.Helpers | |
import Dd.Web.TestHelpers # Helpers added directly to ConnCase | |
@endpoint Dd.Web.Endpoint | |
end | |
end | |
setup tags do | |
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Dd.Repo) | |
unless tags[:async] do | |
Ecto.Adapters.SQL.Sandbox.mode(Dd.Repo, {:shared, self()}) | |
end | |
{:ok, conn: Phoenix.ConnTest.build_conn()} | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Dd.Web.TestHelpers do | |
use Phoenix.ConnTest | |
def json_api_conn do | |
build_conn() | |
|> put_req_header("accept", "application/vnd.api+json") | |
|> put_req_header("content-type", "application/vnd.api+json") | |
end | |
def json_api_conn(user) do | |
conn = Guardian.Plug.api_sign_in(build_conn(), user) | |
token = Guardian.Plug.current_token(conn) | |
json_api_conn() | |
|> put_req_header("authorization", "Bearer " <> token) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment