Add start of controller testing

This commit is contained in:
Pim Kunis 2021-07-13 17:08:07 +02:00
parent 598af7a884
commit 096c99df92
14 changed files with 106 additions and 87 deletions

View file

@ -0,0 +1,29 @@
defmodule MatrixServerWeb.AuthControllerTest do
use MatrixServerWeb.ConnCase
alias MatrixServerWeb.Endpoint
describe "register endpoint" do
test "renders the auth flow when no auth parameter is given", %{conn: conn} do
conn = post(conn, Routes.auth_path(conn, :register))
assert %{"flows" => flows, "params" => _} = json_response(conn, 401)
assert is_list(flows)
end
test "registers account with minimal information", %{conn: conn} do
params = %{
"username" => "user",
"password" => "lemmein",
"auth" => %{"type" => "m.login.dummy"}
}
conn = post_json(conn, Routes.auth_path(Endpoint, :register), params)
user_id = MatrixServer.get_mxid("user")
assert %{"access_token" => _, "device_id" => _, "user_id" => ^user_id} =
json_response(conn, 200)
end
end
end

View file

@ -0,0 +1,16 @@
defmodule MatrixServerWeb.InfoControllerTest do
use MatrixServerWeb.ConnCase
test "versions endpoint returns a list of supported Matrix spec versions", %{conn: conn} do
conn = get(conn, Routes.info_path(conn, :versions))
assert %{"versions" => versions} = json_response(conn, 200)
assert is_list(versions)
end
test "unrecognized route renders M_UNRECOGNIZED error", %{conn: conn} do
conn = get(conn, MatrixServerWeb.Endpoint.url() <> "/sneed")
assert %{"errcode" => "M_UNRECOGNIZED"} = json_response(conn, 400)
end
end