fix tests

This commit is contained in:
shibao 2022-01-22 15:00:30 -05:00 committed by oliviasculley
parent f0676a2433
commit 3674eeaf5a
15 changed files with 83 additions and 1096 deletions

View File

@ -2,8 +2,9 @@ import Config
# Configure your database # Configure your database
config :lokal, Lokal.Repo, config :lokal, Lokal.Repo,
url: System.get_env("DATABASE_URL") || url:
"ecto://postgres:postgres@localhost/lokal_dev", System.get_env("DATABASE_URL") ||
"ecto://postgres:postgres@localhost/lokal_dev",
show_sensitive_data_on_connection_error: true, show_sensitive_data_on_connection_error: true,
pool_size: 10 pool_size: 10

View File

@ -18,70 +18,83 @@ defmodule LokalWeb.Component.Topbar do
<div class="flex flex-row justify-between items-center space-x-4"> <div class="flex flex-row justify-between items-center space-x-4">
<div class="flex flex-row justify-start items-center space-x-2"> <div class="flex flex-row justify-start items-center space-x-2">
<%= link to: Routes.live_path(LokalWeb.Endpoint, PageLive) do %> <%= link to: Routes.live_path(LokalWeb.Endpoint, PageLive) do %>
<h1 class="leading-5 text-xl text-white hover:underline">Lokal</h1> <h1 class="leading-5 text-xl text-white hover:underline">
Lokal
</h1>
<% end %> <% end %>
<%= if @title_content do %> <%= if @title_content do %>
<span>|</span> <span>|</span>
<%= render_slot(@title_content) %> <%= render_slot(@title_content) %>
<% end %> <% end %>
</div> </div>
<ul class="flex flex-row flex-wrap justify-center items-center <ul class="flex flex-row flex-wrap justify-center items-center
text-lg space-x-4 text-lg text-white"> text-lg space-x-4 text-lg text-white">
<%# search %>
<form phx-change="suggest" phx-submit="search"> <form phx-change="suggest" phx-submit="search">
<input type="text" name="q" class="input input-primary" <input
placeholder="Search" list="results" autocomplete="off"/> type="text"
name="q"
class="input input-primary"
placeholder="Search"
list="results"
autocomplete="off"
/>
<datalist id="results"> <datalist id="results">
<%= for {app, _vsn} <- @results do %> <%= for {app, _vsn} <- @results do %>
<option value={app}>"><%= app %></option> <option value={app}>
"> <%= app %>
</option>
<% end %> <% end %>
</datalist> </datalist>
</form> </form>
<%# user settings %>
<%= if @current_user do %> <%= if @current_user do %>
<li><%= @current_user.email %></li>
<li> <li>
<%= link "Settings", class: "hover:underline", <%= @current_user.email %>
to: Routes.user_settings_path(LokalWeb.Endpoint, :edit) %>
</li> </li>
<li> <li>
<%= link "Log out", class: "hover:underline", <%= link("Settings",
to: Routes.user_session_path(LokalWeb.Endpoint, :delete), method: :delete %> class: "hover:underline",
to: Routes.user_settings_path(LokalWeb.Endpoint, :edit)
) %>
</li>
<li>
<%= link("Log out",
class: "hover:underline",
to: Routes.user_session_path(LokalWeb.Endpoint, :delete),
method: :delete
) %>
</li> </li>
<%= if function_exported?(Routes, :live_dashboard_path, 2) do %> <%= if function_exported?(Routes, :live_dashboard_path, 2) do %>
<li> <li>
<%= link "LiveDashboard", class: "hover:underline", <%= link("LiveDashboard",
to: Routes.live_dashboard_path(LokalWeb.Endpoint, :home) %> class: "hover:underline",
to: Routes.live_dashboard_path(LokalWeb.Endpoint, :home)
) %>
</li> </li>
<% end %> <% end %>
<% else %> <% else %>
<li> <li>
<%= link "Register", class: "hover:underline", <%= link("Register",
to: Routes.user_registration_path(LokalWeb.Endpoint, :new) %> class: "hover:underline",
to: Routes.user_registration_path(LokalWeb.Endpoint, :new)
) %>
</li> </li>
<li> <li>
<%= link "Log in", class: "hover:underline", <%= link("Log in",
to: Routes.user_session_path(LokalWeb.Endpoint, :new) %> class: "hover:underline",
to: Routes.user_session_path(LokalWeb.Endpoint, :new)
) %>
</li> </li>
<% end %> <% end %>
</ul> </ul>
</div> </div>
</nav> </nav>
<%= if @flash && @flash |> Map.has_key?(:info) do %> <%= if @flash && @flash |> Map.has_key?(:info) do %>
<p class="alert alert-info" role="alert" <p class="alert alert-info" role="alert" phx-click="lv:clear-flash" phx-value-key="info">
phx-click="lv:clear-flash" phx-value-key="info">
<%= live_flash(@flash, :info) %> <%= live_flash(@flash, :info) %>
</p> </p>
<% end %> <% end %>
<%= if @flash && @flash |> Map.has_key?(:error) do %> <%= if @flash && @flash |> Map.has_key?(:error) do %>
<p class="alert alert-danger" role="alert" <p class="alert alert-danger" role="alert" phx-click="lv:clear-flash" phx-value-key="error">
phx-click="lv:clear-flash" phx-value-key="error">
<%= live_flash(@flash, :error) %> <%= live_flash(@flash, :error) %>
</p> </p>
<% end %> <% end %>

