Commit 7a13f096 authored by Frank Rousseau's avatar Frank Rousseau
Browse files

fixup

parent e63dab89
......@@ -3,7 +3,7 @@ defmodule Gaja.SessionsTest do
import Gaja.AuthCase
alias Gaja.{Accounts, Sessions, Sessions.Session}
alias Gaja.{Sessions, Sessions.Session}
setup do
user = add_user("fred@example.com")
......
......@@ -12,11 +12,11 @@ defmodule Gaja.Web.TrackerControllerTest do
name: "First tracker"
}
if config[:login] do
{:ok, tracker} = Trackers.create_tracker(attrs)
{:ok, tracker} = Trackers.create_tracker(user, attrs)
conn = conn |> add_token_conn(user)
{:ok, %{conn: conn, tracker: tracker, user: user}}
else
{:ok, tracker} = Trackers.create_tracker(attrs)
{:ok, tracker} = Trackers.create_tracker(user, attrs)
{:ok, %{conn: conn, tracker: tracker, user: user}}
end
end
......@@ -36,7 +36,7 @@ defmodule Gaja.Web.TrackerControllerTest do
describe "show |" do
@tag login: "bill@example.com"
test "show tracker page", %{conn: conn, tracker: tracker} do
test "show tracker info", %{conn: conn, tracker: tracker} do
conn = get(conn, Routes.tracker_path(conn, :show, tracker))
assert json_response(conn, 200)["data"]["uuid"] == tracker.id
end
......@@ -55,13 +55,13 @@ defmodule Gaja.Web.TrackerControllerTest do
name: "New tracker"
}
conn = post(
conn,
Routes.tracker_path(conn, :create),
conn,
Routes.tracker_path(conn, :create),
attrs
)
assert json_response(conn, 201)["data"]["uuid"]
assert length(Trackers.list_trackers) == 2
assert Trackers.get_by %{"name" => "New tracker"}
assert Trackers.get_by name: "New tracker"
assert length(Trackers.list_trackers(user)) == 2
end
@tag login: "bill@example.com"
......@@ -86,43 +86,37 @@ defmodule Gaja.Web.TrackerControllerTest do
describe "update |" do
@tag login: "reg@example.com"
test "data is valid", %{conn: conn, tracker: tracker} do
test "data is valid", %{conn: conn, user: user, tracker: tracker} do
attrs = %{
name: "New name"
}
conn = put(conn, Routes.tracker_path(conn, :update, tracker), attrs)
conn = put(conn, Routes.tracker_path(conn, :update, tracker.id), tracker: attrs)
assert json_response(conn, 200)
updated_tracker = Trackers.get_tracker(tracker.id)
updated_tracker = Trackers.get_tracker(user, tracker.id)
assert updated_tracker.name == "New name"
end
"""
@tag login: "reg@example.com"
test "does not update chosen user and renders errors when data is invalid", %{
conn: conn,
user: user
} do
conn = put(conn, Routes.user_path(conn, :update, user), user: @invalid_attrs)
test "data is invalid", %{conn: conn, tracker: tracker} do
invalid_attrs = %{
name: nil
}
conn = put(conn, Routes.tracker_path(conn, :update, tracker.id), tracker: invalid_attrs)
assert json_response(conn, 422)["errors"] != %{}
end
"""
end
"""
describe "delete user" do
describe "delete |" do
@tag login: "reg@example.com"
test "deletes chosen user", %{conn: conn, user: user} do
conn = delete(conn, Routes.user_path(conn, :delete, user))
test "success", %{conn: conn, user: user, tracker: tracker} do
conn = delete(conn, Routes.tracker_path(conn, :delete, tracker.id))
assert response(conn, 204)
refute Accounts.get_user(user.id)
refute Trackers.get_tracker(user, tracker.id)
end
@tag login: "reg@example.com"
test "cannot delete other user", %{conn: conn, other: other} do
conn = delete(conn, Routes.user_path(conn, :delete, other))
assert json_response(conn, 403)["errors"]["detail"] =~ "Not authorized"
assert Accounts.get_user(other.id)
test "401 for unauthorized user", %{conn: conn, tracker: tracker} do
conn = delete(conn, Routes.tracker_path(conn, :delete, tracker))
assert json_response(conn, 401)
end
end
"""
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment