View Source FlEx.ConnTest (fl_ex v0.1.0)

Summary

Functions

Creates a connection.

Creates a connection with a preset method, path and body.

Ensures the connection is recycled ans recycles in case that wasn't.

Asserts the given status code, that we have a json response and returns the decoded JSON response if one was set or sent.

Asserts the given status code and returns the response body if one was set or sent.

Returns the content type as long as it matches the given format.

Functions

@spec build_conn() :: Conn.t()

Creates a connection.

Link to this function

build_conn(method, path, params_or_body \\ nil)

View Source
@spec build_conn(atom() | binary(), binary(), binary() | list() | map() | nil) ::
  Conn.t()

Creates a connection with a preset method, path and body.

@spec ensure_recycled(Conn.t()) :: Conn.t()

Ensures the connection is recycled ans recycles in case that wasn't.

Link to this function

json_response(conn, status)

View Source
@spec json_response(Conn.t(), status :: integer() | atom()) :: term()

Asserts the given status code, that we have a json response and returns the decoded JSON response if one was set or sent.

Examples

body = json_response(conn, 200)
assert "can't be blank" in body["errors"]
Link to this function

recycle(conn, headers \\ ~w(accept accept-language authorization))

View Source
@spec recycle(Conn.t(), [String.t()]) :: Conn.t()

Recycles the connection.

Recycling receives a connection and returns a new connection, containing cookies and relevant information from the given one.

This emulates behaviour performed by browsers where cookies returned in the response are available in following requests.

Note recycle/1 is automatically invoked when dispatching to the endpoint, unless the connection has already been recycled.

Link to this function

request(conn, endpoint, method, path_or_action, params_or_body)

View Source
@spec response(Plug.Conn.t(), status :: integer() | atom()) :: binary()

Asserts the given status code and returns the response body if one was set or sent.

Examples

conn = get(build_conn(), "/")
assert response(conn, 200) =~ "hello world"
Link to this function

response_content_type(conn, format)

View Source
@spec response_content_type(Plug.Conn.t(), atom()) :: String.t()

Returns the content type as long as it matches the given format.

Examples

# Assert we have an html response with utf-8 charset
assert response_content_type(conn, :html) =~ "charset=utf-8"