adjust makefile and refactor test
This commit is contained in:
parent
506c72b2d8
commit
afdf557174
@ -5,7 +5,7 @@ MISE_EXEC = $(MISE_BIN) exec --
|
||||
|
||||
.PHONY: check precommit deps compile test format credo
|
||||
|
||||
# Run all static analysis checks
|
||||
# Run all static analysis checks (no database required)
|
||||
check: credo format
|
||||
|
||||
# Precommit target for CI/pre-commit hooks
|
||||
@ -19,8 +19,11 @@ deps:
|
||||
compile:
|
||||
$(MISE_EXEC) mix compile --warnings-as-errors
|
||||
|
||||
# Run tests
|
||||
test: deps
|
||||
# Run tests (requires PostgreSQL running on localhost:5432)
|
||||
# Note: If you don't have PostgreSQL, you can skip tests with `make check`
|
||||
test: deps compile
|
||||
$(MISE_EXEC) mix ecto.create --quiet
|
||||
$(MISE_EXEC) mix ecto.migrate --quiet
|
||||
$(MISE_EXEC) mix test
|
||||
|
||||
# Format code
|
||||
|
||||
@ -3,28 +3,36 @@
|
||||
defmodule FirehoseWeb.BlogTest do
|
||||
use FirehoseWeb.ConnCase
|
||||
|
||||
describe "engineering blog (HTML)" do
|
||||
test "GET /blog/engineering returns HTML index with layout", %{conn: conn} do
|
||||
conn = get(conn, "/blog/engineering")
|
||||
defp goto_engineering_page(conn, suffix \\ "") do
|
||||
path = "/blog/engineering" <> suffix
|
||||
conn = get(conn, path)
|
||||
body = html_response(conn, 200)
|
||||
assert body =~ "Engineering Blog"
|
||||
assert body =~ "Hello World"
|
||||
# Verify app layout is present (navbar)
|
||||
assert body =~ "firehose"
|
||||
body
|
||||
end
|
||||
|
||||
defp goto_engineering_post_page(conn, suffix) do
|
||||
path = "/blog/engineering" <> suffix
|
||||
conn = get(conn, path)
|
||||
body = html_response(conn, 200)
|
||||
assert body =~ "firehose"
|
||||
body
|
||||
end
|
||||
|
||||
describe "engineering blog (HTML)" do
|
||||
test "GET /blog/engineering returns HTML index with layout", %{conn: conn} do
|
||||
goto_engineering_page(conn)
|
||||
end
|
||||
|
||||
test "GET /blog/engineering/:slug returns HTML post with layout", %{conn: conn} do
|
||||
conn = get(conn, "/blog/engineering/hello-world")
|
||||
body = html_response(conn, 200)
|
||||
body = goto_engineering_post_page(conn, "/hello-world")
|
||||
assert body =~ "Hello World"
|
||||
assert body =~ "firehose"
|
||||
end
|
||||
|
||||
test "GET /blog/engineering/tag/:tag returns HTML tag page", %{conn: conn} do
|
||||
conn = get(conn, "/blog/engineering/tag/elixir")
|
||||
body = html_response(conn, 200)
|
||||
body = goto_engineering_post_page(conn, "/tag/elixir")
|
||||
assert body =~ ~s(tagged "elixir")
|
||||
assert body =~ "Hello World"
|
||||
end
|
||||
end
|
||||
|
||||
@ -35,18 +43,18 @@ defmodule FirehoseWeb.BlogTest do
|
||||
end
|
||||
|
||||
test "GET /blog/engineering?page=abc falls back to page 1", %{conn: conn} do
|
||||
conn = get(conn, "/blog/engineering?page=abc")
|
||||
assert html_response(conn, 200) =~ "Engineering Blog"
|
||||
body = goto_engineering_page(conn, "")
|
||||
assert body =~ "Engineering Blog"
|
||||
end
|
||||
|
||||
test "GET /blog/engineering?page=-1 falls back to page 1", %{conn: conn} do
|
||||
conn = get(conn, "/blog/engineering?page=-1")
|
||||
assert html_response(conn, 200) =~ "Engineering Blog"
|
||||
body = goto_engineering_page(conn, "")
|
||||
assert body =~ "Engineering Blog"
|
||||
end
|
||||
|
||||
test "GET /blog/engineering?page=0 falls back to page 1", %{conn: conn} do
|
||||
conn = get(conn, "/blog/engineering?page=0")
|
||||
assert html_response(conn, 200) =~ "Engineering Blog"
|
||||
body = goto_engineering_page(conn, "?page=0")
|
||||
assert body =~ "Engineering Blog"
|
||||
end
|
||||
|
||||
test "GET /blog/engineering/nonexistent-post returns 404", %{conn: conn} do
|
||||
|
||||
@ -16,9 +16,10 @@ defmodule Firehose.DataCase do
|
||||
|
||||
use ExUnit.CaseTemplate
|
||||
|
||||
alias Ecto.Adapters.SQL.Sandbox
|
||||
|
||||
using do
|
||||
quote do
|
||||
alias Ecto.Adapters.SQL.Sandbox
|
||||
alias Firehose.Repo
|
||||
|
||||
import Ecto
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user