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.
Recycles the connection.
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.
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.
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"]
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.
@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"
@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"