Fixing remaining auth tests
This commit is contained in:
parent
fa15a25044
commit
17fdc7085e
4 changed files with 14 additions and 15 deletions
|
@ -377,7 +377,7 @@ defmodule RecycledCloud.Accounts do
|
||||||
changeset = user
|
changeset = user
|
||||||
|> User.password_changeset(attrs)
|
|> User.password_changeset(attrs)
|
||||||
|
|
||||||
set_user_password(user, changeset, attrs["password"])
|
set_user_password(user, changeset, changeset.changes.password)
|
||||||
end
|
end
|
||||||
|
|
||||||
## Keys
|
## Keys
|
||||||
|
|
|
@ -22,7 +22,7 @@ defmodule RecycledCloudWeb.UserConfirmationControllerTest do
|
||||||
test "sends a new confirmation token", %{conn: conn, user: user} do
|
test "sends a new confirmation token", %{conn: conn, user: user} do
|
||||||
conn =
|
conn =
|
||||||
post(conn, Routes.user_confirmation_path(conn, :create), %{
|
post(conn, Routes.user_confirmation_path(conn, :create), %{
|
||||||
"user" => %{"email" => user.email}
|
"user" => %{"username" => user.username}
|
||||||
})
|
})
|
||||||
|
|
||||||
assert redirected_to(conn) == "/"
|
assert redirected_to(conn) == "/"
|
||||||
|
@ -35,7 +35,7 @@ defmodule RecycledCloudWeb.UserConfirmationControllerTest do
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
post(conn, Routes.user_confirmation_path(conn, :create), %{
|
post(conn, Routes.user_confirmation_path(conn, :create), %{
|
||||||
"user" => %{"email" => user.email}
|
"user" => %{"username" => user.username}
|
||||||
})
|
})
|
||||||
|
|
||||||
assert redirected_to(conn) == "/"
|
assert redirected_to(conn) == "/"
|
||||||
|
@ -43,10 +43,10 @@ defmodule RecycledCloudWeb.UserConfirmationControllerTest do
|
||||||
refute Repo.get_by(Accounts.UserToken, user_id: user.id)
|
refute Repo.get_by(Accounts.UserToken, user_id: user.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "does not send confirmation token if email is invalid", %{conn: conn} do
|
test "does not send confirmation token if usernameis invalid", %{conn: conn} do
|
||||||
conn =
|
conn =
|
||||||
post(conn, Routes.user_confirmation_path(conn, :create), %{
|
post(conn, Routes.user_confirmation_path(conn, :create), %{
|
||||||
"user" => %{"email" => "unknown@example.com"}
|
"user" => %{"username" => "unknown"}
|
||||||
})
|
})
|
||||||
|
|
||||||
assert redirected_to(conn) == "/"
|
assert redirected_to(conn) == "/"
|
||||||
|
|
|
@ -21,11 +21,12 @@ defmodule RecycledCloudWeb.UserRegistrationControllerTest do
|
||||||
describe "POST /users/register" do
|
describe "POST /users/register" do
|
||||||
@tag :capture_log
|
@tag :capture_log
|
||||||
test "creates account and logs the user in", %{conn: conn} do
|
test "creates account and logs the user in", %{conn: conn} do
|
||||||
|
username = unique_user_name()
|
||||||
email = unique_user_email()
|
email = unique_user_email()
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
post(conn, Routes.user_registration_path(conn, :create), %{
|
post(conn, Routes.user_registration_path(conn, :create), %{
|
||||||
"user" => %{"email" => email, "password" => valid_user_password()}
|
"user" => %{"username" => username, "email" => email, "password" => valid_user_password()}
|
||||||
})
|
})
|
||||||
|
|
||||||
assert get_session(conn, :user_token)
|
assert get_session(conn, :user_token)
|
||||||
|
@ -34,7 +35,6 @@ defmodule RecycledCloudWeb.UserRegistrationControllerTest do
|
||||||
# Now do a logged in request and assert on the menu
|
# Now do a logged in request and assert on the menu
|
||||||
conn = get(conn, "/")
|
conn = get(conn, "/")
|
||||||
response = html_response(conn, 200)
|
response = html_response(conn, 200)
|
||||||
assert response =~ email
|
|
||||||
assert response =~ "Settings</a>"
|
assert response =~ "Settings</a>"
|
||||||
assert response =~ "Log out</a>"
|
assert response =~ "Log out</a>"
|
||||||
end
|
end
|
||||||
|
@ -42,13 +42,13 @@ defmodule RecycledCloudWeb.UserRegistrationControllerTest do
|
||||||
test "render errors for invalid data", %{conn: conn} do
|
test "render errors for invalid data", %{conn: conn} do
|
||||||
conn =
|
conn =
|
||||||
post(conn, Routes.user_registration_path(conn, :create), %{
|
post(conn, Routes.user_registration_path(conn, :create), %{
|
||||||
"user" => %{"email" => "with spaces", "password" => "too short"}
|
"user" => %{"username" => "with spaces", "email" => "with spaces", "password" => "too"}
|
||||||
})
|
})
|
||||||
|
|
||||||
response = html_response(conn, 200)
|
response = html_response(conn, 200)
|
||||||
assert response =~ "<h1>Register</h1>"
|
assert response =~ "<h1>Register</h1>"
|
||||||
assert response =~ "must have the @ sign and no spaces"
|
assert response =~ "must have the @ sign and no spaces"
|
||||||
assert response =~ "should be at least 12 character"
|
assert response =~ "should be at least 6 character"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,7 +26,7 @@ defmodule RecycledCloudWeb.UserSessionControllerTest do
|
||||||
test "logs the user in", %{conn: conn, user: user} do
|
test "logs the user in", %{conn: conn, user: user} do
|
||||||
conn =
|
conn =
|
||||||
post(conn, Routes.user_session_path(conn, :create), %{
|
post(conn, Routes.user_session_path(conn, :create), %{
|
||||||
"user" => %{"email" => user.email, "password" => valid_user_password()}
|
"user" => %{"username" => user.username, "password" => valid_user_password()}
|
||||||
})
|
})
|
||||||
|
|
||||||
assert get_session(conn, :user_token)
|
assert get_session(conn, :user_token)
|
||||||
|
@ -35,7 +35,6 @@ defmodule RecycledCloudWeb.UserSessionControllerTest do
|
||||||
# Now do a logged in request and assert on the menu
|
# Now do a logged in request and assert on the menu
|
||||||
conn = get(conn, "/")
|
conn = get(conn, "/")
|
||||||
response = html_response(conn, 200)
|
response = html_response(conn, 200)
|
||||||
assert response =~ user.email
|
|
||||||
assert response =~ "Settings</a>"
|
assert response =~ "Settings</a>"
|
||||||
assert response =~ "Log out</a>"
|
assert response =~ "Log out</a>"
|
||||||
end
|
end
|
||||||
|
@ -44,7 +43,7 @@ defmodule RecycledCloudWeb.UserSessionControllerTest do
|
||||||
conn =
|
conn =
|
||||||
post(conn, Routes.user_session_path(conn, :create), %{
|
post(conn, Routes.user_session_path(conn, :create), %{
|
||||||
"user" => %{
|
"user" => %{
|
||||||
"email" => user.email,
|
"username" => user.username,
|
||||||
"password" => valid_user_password(),
|
"password" => valid_user_password(),
|
||||||
"remember_me" => "true"
|
"remember_me" => "true"
|
||||||
}
|
}
|
||||||
|
@ -60,7 +59,7 @@ defmodule RecycledCloudWeb.UserSessionControllerTest do
|
||||||
|> init_test_session(user_return_to: "/foo/bar")
|
|> init_test_session(user_return_to: "/foo/bar")
|
||||||
|> post(Routes.user_session_path(conn, :create), %{
|
|> post(Routes.user_session_path(conn, :create), %{
|
||||||
"user" => %{
|
"user" => %{
|
||||||
"email" => user.email,
|
"username" => user.username,
|
||||||
"password" => valid_user_password()
|
"password" => valid_user_password()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -71,12 +70,12 @@ defmodule RecycledCloudWeb.UserSessionControllerTest do
|
||||||
test "emits error message with invalid credentials", %{conn: conn, user: user} do
|
test "emits error message with invalid credentials", %{conn: conn, user: user} do
|
||||||
conn =
|
conn =
|
||||||
post(conn, Routes.user_session_path(conn, :create), %{
|
post(conn, Routes.user_session_path(conn, :create), %{
|
||||||
"user" => %{"email" => user.email, "password" => "invalid_password"}
|
"user" => %{"username" => user.username, "password" => "invalid_password"}
|
||||||
})
|
})
|
||||||
|
|
||||||
response = html_response(conn, 200)
|
response = html_response(conn, 200)
|
||||||
assert response =~ "<h1>Log in</h1>"
|
assert response =~ "<h1>Log in</h1>"
|
||||||
assert response =~ "Invalid email or password"
|
assert response =~ "Invalid username or password"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue