Skip to content

Commit

Permalink
100% cov for lib/auth/apikey.ex #42
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Apr 26, 2020
1 parent d2842e7 commit bfb19c7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
14 changes: 5 additions & 9 deletions lib/auth_web/controllers/apikey_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
33 changes: 19 additions & 14 deletions test/auth_web/controllers/apikey_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bfb19c7

Please sign in to comment.