comfycamp/test/comfycamp_web/controllers/oidc_app_controller_test.exs

101 lines
3.1 KiB
Elixir
Raw Normal View History

2024-09-05 02:27:33 +05:00
defmodule ComfycampWeb.OIDCAppControllerTest do
use ComfycampWeb.ConnCase
import Comfycamp.SSOFixtures
@create_attrs %{
2024-09-06 13:12:30 +05:00
client_id: "some_client_id",
client_secret: "some client_secret",
2024-09-05 02:27:33 +05:00
name: "some name",
2024-09-06 13:12:30 +05:00
enabled: true
2024-09-05 02:27:33 +05:00
}
@update_attrs %{
2024-09-06 13:12:30 +05:00
client_id: "some_client_id",
client_secret: "some updated client_secret",
2024-09-05 02:27:33 +05:00
name: "some updated name",
2024-09-06 13:12:30 +05:00
enabled: false
2024-09-05 02:27:33 +05:00
}
@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")
2024-09-06 13:12:30 +05:00
assert html_response(conn, 200) =~ "Listing OpenID Connect apps"
2024-09-05 02:27:33 +05:00
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")
2024-09-06 13:12:30 +05:00
assert html_response(conn, 200) =~ "New OpenID Connect app"
2024-09-05 02:27:33 +05:00
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)
2024-09-06 13:12:30 +05:00
assert %{id: client_id} = redirected_params(conn)
assert redirected_to(conn) == ~p"/admin/oidc_apps/#{client_id}"
2024-09-05 02:27:33 +05:00
2024-09-06 13:12:30 +05:00
conn = get(conn, ~p"/admin/oidc_apps/#{client_id}")
assert html_response(conn, 200) =~ "OpenID app"
2024-09-05 02:27:33 +05:00
end
test "renders errors when data is invalid", %{conn: conn} do
conn = post(conn, ~p"/admin/oidc_apps", oidc_app: @invalid_attrs)
2024-09-06 13:12:30 +05:00
assert html_response(conn, 200) =~ "New OpenID Connect app"
2024-09-05 02:27:33 +05:00
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")
2024-09-06 13:12:30 +05:00
assert html_response(conn, 200) =~ "Edit OpenID app"
2024-09-05 02:27:33 +05:00
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)
2024-09-06 13:12:30 +05:00
assert html_response(conn, 200) =~ "Edit OpenID app"
2024-09-05 02:27:33 +05:00
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