upgrade to phoenix 1.7
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-04-13 23:29:29 -04:00
parent a1c846be33
commit 63d854ffbe
116 changed files with 1156 additions and 1111 deletions

View File

@ -368,11 +368,11 @@ defmodule Memex.AccountsTest do
end
end
describe "delete_session_token/1" do
describe "delete_user_session_token/1" do
test "deletes the token" do
user = user_fixture()
token = Accounts.generate_user_session_token(user)
assert Accounts.delete_session_token(token) == :ok
assert Accounts.delete_user_session_token(token) == :ok
refute Accounts.get_user_by_session_token(token)
end
end

View File

@ -0,0 +1,14 @@
defmodule MemexWeb.ErrorHTMLTest do
use MemexWeb.ConnCase, async: true
# Bring render_to_string/4 for testing custom views
import Phoenix.Template
alias MemexWeb.ErrorHTML
test "renders 404.html" do
assert render_to_string(ErrorHTML, "404", "html", []) =~ "not found"
end
test "renders 500.html" do
assert render_to_string(ErrorHTML, "500", "html", []) =~ "internal server error"
end
end

View File

@ -0,0 +1,12 @@
defmodule MemexWeb.ErrorJSONTest do
use MemexWeb.ConnCase, async: true
alias MemexWeb.ErrorJSON
test "renders 404" do
assert ErrorJSON.render("404.json", %{}) == %{errors: %{detail: "not found"}}
end
test "renders 500" do
assert ErrorJSON.render("500.json", %{}) == %{errors: %{detail: "internal server error"}}
end
end

View File

