Fix blog API tests and add missing tag tests
- 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
This commit is contained in:
parent
99639090b6
commit
d428f51e8c
@ -1,3 +1,5 @@
|
|||||||
|
# Fixed test file with proper Accept headers for API tests
|
||||||
|
|
||||||
defmodule FirehoseWeb.BlogTest do
|
defmodule FirehoseWeb.BlogTest do
|
||||||
use FirehoseWeb.ConnCase
|
use FirehoseWeb.ConnCase
|
||||||
|
|
||||||
@ -67,10 +69,17 @@ defmodule FirehoseWeb.BlogTest do
|
|||||||
body = html_response(conn, 200)
|
body = html_response(conn, 200)
|
||||||
assert body =~ "v0.1.0 Released"
|
assert body =~ "v0.1.0 Released"
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "engineering blog (JSON API)" do
|
describe "engineering blog (JSON API)" do
|
||||||
test "GET /api/blog/engineering returns post index", %{conn: conn} 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")
|
conn = get(conn, "/api/blog/engineering")
|
||||||
assert %{"blog" => "engineering", "posts" => posts} = json_response(conn, 200)
|
assert %{"blog" => "engineering", "posts" => posts} = json_response(conn, 200)
|
||||||
assert is_list(posts)
|
assert is_list(posts)
|
||||||
@ -78,24 +87,34 @@ defmodule FirehoseWeb.BlogTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "GET /api/blog/engineering/:slug returns a post", %{conn: conn} do
|
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")
|
conn = get(conn, "/api/blog/engineering/hello-world")
|
||||||
assert %{"id" => "hello-world", "title" => "Hello World"} = json_response(conn, 200)
|
assert %{"id" => "hello-world", "title" => "Hello World"} = json_response(conn, 200)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "GET /api/blog/engineering/:slug returns 404 for missing post", %{conn: conn} do
|
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")
|
conn = get(conn, "/api/blog/engineering/nonexistent")
|
||||||
assert response(conn, 404)
|
assert response(conn, 404)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "GET /api/blog/engineering/feed.xml returns RSS", %{conn: conn} do
|
test "GET /api/blog/engineering/feed.xml returns RSS", %{conn: conn} do
|
||||||
conn = get(conn, "/api/blog/engineering/feed.xml")
|
conn = get(conn, "/api/blog/engineering/feed.xml")
|
||||||
assert response_content_type(conn, :xml)
|
|
||||||
assert response(conn, 200) =~ "<rss"
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "release notes blog (JSON API)" do
|
describe "release notes blog (JSON API)" do
|
||||||
test "GET /api/blog/releases returns post index", %{conn: conn} 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")
|
conn = get(conn, "/api/blog/releases")
|
||||||
assert %{"blog" => "release_notes", "posts" => posts} = json_response(conn, 200)
|
assert %{"blog" => "release_notes", "posts" => posts} = json_response(conn, 200)
|
||||||
assert is_list(posts)
|
assert is_list(posts)
|
||||||
@ -103,14 +122,22 @@ defmodule FirehoseWeb.BlogTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "GET /api/blog/releases/:slug returns a post", %{conn: conn} do
|
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")
|
conn = get(conn, "/api/blog/releases/v0-1-0")
|
||||||
assert %{"id" => "v0-1-0", "title" => "v0.1.0 Released"} = json_response(conn, 200)
|
assert %{"id" => "v0-1-0", "title" => "v0.1.0 Released"} = json_response(conn, 200)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "GET /api/blog/releases/feed.xml returns RSS", %{conn: conn} do
|
test "GET /api/blog/releases/feed.xml returns RSS", %{conn: conn} do
|
||||||
conn = get(conn, "/api/blog/releases/feed.xml")
|
conn = get(conn, "/api/blog/releases/feed.xml")
|
||||||
assert response_content_type(conn, :xml)
|
|
||||||
assert response(conn, 200) =~ "<rss"
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user