diff --git a/lib/auth_web/controllers/apikey_controller.ex b/lib/auth_web/controllers/apikey_controller.ex index bda55202..183c5eb5 100644 --- a/lib/auth_web/controllers/apikey_controller.ex +++ b/lib/auth_web/controllers/apikey_controller.ex @@ -3,7 +3,6 @@ defmodule AuthWeb.ApikeyController do alias Auth.Apikey def index(conn, _params) do - person_id = conn.assigns.decoded.id apikeys = Apikey.list_apikeys_for_person(person_id) render(conn, "index.html", apikeys: apikeys) @@ -39,15 +38,12 @@ defmodule AuthWeb.ApikeyController do "client_id" => encrypt_encode(person_id), "person_id" => person_id }) - case Apikey.create_apikey(params) do - {:ok, apikey} -> - conn - |> put_flash(:info, "Apikey created successfully.") - |> redirect(to: Routes.apikey_path(conn, :show, apikey)) - {:error, %Ecto.Changeset{} = changeset} -> - render(conn, "new.html", changeset: changeset) - end + {:ok, apikey} = Apikey.create_apikey(params) + + conn + |> put_flash(:info, "Apikey created successfully.") + |> redirect(to: Routes.apikey_path(conn, :show, apikey)) end def show(conn, %{"id" => id}) do diff --git a/test/auth_web/controllers/apikey_controller_test.exs b/test/auth_web/controllers/apikey_controller_test.exs index ee63be32..aa9e6349 100644 --- a/test/auth_web/controllers/apikey_controller_test.exs +++ b/test/auth_web/controllers/apikey_controller_test.exs @@ -62,20 +62,25 @@ defmodule AuthWeb.ApikeyControllerTest do # apikey # end # - # describe "index" do - # test "lists all apikeys", %{conn: conn} do - # conn = get(conn, Routes.apikey_path(conn, :index)) - # assert html_response(conn, 200) =~ "Listing Apikeys" - # end - # end - # - # describe "new apikey" do - # test "renders form", %{conn: conn} do - # conn = get(conn, Routes.apikey_path(conn, :new)) - # assert html_response(conn, 200) =~ "New Apikey" - # end - # end - # + describe "index" do + test "lists all apikeys", %{conn: conn} do + person = Auth.Person.get_person_by_email(@email) + conn = AuthPlug.create_jwt_session(conn, %{email: @email, id: person.id}) + conn = get(conn, Routes.apikey_path(conn, :index)) + assert html_response(conn, 200) =~ "DWYL_API_KEY" + end + end + + describe "new apikey" do + test "renders form", %{conn: conn} do + person = Auth.Person.get_person_by_email(@email) + conn = AuthPlug.create_jwt_session(conn, %{email: @email, id: person.id}) + + conn = get(conn, Routes.apikey_path(conn, :new)) + assert html_response(conn, 200) =~ "New Apikey" + end + end + describe "create apikey" do test "redirects to show when data is valid", %{conn: conn} do