Verify router respects date filtering on all endpoints

This commit is contained in:
Willem van den Ende 2026-04-01 21:46:59 +00:00
parent 2591796d82
commit 8d40e09e90

View File

@ -9,7 +9,8 @@ defmodule Blogex.RouterTest do
posts = [ posts = [
build(id: "first-post", title: "First", tags: ["elixir"], date: ~D[2026-03-10]), build(id: "first-post", title: "First", tags: ["elixir"], date: ~D[2026-03-10]),
build(id: "second-post", title: "Second", tags: ["otp"], date: ~D[2026-02-01]), build(id: "second-post", title: "Second", tags: ["otp"], date: ~D[2026-02-01]),
build(id: "draft", published: false, date: ~D[2026-03-12]) build(id: "draft", published: false, date: ~D[2026-03-12]),
build(id: "future-post", title: "Future", tags: ["elixir"], date: ~D[2099-01-01], published: true)
] ]
{:ok, _} = FakeBlog.start(posts, {:ok, _} = FakeBlog.start(posts,
@ -42,6 +43,12 @@ defmodule Blogex.RouterTest do
assert conn.resp_body =~ "first-post" assert conn.resp_body =~ "first-post"
refute conn.resp_body =~ "draft" refute conn.resp_body =~ "draft"
end end
test "excludes future-dated posts from feed" do
conn = call(:get, "/feed.xml")
refute conn.resp_body =~ "future-post"
end
end end
describe "GET /atom.xml" do describe "GET /atom.xml" do
@ -75,6 +82,14 @@ defmodule Blogex.RouterTest do
assert conn.status == 200 assert conn.status == 200
end end
test "returns 200 for future-dated post accessed by slug" do
conn = call(:get, "/future-post")
assert conn.status == 200
body = Jason.decode!(conn.resp_body)
assert body["id"] == "future-post"
end
end end
describe "GET /tag/:tag" do describe "GET /tag/:tag" do
@ -88,6 +103,14 @@ defmodule Blogex.RouterTest do
assert hd(body["posts"])["id"] == "first-post" assert hd(body["posts"])["id"] == "first-post"
end end
test "excludes future-dated posts from tag results" do
conn = call(:get, "/tag/elixir")
body = Jason.decode!(conn.resp_body)
ids = Enum.map(body["posts"], & &1["id"])
refute "future-post" in ids
end
test "returns empty list for unknown tag" do test "returns empty list for unknown tag" do
conn = call(:get, "/tag/unknown") conn = call(:get, "/tag/unknown")
@ -113,6 +136,14 @@ defmodule Blogex.RouterTest do
ids = Enum.map(body["posts"], & &1["id"]) ids = Enum.map(body["posts"], & &1["id"])
refute "draft" in ids refute "draft" in ids
end end
test "excludes future-dated posts from listing" do
conn = call(:get, "/")
body = Jason.decode!(conn.resp_body)
ids = Enum.map(body["posts"], & &1["id"])
refute "future-post" in ids
end
end end
defp get_content_type(conn) do defp get_content_type(conn) do