100 lines
3.1 KiB
Elixir
100 lines
3.1 KiB
Elixir
defmodule ComfycampWeb.OIDCAppControllerTest do
|
|
use ComfycampWeb.ConnCase
|
|
|
|
import Comfycamp.SSOFixtures
|
|
|
|
@create_attrs %{
|
|
client_id: "some_client_id",
|
|
client_secret: "some client_secret",
|
|
name: "some name",
|
|
enabled: true
|
|
}
|
|
@update_attrs %{
|
|
client_id: "some_client_id",
|
|
client_secret: "some updated client_secret",
|
|
name: "some updated name",
|
|
enabled: false
|
|
}
|
|
@invalid_attrs %{enabled: nil, name: nil, client_id: nil, client_secret: nil}
|
|
|
|
describe "index" do
|
|
setup [:register_and_log_in_admin_user]
|
|
|
|
test "lists all oidc_apps", %{conn: conn} do
|
|
conn = get(conn, ~p"/admin/oidc_apps")
|
|
assert html_response(conn, 200) =~ "Listing OpenID Connect apps"
|
|
end
|
|
end
|
|
|
|
describe "new oidc_app" do
|
|
setup [:register_and_log_in_admin_user]
|
|
|
|
test "renders form", %{conn: conn} do
|
|
conn = get(conn, ~p"/admin/oidc_apps/new")
|
|
assert html_response(conn, 200) =~ "New OpenID Connect app"
|
|
end
|
|
end
|
|
|
|
describe "create oidc_app" do
|
|
setup [:register_and_log_in_admin_user]
|
|
|
|
test "redirects to show when data is valid", %{conn: conn} do
|
|
conn = post(conn, ~p"/admin/oidc_apps", oidc_app: @create_attrs)
|
|
|
|
assert %{id: client_id} = redirected_params(conn)
|
|
assert redirected_to(conn) == ~p"/admin/oidc_apps/#{client_id}"
|
|
|
|
conn = get(conn, ~p"/admin/oidc_apps/#{client_id}")
|
|
assert html_response(conn, 200) =~ "OpenID app"
|
|
end
|
|
|
|
test "renders errors when data is invalid", %{conn: conn} do
|
|
conn = post(conn, ~p"/admin/oidc_apps", oidc_app: @invalid_attrs)
|
|
assert html_response(conn, 200) =~ "New OpenID Connect app"
|
|
end
|
|
end
|
|
|
|
describe "edit oidc_app" do
|
|
setup [:create_oidc_app, :register_and_log_in_admin_user]
|
|
|
|
test "renders form for editing chosen oidc_app", %{conn: conn, oidc_app: oidc_app} do
|
|
conn = get(conn, ~p"/admin/oidc_apps/#{oidc_app}/edit")
|
|
assert html_response(conn, 200) =~ "Edit OpenID app"
|
|
end
|
|
end
|
|
|
|
describe "update oidc_app" do
|
|
setup [:create_oidc_app, :register_and_log_in_admin_user]
|
|
|
|
test "redirects when data is valid", %{conn: conn, oidc_app: oidc_app} do
|
|
conn = put(conn, ~p"/admin/oidc_apps/#{oidc_app}", oidc_app: @update_attrs)
|
|
assert redirected_to(conn) == ~p"/admin/oidc_apps/#{oidc_app}"
|
|
|
|
conn = get(conn, ~p"/admin/oidc_apps/#{oidc_app}")
|
|
assert html_response(conn, 200) =~ "some updated name"
|
|
end
|
|
|
|
test "renders errors when data is invalid", %{conn: conn, oidc_app: oidc_app} do
|
|
conn = put(conn, ~p"/admin/oidc_apps/#{oidc_app}", oidc_app: @invalid_attrs)
|
|
assert html_response(conn, 200) =~ "Edit OpenID app"
|
|
end
|
|
end
|
|
|
|
describe "delete oidc_app" do
|
|
setup [:create_oidc_app, :register_and_log_in_admin_user]
|
|
|
|
test "deletes chosen oidc_app", %{conn: conn, oidc_app: oidc_app} do
|
|
conn = delete(conn, ~p"/admin/oidc_apps/#{oidc_app}")
|
|
assert redirected_to(conn) == ~p"/admin/oidc_apps"
|
|
|
|
assert_error_sent 404, fn ->
|
|
get(conn, ~p"/admin/oidc_apps/#{oidc_app}")
|
|
end
|
|
end
|
|
end
|
|
|
|
defp create_oidc_app(_) do
|
|
oidc_app = oidc_app_fixture()
|
|
%{oidc_app: oidc_app}
|
|
end
|
|
end
|