View File

@ -1,19 +1,16 @@
<main class="container min-h-full min-w-full"> <main class="container min-h-full min-w-full">
<header class="mb-4 px-8 py-4 w-full bg-primary-400"> <header class="mb-4 px-8 py-4 w-full bg-primary-400">
<%= render "topbar.html", assigns %> <%= render("topbar.html", assigns) %>
<%= if get_flash(@conn, :info) do %> <%= if get_flash(@conn, :info) do %>
<p class="alert alert-info" role="alert"> <p class="alert alert-info" role="alert">
<%= get_flash(@conn, :info) %> <%= get_flash(@conn, :info) %>
</p> </p>
<% end %> <% end %>
<%= if get_flash(@conn, :error) do %> <%= if get_flash(@conn, :error) do %>
<p class="alert alert-danger" role="alert"> <p class="alert alert-danger" role="alert">
<%= get_flash(@conn, :error) %> <%= get_flash(@conn, :error) %>
</p> </p>
<% end %> <% end %>
</header> </header>
<%= @inner_content %> <%= @inner_content %>
</main> </main>

View File

@ -1,19 +1,15 @@
<main class="container"> <main class="container">
<LokalWeb.Component.Topbar.topbar <LokalWeb.Component.Topbar.topbar current_user={assigns[:current_user]}>
current_user={assigns[:current_user]}>
</LokalWeb.Component.Topbar.topbar> </LokalWeb.Component.Topbar.topbar>
<%= if @flash && @flash |> Map.has_key?(:info) do %> <%= if @flash && @flash |> Map.has_key?(:info) do %>
<p class="alert alert-info" role="alert" <p class="alert alert-info" role="alert" phx-click="lv:clear-flash" phx-value-key="info">
phx-click="lv:clear-flash" <%= live_flash(@flash, :info) %>
phx-value-key="info"><%= live_flash(@flash, :info) %></p> </p>
<% end %> <% end %>
<%= if @flash && @flash |> Map.has_key?(:error) do %>
<%= if @flash && @flash |> Map.has_key?(:error) do %> <p class="alert alert-danger" role="alert" phx-click="lv:clear-flash" phx-value-key="error">
<p class="alert alert-danger" role="alert" <%= live_flash(@flash, :error) %>
phx-click="lv:clear-flash" </p>
phx-value-key="error"><%= live_flash(@flash, :error) %></p>
<% end %> <% end %>
<%= @inner_content %> <%= @inner_content %>
</main> </main>

View File

@ -1,13 +1,19 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"/> <meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge"/> <meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<%= csrf_meta_tag() %> <%= csrf_meta_tag() %>
<%= live_title_tag assigns[:page_title] || "Lokal", suffix: "" %> <%= live_title_tag(assigns[:page_title] || "Lokal", suffix: "") %>
<link phx-track-static rel="stylesheet" href={Routes.static_path(@conn, "/css/app.css")}/> <link phx-track-static rel="stylesheet" href={Routes.static_path(@conn, "/css/app.css")} />
<script defer phx-track-static type="text/javascript" src={Routes.static_path(@conn, "/js/app.js")}></script> <script
defer
phx-track-static
type="text/javascript"
src={Routes.static_path(@conn, "/js/app.js")}
>
</script>
</head> </head>
<body class="m-0 p-0 min-w-full min-h-full"> <body class="m-0 p-0 min-w-full min-h-full">
<%= @inner_content %> <%= @inner_content %>

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,6 @@ defmodule LokalWeb.PageControllerTest do
test "GET /", %{conn: conn} do test "GET /", %{conn: conn} do
conn = get(conn, "/") conn = get(conn, "/")
assert html_response(conn, 200) =~ "Welcome to Phoenix!" assert html_response(conn, 200) =~ "Welcome to Lokal"
end end
end end

