# `Charon.TestHelpers`
[🔗](https://github.com/weareyipyip/charon/blob/v4.3.0/lib/charon/test_helpers.ex#L1)

Utility functions for writing tests.

# `test_session`

```elixir
@type test_session() :: %{
  session: Charon.Models.Session.t(),
  tokens: Charon.Models.Tokens.t(),
  cookies: Plug.Conn.resp_cookies()
}
```

# `create_session`

```elixir
@spec create_session(Charon.Config.t(), Charon.SessionPlugs.upsert_session_opts()) ::
  test_session()
```

Create a test session and return the session, a set of tokens for it and the response cookies.

## Options

  - `:upsert_session_opts` (default `[]`) as defined in `t:Charon.SessionPlugs.upsert_session_opts/0`

# `override_opt_mod_conf`

```elixir
@spec override_opt_mod_conf(Charon.Config.t(), atom() | binary(), map() | keyword()) ::
  Charon.Config.t()
```

Override configuration for an optional module.

# `put_token`

```elixir
@spec put_token(Plug.Conn.t(), Charon.Config.t(), keyword()) :: Plug.Conn.t()
```

Create a new test session and put a token (and its cookie when needed) on the conn.
This is essentially `create_session/3` and `put_token_for/3` combined into one
convenience function.

## Options

  The upsert_session_opts defined in `t:Charon.SessionPlugs.upsert_session_opts/0` AND
  - `:token` is either `:access` (default) or `:refresh`

# `put_token_for`

```elixir
@spec put_token_for(Plug.Conn.t(), test_session(), [{:token, :access | :refresh}]) ::
  Plug.Conn.t()
```

Put a token (and its cookie when needed) from the test session on the conn.
Use `create_session/3` to create the test session.

## Options

  - `:token` is either `:access` (default) or `:refresh`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
