Verify router respects date filtering on all endpoints
This commit is contained in:
parent
2591796d82
commit
8d40e09e90
@ -9,7 +9,8 @@ defmodule Blogex.RouterTest do
|
||||
posts = [
|
||||
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: "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,
|
||||
@ -42,6 +43,12 @@ defmodule Blogex.RouterTest do
|
||||
assert conn.resp_body =~ "first-post"
|
||||
refute conn.resp_body =~ "draft"
|
||||
end
|
||||
|
||||
test "excludes future-dated posts from feed" do
|
||||
conn = call(:get, "/feed.xml")
|
||||
|
||||
refute conn.resp_body =~ "future-post"
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /atom.xml" do
|
||||
@ -75,6 +82,14 @@ defmodule Blogex.RouterTest do
|
||||
|
||||
assert conn.status == 200
|
||||
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
|
||||
|
||||
describe "GET /tag/:tag" do
|
||||
@ -88,6 +103,14 @@ defmodule Blogex.RouterTest do
|
||||
assert hd(body["posts"])["id"] == "first-post"
|
||||
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
|
||||
conn = call(:get, "/tag/unknown")
|
||||
|
||||
@ -113,6 +136,14 @@ defmodule Blogex.RouterTest do
|
||||
ids = Enum.map(body["posts"], & &1["id"])
|
||||
refute "draft" in ids
|
||||
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
|
||||
|
||||
defp get_content_type(conn) do
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user