View File

@ -140,7 +140,7 @@ defmodule LokalWeb.UserAuthTest do
test "stores the path to redirect to on GET", %{conn: conn} do test "stores the path to redirect to on GET", %{conn: conn} do
halted_conn = halted_conn =
%{conn | request_path: "/foo", query_string: ""} %{conn | path_info: ["foo"], query_string: ""}
|> fetch_flash() |> fetch_flash()
|> UserAuth.require_authenticated_user([]) |> UserAuth.require_authenticated_user([])
@ -148,7 +148,7 @@ defmodule LokalWeb.UserAuthTest do
assert get_session(halted_conn, :user_return_to) == "/foo" assert get_session(halted_conn, :user_return_to) == "/foo"
halted_conn = halted_conn =
%{conn | request_path: "/foo", query_string: "bar=baz"} %{conn | path_info: ["foo"], query_string: "bar=baz"}
|> fetch_flash() |> fetch_flash()
|> UserAuth.require_authenticated_user([]) |> UserAuth.require_authenticated_user([])
@ -156,7 +156,7 @@ defmodule LokalWeb.UserAuthTest do
assert get_session(halted_conn, :user_return_to) == "/foo?bar=baz" assert get_session(halted_conn, :user_return_to) == "/foo?bar=baz"
halted_conn = halted_conn =
%{conn | request_path: "/foo?bar", method: "POST"} %{conn | path_info: ["foo"], query_string: "bar", method: "POST"}
|> fetch_flash() |> fetch_flash()
|> UserAuth.require_authenticated_user([]) |> UserAuth.require_authenticated_user([])

View File

@ -13,7 +13,7 @@ defmodule LokalWeb.UserConfirmationControllerTest do
test "renders the confirmation page", %{conn: conn} do test "renders the confirmation page", %{conn: conn} do
conn = get(conn, Routes.user_confirmation_path(conn, :new)) conn = get(conn, Routes.user_confirmation_path(conn, :new))
response = html_response(conn, 200) response = html_response(conn, 200)
assert response =~ "<h1>Resend confirmation instructions</h1>" assert response =~ "Resend confirmation instructions"
end end
end end

View File

@ -7,7 +7,7 @@ defmodule LokalWeb.UserRegistrationControllerTest do
test "renders registration page", %{conn: conn} do test "renders registration page", %{conn: conn} do
conn = get(conn, Routes.user_registration_path(conn, :new)) conn = get(conn, Routes.user_registration_path(conn, :new))
response = html_response(conn, 200) response = html_response(conn, 200)
assert response =~ "<h1>Register</h1>" assert response =~ "Register"
assert response =~ "Log in</a>" assert response =~ "Log in</a>"
assert response =~ "Register</a>" assert response =~ "Register</a>"
end end
@ -46,7 +46,7 @@ defmodule LokalWeb.UserRegistrationControllerTest do
}) })
response = html_response(conn, 200) response = html_response(conn, 200)
assert response =~ "<h1>Register</h1>" assert response =~ "Register"
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 12 character"
end end

View File

@ -13,7 +13,7 @@ defmodule LokalWeb.UserResetPasswordControllerTest do
test "renders the reset password page", %{conn: conn} do test "renders the reset password page", %{conn: conn} do
conn = get(conn, Routes.user_reset_password_path(conn, :new)) conn = get(conn, Routes.user_reset_password_path(conn, :new))
response = html_response(conn, 200) response = html_response(conn, 200)
assert response =~ "<h1>Forgot your password?</h1>" assert response =~ "Forgot your password?"
end end
end end
@ -54,7 +54,7 @@ defmodule LokalWeb.UserResetPasswordControllerTest do
test "renders reset password", %{conn: conn, token: token} do test "renders reset password", %{conn: conn, token: token} do
conn = get(conn, Routes.user_reset_password_path(conn, :edit, token)) conn = get(conn, Routes.user_reset_password_path(conn, :edit, token))
assert html_response(conn, 200) =~ "<h1>Reset password</h1>" assert html_response(conn, 200) =~ "Reset password"
end end
test "does not render reset password with invalid token", %{conn: conn} do test "does not render reset password with invalid token", %{conn: conn} do
@ -99,7 +99,7 @@ defmodule LokalWeb.UserResetPasswordControllerTest do
}) })
response = html_response(conn, 200) response = html_response(conn, 200)
assert response =~ "<h1>Reset password</h1>" assert response =~ "Reset password"
assert response =~ "should be at least 12 character(s)" assert response =~ "should be at least 12 character(s)"
assert response =~ "does not match password" assert response =~ "does not match password"
end end

