View Source Charon.TestHelpers (Charon v3.1.1)

Utility functions for writing tests.

Link to this section Summary

Functions

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

Override configuration for an optional module.

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.

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

Link to this section Types

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

Link to this section Functions

Link to this function

create_session(config, upsert_session_opts \\ [])

View Source

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

options

Options

Link to this function

override_opt_mod_conf(config, module, overrides)

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

Override configuration for an optional module.

Link to this function

put_token(conn, config, opts \\ [])

View Source
@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

Options

The upsert_session_opts defined in Charon.SessionPlugs.upsert_session_opts/0 AND

  • :token is either :access (default) or :refresh
Link to this function

put_token_for(conn, test_session, opts \\ [])

View Source
@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

Options

  • :token is either :access (default) or :refresh