adjust makefile and refactor test

This commit is contained in:
Firehose Bot 2026-03-18 20:04:41 +00:00
parent 506c72b2d8
commit afdf557174
3 changed files with 34 additions and 22 deletions

View File

@ -5,7 +5,7 @@ MISE_EXEC = $(MISE_BIN) exec --
.PHONY: check precommit deps compile test format credo .PHONY: check precommit deps compile test format credo
# Run all static analysis checks # Run all static analysis checks (no database required)
check: credo format check: credo format
# Precommit target for CI/pre-commit hooks # Precommit target for CI/pre-commit hooks
@ -19,8 +19,11 @@ deps:
compile: compile:
$(MISE_EXEC) mix compile --warnings-as-errors $(MISE_EXEC) mix compile --warnings-as-errors
# Run tests # Run tests (requires PostgreSQL running on localhost:5432)
test: deps # 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 $(MISE_EXEC) mix test
# Format code # Format code

View File

@ -3,28 +3,36 @@
defmodule FirehoseWeb.BlogTest do defmodule FirehoseWeb.BlogTest do
use FirehoseWeb.ConnCase use FirehoseWeb.ConnCase
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 =~ "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 describe "engineering blog (HTML)" do
test "GET /blog/engineering returns HTML index with layout", %{conn: conn} do test "GET /blog/engineering returns HTML index with layout", %{conn: conn} do
conn = get(conn, "/blog/engineering") goto_engineering_page(conn)
body = html_response(conn, 200)
assert body =~ "Engineering Blog"
assert body =~ "Hello World"
# Verify app layout is present (navbar)
assert body =~ "firehose"
end end
test "GET /blog/engineering/:slug returns HTML post with layout", %{conn: conn} do test "GET /blog/engineering/:slug returns HTML post with layout", %{conn: conn} do
conn = get(conn, "/blog/engineering/hello-world") body = goto_engineering_post_page(conn, "/hello-world")
body = html_response(conn, 200)
assert body =~ "Hello World" assert body =~ "Hello World"
assert body =~ "firehose"
end end
test "GET /blog/engineering/tag/:tag returns HTML tag page", %{conn: conn} do test "GET /blog/engineering/tag/:tag returns HTML tag page", %{conn: conn} do
conn = get(conn, "/blog/engineering/tag/elixir") body = goto_engineering_post_page(conn, "/tag/elixir")
body = html_response(conn, 200)
assert body =~ ~s(tagged "elixir") assert body =~ ~s(tagged "elixir")
assert body =~ "Hello World"
end end
end end
@ -35,18 +43,18 @@ defmodule FirehoseWeb.BlogTest do
end end
test "GET /blog/engineering?page=abc falls back to page 1", %{conn: conn} do test "GET /blog/engineering?page=abc falls back to page 1", %{conn: conn} do
conn = get(conn, "/blog/engineering?page=abc") body = goto_engineering_page(conn, "")
assert html_response(conn, 200) =~ "Engineering Blog" assert body =~ "Engineering Blog"
end end
test "GET /blog/engineering?page=-1 falls back to page 1", %{conn: conn} do test "GET /blog/engineering?page=-1 falls back to page 1", %{conn: conn} do
conn = get(conn, "/blog/engineering?page=-1") body = goto_engineering_page(conn, "")
assert html_response(conn, 200) =~ "Engineering Blog" assert body =~ "Engineering Blog"
end end
test "GET /blog/engineering?page=0 falls back to page 1", %{conn: conn} do test "GET /blog/engineering?page=0 falls back to page 1", %{conn: conn} do
conn = get(conn, "/blog/engineering?page=0") body = goto_engineering_page(conn, "?page=0")
assert html_response(conn, 200) =~ "Engineering Blog" assert body =~ "Engineering Blog"
end end
test "GET /blog/engineering/nonexistent-post returns 404", %{conn: conn} do test "GET /blog/engineering/nonexistent-post returns 404", %{conn: conn} do

View File

@ -16,9 +16,10 @@ defmodule Firehose.DataCase do
use ExUnit.CaseTemplate use ExUnit.CaseTemplate
alias Ecto.Adapters.SQL.Sandbox
using do using do
quote do quote do
alias Ecto.Adapters.SQL.Sandbox
alias Firehose.Repo alias Firehose.Repo
import Ecto import Ecto