chore: Expand test coverage
This commit is contained in:
parent
259cabc5d8
commit
53af5b1610
46 changed files with 750 additions and 192 deletions
0
apps/admin/lib/admin/controllers/.keep
Normal file
0
apps/admin/lib/admin/controllers/.keep
Normal file
|
@ -1,7 +0,0 @@
|
|||
defmodule Admin.PageController do
|
||||
use Admin, :controller
|
||||
|
||||
def index(conn, _params) do
|
||||
render(conn, "index.html")
|
||||
end
|
||||
end
|
|
@ -5,17 +5,8 @@ defmodule Admin.ErrorHelpers do
|
|||
|
||||
use Phoenix.HTML
|
||||
|
||||
@doc """
|
||||
Generates tag for inlined form input errors.
|
||||
"""
|
||||
def error_tag(form, field) do
|
||||
Enum.map(Keyword.get_values(form.errors, field), fn error ->
|
||||
content_tag(:span, translate_error(error),
|
||||
class: "invalid-feedback",
|
||||
phx_feedback_for: input_id(form, field)
|
||||
)
|
||||
end)
|
||||
end
|
||||
defdelegate error_tag(form, field), to: CoreWeb.ErrorHelpers
|
||||
defdelegate error_tag(form, field, opts), to: CoreWeb.ErrorHelpers
|
||||
|
||||
@doc """
|
||||
Translates an error message using gettext.
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
defmodule Mix.Tasks.Legendary.CustomizeKaffyTemplates do
|
||||
use Mix.Task
|
||||
|
||||
@shortdoc "Overwrites kaffy templates with custom versions."
|
||||
def run(_) do
|
||||
base = Path.expand("lib/kaffy_web/templates/")
|
||||
|
||||
replacements =
|
||||
base
|
||||
|> Path.join("**/*.eex")
|
||||
|> Path.wildcard()
|
||||
|
||||
new_base =
|
||||
Mix.Project.deps_path()
|
||||
|> Path.join("kaffy/lib/kaffy_web/templates")
|
||||
|
||||
replacements
|
||||
|> Enum.each(fn template_path ->
|
||||
File.copy(template_path, template_path |> String.replace(base, new_base))
|
||||
end)
|
||||
end
|
||||
end
|
|
@ -16,6 +16,7 @@ defmodule Admin.MixProject do
|
|||
aliases: aliases(),
|
||||
deps: deps(),
|
||||
test_coverage: [tool: ExCoveralls],
|
||||
preferred_cli_env: [coveralls: :test, "coveralls.detail": :test, "coveralls.post": :test, "coveralls.html": :test],
|
||||
]
|
||||
end
|
||||
|
||||
|
@ -39,6 +40,7 @@ defmodule Admin.MixProject do
|
|||
defp deps do
|
||||
[
|
||||
{:auth_web, in_umbrella: true},
|
||||
{:core, in_umbrella: true},
|
||||
{:ecto_sql, "~> 3.4"},
|
||||
{:excoveralls, "~> 0.10", only: [:dev, :test]},
|
||||
{:kaffy, path: "kaffy"},
|
||||
|
|
32
apps/admin/test/admin/views/error_helpers_test.exs
Normal file
32
apps/admin/test/admin/views/error_helpers_test.exs
Normal file
|
@ -0,0 +1,32 @@
|
|||
defmodule Admin.ErrorHelpersTest do
|
||||
use Admin.ConnCase
|
||||
|
||||
import Phoenix.HTML, only: [safe_to_string: 1]
|
||||
import Phoenix.HTML.Form, only: [form_for: 3]
|
||||
|
||||
import Admin.ErrorHelpers
|
||||
|
||||
def form do
|
||||
:example
|
||||
|> form_for(
|
||||
"/example",
|
||||
as: :test_params,
|
||||
errors: [error_field: {"is an error", []}],
|
||||
)
|
||||
end
|
||||
|
||||
test "error_tag/2" do
|
||||
[safe] = error_tag(form(), :error_field)
|
||||
assert safe_to_string(safe) =~ "invalid-feedback"
|
||||
end
|
||||
|
||||
test "error_tag/3" do
|
||||
[safe] = error_tag(form(), :error_field, class: "test-class")
|
||||
assert safe_to_string(safe) =~ "test-class"
|
||||
end
|
||||
|
||||
test "translate_error/1" do
|
||||
assert translate_error({"is an error", []}) == "is an error"
|
||||
assert translate_error({"%{count} errors", %{count: 3}}) == "3 errors"
|
||||
end
|
||||
end
|
|
@ -16,6 +16,7 @@ defmodule App.MixProject do
|
|||
aliases: aliases(),
|
||||
deps: deps(),
|
||||
test_coverage: [tool: ExCoveralls],
|
||||
preferred_cli_env: [coveralls: :test, "coveralls.detail": :test, "coveralls.post": :test, "coveralls.html": :test],
|
||||
]
|
||||
end
|
||||
|
||||
|
|
|
@ -2,12 +2,6 @@ defmodule Auth.Roles do
|
|||
def has_role?(userlike, role) when is_atom(role), do: has_role?(userlike, Atom.to_string(role))
|
||||
def has_role?(nil, _), do: false
|
||||
def has_role?(user = %Auth.User{}, role) do
|
||||
Enum.any?(user.roles, & &1 == role)
|
||||
end
|
||||
|
||||
def has_role?(conn = %Plug.Conn{}, role) do
|
||||
conn
|
||||
|> Pow.Plug.current_user()
|
||||
|> has_role?(role)
|
||||
Enum.any?(user.roles || [], & &1 == role)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -40,7 +40,7 @@ defmodule Auth.User do
|
|||
|> pow_extension_changeset(attrs)
|
||||
end
|
||||
|
||||
def reset_password_changeset(user = %user_mod{}, params) do
|
||||
def reset_password_changeset(user = %Auth.User{}, params) do
|
||||
user
|
||||
|> new_password_changeset(params, @pow_config)
|
||||
|> Changeset.validate_required([:password])
|
||||
|
|
|
@ -15,6 +15,7 @@ defmodule Auth.MixProject do
|
|||
aliases: aliases(),
|
||||
deps: deps(),
|
||||
test_coverage: [tool: ExCoveralls],
|
||||
preferred_cli_env: [coveralls: :test, "coveralls.detail": :test, "coveralls.post": :test, "coveralls.html": :test],
|
||||
]
|
||||
end
|
||||
|
||||
|
|
23
apps/auth/test/auth/roles_test.exs
Normal file
23
apps/auth/test/auth/roles_test.exs
Normal file
|
@ -0,0 +1,23 @@
|
|||
defmodule Auth.RolesTest do
|
||||
use Auth.DataCase
|
||||
|
||||
import Auth.Roles
|
||||
|
||||
alias Auth.User
|
||||
|
||||
describe "has_role?/2" do
|
||||
test "with no user" do
|
||||
refute has_role?(nil, "admin")
|
||||
end
|
||||
|
||||
test "with an atom role" do
|
||||
assert has_role?(%User{roles: ["admin"]}, :admin)
|
||||
refute has_role?(%User{roles: ["admin"]}, :blooper)
|
||||
end
|
||||
|
||||
test "with a string role" do
|
||||
assert has_role?(%User{roles: ["admin"]}, "admin")
|
||||
refute has_role?(%User{roles: ["admin"]}, "blooper")
|
||||
end
|
||||
end
|
||||
end
|
37
apps/auth/test/auth/user_test.exs
Normal file
37
apps/auth/test/auth/user_test.exs
Normal file
|
@ -0,0 +1,37 @@
|
|||
defmodule Auth.UserTest do
|
||||
use Auth.DataCase
|
||||
|
||||
import Auth.User
|
||||
|
||||
alias Auth.User
|
||||
|
||||
describe "admin_changeset/2" do
|
||||
test "handles roles from text properly" do
|
||||
changeset = admin_changeset(%User{}, %{"roles" => ~S(["snorlax", "pikachu"])})
|
||||
|
||||
assert changeset.changes.roles == ["snorlax", "pikachu"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "changeset/2" do
|
||||
test "requires an email" do
|
||||
changeset = changeset(%User{}, %{"password" => "bloopers"})
|
||||
|
||||
refute changeset.valid?
|
||||
end
|
||||
|
||||
test "does not require password confirmation" do
|
||||
changeset = changeset(%User{}, %{"email" => "bloop@example.org", "password" => "bloopers"})
|
||||
|
||||
assert changeset.valid?
|
||||
end
|
||||
end
|
||||
|
||||
describe "reset_password_changeset/2" do
|
||||
test "does not require password confirmation" do
|
||||
changeset = reset_password_changeset(%User{}, %{"password" => "bloopers"})
|
||||
|
||||
assert changeset.valid?
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,21 +0,0 @@
|
|||
defmodule AuthWeb.Plugs.RequireAuth do
|
||||
@moduledoc """
|
||||
A plug that returns 403 unauthorized if the user is not authenticated. Used
|
||||
to block out logged-in-only routes.
|
||||
"""
|
||||
import Plug.Conn
|
||||
|
||||
def init(opts) do
|
||||
opts
|
||||
end
|
||||
|
||||
def call(conn, _opts) do
|
||||
if Pow.Plug.current_user(conn) do
|
||||
conn
|
||||
else
|
||||
conn
|
||||
|> send_resp(403, "Unauthorized")
|
||||
|> halt()
|
||||
end
|
||||
end
|
||||
end
|
|
@ -16,6 +16,7 @@ defmodule AuthWeb.MixProject do
|
|||
aliases: aliases(),
|
||||
deps: deps(),
|
||||
test_coverage: [tool: ExCoveralls],
|
||||
preferred_cli_env: [coveralls: :test, "coveralls.detail": :test, "coveralls.post": :test, "coveralls.html": :test],
|
||||
]
|
||||
end
|
||||
|
||||
|
|
30
apps/auth_web/test/auth_web/plugs/require_admin_test.exs
Normal file
30
apps/auth_web/test/auth_web/plugs/require_admin_test.exs
Normal file
|
@ -0,0 +1,30 @@
|
|||
defmodule AuthWeb.Plugs.RequireAdminTest do
|
||||
use AuthWeb.ConnCase
|
||||
|
||||
alias AuthWeb.Plugs.RequireAdmin
|
||||
alias Auth.User
|
||||
|
||||
setup %{conn: conn} do
|
||||
%{conn: Pow.Plug.put_config(conn, current_user_assigns_key: :current_user)}
|
||||
end
|
||||
|
||||
test "init/1" do
|
||||
assert RequireAdmin.init([]) == []
|
||||
end
|
||||
|
||||
test "call/2 without user", %{conn: conn} do
|
||||
conn = RequireAdmin.call(conn, [])
|
||||
|
||||
assert response(conn, 403)
|
||||
assert conn.halted
|
||||
end
|
||||
|
||||
test "call/2 with a user", %{conn: conn} do
|
||||
conn =
|
||||
conn
|
||||
|> Pow.Plug.assign_current_user(%User{roles: ["admin"]}, [])
|
||||
|> RequireAdmin.call([])
|
||||
|
||||
assert !conn.halted
|
||||
end
|
||||
end
|
32
apps/auth_web/test/auth_web/pow/mailer_test.exs
Normal file
32
apps/auth_web/test/auth_web/pow/mailer_test.exs
Normal file
|
@ -0,0 +1,32 @@
|
|||
defmodule AuthWeb.Pow.MailerTest do
|
||||
use ExUnit.Case
|
||||
use Bamboo.Test
|
||||
|
||||
import AuthWeb.Pow.Mailer
|
||||
|
||||
alias Auth.User
|
||||
|
||||
def hello_email do
|
||||
cast(%{
|
||||
user: %User{email: "test@example.org"},
|
||||
subject: "Hello, email",
|
||||
text: "This is a hello email.",
|
||||
html: "<h1>Hello!</h1>",
|
||||
})
|
||||
end
|
||||
|
||||
test "cast/1" do
|
||||
email = hello_email()
|
||||
assert %{to: "test@example.org"} = email
|
||||
assert email.text_body =~ "This is a hello email."
|
||||
assert email.html_body =~ "<h1>Hello!</h1>"
|
||||
end
|
||||
|
||||
test "process/1" do
|
||||
email = hello_email()
|
||||
|
||||
process(email)
|
||||
|
||||
assert_delivered_email email
|
||||
end
|
||||
end
|
|
@ -22,9 +22,4 @@ defmodule Content.Option do
|
|||
values
|
||||
end
|
||||
end
|
||||
|
||||
def put_new_value(struct, value) do
|
||||
struct
|
||||
|> change(%{value: PhpSerializer.serialize(value)})
|
||||
end
|
||||
end
|
||||
|
|
|
@ -108,13 +108,6 @@ defmodule Content.Post do
|
|||
content_page_count(struct) > 1
|
||||
end
|
||||
|
||||
def metas_map(list) when is_list(list) do
|
||||
list
|
||||
|> Enum.map(fn post ->
|
||||
{post.id, metas_map(post)}
|
||||
end)
|
||||
|> Map.new
|
||||
end
|
||||
def metas_map(%Content.Post{} = struct) do
|
||||
struct.metas
|
||||
|> Enum.map(&({&1.key, &1.value}))
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
defmodule Content.PageController do
|
||||
use Content, :controller
|
||||
|
||||
def index(conn, _params) do
|
||||
render(conn, "index.html")
|
||||
end
|
||||
|
||||
def show(conn, %{"id" => id}) do
|
||||
render(conn, "#{id}.html")
|
||||
end
|
||||
end
|
|
@ -5,6 +5,10 @@ defmodule Content.PostsController do
|
|||
|
||||
plug :put_layout, false when action in [:preview]
|
||||
|
||||
def index(conn, %{"category" => _} = params) do
|
||||
conn |> index_posts(params)
|
||||
end
|
||||
|
||||
def index(conn, params) do
|
||||
show_on_front = Options.get_value("show_on_front") || "page"
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
defmodule Content.Router do
|
||||
use Content, :router
|
||||
alias AuthWeb.Plugs.{RequireAdmin, RequireAuth}
|
||||
alias AuthWeb.Plugs.{RequireAdmin}
|
||||
|
||||
pipeline :browser do
|
||||
plug :accepts, ["html"]
|
||||
|
@ -23,7 +23,7 @@ defmodule Content.Router do
|
|||
end
|
||||
|
||||
pipeline :require_auth do
|
||||
plug(RequireAuth)
|
||||
plug Pow.Plug.RequireAuthenticated, error_handler: Pow.Phoenix.PlugErrorHandler
|
||||
end
|
||||
|
||||
pipeline :require_admin do
|
||||
|
|
|
@ -16,12 +16,7 @@ defmodule Content.LayoutView do
|
|||
end
|
||||
|
||||
def title(_, _, _) do
|
||||
case Options.get("blogname") do
|
||||
opt = %Option{} ->
|
||||
opt.value
|
||||
_ ->
|
||||
I18n.t! "en", "site.title"
|
||||
end
|
||||
I18n.t! "en", "site.title"
|
||||
end
|
||||
|
||||
def excerpt(Content.PostsView, "show.html", assigns) do
|
||||
|
@ -34,12 +29,7 @@ defmodule Content.LayoutView do
|
|||
end
|
||||
|
||||
def excerpt(_, _, _) do
|
||||
case Options.get("blogdescription") do
|
||||
opt = %Option{} ->
|
||||
opt.value
|
||||
_ ->
|
||||
I18n.t! "en", "site.excerpt"
|
||||
end
|
||||
I18n.t! "en", "site.excerpt"
|
||||
end
|
||||
|
||||
def author(Content.PostsView, "show.html", assigns) do
|
||||
|
@ -66,27 +56,4 @@ defmodule Content.LayoutView do
|
|||
def corresponding_feed_url(conn, _, _, _) do
|
||||
Routes.index_feed_url(conn, :index)
|
||||
end
|
||||
|
||||
def menu_markup(menu_items, conn), do: menu_markup(menu_items, conn, 0)
|
||||
def menu_markup(nil, _, _), do: ""
|
||||
def menu_markup([], _, _), do: ""
|
||||
def menu_markup(menu_items, conn, level) do
|
||||
~E"""
|
||||
<ul style="--menu-level: <%= level %>;">
|
||||
<%= for item <- menu_items do %>
|
||||
<li>
|
||||
<label>
|
||||
<%= case item[:type] do %>
|
||||
<% "category" -> %>
|
||||
<%= link item[:related_item].title, to: Routes.category_path(conn, :index_posts, item[:related_item].slug) %>
|
||||
<% _ -> %>
|
||||
<%= link item[:related_item].title, to: Routes.posts_path(conn, :show, item[:related_item].slug) %>
|
||||
<% end %>
|
||||
<%= menu_markup(item[:children], conn, level + 1) %>
|
||||
</label>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
"""
|
||||
end
|
||||
end
|
||||
|
|
|
@ -38,14 +38,6 @@ defmodule Content.PostsView do
|
|||
|> Comment.changeset()
|
||||
end
|
||||
|
||||
def comment_changeset_for_parent(%Comment{} = comment) do
|
||||
%Comment{
|
||||
parent: comment.id,
|
||||
post_id: comment.post_id
|
||||
}
|
||||
|> Comment.changeset()
|
||||
end
|
||||
|
||||
def auto_paragraph_tags(string) do
|
||||
string
|
||||
|> Kernel.||("")
|
||||
|
|
|
@ -16,7 +16,7 @@ defmodule Content.MixProject do
|
|||
aliases: aliases(),
|
||||
deps: deps(),
|
||||
test_coverage: [tool: ExCoveralls],
|
||||
preferred_cli_env: [coveralls: :test, "coveralls.detail": :test, "coveralls.post": :test, "coveralls.html": :test]
|
||||
preferred_cli_env: [coveralls: :test, "coveralls.detail": :test, "coveralls.post": :test, "coveralls.html": :test],
|
||||
]
|
||||
end
|
||||
|
||||
|
|
61
apps/content/test/content/posts_test.exs
Normal file
61
apps/content/test/content/posts_test.exs
Normal file
|
@ -0,0 +1,61 @@
|
|||
defmodule Content.PostsTest do
|
||||
use Content.DataCase
|
||||
|
||||
alias Content.{Post, Posts, Repo}
|
||||
|
||||
setup do
|
||||
admin_only_post =
|
||||
%Post{
|
||||
title: "Admin-only post",
|
||||
name: "admin-only-post",
|
||||
status: "draft",
|
||||
type: "post",
|
||||
date: ~N[2020-02-01T00:00:00],
|
||||
}
|
||||
|> Repo.insert!()
|
||||
|
||||
public_post =
|
||||
%Post{
|
||||
title: "Public post",
|
||||
name: "public-post",
|
||||
status: "publish",
|
||||
type: "post",
|
||||
date: ~N[2020-01-01T00:00:00],
|
||||
}
|
||||
|> Repo.insert!()
|
||||
|
||||
%{
|
||||
admin_only_post: admin_only_post,
|
||||
public_post: public_post,
|
||||
}
|
||||
end
|
||||
|
||||
test "list_admin_posts/2" do
|
||||
results = Posts.list_admin_posts("1")
|
||||
|
||||
assert Enum.count(results) == 2
|
||||
assert [%{name: "admin-only-post"}, %{name: "public-post"}] = results
|
||||
end
|
||||
|
||||
test "get_post_with_drafts!/1 with slug" do
|
||||
assert %Post{} = Posts.get_post_with_drafts!("admin-only-post")
|
||||
end
|
||||
|
||||
test "get_post_with_drafts!/1 with id", %{admin_only_post: %{id: id}} do
|
||||
assert %Post{} = Posts.get_post_with_drafts!(Integer.to_string(id))
|
||||
end
|
||||
|
||||
test "update_posts/2", %{public_post: post} do
|
||||
assert {:ok, %Post{content: "boop"}} = Posts.update_posts(post, %{content: "boop"})
|
||||
end
|
||||
|
||||
test "delete_posts/1", %{public_post: post} do
|
||||
assert Enum.count(Posts.list_posts()) == 1
|
||||
assert {:ok, _} = Posts.delete_posts(post)
|
||||
assert Enum.count(Posts.list_posts()) == 0
|
||||
end
|
||||
|
||||
test "change_posts/1", %{public_post: post} do
|
||||
assert %{data: %Post{name: "public-post"}} = Posts.change_posts(post)
|
||||
end
|
||||
end
|
|
@ -67,5 +67,9 @@ defmodule Content.ShortcodesTest do
|
|||
test "handles mangled shortcodes gracefully" do
|
||||
assert expand_shortcodes("[[unclosed shortcode") == "[[unclosed shortcode"
|
||||
end
|
||||
|
||||
test "handles comments in html" do
|
||||
assert expand_shortcodes("<!-- comment -->") == "<!-- comment -->"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
defmodule Content.FeedsControllerTest do
|
||||
use Content.ConnCase
|
||||
|
||||
alias Content.{Term, TermRelationship, TermTaxonomy, Posts, Repo}
|
||||
|
||||
@post_attrs %{
|
||||
id: 456,
|
||||
title: "Test post",
|
||||
type: "post",
|
||||
name: "blergh",
|
||||
status: "publish",
|
||||
date: ~N[2020-02-01T00:00:00],
|
||||
}
|
||||
@post_category %Term{
|
||||
id: 42,
|
||||
name: "Test Category",
|
||||
slug: "test-category",
|
||||
}
|
||||
@post_category_taxonomy %TermTaxonomy{
|
||||
id: 64,
|
||||
term_id: 42,
|
||||
taxonomy: "category",
|
||||
description: "A test category",
|
||||
parent: 0,
|
||||
}
|
||||
@post_category_relationship %TermRelationship{
|
||||
term_taxonomy_id: 64,
|
||||
object_id: 456,
|
||||
}
|
||||
|
||||
def fixture(:category) do
|
||||
{:ok, category} = @post_category |> Repo.insert()
|
||||
{:ok, _term_taxonomy} = @post_category_taxonomy |> Repo.insert()
|
||||
{:ok, _term_relationship} = @post_category_relationship |> Repo.insert()
|
||||
category
|
||||
end
|
||||
|
||||
def fixture(:post) do
|
||||
{:ok, post} = Posts.create_posts(@post_attrs)
|
||||
post
|
||||
end
|
||||
|
||||
setup %{conn: conn} do
|
||||
|
||||
%{
|
||||
conn: conn,
|
||||
post: fixture(:post),
|
||||
category: fixture(:category),
|
||||
}
|
||||
end
|
||||
|
||||
describe "feeds" do
|
||||
test "index/2 without category", %{conn: conn} do
|
||||
conn = get conn, Routes.index_feed_path(conn, :index)
|
||||
|
||||
assert response(conn, 200) =~ "<item>"
|
||||
end
|
||||
|
||||
test "index/2 with category", %{conn: conn} do
|
||||
conn = get conn, Routes.category_feed_path(conn, :index, "test-category")
|
||||
|
||||
assert response(conn, 200) =~ "<item>"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,8 +0,0 @@
|
|||
defmodule Content.PageControllerTest do
|
||||
use Content.ConnCase
|
||||
|
||||
test "GET /", %{conn: conn} do
|
||||
conn = get(conn, "/index")
|
||||
assert html_response(conn, 200)
|
||||
end
|
||||
end
|
|
@ -116,6 +116,14 @@ defmodule Content.PostsControllerTest do
|
|||
assert html_response(conn, 200) =~ "My Post"
|
||||
end
|
||||
|
||||
test "lists all posts by category page", %{conn: conn} do
|
||||
fixture(:posts)
|
||||
fixture(:category)
|
||||
|
||||
conn = get conn, Routes.category_page_path(conn, :index, @post_category.slug, "2")
|
||||
assert html_response(conn, 200)
|
||||
end
|
||||
|
||||
test "lists all posts for page", %{conn: conn} do
|
||||
fixture(:posts)
|
||||
|
||||
|
@ -151,6 +159,18 @@ defmodule Content.PostsControllerTest do
|
|||
|
||||
assert html_response(conn, 200) =~ posts.title
|
||||
end
|
||||
|
||||
test "show a static page", %{conn: conn} do
|
||||
conn = get conn, Routes.posts_path(conn, :show, "index")
|
||||
|
||||
assert html_response(conn, 200)
|
||||
end
|
||||
|
||||
test "show a 404 if there's no match", %{conn: conn} do
|
||||
assert_raise Phoenix.Router.NoRouteError, fn ->
|
||||
get conn, Routes.posts_path(conn, :show, "blooper")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "show the front post" do
|
||||
|
|
|
@ -1,8 +1,70 @@
|
|||
defmodule Content.LayoutViewTest do
|
||||
use Content.ConnCase, async: true
|
||||
use Content.ConnCase
|
||||
|
||||
# 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
|
||||
|
||||
import Content.LayoutView
|
||||
|
||||
describe "title/3" do
|
||||
def default_title do
|
||||
I18n.t! "en", "site.title"
|
||||
end
|
||||
|
||||
test "for index" do
|
||||
assert title(Content.PostsView, "index.html", %{page: 1}) =~ "Page 1 | #{default_title()}"
|
||||
end
|
||||
|
||||
test "for feed" do
|
||||
assert title(Content.FeedsView, "index.rss", %{category: "Category Test"}) =~ "Category Test | #{default_title()}"
|
||||
end
|
||||
|
||||
test "for category" do
|
||||
assert title(Content.PostsView, "show.html", %{post: %{title: "Test"}}) =~ "Test | #{default_title()}"
|
||||
end
|
||||
|
||||
test "for nil" do
|
||||
title(nil, nil, nil)
|
||||
end
|
||||
end
|
||||
|
||||
describe "excerpt/3" do
|
||||
test "for a post" do
|
||||
assert excerpt(Content.PostsView, "show.html", %{post: %{excerpt: "Excerpt test"}}) =~ "Excerpt test"
|
||||
end
|
||||
|
||||
test "for a category" do
|
||||
assert excerpt(Content.FeedsView, "index.rss", %{category: "category-test"}) =~ "category-test |"
|
||||
end
|
||||
end
|
||||
|
||||
describe "author/3" do
|
||||
test "with a display name" do
|
||||
assert author(Content.PostsView, "show.html", %{author: %{display_name: "Rufus"}}) =~ "Rufus"
|
||||
end
|
||||
|
||||
test "without a display name" do
|
||||
assert author(Content.PostsView, "show.html", %{}) =~ "Anonymous"
|
||||
end
|
||||
end
|
||||
|
||||
describe "corresponding_feed_url/4" do
|
||||
setup %{conn: conn} do
|
||||
%{conn: put_private(conn, :phoenix_router_url, "/pages")}
|
||||
end
|
||||
|
||||
test "with a nil category", %{conn: conn} do
|
||||
assert corresponding_feed_url(conn, nil, nil, %{category: nil}) == "/pages/feed.rss"
|
||||
end
|
||||
|
||||
test "with a non-nil category", %{conn: conn} do
|
||||
assert corresponding_feed_url(conn, Content.PostsView, "index.html", %{category: "test-category"}) == "/pages/category/test-category/feed.rss"
|
||||
end
|
||||
|
||||
test "without a category", %{conn: conn} do
|
||||
assert corresponding_feed_url(conn, nil, nil, %{}) == "/pages/feed.rss"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
14
apps/content/test/content_web/views/posts_view_test.exs
Normal file
14
apps/content/test/content_web/views/posts_view_test.exs
Normal file
|
@ -0,0 +1,14 @@
|
|||
defmodule Content.PostsViewTest do
|
||||
use Content.ConnCase
|
||||
|
||||
import Content.PostsView
|
||||
import Phoenix.HTML, only: [safe_to_string: 1]
|
||||
|
||||
test "auto_paragraph_tags/1 with nil" do
|
||||
assert safe_to_string(auto_paragraph_tags(nil)) =~ ""
|
||||
end
|
||||
|
||||
test "auto_paragraph_tags/1 with text" do
|
||||
assert safe_to_string(auto_paragraph_tags("Bloop\n\nBloop")) =~ "<p>Bloop</p>\n<p>Bloop</p>"
|
||||
end
|
||||
end
|
|
@ -32,7 +32,7 @@ defmodule Content.ConnCase do
|
|||
|
||||
defmacro as_admin(do: expression) do
|
||||
quote do
|
||||
with_mock AuthWeb.Plugs.RequireAuth, [call: fn(conn, _opts) -> conn end] do
|
||||
with_mock Pow.Plug.RequireAuthenticated, [call: fn(conn, _opts) -> conn end] do
|
||||
with_mock AuthWeb.Plugs.RequireAdmin, [call: fn(conn, _opts) -> conn end] do
|
||||
unquote(expression)
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<i class="sidebar icon"></i>
|
||||
</a>
|
||||
<a class="item" href="/">Home</a>
|
||||
<%= if Auth.Roles.has_role?(@conn, :admin) do %>
|
||||
<%= if has_role?(@conn, :admin) do %>
|
||||
<a class="item" href="/admin">Admin</a>
|
||||
<% end %>
|
||||
<div class="right item">
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<div class="ui vertical inverted left sidebar menu">
|
||||
<a class="item" href="/">Home</a>
|
||||
<%= if Auth.Roles.has_role?(@conn, :admin) do %>
|
||||
<%= if has_role?(@conn, :admin) do %>
|
||||
<a class="item" href="/admin">Admin</a>
|
||||
<% end %>
|
||||
<%= if Pow.Plug.current_user(@conn) do %>
|
||||
|
|
|
@ -7,6 +7,12 @@ defmodule CoreWeb.Helpers do
|
|||
import Phoenix.Controller, only: [get_flash: 2]
|
||||
import CoreWeb.ErrorHelpers
|
||||
|
||||
def has_role?(conn = %Plug.Conn{}, role) do
|
||||
conn
|
||||
|> Pow.Plug.current_user()
|
||||
|> Auth.Roles.has_role?(role)
|
||||
end
|
||||
|
||||
def changeset_error_block(changeset) do
|
||||
~E"""
|
||||
<%= if changeset.action do %>
|
||||
|
@ -21,7 +27,7 @@ defmodule CoreWeb.Helpers do
|
|||
~E"""
|
||||
<%= [info: "info", error: "negative"] |> Enum.map(fn {level, class} -> %>
|
||||
<%= if get_flash(conn, level) do %>
|
||||
<p class="ui message <%= class %>" role="alert"><%= get_flash(conn, level) %></p>
|
||||
<p class="ui <%= class %> message" role="alert"><%= get_flash(conn, level) %></p>
|
||||
<% end %>
|
||||
<% end) %>
|
||||
"""
|
||||
|
@ -63,6 +69,6 @@ defmodule CoreWeb.Helpers do
|
|||
def pow_extension_enabled?(extension) do
|
||||
{extensions, _rest} = Application.get_env(:auth_web, :pow) |> Keyword.pop(:extensions, [])
|
||||
|
||||
Enum.any?(extensions, & &1 == PowResetPassword)
|
||||
Enum.any?(extensions, & &1 == extension)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,6 +16,7 @@ defmodule Core.MixProject do
|
|||
aliases: aliases(),
|
||||
deps: deps(),
|
||||
test_coverage: [tool: ExCoveralls],
|
||||
preferred_cli_env: [coveralls: :test, "coveralls.detail": :test, "coveralls.post": :test, "coveralls.html": :test],
|
||||
]
|
||||
end
|
||||
|
||||
|
@ -38,6 +39,7 @@ defmodule Core.MixProject do
|
|||
# Type `mix help deps` for examples and options.
|
||||
defp deps do
|
||||
[
|
||||
{:auth, in_umbrella: true},
|
||||
{:bamboo, "~> 1.5"},
|
||||
{:credo, "~> 1.4", only: [:dev, :test], runtime: false},
|
||||
{:ex_cldr, "~> 2.13.0"},
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
%{
|
||||
"bamboo": {:hex, :bamboo, "1.5.0", "1926107d58adba6620450f254dfe8a3686637a291851fba125686fa8574842af", [:mix], [{:hackney, ">= 1.13.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "d5f3d04d154e80176fd685e2531e73870d8700679f14d25a567e448abce6298d"},
|
||||
"certifi": {:hex, :certifi, "2.5.2", "b7cfeae9d2ed395695dd8201c57a2d019c0c43ecaf8b8bcb9320b40d6662f340", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm", "3b3b5f36493004ac3455966991eaf6e768ce9884693d9968055aeeeb1e575040"},
|
||||
"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm", "4a0850c9be22a43af9920a71ab17c051f5f7d45c209e40269a1938832510e4d9"},
|
||||
"cowboy": {:hex, :cowboy, "2.8.0", "f3dc62e35797ecd9ac1b50db74611193c29815401e53bac9a5c0577bd7bc667d", [:rebar3], [{:cowlib, "~> 2.9.1", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.7.1", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "4643e4fba74ac96d4d152c75803de6fad0b3fa5df354c71afdd6cbeeb15fac8a"},
|
||||
"cowlib": {:hex, :cowlib, "2.9.1", "61a6c7c50cf07fdd24b2f45b89500bb93b6686579b069a89f88cb211e1125c78", [:rebar3], [], "hexpm", "e4175dc240a70d996156160891e1c62238ede1729e45740bdd38064dad476170"},
|
||||
"db_connection": {:hex, :db_connection, "2.2.2", "3bbca41b199e1598245b716248964926303b5d4609ff065125ce98bcd368939e", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm", "642af240d8a8affb93b4ba5a6fcd2bbcbdc327e1a524b825d383711536f8070c"},
|
||||
"decimal": {:hex, :decimal, "1.8.1", "a4ef3f5f3428bdbc0d35374029ffcf4ede8533536fa79896dd450168d9acdf3c", [:mix], [], "hexpm", "3cb154b00225ac687f6cbd4acc4b7960027c757a5152b369923ead9ddbca7aec"},
|
||||
"ecto": {:hex, :ecto, "3.4.5", "2bcd262f57b2c888b0bd7f7a28c8a48aa11dc1a2c6a858e45dd8f8426d504265", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "8c6d1d4d524559e9b7a062f0498e2c206122552d63eacff0a6567ffe7a8e8691"},
|
||||
"ecto_sql": {:hex, :ecto_sql, "3.4.4", "d28bac2d420f708993baed522054870086fd45016a9d09bb2cd521b9c48d32ea", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.4.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.3.0 or ~> 0.4.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.0", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "edb49af715dd72f213b66adfd0f668a43c17ed510b5d9ac7528569b23af57fe8"},
|
||||
"file_system": {:hex, :file_system, "0.2.8", "f632bd287927a1eed2b718f22af727c5aeaccc9a98d8c2bd7bff709e851dc986", [:mix], [], "hexpm", "97a3b6f8d63ef53bd0113070102db2ce05352ecf0d25390eb8d747c2bde98bca"},
|
||||
"gettext": {:hex, :gettext, "0.18.0", "406d6b9e0e3278162c2ae1de0a60270452c553536772167e2d701f028116f870", [:mix], [], "hexpm", "c3f850be6367ebe1a08616c2158affe4a23231c70391050bf359d5f92f66a571"},
|
||||
"hackney": {:hex, :hackney, "1.16.0", "5096ac8e823e3a441477b2d187e30dd3fff1a82991a806b2003845ce72ce2d84", [:rebar3], [{:certifi, "2.5.2", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.1", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.0", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.6", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "3bf0bebbd5d3092a3543b783bf065165fa5d3ad4b899b836810e513064134e18"},
|
||||
"idna": {:hex, :idna, "6.0.1", "1d038fb2e7668ce41fbf681d2c45902e52b3cb9e9c77b55334353b222c2ee50c", [:rebar3], [{:unicode_util_compat, "0.5.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "a02c8a1c4fd601215bb0b0324c8a6986749f807ce35f25449ec9e69758708122"},
|
||||
"jason": {:hex, :jason, "1.2.1", "12b22825e22f468c02eb3e4b9985f3d0cb8dc40b9bd704730efa11abd2708c44", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "b659b8571deedf60f79c5a608e15414085fa141344e2716fbd6988a084b5f993"},
|
||||
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
|
||||
"mime": {:hex, :mime, "1.3.1", "30ce04ab3175b6ad0bdce0035cba77bba68b813d523d1aac73d9781b4d193cf8", [:mix], [], "hexpm", "6cbe761d6a0ca5a31a0931bf4c63204bceb64538e664a8ecf784a9a6f3b875f1"},
|
||||
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
|
||||
"parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm", "17ef63abde837ad30680ea7f857dd9e7ced9476cdd7b0394432af4bfc241b960"},
|
||||
"phoenix": {:hex, :phoenix, "1.5.3", "bfe0404e48ea03dfe17f141eff34e1e058a23f15f109885bbdcf62be303b49ff", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_html, "~> 2.13", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.1.2 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "8e16febeb9640d8b33895a691a56481464b82836d338bb3a23125cd7b6157c25"},
|
||||
"phoenix_ecto": {:hex, :phoenix_ecto, "4.1.0", "a044d0756d0464c5a541b4a0bf4bcaf89bffcaf92468862408290682c73ae50d", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.9", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "c5e666a341ff104d0399d8f0e4ff094559b2fde13a5985d4cb5023b2c2ac558b"},
|
||||
"phoenix_html": {:hex, :phoenix_html, "2.14.2", "b8a3899a72050f3f48a36430da507dd99caf0ac2d06c77529b1646964f3d563e", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "58061c8dfd25da5df1ea0ca47c972f161beb6c875cd293917045b92ffe1bf617"},
|
||||
"phoenix_live_dashboard": {:hex, :phoenix_live_dashboard, "0.2.6", "1b4e1b7d797386b7f9d70d2af931dc9843a5f2f2423609d22cef1eec4e4dba7d", [:mix], [{:phoenix_html, "~> 2.14.1 or ~> 2.15", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.13.1", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 0.4.0 or ~> 0.5.0", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}], "hexpm", "b20dcad98c4ca63d38a7f5e7a40936e1e8e9da983d3d722b88ae33afb866c9ca"},
|
||||
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.2.4", "940c0344b1d66a2e46eef02af3a70e0c5bb45a4db0bf47917add271b76cd3914", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "38f9308357dea4cc77f247e216da99fcb0224e05ada1469167520bed4cb8cccd"},
|
||||
"phoenix_live_view": {:hex, :phoenix_live_view, "0.13.3", "2186c55cc7c54ca45b97c6f28cfd267d1c61b5f205f3c83533704cd991bdfdec", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.4.17 or ~> 1.5.2", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14", [hex: :phoenix_html, repo: "hexpm", optional: false]}], "hexpm", "c6309a7da2e779cb9cdf2fb603d75f38f49ef324bedc7a81825998bd1744ff8a"},
|
||||
"phoenix_pubsub": {:hex, :phoenix_pubsub, "2.0.0", "a1ae76717bb168cdeb10ec9d92d1480fec99e3080f011402c0a2d68d47395ffb", [:mix], [], "hexpm", "c52d948c4f261577b9c6fa804be91884b381a7f8f18450c5045975435350f771"},
|
||||
"plug": {:hex, :plug, "1.10.3", "c9cebe917637d8db0e759039cc106adca069874e1a9034fd6e3fdd427fd3c283", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "01f9037a2a1de1d633b5a881101e6a444bcabb1d386ca1e00bb273a1f1d9d939"},
|
||||
"plug_cowboy": {:hex, :plug_cowboy, "2.3.0", "149a50e05cb73c12aad6506a371cd75750c0b19a32f81866e1a323dda9e0e99d", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "bc595a1870cef13f9c1e03df56d96804db7f702175e4ccacdb8fc75c02a7b97e"},
|
||||
"plug_crypto": {:hex, :plug_crypto, "1.1.2", "bdd187572cc26dbd95b87136290425f2b580a116d3fb1f564216918c9730d227", [:mix], [], "hexpm", "6b8b608f895b6ffcfad49c37c7883e8df98ae19c6a28113b02aa1e9c5b22d6b5"},
|
||||
"postgrex": {:hex, :postgrex, "0.15.5", "aec40306a622d459b01bff890fa42f1430dac61593b122754144ad9033a2152f", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "ed90c81e1525f65a2ba2279dbcebf030d6d13328daa2f8088b9661eb9143af7f"},
|
||||
"ranch": {:hex, :ranch, "1.7.1", "6b1fab51b49196860b733a49c07604465a47bdb78aa10c1c16a3d199f7f8c881", [:rebar3], [], "hexpm", "451d8527787df716d99dc36162fca05934915db0b6141bbdac2ea8d3c7afc7d7"},
|
||||
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"},
|
||||
"telemetry": {:hex, :telemetry, "0.4.2", "2808c992455e08d6177322f14d3bdb6b625fbcfd233a73505870d8738a2f4599", [:rebar3], [], "hexpm", "2d1419bd9dda6a206d7b5852179511722e2b18812310d304620c7bd92a13fcef"},
|
||||
"telemetry_metrics": {:hex, :telemetry_metrics, "0.5.0", "1b796e74add83abf844e808564275dfb342bcc930b04c7577ab780e262b0d998", [:mix], [{:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "31225e6ce7a37a421a0a96ec55244386aec1c190b22578bd245188a4a33298fd"},
|
||||
"telemetry_poller": {:hex, :telemetry_poller, "0.5.1", "21071cc2e536810bac5628b935521ff3e28f0303e770951158c73eaaa01e962a", [:rebar3], [{:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "4cab72069210bc6e7a080cec9afffad1b33370149ed5d379b81c7c5f0c663fd4"},
|
||||
"unicode_util_compat": {:hex, :unicode_util_compat, "0.5.0", "8516502659002cec19e244ebd90d312183064be95025a319a6c7e89f4bccd65b", [:rebar3], [], "hexpm", "d48d002e15f5cc105a696cf2f1bbb3fc72b4b770a184d8420c8db20da2674b38"},
|
||||
}
|
9
apps/core/test/core/core_email_test.exs
Normal file
9
apps/core/test/core/core_email_test.exs
Normal file
|
@ -0,0 +1,9 @@
|
|||
defmodule CoreEmailTest do
|
||||
use Core.DataCase
|
||||
|
||||
import CoreEmail
|
||||
|
||||
test "base_email/1" do
|
||||
assert %Bamboo.Email{} = base_email()
|
||||
end
|
||||
end
|
16
apps/core/test/core/map_utils_test.exs
Normal file
16
apps/core/test/core/map_utils_test.exs
Normal file
|
@ -0,0 +1,16 @@
|
|||
defmodule Core.MapUtilsTest do
|
||||
use Core.DataCase
|
||||
|
||||
import Core.MapUtils
|
||||
|
||||
test "deep_merge/2" do
|
||||
assert deep_merge(
|
||||
%{
|
||||
profile: %{first: "George", last: "Washington"}
|
||||
},
|
||||
%{
|
||||
profile: %{last: "Harrison"}
|
||||
}
|
||||
) == %{profile: %{first: "George", last: "Harrison"}}
|
||||
end
|
||||
end
|
97
apps/core/test/core_web/views/email_helpers_test.exs
Normal file
97
apps/core/test/core_web/views/email_helpers_test.exs
Normal file
|
@ -0,0 +1,97 @@
|
|||
defmodule CoreWeb.EmailHelpersTest do
|
||||
use Core.DataCase
|
||||
|
||||
import CoreWeb.EmailHelpers
|
||||
import Phoenix.HTML, only: [safe_to_string: 1]
|
||||
|
||||
test "framework_styles/0" do
|
||||
assert %{background: _, body: _} = framework_styles()
|
||||
end
|
||||
|
||||
test "framework_styles/1" do
|
||||
assert framework_styles().background == framework_styles(:background)
|
||||
end
|
||||
|
||||
test "application_styles/1" do
|
||||
assert %{} = application_styles(:background)
|
||||
end
|
||||
|
||||
test "effective_styles/2" do
|
||||
assert %{color: "#FFF"} = effective_styles(:test, %{color: "#FFF"})
|
||||
assert Map.merge(framework_styles(:background), %{color: "#FFF"}) == effective_styles(:background, %{color: "#FFF"})
|
||||
end
|
||||
|
||||
test "preview/1" do
|
||||
assert {:safe, [opening_tag, "test preview", _]} = preview do: "test preview"
|
||||
assert opening_tag =~ "<div"
|
||||
end
|
||||
|
||||
test "header/1" do
|
||||
assert {:safe, _} = safe = header do: "Test Header!"
|
||||
|
||||
assert safe_to_string(safe) =~ "Test Header!"
|
||||
end
|
||||
|
||||
test "spacer/0" do
|
||||
assert {:safe, _} = spacer()
|
||||
end
|
||||
|
||||
test "row/1" do
|
||||
assert {:safe, _} = safe = row do: "Row test"
|
||||
|
||||
assert safe_to_string(safe) =~ "Row test"
|
||||
end
|
||||
|
||||
test "col/3" do
|
||||
assert {:safe, _} = safe = col 1, [of: 2], do: "Column test"
|
||||
|
||||
assert safe_to_string(safe) =~ "Column test"
|
||||
assert safe_to_string(safe) =~ "width=\"50.0%\""
|
||||
end
|
||||
|
||||
test "hero_image/1" do
|
||||
assert {:safe, _} = safe = hero_image(src: "src.jpg")
|
||||
|
||||
assert safe_to_string(safe) =~ "src.jpg"
|
||||
assert safe_to_string(safe) =~ "<img"
|
||||
end
|
||||
|
||||
test "h1/1" do
|
||||
assert {:safe, _} = safe = h1 do: "H1 Test!"
|
||||
|
||||
assert safe_to_string(safe) =~ "H1 Test!"
|
||||
end
|
||||
|
||||
test "h2/1" do
|
||||
assert {:safe, _} = safe = h2 do: "H2 Test!"
|
||||
|
||||
assert safe_to_string(safe) =~ "H2 Test!"
|
||||
end
|
||||
|
||||
test "p/1" do
|
||||
assert {:safe, _} = safe = p do: "This is the test paragraph."
|
||||
|
||||
assert safe_to_string(safe) =~ "This is the test paragraph."
|
||||
end
|
||||
|
||||
test "button/2" do
|
||||
assert {:safe, _} = safe = button [href: "http://duckduckgo.com"], do: "Button text!"
|
||||
|
||||
assert safe_to_string(safe) =~ "duckduckgo.com"
|
||||
assert safe_to_string(safe) =~ "Button text!"
|
||||
end
|
||||
|
||||
test "ul/1" do
|
||||
markup = safe_to_string(ul(items: ["First item", "Second item"]))
|
||||
|
||||
assert markup =~ "<li"
|
||||
assert markup =~ "First item"
|
||||
assert markup =~ "Second item"
|
||||
end
|
||||
|
||||
test "footer/0" do
|
||||
markup = safe_to_string(footer())
|
||||
|
||||
assert markup =~ I18n.t! "en", "email.company.name"
|
||||
end
|
||||
end
|
34
apps/core/test/core_web/views/error_helpers_test.exs
Normal file
34
apps/core/test/core_web/views/error_helpers_test.exs
Normal file
|
@ -0,0 +1,34 @@
|
|||
defmodule CoreWeb.ErrorHelpersTest do
|
||||
use Core.DataCase
|
||||
|
||||
import CoreWeb.ErrorHelpers
|
||||
import Phoenix.HTML, only: [safe_to_string: 1]
|
||||
import Phoenix.HTML.Form, only: [form_for: 3]
|
||||
import Ecto.Changeset, only: [cast: 3, add_error: 3]
|
||||
|
||||
def form do
|
||||
:example
|
||||
|> form_for(
|
||||
"/example",
|
||||
as: :test_params,
|
||||
errors: [error_field: {"is an error", []}],
|
||||
)
|
||||
end
|
||||
|
||||
test "error_class/2" do
|
||||
assert error_class(form, :error_field) == "error"
|
||||
assert error_class(form, :no_error_field) == ""
|
||||
end
|
||||
|
||||
test "error_tag/3" do
|
||||
markup =
|
||||
form
|
||||
|> error_tag(:error_field, class: "foobar")
|
||||
|> Enum.at(0)
|
||||
|> safe_to_string()
|
||||
|
||||
assert markup =~ "foobar"
|
||||
assert markup =~ "span"
|
||||
assert markup =~ "is an error"
|
||||
end
|
||||
end
|
116
apps/core/test/core_web/views/helpers_test.exs
Normal file
116
apps/core/test/core_web/views/helpers_test.exs
Normal file
|
@ -0,0 +1,116 @@
|
|||
defmodule CoreWeb.HelpersTest do
|
||||
use CoreWeb.ConnCase
|
||||
|
||||
import CoreWeb.Helpers
|
||||
import Ecto.Changeset,
|
||||
only: [cast: 3, validate_required: 2, apply_action: 2]
|
||||
import Phoenix.HTML, only: [safe_to_string: 1]
|
||||
import Phoenix.HTML.Form, only: [form_for: 3]
|
||||
|
||||
def form do
|
||||
:example
|
||||
|> form_for(
|
||||
"/example",
|
||||
as: :test_params,
|
||||
errors: [error_field: {"is an error", []}],
|
||||
)
|
||||
end
|
||||
|
||||
def changeset(:error) do
|
||||
{:error, changeset} =
|
||||
{%{name: nil}, %{name: :string}}
|
||||
|> cast(%{}, [:name])
|
||||
|> validate_required(:name)
|
||||
|> apply_action(:update)
|
||||
|
||||
changeset
|
||||
end
|
||||
|
||||
def changeset(:success) do
|
||||
{:ok, changeset} =
|
||||
{%{name: nil}, %{name: :string}}
|
||||
|> cast(%{}, [:name])
|
||||
|> apply_action(:update)
|
||||
|
||||
changeset
|
||||
end
|
||||
|
||||
describe "has_role?/2" do
|
||||
test "with a user", %{conn: conn} do
|
||||
conn =
|
||||
conn
|
||||
|> Pow.Plug.put_config(current_user_assigns_key: :current_user)
|
||||
|> Pow.Plug.assign_current_user(%Auth.User{roles: ["admin"]}, [])
|
||||
|
||||
assert has_role?(conn, "admin")
|
||||
refute has_role?(conn, "blooper")
|
||||
end
|
||||
|
||||
test "without a user", %{conn: conn} do
|
||||
conn =
|
||||
conn
|
||||
|> Pow.Plug.put_config(current_user_assigns_key: :current_user)
|
||||
|
||||
refute has_role?(conn, "admin")
|
||||
end
|
||||
end
|
||||
|
||||
test "changeset_error_block/1" do
|
||||
markup =
|
||||
:error
|
||||
|> changeset()
|
||||
|> changeset_error_block()
|
||||
|> safe_to_string()
|
||||
|
||||
assert markup =~ "Please check the errors below."
|
||||
end
|
||||
|
||||
test "flash_block/1", %{conn: conn} do
|
||||
markup =
|
||||
conn
|
||||
|> init_test_session([])
|
||||
|> fetch_flash()
|
||||
|> put_flash(:error, "The server melted.")
|
||||
|> flash_block()
|
||||
|> safe_to_string()
|
||||
|
||||
assert markup =~ "ui negative message"
|
||||
end
|
||||
|
||||
test "styled_input/4 (without error)" do
|
||||
markup = safe_to_string(styled_input(form, :no_error_field))
|
||||
|
||||
assert markup =~ ~S{<div class="field "}
|
||||
assert markup =~ "<input"
|
||||
assert markup =~ "<label"
|
||||
end
|
||||
|
||||
test "styled_input/4 (with error)" do
|
||||
markup = safe_to_string(styled_input(form, :error_field))
|
||||
|
||||
assert markup =~ ~S{<div class="field error"}
|
||||
assert markup =~ "<input"
|
||||
assert markup =~ "<label"
|
||||
assert markup =~ "ui pointing red basic label"
|
||||
end
|
||||
|
||||
test "styled_input/5 with content" do
|
||||
config = [input_helper: :select, label: "Mode"]
|
||||
options = [{"Test", 1}]
|
||||
|
||||
markup =
|
||||
styled_input(form, :no_error_field, config, options) do
|
||||
|
||||
end
|
||||
|> safe_to_string()
|
||||
|
||||
assert markup =~ ~S{<div class="field "}
|
||||
assert markup =~ "<select"
|
||||
assert markup =~ "<label"
|
||||
end
|
||||
|
||||
test "pow_extension_enabled?/1" do
|
||||
assert pow_extension_enabled?(PowEmailConfirmation) == true
|
||||
assert pow_extension_enabled?(:donkdonk) == false
|
||||
end
|
||||
end
|
59
apps/core/test/mix/legendary_test.exs
Normal file
59
apps/core/test/mix/legendary_test.exs
Normal file
|
@ -0,0 +1,59 @@
|
|||
defmodule Mix.LegendaryTest do
|
||||
use Core.DataCase
|
||||
|
||||
alias Mix.Phoenix.{Schema}
|
||||
|
||||
import Mix.Legendary
|
||||
|
||||
def schema do
|
||||
%Schema{
|
||||
attrs: [
|
||||
reference: {:references, :foobar},
|
||||
integer: :integer,
|
||||
float: :float,
|
||||
decimal: :decimal,
|
||||
boolean: :boolean,
|
||||
text: :text,
|
||||
date: :date,
|
||||
time: :time,
|
||||
utc_datetime: :utc_datetime,
|
||||
naive_datetime: :naive_datetime,
|
||||
array_of_integers: {:array, :integer},
|
||||
array_of_strings: {:array, :string},
|
||||
other: :other,
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
test "inputs/1" do
|
||||
[
|
||||
reference_input,
|
||||
integer_input,
|
||||
float_input,
|
||||
decimal_input,
|
||||
boolean_input,
|
||||
text_input,
|
||||
date_input,
|
||||
time_input,
|
||||
utc_datetime_input,
|
||||
naive_datetime_input,
|
||||
integer_array_input,
|
||||
array_input,
|
||||
other_input,
|
||||
] = inputs(schema)
|
||||
|
||||
assert reference_input == nil
|
||||
assert integer_input =~ ~s(number_input)
|
||||
assert float_input =~ ~s(number_input)
|
||||
assert decimal_input =~ ~s(number_input)
|
||||
assert boolean_input =~ ~s(checkbox)
|
||||
assert text_input =~ ~s(textarea)
|
||||
assert date_input =~ ~s(date_select)
|
||||
assert time_input =~ ~s(time_select)
|
||||
assert utc_datetime_input =~ ~s(datetime_select)
|
||||
assert naive_datetime_input =~ ~s(datetime_select)
|
||||
assert integer_array_input =~ ~s(multiple_select)
|
||||
assert array_input =~ ~s(multiple_select)
|
||||
assert other_input =~ ~s(:other %>)
|
||||
end
|
||||
end
|
|
@ -56,3 +56,6 @@ config :auth_web, AuthWeb.Endpoint,
|
|||
config :content, Content.Endpoint,
|
||||
http: [port: 4002],
|
||||
server: false
|
||||
|
||||
|
||||
config :core, CoreMailer, adapter: Bamboo.TestAdapter
|
||||
|
|
3
mix.exs
3
mix.exs
|
@ -9,6 +9,7 @@ defmodule Legendary.Mixfile do
|
|||
deps: deps(),
|
||||
aliases: aliases(),
|
||||
test_coverage: [tool: ExCoveralls],
|
||||
preferred_cli_env: [coveralls: :test, "coveralls.detail": :test, "coveralls.post": :test, "coveralls.html": :test],
|
||||
]
|
||||
end
|
||||
|
||||
|
@ -19,7 +20,7 @@ defmodule Legendary.Mixfile do
|
|||
defp aliases do
|
||||
[
|
||||
"deps.get": ["cmd mix deps.get"],
|
||||
"coveralls.html": ["cmd MIX_ENV=test mix coveralls.html"],
|
||||
"coveralls.html": ["cmd mix coveralls.html"],
|
||||
"ecto.migrate": ["cmd mix ecto.migrate"],
|
||||
"npm.install": ["cmd npm install --prefix assets"],
|
||||
test: ["cmd mix test"]
|
||||
|
|
4
mix.lock
4
mix.lock
|
@ -15,7 +15,7 @@
|
|||
"decimal": {:hex, :decimal, "1.8.1", "a4ef3f5f3428bdbc0d35374029ffcf4ede8533536fa79896dd450168d9acdf3c", [:mix], [], "hexpm", "3cb154b00225ac687f6cbd4acc4b7960027c757a5152b369923ead9ddbca7aec"},
|
||||
"earmark": {:hex, :earmark, "1.4.10", "bddce5e8ea37712a5bfb01541be8ba57d3b171d3fa4f80a0be9bcf1db417bcaf", [:mix], [{:earmark_parser, ">= 1.4.10", [hex: :earmark_parser, repo: "hexpm", optional: false]}], "hexpm", "12dbfa80810478e521d3ffb941ad9fbfcbbd7debe94e1341b4c4a1b2411c1c27"},
|
||||
"earmark_parser": {:hex, :earmark_parser, "1.4.10", "6603d7a603b9c18d3d20db69921527f82ef09990885ed7525003c7fe7dc86c56", [:mix], [], "hexpm", "8e2d5370b732385db2c9b22215c3f59c84ac7dda7ed7e544d7c459496ae519c0"},
|
||||
"ecto": {:hex, :ecto, "3.4.5", "2bcd262f57b2c888b0bd7f7a28c8a48aa11dc1a2c6a858e45dd8f8426d504265", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "8c6d1d4d524559e9b7a062f0498e2c206122552d63eacff0a6567ffe7a8e8691"},
|
||||
"ecto": {:hex, :ecto, "3.4.6", "08f7afad3257d6eb8613309af31037e16c36808dfda5a3cd0cb4e9738db030e4", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "6f13a9e2a62e75c2dcfc7207bfc65645ab387af8360db4c89fee8b5a4bf3f70b"},
|
||||
"ecto_sql": {:hex, :ecto_sql, "3.4.4", "d28bac2d420f708993baed522054870086fd45016a9d09bb2cd521b9c48d32ea", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.4.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.3.0 or ~> 0.4.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.0", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "edb49af715dd72f213b66adfd0f668a43c17ed510b5d9ac7528569b23af57fe8"},
|
||||
"elixir_make": {:hex, :elixir_make, "0.6.0", "38349f3e29aff4864352084fc736fa7fa0f2995a819a737554f7ebd28b85aaab", [:mix], [], "hexpm", "d522695b93b7f0b4c0fcb2dfe73a6b905b1c301226a5a55cb42e5b14d509e050"},
|
||||
"ex_cldr": {:hex, :ex_cldr, "2.13.0", "742f14a4afcfea61a190d603d8e555d2c91d71e4e8fc2520d5dc35616969e225", [:mix], [{:cldr_utils, "~> 2.3", [hex: :cldr_utils, repo: "hexpm", optional: false]}, {:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:gettext, "~> 0.13", [hex: :gettext, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:plug, "~> 1.4", [hex: :plug, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "5e4cf3e945ee60156a3342e2a762f69036ffbe1f80520cc88592d68f12c5db55"},
|
||||
|
@ -51,7 +51,7 @@
|
|||
"phoenix_live_view": {:hex, :phoenix_live_view, "0.13.3", "2186c55cc7c54ca45b97c6f28cfd267d1c61b5f205f3c83533704cd991bdfdec", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.4.17 or ~> 1.5.2", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14", [hex: :phoenix_html, repo: "hexpm", optional: false]}], "hexpm", "c6309a7da2e779cb9cdf2fb603d75f38f49ef324bedc7a81825998bd1744ff8a"},
|
||||
"phoenix_pubsub": {:hex, :phoenix_pubsub, "2.0.0", "a1ae76717bb168cdeb10ec9d92d1480fec99e3080f011402c0a2d68d47395ffb", [:mix], [], "hexpm", "c52d948c4f261577b9c6fa804be91884b381a7f8f18450c5045975435350f771"},
|
||||
"php_serializer": {:hex, :php_serializer, "0.9.2", "59c5fd6bd3096671fd89358fb8229341ac7423b50ad8d45a15213b02ea2edab2", [:mix], [], "hexpm", "34eb835a460944f7fc216773b363c02e7dcf8ac0390c9e9ccdbd92b31a7ca59a"},
|
||||
"plug": {:hex, :plug, "1.10.3", "c9cebe917637d8db0e759039cc106adca069874e1a9034fd6e3fdd427fd3c283", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "01f9037a2a1de1d633b5a881101e6a444bcabb1d386ca1e00bb273a1f1d9d939"},
|
||||
"plug": {:hex, :plug, "1.10.4", "41eba7d1a2d671faaf531fa867645bd5a3dce0957d8e2a3f398ccff7d2ef017f", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ad1e233fe73d2eec56616568d260777b67f53148a999dc2d048f4eb9778fe4a0"},
|
||||
"plug_cowboy": {:hex, :plug_cowboy, "2.3.0", "149a50e05cb73c12aad6506a371cd75750c0b19a32f81866e1a323dda9e0e99d", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "bc595a1870cef13f9c1e03df56d96804db7f702175e4ccacdb8fc75c02a7b97e"},
|
||||
"plug_crypto": {:hex, :plug_crypto, "1.1.2", "bdd187572cc26dbd95b87136290425f2b580a116d3fb1f564216918c9730d227", [:mix], [], "hexpm", "6b8b608f895b6ffcfad49c37c7883e8df98ae19c6a28113b02aa1e9c5b22d6b5"},
|
||||
"postgrex": {:hex, :postgrex, "0.15.5", "aec40306a622d459b01bff890fa42f1430dac61593b122754144ad9033a2152f", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "ed90c81e1525f65a2ba2279dbcebf030d6d13328daa2f8088b9661eb9143af7f"},
|
||||
|
|
Loading…
Reference in a new issue