@ -35,7 +35,7 @@ defmodule MemexWeb.ExportControllerTest do
pipeline: pipeline,
step: step
} do
conn = get(conn, Routes.export_path(conn, :export, :json))
conn = get(conn, ~p"/export/json")
ideal_note = %{
"slug" => note.slug,

View File

@ -1,14 +0,0 @@
defmodule MemexWeb.HomeControllerTest do
@moduledoc """
Tests the home page
"""
use MemexWeb.ConnCase
@moduletag :home_controller_test
test "GET /", %{conn: conn} do
conn = get(conn, "/")
assert html_response(conn, 200) =~ "memEx"
end
end

View File

@ -143,9 +143,9 @@ defmodule MemexWeb.UserAuthTest do
test "redirects if user is not authenticated", %{conn: conn} do
conn = conn |> fetch_flash() |> UserAuth.require_authenticated_user([])
assert conn.halted
assert redirected_to(conn) == Routes.user_session_path(conn, :new)
assert redirected_to(conn) == ~p"/users/log_in"
assert get_flash(conn, :error) ==
assert conn.assigns.flash["error"] ==
"You must confirm your account and log in to access this page."
end

View File

@ -14,7 +14,7 @@ defmodule MemexWeb.UserConfirmationControllerTest do
describe "GET /users/confirm" do
test "renders the confirmation page", %{conn: conn} do
conn = get(conn, Routes.user_confirmation_path(conn, :new))
conn = get(conn, ~p"/users/confirm")
response = html_response(conn, 200)
assert response =~ "Resend confirmation instructions"
end
@ -24,14 +24,14 @@ defmodule MemexWeb.UserConfirmationControllerTest do
@tag :capture_log
test "sends a new confirmation token", %{conn: conn, user: user} do
conn =
post(conn, Routes.user_confirmation_path(conn, :create), %{
post(conn, ~p"/users/confirm", %{
user: %{email: user.email}
})
assert redirected_to(conn) == "/"
assert get_flash(conn, :info) =~
"If your email is in our system and it has not been confirmed yet, you will receive an email with instructions shortly."
conn.assigns.flash["info"] =~
"If your email is in our system and it has not been confirmed yet, you will receive an email with instructions shortly."
assert Repo.get_by!(Accounts.UserToken, user_id: user.id).context == "confirm"
end
@ -40,26 +40,26 @@ defmodule MemexWeb.UserConfirmationControllerTest do
Repo.update!(Accounts.User.confirm_changeset(user))
conn =
post(conn, Routes.user_confirmation_path(conn, :create), %{
post(conn, ~p"/users/confirm", %{
user: %{email: user.email}
})
assert redirected_to(conn) == "/"
assert get_flash(conn, :info) =~
"If your email is in our system and it has not been confirmed yet, you will receive an email with instructions shortly."
conn.assigns.flash["info"] =~
"If your email is in our system and it has not been confirmed yet, you will receive an email with instructions shortly."
end
test "does not send confirmation token if email is invalid", %{conn: conn} do
conn =
post(conn, Routes.user_confirmation_path(conn, :create), %{
post(conn, ~p"/users/confirm", %{
user: %{email: "unknown@example.com"}
})
assert redirected_to(conn) == "/"
assert get_flash(conn, :info) =~
"If your email is in our system and it has not been confirmed yet, you will receive an email with instructions shortly."
conn.assigns.flash["info"] =~
"If your email is in our system and it has not been confirmed yet, you will receive an email with instructions shortly."
assert Repo.all(Accounts.UserToken) == []
end
@ -72,34 +72,34 @@ defmodule MemexWeb.UserConfirmationControllerTest do
Accounts.deliver_user_confirmation_instructions(user, url)
end)
conn = get(conn, Routes.user_confirmation_path(conn, :confirm, token))
conn = get(conn, ~p"/users/confirm/#{token}")
assert redirected_to(conn) == "/"
assert get_flash(conn, :info) =~ "#{user.email} confirmed successfully"
conn.assigns.flash["info"] =~ "#{user.email} confirmed successfully"
assert Accounts.get_user!(user.id).confirmed_at
refute get_session(conn, :user_token)
assert Repo.all(Accounts.UserToken) == []
# When not logged in
conn = get(conn, Routes.user_confirmation_path(conn, :confirm, token))
conn = get(conn, ~p"/users/confirm/#{token}")
assert redirected_to(conn) == "/"
assert get_flash(conn, :error) =~ "User confirmation link is invalid or it has expired"
conn.assigns.flash["error"] =~ "User confirmation link is invalid or it has expired"
# When logged in
conn =
build_conn()
|> log_in_user(user)
|> get(Routes.user_confirmation_path(conn, :confirm, token))
|> get(~p"/users/confirm/#{token}")
assert redirected_to(conn) == "/"
refute get_flash(conn, :error)
refute conn.assigns.flash["error"]
end
test "does not confirm email with invalid token", %{conn: conn, user: user} do
conn = get(conn, Routes.user_confirmation_path(conn, :confirm, "oops"))
conn = get(conn, ~p"/users/confirm/#{"oops"}")
assert redirected_to(conn) == "/"
assert get_flash(conn, :error) =~ "User confirmation link is invalid or it has expired"
conn.assigns.flash["error"] =~ "User confirmation link is invalid or it has expired"
refute Accounts.get_user!(user.id).confirmed_at
end

View File

@ -9,14 +9,14 @@ defmodule MemexWeb.UserRegistrationControllerTest do
describe "GET /users/register" do
test "renders registration page", %{conn: conn} do
conn = get(conn, Routes.user_registration_path(conn, :new))
conn = get(conn, ~p"/users/register")
response = html_response(conn, 200)
assert response =~ "register"
assert response =~ "log in"
end
test "redirects if already logged in", %{conn: conn} do
conn = conn |> log_in_user(user_fixture()) |> get(Routes.user_registration_path(conn, :new))
conn = conn |> log_in_user(user_fixture()) |> get(~p"/users/register")
assert redirected_to(conn) == "/"
end
end
@ -27,7 +27,7 @@ defmodule MemexWeb.UserRegistrationControllerTest do
email = unique_user_email()
conn =
post(conn, Routes.user_registration_path(conn, :create), %{
post(conn, ~p"/users/register", %{
user: valid_user_attributes(email: email)
})
@ -40,7 +40,7 @@ defmodule MemexWeb.UserRegistrationControllerTest do
test "render errors for invalid data", %{conn: conn} do
conn =
post(conn, Routes.user_registration_path(conn, :create), %{
post(conn, ~p"/users/register", %{
user: %{email: "with spaces", password: "too short"}
})

View File

@ -14,7 +14,7 @@ defmodule MemexWeb.UserResetPasswordControllerTest do
describe "GET /users/reset_password" do
test "renders the reset password page", %{conn: conn} do
conn = get(conn, Routes.user_reset_password_path(conn, :new))
conn = get(conn, ~p"/users/reset_password")
response = html_response(conn, 200)
assert response =~ "forgot your password?"
end
@ -24,28 +24,28 @@ defmodule MemexWeb.UserResetPasswordControllerTest do
@tag :capture_log
test "sends a new reset password token", %{conn: conn, user: user} do
conn =
post(conn, Routes.user_reset_password_path(conn, :create), %{
post(conn, ~p"/users/reset_password", %{
user: %{email: user.email}
})
assert redirected_to(conn) == "/"
assert get_flash(conn, :info) =~
"If your email is in our system, you will receive instructions to reset your password shortly."
conn.assigns.flash["info"] =~
"If your email is in our system, you will receive instructions to reset your password shortly."
assert Repo.get_by!(Accounts.UserToken, user_id: user.id).context == "reset_password"
end
test "does not send reset password token if email is invalid", %{conn: conn} do
conn =
post(conn, Routes.user_reset_password_path(conn, :create), %{
post(conn, ~p"/users/reset_password", %{
user: %{email: "unknown@example.com"}
})
assert redirected_to(conn) == "/"
assert get_flash(conn, :info) =~
"If your email is in our system, you will receive instructions to reset your password shortly."
conn.assigns.flash["info"] =~
"If your email is in our system, you will receive instructions to reset your password shortly."
assert Repo.all(Accounts.UserToken) == []
end
@ -62,14 +62,14 @@ defmodule MemexWeb.UserResetPasswordControllerTest do
end
test "renders reset password", %{conn: conn, token: token} do
conn = get(conn, Routes.user_reset_password_path(conn, :edit, token))
conn = get(conn, ~p"/users/reset_password/#{token}")
assert html_response(conn, 200) =~ "Reset password"
end
test "does not render reset password with invalid token", %{conn: conn} do
conn = get(conn, Routes.user_reset_password_path(conn, :edit, "oops"))
conn = get(conn, ~p"/users/reset_password/#{"oops"}")
assert redirected_to(conn) == "/"
assert get_flash(conn, :error) =~ "Reset password link is invalid or it has expired"
conn.assigns.flash["error"] =~ "Reset password link is invalid or it has expired"
end
end
@ -85,22 +85,22 @@ defmodule MemexWeb.UserResetPasswordControllerTest do
test "resets password once", %{conn: conn, user: user, token: token} do
conn =
put(conn, Routes.user_reset_password_path(conn, :update, token), %{
put(conn, ~p"/users/reset_password/#{token}", %{
user: %{
password: "new valid password",
password_confirmation: "new valid password"
}
})
assert redirected_to(conn) == Routes.user_session_path(conn, :new)
assert redirected_to(conn) == ~p"/users/log_in"
refute get_session(conn, :user_token)
assert get_flash(conn, :info) =~ "Password reset successfully"
conn.assigns.flash["info"] =~ "Password reset successfully"
assert Accounts.get_user_by_email_and_password(user.email, "new valid password")
end
test "does not reset password on invalid data", %{conn: conn, token: token} do
conn =
put(conn, Routes.user_reset_password_path(conn, :update, token), %{
put(conn, ~p"/users/reset_password/#{token}", %{
user: %{
password: "too short",
password_confirmation: "does not match"
@ -114,9 +114,9 @@ defmodule MemexWeb.UserResetPasswordControllerTest do
end
test "does not reset password with invalid token", %{conn: conn} do
conn = put(conn, Routes.user_reset_password_path(conn, :update, "oops"))
conn = put(conn, ~p"/users/reset_password/#{"oops"}")
assert redirected_to(conn) == "/"
assert get_flash(conn, :error) =~ "Reset password link is invalid or it has expired"
conn.assigns.flash["error"] =~ "Reset password link is invalid or it has expired"
end
end
end

View File

@ -13,13 +13,13 @@ defmodule MemexWeb.UserSessionControllerTest do
describe "GET /users/log_in" do
test "renders log in page", %{conn: conn} do
conn = get(conn, Routes.user_session_path(conn, :new))
conn = get(conn, ~p"/users/log_in")
response = html_response(conn, 200)
assert response =~ "log in"
end
test "redirects if already logged in", %{conn: conn, current_user: current_user} do
conn = conn |> log_in_user(current_user) |> get(Routes.user_session_path(conn, :new))
conn = conn |> log_in_user(current_user) |> get(~p"/users/log_in")
assert redirected_to(conn) == "/"
end
end
@ -27,7 +27,7 @@ defmodule MemexWeb.UserSessionControllerTest do
describe "POST /users/log_in" do
test "logs the user in", %{conn: conn, current_user: current_user} do
conn =
post(conn, Routes.user_session_path(conn, :create), %{
post(conn, ~p"/users/log_in", %{
user: %{email: current_user.email, password: valid_user_password()}
})
@ -43,7 +43,7 @@ defmodule MemexWeb.UserSessionControllerTest do
test "logs the user in with remember me", %{conn: conn, current_user: current_user} do
conn =
post(conn, Routes.user_session_path(conn, :create), %{
post(conn, ~p"/users/log_in", %{
user: %{
email: current_user.email,
password: valid_user_password(),
@ -59,7 +59,7 @@ defmodule MemexWeb.UserSessionControllerTest do
conn =
conn
|> init_test_session(user_return_to: "/foo/bar")
|> post(Routes.user_session_path(conn, :create), %{
|> post(~p"/users/log_in", %{
user: %{
email: current_user.email,
password: valid_user_password()
@ -72,7 +72,7 @@ defmodule MemexWeb.UserSessionControllerTest do
test "emits error message with invalid credentials",
%{conn: conn, current_user: current_user} do
conn =
post(conn, Routes.user_session_path(conn, :create), %{
post(conn, ~p"/users/log_in", %{
user: %{email: current_user.email, password: "bad"}
})
@ -84,17 +84,17 @@ defmodule MemexWeb.UserSessionControllerTest do
describe "DELETE /users/log_out" do
test "logs the user out", %{conn: conn, current_user: current_user} do
conn = conn |> log_in_user(current_user) |> delete(Routes.user_session_path(conn, :delete))
conn = conn |> log_in_user(current_user) |> delete(~p"/users/log_out")
assert redirected_to(conn) == "/"
refute get_session(conn, :user_token)
assert get_flash(conn, :info) =~ "logged out successfully"
conn.assigns.flash["info"] =~ "logged out successfully"
end
test "succeeds even if the user is not logged in", %{conn: conn} do
conn = delete(conn, Routes.user_session_path(conn, :delete))
conn = delete(conn, ~p"/users/log_out")
assert redirected_to(conn) == "/"
refute get_session(conn, :user_token)
assert get_flash(conn, :info) =~ "logged out successfully"
conn.assigns.flash["info"] =~ "logged out successfully"
end
end
end

View File

@ -12,15 +12,15 @@ defmodule MemexWeb.UserSettingsControllerTest do
describe "GET /users/settings" do
test "renders settings page", %{conn: conn} do
conn = get(conn, Routes.user_settings_path(conn, :edit))
conn = get(conn, ~p"/users/settings")
response = html_response(conn, 200)
assert response =~ "settings"
end
test "redirects if user is not logged in" do
conn = build_conn()
conn = get(conn, Routes.user_settings_path(conn, :edit))
assert redirected_to(conn) == Routes.user_session_path(conn, :new)
conn = get(conn, ~p"/users/settings")
assert redirected_to(conn) == ~p"/users/log_in"
end
end
@ -28,7 +28,7 @@ defmodule MemexWeb.UserSettingsControllerTest do
test "updates the user password and resets tokens",
%{conn: conn, current_user: current_user} do
new_password_conn =
put(conn, Routes.user_settings_path(conn, :update), %{
put(conn, ~p"/users/settings", %{
action: "update_password",
current_password: valid_user_password(),
user: %{
@ -37,16 +37,16 @@ defmodule MemexWeb.UserSettingsControllerTest do
}
})
assert redirected_to(new_password_conn) == Routes.user_settings_path(conn, :edit)
assert redirected_to(new_password_conn) == ~p"/users/settings"
assert get_session(new_password_conn, :user_token) != get_session(conn, :user_token)
assert get_flash(new_password_conn, :info) =~ "password updated successfully"
new_password_conn.assigns.flash["info"] =~ "password updated successfully"
assert Accounts.get_user_by_email_and_password(current_user.email, "new valid password")
end
test "does not update password on invalid data", %{conn: conn} do
old_password_conn =
put(conn, Routes.user_settings_path(conn, :update), %{
put(conn, ~p"/users/settings", %{
action: "update_password",
current_password: "invalid",
user: %{
@ -69,23 +69,23 @@ defmodule MemexWeb.UserSettingsControllerTest do
@tag :capture_log
test "updates the user email", %{conn: conn, current_user: current_user} do
conn =
put(conn, Routes.user_settings_path(conn, :update), %{
put(conn, ~p"/users/settings", %{
action: "update_email",
current_password: valid_user_password(),
user: %{"email" => unique_user_email()}
})
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
assert redirected_to(conn) == ~p"/users/settings"
assert get_flash(conn, :info) =~
"a link to confirm your email change has been sent to the new address."
conn.assigns.flash["info"] =~
"a link to confirm your email change has been sent to the new address."
assert Accounts.get_user_by_email(current_user.email)
end
test "does not update email on invalid data", %{conn: conn} do
conn =
put(conn, Routes.user_settings_path(conn, :update), %{
put(conn, ~p"/users/settings", %{
"action" => "update_email",
"current_password" => "invalid",
"user" => %{"email" => "with spaces"}
@ -116,28 +116,28 @@ defmodule MemexWeb.UserSettingsControllerTest do
test "updates the user email once",
%{conn: conn, current_user: current_user, token: token, email: email} do
conn = get(conn, Routes.user_settings_path(conn, :confirm_email, token))
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
assert get_flash(conn, :info) =~ "email changed successfully"
conn = get(conn, ~p"/users/settings/confirm_email/#{token}")
assert redirected_to(conn) == ~p"/users/settings"
conn.assigns.flash["info"] =~ "email changed successfully"
refute Accounts.get_user_by_email(current_user.email)
assert Accounts.get_user_by_email(email)
conn = get(conn, Routes.user_settings_path(conn, :confirm_email, token))
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
assert get_flash(conn, :error) =~ "email change link is invalid or it has expired"
conn = get(conn, ~p"/users/settings/confirm_email/#{token}")
assert redirected_to(conn) == ~p"/users/settings"
conn.assigns.flash["error"] =~ "email change link is invalid or it has expired"
end
test "does not update email with invalid token", %{conn: conn, current_user: current_user} do
conn = get(conn, Routes.user_settings_path(conn, :confirm_email, "oops"))
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
assert get_flash(conn, :error) =~ "email change link is invalid or it has expired"
conn = get(conn, ~p"/users/settings/confirm_email/#{"oops"}")
assert redirected_to(conn) == ~p"/users/settings"
conn.assigns.flash["error"] =~ "email change link is invalid or it has expired"
assert Accounts.get_user_by_email(current_user.email)
end
test "redirects if user is not logged in", %{token: token} do
conn = build_conn()
conn = get(conn, Routes.user_settings_path(conn, :confirm_email, token))
assert redirected_to(conn) == Routes.user_session_path(conn, :new)
conn = get(conn, ~p"/users/settings/confirm_email/#{token}")
assert redirected_to(conn) == ~p"/users/log_in"
end
end
end

View File

@ -2,7 +2,6 @@ defmodule MemexWeb.ContextLiveTest do
use MemexWeb.ConnCase
import Phoenix.LiveViewTest
import Memex.Fixtures
alias MemexWeb.Endpoint
@create_attrs %{
content: "some content",
@ -18,7 +17,7 @@ defmodule MemexWeb.ContextLiveTest do
}
@invalid_attrs %{
content: nil,
tags_string: " ",
tags_string: "invalid tags",
slug: nil,
visibility: nil
}
@ -31,24 +30,24 @@ defmodule MemexWeb.ContextLiveTest do
setup [:register_and_log_in_user, :create_context]
test "lists all contexts", %{conn: conn, context: context} do
{:ok, _index_live, html} = live(conn, Routes.context_index_path(conn, :index))
{:ok, _index_live, html} = live(conn, ~p"/contexts")
assert html =~ "contexts"
assert html =~ context.slug
end
test "searches by tag", %{conn: conn, context: %{tags: [tag]}} do
{:ok, index_live, html} = live(conn, Routes.context_index_path(conn, :index))
{:ok, index_live, html} = live(conn, ~p"/contexts")
assert html =~ tag
assert index_live |> element("a", tag) |> render_click()
assert_patch(index_live, Routes.context_index_path(conn, :search, tag))
assert_patch(index_live, ~p"/contexts/#{tag}")
end
test "saves new context", %{conn: conn} do
{:ok, index_live, _html} = live(conn, Routes.context_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/contexts")
assert index_live |> element("a", "new context") |> render_click() =~ "new context"
assert_patch(index_live, Routes.context_index_path(conn, :new))
assert_patch(index_live, ~p"/contexts/new")
assert index_live
|> form("#context-form")
@ -58,19 +57,19 @@ defmodule MemexWeb.ContextLiveTest do
index_live
|> form("#context-form")
|> render_submit(context: @create_attrs)
|> follow_redirect(conn, Routes.context_index_path(conn, :index))
|> follow_redirect(conn, ~p"/contexts")
assert html =~ "#{@create_attrs.slug} created"
assert html =~ @create_attrs.slug
end
test "updates context in listing", %{conn: conn, context: context} do
{:ok, index_live, _html} = live(conn, Routes.context_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/contexts")
assert index_live |> element(~s/a[aria-label="edit #{context.slug}"]/) |> render_click() =~
"edit"
assert_patch(index_live, Routes.context_index_path(conn, :edit, context.slug))
assert_patch(index_live, ~p"/contexts/#{context}/edit")
assert index_live
|> form("#context-form")
@ -80,14 +79,14 @@ defmodule MemexWeb.ContextLiveTest do
index_live
|> form("#context-form")
|> render_submit(context: @update_attrs)
|> follow_redirect(conn, Routes.context_index_path(conn, :index))
|> follow_redirect(conn, ~p"/contexts")
assert html =~ "#{@update_attrs.slug} saved"
assert html =~ "some-updated-slug"
end
test "deletes context in listing", %{conn: conn, context: context} do
{:ok, index_live, _html} = live(conn, Routes.context_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/contexts")
assert index_live |> element(~s/a[aria-label="delete #{context.slug}"]/) |> render_click()
refute has_element?(index_live, "#context-#{context.id}")
@ -98,16 +97,16 @@ defmodule MemexWeb.ContextLiveTest do
setup [:register_and_log_in_user, :create_context]
test "displays context", %{conn: conn, context: context} do
{:ok, _show_live, html} = live(conn, Routes.context_show_path(conn, :show, context.slug))
{:ok, _show_live, html} = live(conn, ~p"/context/#{context}")
assert html =~ "context"
assert html =~ context.slug
end
test "updates context within modal", %{conn: conn, context: context} do
{:ok, show_live, _html} = live(conn, Routes.context_show_path(conn, :show, context.slug))
{:ok, show_live, _html} = live(conn, ~p"/context/#{context}")
assert show_live |> element("a", "edit") |> render_click() =~ "edit"
assert_patch(show_live, Routes.context_show_path(conn, :edit, context.slug))
assert_patch(show_live, ~p"/context/#{context}/edit")
html =
show_live
@ -121,20 +120,20 @@ defmodule MemexWeb.ContextLiveTest do
show_live
|> form("#context-form")
|> render_submit(context: Map.put(@update_attrs, "slug", context.slug))
|> follow_redirect(conn, Routes.context_show_path(conn, :show, context.slug))
|> follow_redirect(conn, ~p"/context/#{context}")
assert html =~ "#{context.slug} saved"
assert html =~ "tag2"
end
test "deletes context", %{conn: conn, context: context} do
{:ok, show_live, _html} = live(conn, Routes.context_show_path(conn, :show, context.slug))
{:ok, show_live, _html} = live(conn, ~p"/context/#{context}")
{:ok, index_live, _html} =
show_live
|> element(~s/button[aria-label="delete #{context.slug}"]/)
|> render_click()
|> follow_redirect(conn, Routes.context_index_path(conn, :index))
|> follow_redirect(conn, ~p"/contexts")
refute has_element?(index_live, "#context-#{context.id}")
end
@ -157,18 +156,18 @@ defmodule MemexWeb.ContextLiveTest do
end
test "searches by tag", %{conn: conn, context: %{tags: [tag]} = context} do
{:ok, show_live, html} = live(conn, Routes.context_show_path(conn, :show, context.slug))
{:ok, show_live, html} = live(conn, ~p"/context/#{context}")
assert html =~ tag
assert show_live |> element("a", tag) |> render_click()
assert_redirect(show_live, Routes.context_index_path(conn, :search, tag))
assert_redirect(show_live, ~p"/contexts/#{tag}")
end
test "displays context", %{conn: conn, context: context, note: %{slug: note_slug}} do
{:ok, show_live, html} = live(conn, Routes.context_show_path(conn, :show, context.slug))
{:ok, show_live, html} = live(conn, ~p"/context/#{context}")
assert html =~ "context"
assert html =~ Routes.note_show_path(Endpoint, :show, note_slug)
assert html =~ ~p"/note/#{note_slug}"
assert has_element?(show_live, "a", note_slug)
end
end

View File

@ -0,0 +1,11 @@
defmodule MemexWeb.FaqLiveTest do
use MemexWeb.ConnCase
import Phoenix.LiveViewTest
test "disconnected and connected render", %{conn: conn} do
{:ok, page_live, disconnected_html} = live(conn, ~p"/faq")
assert disconnected_html =~ "faq"
assert render(page_live) =~ "faq"
end
end

View File

@ -4,7 +4,7 @@ defmodule MemexWeb.HomeLiveTest do
import Phoenix.LiveViewTest
test "disconnected and connected render", %{conn: conn} do
{:ok, page_live, disconnected_html} = live(conn, "/")
{:ok, page_live, disconnected_html} = live(conn, ~p"/")
assert disconnected_html =~ "memEx"
assert render(page_live) =~ "memEx"
end

View File

@ -21,16 +21,16 @@ defmodule MemexWeb.InviteLiveTest do
end
test "lists all invites", %{conn: conn, invite: invite} do
{:ok, _index_live, html} = live(conn, Routes.invite_index_path(conn, :index))
{:ok, _index_live, html} = live(conn, ~p"/invites")
assert html =~ "invites"
assert html =~ invite.name
end
test "saves new invite", %{conn: conn} do
{:ok, index_live, _html} = live(conn, Routes.invite_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/invites")
assert index_live |> element("a", "create invite") |> render_click() =~ "new invite"
assert_patch(index_live, Routes.invite_index_path(conn, :new))
assert_patch(index_live, ~p"/invites/new")
assert index_live
|> form("#invite-form")
@ -40,19 +40,19 @@ defmodule MemexWeb.InviteLiveTest do
index_live
|> form("#invite-form")
|> render_submit(invite: @create_attrs)
|> follow_redirect(conn, Routes.invite_index_path(conn, :index))
|> follow_redirect(conn, ~p"/invites")
assert html =~ "some name created successfully"
end
test "updates invite in listing", %{conn: conn, invite: invite} do
{:ok, index_live, _html} = live(conn, Routes.invite_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/invites")
assert index_live
|> element(~s/a[aria-label="edit invite for #{invite.name}"]/)
|> render_click() =~ "edit invite"
assert_patch(index_live, Routes.invite_index_path(conn, :edit, invite))
assert_patch(index_live, ~p"/invites/#{invite}/edit")
assert index_live
|> form("#invite-form")
@ -62,13 +62,13 @@ defmodule MemexWeb.InviteLiveTest do
index_live
|> form("#invite-form")
|> render_submit(invite: @update_attrs)
|> follow_redirect(conn, Routes.invite_index_path(conn, :index))
|> follow_redirect(conn, ~p"/invites")
assert html =~ "some updated name updated successfully"
end
test "deletes invite in listing", %{conn: conn, invite: invite} do
{:ok, index_live, _html} = live(conn, Routes.invite_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/invites")
assert index_live
|> element(~s/a[aria-label="delete invite for #{invite.name}"]/)

View File

@ -3,7 +3,6 @@ defmodule MemexWeb.NoteLiveTest do
import Phoenix.LiveViewTest
import Memex.Fixtures
alias MemexWeb.Endpoint
@create_attrs %{
content: "some content",
@ -19,7 +18,7 @@ defmodule MemexWeb.NoteLiveTest do
}
@invalid_attrs %{
content: nil,
tags_string: " ",
tags_string: "invalid tags",
slug: nil,
visibility: nil
}
@ -32,24 +31,24 @@ defmodule MemexWeb.NoteLiveTest do
setup [:register_and_log_in_user, :create_note]
test "lists all notes", %{conn: conn, note: note} do
{:ok, _index_live, html} = live(conn, Routes.note_index_path(conn, :index))
{:ok, _index_live, html} = live(conn, ~p"/notes")
assert html =~ "notes"
assert html =~ note.slug
end
test "searches by tag", %{conn: conn, note: %{tags: [tag]}} do
{:ok, index_live, html} = live(conn, Routes.note_index_path(conn, :index))
{:ok, index_live, html} = live(conn, ~p"/notes")
assert html =~ tag
assert index_live |> element("a", tag) |> render_click()
assert_patch(index_live, Routes.note_index_path(conn, :search, tag))
assert_patch(index_live, ~p"/notes/#{tag}")
end
test "saves new note", %{conn: conn} do
{:ok, index_live, _html} = live(conn, Routes.note_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/notes")
assert index_live |> element("a", "new note") |> render_click() =~ "new note"
assert_patch(index_live, Routes.note_index_path(conn, :new))
assert_patch(index_live, ~p"/notes/new")
html =
index_live
@ -63,19 +62,19 @@ defmodule MemexWeb.NoteLiveTest do
index_live
|> form("#note-form")
|> render_submit(note: @create_attrs)
|> follow_redirect(conn, Routes.note_index_path(conn, :index))
|> follow_redirect(conn, ~p"/notes")
assert html =~ "#{@create_attrs.slug} created"
assert html =~ @create_attrs.slug
end
test "updates note in listing", %{conn: conn, note: note} do
{:ok, index_live, _html} = live(conn, Routes.note_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/notes")
assert index_live |> element(~s/a[aria-label="edit #{note.slug}"]/) |> render_click() =~
"edit"
assert_patch(index_live, Routes.note_index_path(conn, :edit, note.slug))
assert_patch(index_live, ~p"/notes/#{note}/edit")
assert index_live
|> form("#note-form")
@ -85,14 +84,14 @@ defmodule MemexWeb.NoteLiveTest do
index_live
|> form("#note-form")
|> render_submit(note: @update_attrs)
|> follow_redirect(conn, Routes.note_index_path(conn, :index))
|> follow_redirect(conn, ~p"/notes")
assert html =~ "#{@update_attrs.slug} saved"
assert html =~ @update_attrs.slug
end
test "deletes note in listing", %{conn: conn, note: note} do
{:ok, index_live, _html} = live(conn, Routes.note_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/notes")
assert index_live |> element(~s/a[aria-label="delete #{note.slug}"]/) |> render_click()
refute has_element?(index_live, "#note-#{note.id}")
@ -103,16 +102,16 @@ defmodule MemexWeb.NoteLiveTest do
setup [:register_and_log_in_user, :create_note]
test "displays note", %{conn: conn, note: note} do
{:ok, _show_live, html} = live(conn, Routes.note_show_path(conn, :show, note.slug))
{:ok, _show_live, html} = live(conn, ~p"/note/#{note}")
assert html =~ "note"
assert html =~ note.slug
end
test "updates note within modal", %{conn: conn, note: note} do
{:ok, show_live, _html} = live(conn, Routes.note_show_path(conn, :show, note.slug))
{:ok, show_live, _html} = live(conn, ~p"/note/#{note}")
assert show_live |> element("a", "edit") |> render_click() =~ "edit"
assert_patch(show_live, Routes.note_show_path(conn, :edit, note.slug))
assert_patch(show_live, ~p"/note/#{note}/edit")
assert show_live
|> form("#note-form")
@ -122,20 +121,20 @@ defmodule MemexWeb.NoteLiveTest do
show_live
|> form("#note-form")
|> render_submit(note: @update_attrs |> Map.put(:slug, note.slug))
|> follow_redirect(conn, Routes.note_show_path(conn, :show, note.slug))
|> follow_redirect(conn, ~p"/note/#{note}")
assert html =~ "#{note.slug} saved"
assert html =~ note.slug
end
test "deletes note", %{conn: conn, note: note} do
{:ok, show_live, _html} = live(conn, Routes.note_show_path(conn, :show, note.slug))
{:ok, show_live, _html} = live(conn, ~p"/note/#{note}")
{:ok, index_live, _html} =
show_live
|> element(~s/button[aria-label="delete #{note.slug}"]/)
|> render_click()
|> follow_redirect(conn, Routes.note_index_path(conn, :index))
|> follow_redirect(conn, ~p"/notes")
refute has_element?(index_live, "#note-#{note.id}")
end
@ -155,11 +154,11 @@ defmodule MemexWeb.NoteLiveTest do
end
test "searches by tag", %{conn: conn, note: %{tags: [tag]} = note} do
{:ok, show_live, html} = live(conn, Routes.note_show_path(conn, :show, note.slug))
{:ok, show_live, html} = live(conn, ~p"/note/#{note}")
assert html =~ tag
assert show_live |> element("a", tag) |> render_click()
assert_redirect(show_live, Routes.note_index_path(conn, :search, tag))
assert_redirect(show_live, ~p"/notes/#{tag}")
end
test "displays context", %{
@ -167,11 +166,10 @@ defmodule MemexWeb.NoteLiveTest do
backlinked_note: %{slug: backlinked_note_slug},
note: %{slug: note_slug}
} do
{:ok, show_live, html} =
live(conn, Routes.note_show_path(conn, :show, backlinked_note_slug))
{:ok, show_live, html} = live(conn, ~p"/note/#{backlinked_note_slug}")
assert html =~ "context"
assert html =~ Routes.note_show_path(Endpoint, :show, note_slug)
assert html =~ ~p"/note/#{note_slug}"
assert has_element?(show_live, "a", note_slug)
end
end

View File

@ -17,7 +17,7 @@ defmodule MemexWeb.PipelineLiveTest do
}
@invalid_attrs %{
description: nil,
tags_string: " ",
tags_string: "invalid tags",
slug: nil,
visibility: nil
}
@ -42,25 +42,25 @@ defmodule MemexWeb.PipelineLiveTest do
setup [:register_and_log_in_user, :create_pipeline]
test "lists all pipelines", %{conn: conn, pipeline: pipeline} do
{:ok, _index_live, html} = live(conn, Routes.pipeline_index_path(conn, :index))
{:ok, _index_live, html} = live(conn, ~p"/pipelines")
assert html =~ "pipelines"
assert html =~ pipeline.description
end
test "searches by tag", %{conn: conn, pipeline: %{tags: [tag]}} do
{:ok, index_live, html} = live(conn, Routes.pipeline_index_path(conn, :index))
{:ok, index_live, html} = live(conn, ~p"/pipelines")
assert html =~ tag
assert index_live |> element("a", tag) |> render_click()
assert_patch(index_live, Routes.pipeline_index_path(conn, :search, tag))
assert_patch(index_live, ~p"/pipelines/#{tag}")
end
test "saves new pipeline", %{conn: conn} do
{:ok, index_live, _html} = live(conn, Routes.pipeline_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/pipelines")
assert index_live |> element("a", "new pipeline") |> render_click() =~ "new pipeline"
assert_patch(index_live, Routes.pipeline_index_path(conn, :new))
assert_patch(index_live, ~p"/pipelines/new")
assert index_live
|> form("#pipeline-form")
@ -70,19 +70,19 @@ defmodule MemexWeb.PipelineLiveTest do
index_live
|> form("#pipeline-form")
|> render_submit(pipeline: @create_attrs)
|> follow_redirect(conn, Routes.pipeline_index_path(conn, :index))
|> follow_redirect(conn, ~p"/pipelines")
assert html =~ "#{@create_attrs.slug} created"
assert html =~ @create_attrs.description
end
test "updates pipeline in listing", %{conn: conn, pipeline: pipeline} do
{:ok, index_live, _html} = live(conn, Routes.pipeline_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/pipelines")
assert index_live |> element(~s/a[aria-label="edit #{pipeline.slug}"]/) |> render_click() =~
"edit"
assert_patch(index_live, Routes.pipeline_index_path(conn, :edit, pipeline.slug))
assert_patch(index_live, ~p"/pipelines/#{pipeline}/edit")
assert index_live
|> form("#pipeline-form")
@ -92,14 +92,14 @@ defmodule MemexWeb.PipelineLiveTest do
index_live
|> form("#pipeline-form")
|> render_submit(pipeline: @update_attrs)
|> follow_redirect(conn, Routes.pipeline_index_path(conn, :index))
|> follow_redirect(conn, ~p"/pipelines")
assert html =~ "#{@update_attrs.slug} saved"
assert html =~ @update_attrs.description
end
test "deletes pipeline in listing", %{conn: conn, pipeline: pipeline} do
{:ok, index_live, _html} = live(conn, Routes.pipeline_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/pipelines")
assert index_live
|> element(~s/a[aria-label="delete #{pipeline.slug}"]/)
@ -113,16 +113,16 @@ defmodule MemexWeb.PipelineLiveTest do
setup [:register_and_log_in_user, :create_pipeline]
test "displays pipeline", %{conn: conn, pipeline: pipeline} do
{:ok, _show_live, html} = live(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
{:ok, _show_live, html} = live(conn, ~p"/pipeline/#{pipeline}")
assert html =~ "pipeline"
assert html =~ pipeline.description
end
test "updates pipeline within modal", %{conn: conn, pipeline: pipeline} do
{:ok, show_live, _html} = live(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
{:ok, show_live, _html} = live(conn, ~p"/pipeline/#{pipeline}")
assert show_live |> element("a", "edit") |> render_click() =~ "edit"
assert_patch(show_live, Routes.pipeline_show_path(conn, :edit, pipeline.slug))
assert_patch(show_live, ~p"/pipeline/#{pipeline}/edit")
html =
show_live
@ -136,34 +136,34 @@ defmodule MemexWeb.PipelineLiveTest do
show_live
|> form("#pipeline-form")
|> render_submit(pipeline: @update_attrs |> Map.put(:slug, pipeline.slug))
|> follow_redirect(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
|> follow_redirect(conn, ~p"/pipeline/#{pipeline}")
assert html =~ "#{pipeline.slug} saved"
assert html =~ @update_attrs.description
end
test "deletes pipeline", %{conn: conn, pipeline: pipeline} do
{:ok, show_live, _html} = live(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
{:ok, show_live, _html} = live(conn, ~p"/pipeline/#{pipeline}")
{:ok, index_live, _html} =
show_live
|> element(~s/button[aria-label="delete #{pipeline.slug}"]/)
|> render_click()
|> follow_redirect(conn, Routes.pipeline_index_path(conn, :index))
|> follow_redirect(conn, ~p"/pipelines")
refute has_element?(index_live, "#pipeline-#{pipeline.id}")
end
test "creates a step", %{conn: conn, pipeline: pipeline} do
{:ok, show_live, _html} = live(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
{:ok, show_live, _html} = live(conn, ~p"/pipeline/#{pipeline}")
show_live |> element("a", "add step") |> render_click()
assert_patch(show_live, Routes.pipeline_show_path(conn, :add_step, pipeline.slug))
assert_patch(show_live, ~p"/pipeline/#{pipeline}/add_step")
{:ok, _show_live, html} =
show_live
|> form("#step-form")
|> render_submit(step: @step_create_attrs)
|> follow_redirect(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
|> follow_redirect(conn, ~p"/pipeline/#{pipeline}")
assert html =~ @step_create_attrs.title
assert html =~ @step_create_attrs.content
@ -180,21 +180,21 @@ defmodule MemexWeb.PipelineLiveTest do
end
test "searches by tag", %{conn: conn, pipeline: %{tags: [tag]} = pipeline} do
{:ok, show_live, html} = live(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
{:ok, show_live, html} = live(conn, ~p"/pipeline/#{pipeline}")
assert html =~ tag
assert show_live |> element("a", tag) |> render_click()
assert_redirect(show_live, Routes.pipeline_index_path(conn, :search, tag))
assert_redirect(show_live, ~p"/pipelines/#{tag}")
end
test "updates a step", %{conn: conn, pipeline: pipeline, step: step} do
{:ok, show_live, _html} = live(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
{:ok, show_live, _html} = live(conn, ~p"/pipeline/#{pipeline}")
show_live
|> element(~s/a[aria-label="edit #{step.title}"]/)
|> render_click()
assert_patch(show_live, Routes.pipeline_show_path(conn, :edit_step, pipeline.slug, step.id))
assert_patch(show_live, ~p"/pipeline/#{pipeline}/#{step.id}")
assert show_live
|> form("#step-form")
@ -204,21 +204,21 @@ defmodule MemexWeb.PipelineLiveTest do
show_live
|> form("#step-form")
|> render_submit(step: @step_update_attrs)
|> follow_redirect(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
|> follow_redirect(conn, ~p"/pipeline/#{pipeline}")
assert html =~ @step_update_attrs.title
assert html =~ @step_update_attrs.content
end
test "deletes a step", %{conn: conn, pipeline: pipeline, step: step} do
{:ok, show_live, _html} = live(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
{:ok, show_live, _html} = live(conn, ~p"/pipeline/#{pipeline}")
html =
show_live
|> element(~s/button[aria-label="delete #{step.title}"]/)
|> render_click()
assert_patch(show_live, Routes.pipeline_show_path(conn, :show, pipeline.slug))
assert_patch(show_live, ~p"/pipeline/#{pipeline}")
assert html =~ "#{step.title} deleted"
refute html =~ step.content
@ -238,7 +238,7 @@ defmodule MemexWeb.PipelineLiveTest do
test "reorders a step",
%{conn: conn, pipeline: pipeline, first_step: first_step, second_step: second_step} do
{:ok, show_live, _html} = live(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
{:ok, show_live, _html} = live(conn, ~p"/pipeline/#{pipeline}")
html =
show_live

View File

@ -1,19 +0,0 @@
defmodule MemexWeb.ErrorViewTest do
@moduledoc """
Tests the error view
"""
use MemexWeb.ConnCase, async: true
# Bring render/3 and render_to_string/3 for testing custom views
import Phoenix.View
@moduletag :error_view_test
test "renders 404.html" do
assert render_to_string(MemexWeb.ErrorView, "404.html", []) =~ "not found"
end
test "renders 500.html" do
assert render_to_string(MemexWeb.ErrorView, "500.html", []) =~ "internal server error"
end
end

View File

@ -1,3 +0,0 @@
defmodule MemexWeb.PageViewTest do
use MemexWeb.ConnCase, async: true
end

View File

@ -1,8 +0,0 @@
defmodule MemexWeb.LayoutViewTest do
use MemexWeb.ConnCase, async: true
# When testing helpers, you may want to import Phoenix.HTML and
# use functions such as safe_to_string() to convert the helper
# result into an HTML string.
# import Phoenix.HTML
end

View File

@ -29,7 +29,7 @@ defmodule MemexWeb.ConnCase do
import Plug.Conn
import Phoenix.ConnTest
alias MemexWeb.Router.Helpers, as: Routes
use MemexWeb, :verified_routes
# The default endpoint for testing
@endpoint MemexWeb.Endpoint