View File

@ -11,9 +11,8 @@ defmodule LokalWeb.UserSessionControllerTest do
test "renders log in page", %{conn: conn} do test "renders log in page", %{conn: conn} do
conn = get(conn, Routes.user_session_path(conn, :new)) conn = get(conn, Routes.user_session_path(conn, :new))
response = html_response(conn, 200) response = html_response(conn, 200)
assert response =~ "<h1>Log in</h1>" assert response =~ "Log in"
assert response =~ "Log in</a>" assert response =~ "Register"
assert response =~ "Register</a>"
end end
test "redirects if already logged in", %{conn: conn, user: user} do test "redirects if already logged in", %{conn: conn, user: user} do
@ -75,7 +74,7 @@ defmodule LokalWeb.UserSessionControllerTest do
}) })
response = html_response(conn, 200) response = html_response(conn, 200)
assert response =~ "<h1>Log in</h1>" assert response =~ "Log in"
assert response =~ "Invalid email or password" assert response =~ "Invalid email or password"
end end
end end

View File

@ -10,7 +10,7 @@ defmodule LokalWeb.UserSettingsControllerTest do
test "renders settings page", %{conn: conn} do test "renders settings page", %{conn: conn} do
conn = get(conn, Routes.user_settings_path(conn, :edit)) conn = get(conn, Routes.user_settings_path(conn, :edit))
response = html_response(conn, 200) response = html_response(conn, 200)
assert response =~ "<h1>Settings</h1>" assert response =~ "Settings"
end end
test "redirects if user is not logged in" do test "redirects if user is not logged in" do
@ -50,7 +50,7 @@ defmodule LokalWeb.UserSettingsControllerTest do
}) })
response = html_response(old_password_conn, 200) response = html_response(old_password_conn, 200)
assert response =~ "<h1>Settings</h1>" assert response =~ "Settings"
assert response =~ "should be at least 12 character(s)" assert response =~ "should be at least 12 character(s)"
assert response =~ "does not match password" assert response =~ "does not match password"
assert response =~ "is not valid" assert response =~ "is not valid"
@ -83,7 +83,7 @@ defmodule LokalWeb.UserSettingsControllerTest do
}) })
response = html_response(conn, 200) response = html_response(conn, 200)
assert response =~ "<h1>Settings</h1>" assert response =~ "Settings"
assert response =~ "must have the @ sign and no spaces" assert response =~ "must have the @ sign and no spaces"
assert response =~ "is not valid" assert response =~ "is not valid"
end end

View File

@ -5,7 +5,7 @@ defmodule LokalWeb.PageLiveTest do
test "disconnected and connected render", %{conn: conn} do test "disconnected and connected render", %{conn: conn} do
{:ok, page_live, disconnected_html} = live(conn, "/") {:ok, page_live, disconnected_html} = live(conn, "/")
assert disconnected_html =~ "Welcome to Phoenix!" assert disconnected_html =~ "Welcome to Lokal"
assert render(page_live) =~ "Welcome to Phoenix!" assert render(page_live) =~ "Welcome to Lokal"
end end
end end

View File

@ -7,27 +7,6 @@ defmodule Lokal.AccountsFixtures do
def unique_user_email, do: "user#{System.unique_integer()}@example.com" def unique_user_email, do: "user#{System.unique_integer()}@example.com"
def valid_user_password, do: "hello world!" def valid_user_password, do: "hello world!"
def user_fixture(attrs \\ %{}) do
{:ok, user} =
attrs
|> Enum.into(%{
email: unique_user_email(),
password: valid_user_password()
})
|> Lokal.Accounts.register_user()
user
end
def extract_user_token(fun) do
{:ok, captured} = fun.(&"[TOKEN]#{&1}[TOKEN]")
[_, token, _] = String.split(captured.body, "[TOKEN]")
token
end
def unique_user_email, do: "user#{System.unique_integer()}@example.com"
def valid_user_password, do: "hello world!"
def valid_user_attributes(attrs \\ %{}) do def valid_user_attributes(attrs \\ %{}) do
Enum.into(attrs, %{ Enum.into(attrs, %{
email: unique_user_email(), email: unique_user_email(),