- Add Accept: application/json headers to all API endpoint tests - Add GET /blog/releases/tag/:tag HTML page test - Add GET /api/blog/*/tag/:tag JSON API tests for both blogs - Fix feed.xml assertions to check body first, then content type
144 lines
5.4 KiB
Elixir
144 lines
5.4 KiB
Elixir
# Fixed test file with proper Accept headers for API tests
|
|
|
|
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")
|
|
body = html_response(conn, 200)
|
|
assert body =~ "Engineering Blog"
|
|
assert body =~ "Hello World"
|
|
# Verify app layout is present (navbar)
|
|
assert body =~ "firehose"
|
|
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)
|
|
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)
|
|
assert body =~ ~s(tagged "elixir")
|
|
assert body =~ "Hello World"
|
|
end
|
|
end
|
|
|
|
describe "input validation" do
|
|
test "GET /blog/nonexistent returns 404", %{conn: conn} do
|
|
conn = get(conn, "/blog/nonexistent")
|
|
assert html_response(conn, 404)
|
|
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"
|
|
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"
|
|
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"
|
|
end
|
|
|
|
test "GET /blog/engineering/nonexistent-post returns 404", %{conn: conn} do
|
|
assert_raise Blogex.NotFoundError, fn ->
|
|
get(conn, "/blog/engineering/nonexistent-post")
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "release notes blog (HTML)" do
|
|
test "GET /blog/releases returns HTML index", %{conn: conn} do
|
|
conn = get(conn, "/blog/releases")
|
|
body = html_response(conn, 200)
|
|
assert body =~ "Release Notes"
|
|
assert body =~ "v0.1.0 Released"
|
|
end
|
|
|
|
test "GET /blog/releases/:slug returns HTML post", %{conn: conn} do
|
|
conn = get(conn, "/blog/releases/v0-1-0")
|
|
body = html_response(conn, 200)
|
|
assert body =~ "v0.1.0 Released"
|
|
end
|
|
|
|
test "GET /blog/releases/tag/:tag returns HTML tag page", %{conn: conn} do
|
|
conn = get(conn, "/blog/releases/tag/elixir")
|
|
body = html_response(conn, 200)
|
|
assert body =~ ~s(tagged "elixir")
|
|
end
|
|
end
|
|
|
|
describe "engineering blog (JSON API)" do
|
|
test "GET /api/blog/engineering returns post index", %{conn: conn} do
|
|
conn = conn |> put_req_header("accept", "application/json")
|
|
conn = get(conn, "/api/blog/engineering")
|
|
assert %{"blog" => "engineering", "posts" => posts} = json_response(conn, 200)
|
|
assert is_list(posts)
|
|
refute Enum.empty?(posts)
|
|
end
|
|
|
|
test "GET /api/blog/engineering/:slug returns a post", %{conn: conn} do
|
|
conn = conn |> put_req_header("accept", "application/json")
|
|
conn = get(conn, "/api/blog/engineering/hello-world")
|
|
assert %{"id" => "hello-world", "title" => "Hello World"} = json_response(conn, 200)
|
|
end
|
|
|
|
test "GET /api/blog/engineering/:slug returns 404 for missing post", %{conn: conn} do
|
|
conn = conn |> put_req_header("accept", "application/json")
|
|
conn = get(conn, "/api/blog/engineering/nonexistent")
|
|
assert response(conn, 404)
|
|
end
|
|
|
|
test "GET /api/blog/engineering/feed.xml returns RSS", %{conn: conn} do
|
|
conn = get(conn, "/api/blog/engineering/feed.xml")
|
|
assert response(conn, 200) =~ "<rss"
|
|
assert response_content_type(conn, :xml)
|
|
end
|
|
|
|
test "GET /api/blog/engineering/tag/:tag returns JSON with posts", %{conn: conn} do
|
|
conn = conn |> put_req_header("accept", "application/json")
|
|
conn = get(conn, "/api/blog/engineering/tag/elixir")
|
|
assert %{"blog" => "engineering", "tag" => "elixir", "posts" => posts} = json_response(conn, 200)
|
|
assert is_list(posts)
|
|
end
|
|
end
|
|
|
|
describe "release notes blog (JSON API)" do
|
|
test "GET /api/blog/releases returns post index", %{conn: conn} do
|
|
conn = conn |> put_req_header("accept", "application/json")
|
|
conn = get(conn, "/api/blog/releases")
|
|
assert %{"blog" => "release_notes", "posts" => posts} = json_response(conn, 200)
|
|
assert is_list(posts)
|
|
refute Enum.empty?(posts)
|
|
end
|
|
|
|
test "GET /api/blog/releases/:slug returns a post", %{conn: conn} do
|
|
conn = conn |> put_req_header("accept", "application/json")
|
|
conn = get(conn, "/api/blog/releases/v0-1-0")
|
|
assert %{"id" => "v0-1-0", "title" => "v0.1.0 Released"} = json_response(conn, 200)
|
|
end
|
|
|
|
test "GET /api/blog/releases/feed.xml returns RSS", %{conn: conn} do
|
|
conn = get(conn, "/api/blog/releases/feed.xml")
|
|
assert response(conn, 200) =~ "<rss"
|
|
assert response_content_type(conn, :xml)
|
|
end
|
|
|
|
test "GET /api/blog/releases/tag/:tag returns JSON with posts", %{conn: conn} do
|
|
conn = conn |> put_req_header("accept", "application/json")
|
|
conn = get(conn, "/api/blog/releases/tag/elixir")
|
|
assert %{"blog" => "release_notes", "tag" => "elixir", "posts" => posts} = json_response(conn, 200)
|
|
assert is_list(posts)
|
|
end
|
|
end
|
|
end
|