slash v2.0.4 Slash.Test View Source
Use this module for testing your plugs built with Slash.Builder
.
Examples
defmodule Bot.SlackRouterTest do
use ExUnit.Case
use Plug.Test
use Slash.Test
alias Bot.SlackRouter
test "should encode response as json", %{conn: conn} do
conn =
:post
|> conn("/", %{})
|> send_command(SlackRouter, "greet")
|> SlackRouter.call([])
assert %Plug.Conn{resp_body: body} = conn
assert %{"text" => "Hello world!"} = Jason.decode!(body)
end
test "should authenticate user" do
user_id = "slack user id"
conn =
:post
|> conn("/", %{})
|> send_command(SlackRouter, "login", %{"user_id" => user_id})
|> SlackRouter.call([])
assert %Plug.Conn{resp_body: body} = conn
assert %{"text" => "You're authenticated!"} = Jason.decode!(body)
end
end
Link to this section Summary
Functions
Builds a %Conn{}
body for a specific Slack command payload. The optional overrides
map
can be passed which will be merged with default params
Link to this section Functions
Link to this function
send_command(conn, module, command, overrides \\ %{})
View Source
send_command(conn, module, command, overrides \\ %{})
View Source
send_command(
Plug.Conn.t(),
module :: atom(),
command :: String.t(),
overrides :: %{optional(String.t()) => term()}
) :: Plug.Conn.t()
send_command( Plug.Conn.t(), module :: atom(), command :: String.t(), overrides :: %{optional(String.t()) => term()} ) :: Plug.Conn.t()
Builds a %Conn{}
body for a specific Slack command payload. The optional overrides
map
can be passed which will be merged with default params.
If a :signing_key
has not been configured for the test module, a key will be generated and
put into the application environment.
NOTE: This is a little awkward right now due to having to send the mock module as an argument.