chore: apply mix format to blogex test files and router
This commit is contained in:
parent
ab7a520e9e
commit
2b7cf0a3b9
@ -75,11 +75,14 @@ defmodule Blogex.Router do
|
||||
else
|
||||
conn
|
||||
|> put_resp_content_type("application/json")
|
||||
|> send_resp(200, Jason.encode!(%{
|
||||
blog: blog.blog_id(),
|
||||
tag: tag,
|
||||
posts: Enum.map(posts, &post_json/1)
|
||||
}))
|
||||
|> send_resp(
|
||||
200,
|
||||
Jason.encode!(%{
|
||||
blog: blog.blog_id(),
|
||||
tag: tag,
|
||||
posts: Enum.map(posts, &post_json/1)
|
||||
})
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@ -121,14 +124,17 @@ defmodule Blogex.Router do
|
||||
else
|
||||
conn
|
||||
|> put_resp_content_type("application/json")
|
||||
|> send_resp(200, Jason.encode!(%{
|
||||
blog: blog.blog_id(),
|
||||
title: blog.title(),
|
||||
posts: Enum.map(result.entries, &post_json/1),
|
||||
page: result.page,
|
||||
total_pages: result.total_pages,
|
||||
total_entries: result.total_entries
|
||||
}))
|
||||
|> send_resp(
|
||||
200,
|
||||
Jason.encode!(%{
|
||||
blog: blog.blog_id(),
|
||||
title: blog.title(),
|
||||
posts: Enum.map(result.entries, &post_json/1),
|
||||
page: result.page,
|
||||
total_pages: result.total_pages,
|
||||
total_entries: result.total_entries
|
||||
})
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -22,10 +22,11 @@ defmodule Blogex.BlogTest do
|
||||
end
|
||||
|
||||
test "includes today-dated published posts" do
|
||||
{:ok, _} = FakeBlog.start([
|
||||
build(id: "today", date: Date.utc_today(), published: true),
|
||||
build(id: "tomorrow", date: Date.add(Date.utc_today(), 1), published: true)
|
||||
])
|
||||
{:ok, _} =
|
||||
FakeBlog.start([
|
||||
build(id: "today", date: Date.utc_today(), published: true),
|
||||
build(id: "tomorrow", date: Date.add(Date.utc_today(), 1), published: true)
|
||||
])
|
||||
|
||||
ids = FakeBlog.all_posts() |> Enum.map(& &1.id)
|
||||
|
||||
@ -77,10 +78,11 @@ defmodule Blogex.BlogTest do
|
||||
end
|
||||
|
||||
test "excludes drafts even if tag matches" do
|
||||
{:ok, _} = FakeBlog.start([
|
||||
build(id: "pub", tags: ["elixir"], published: true),
|
||||
build(id: "draft", tags: ["elixir"], published: false)
|
||||
])
|
||||
{:ok, _} =
|
||||
FakeBlog.start([
|
||||
build(id: "pub", tags: ["elixir"], published: true),
|
||||
build(id: "draft", tags: ["elixir"], published: false)
|
||||
])
|
||||
|
||||
ids = FakeBlog.posts_by_tag("elixir") |> Enum.map(& &1.id)
|
||||
|
||||
@ -103,10 +105,11 @@ defmodule Blogex.BlogTest do
|
||||
end
|
||||
|
||||
test "excludes tags only appearing on drafts" do
|
||||
{:ok, _} = FakeBlog.start([
|
||||
build(tags: ["visible"], published: true),
|
||||
build(id: "d", tags: ["hidden"], published: false)
|
||||
])
|
||||
{:ok, _} =
|
||||
FakeBlog.start([
|
||||
build(tags: ["visible"], published: true),
|
||||
build(id: "d", tags: ["hidden"], published: false)
|
||||
])
|
||||
|
||||
refute "hidden" in FakeBlog.all_tags()
|
||||
end
|
||||
|
||||
@ -109,10 +109,11 @@ defmodule Blogex.FeedTest do
|
||||
|
||||
describe "XML escaping" do
|
||||
test "escapes special characters in titles" do
|
||||
{:ok, _} = FakeBlog.start(
|
||||
[build(title: "Foo & Bar <Baz>")],
|
||||
title: "A & B"
|
||||
)
|
||||
{:ok, _} =
|
||||
FakeBlog.start(
|
||||
[build(title: "Foo & Bar <Baz>")],
|
||||
title: "A & B"
|
||||
)
|
||||
|
||||
xml = Feed.rss(FakeBlog, @base_url)
|
||||
|
||||
|
||||
@ -6,19 +6,30 @@ defmodule Blogex.RegistryTest do
|
||||
|
||||
defmodule AlphaBlog do
|
||||
def blog_id, do: :alpha
|
||||
def all_posts, do: [Blogex.Test.PostBuilder.build(id: "a1", date: ~D[2026-03-01], blog: :alpha)]
|
||||
|
||||
def all_posts,
|
||||
do: [Blogex.Test.PostBuilder.build(id: "a1", date: ~D[2026-03-01], blog: :alpha)]
|
||||
|
||||
def all_tags, do: ["elixir"]
|
||||
|
||||
def unfiltered_posts,
|
||||
do: [
|
||||
Blogex.Test.PostBuilder.build(id: "a1", date: ~D[2026-03-01], blog: :alpha),
|
||||
Blogex.Test.PostBuilder.build(id: "a-draft", date: ~D[2026-03-05], blog: :alpha, published: false)
|
||||
Blogex.Test.PostBuilder.build(
|
||||
id: "a-draft",
|
||||
date: ~D[2026-03-05],
|
||||
blog: :alpha,
|
||||
published: false
|
||||
)
|
||||
]
|
||||
end
|
||||
|
||||
defmodule BetaBlog do
|
||||
def blog_id, do: :beta
|
||||
def all_posts, do: [Blogex.Test.PostBuilder.build(id: "b1", date: ~D[2026-03-15], blog: :beta)]
|
||||
|
||||
def all_posts,
|
||||
do: [Blogex.Test.PostBuilder.build(id: "b1", date: ~D[2026-03-15], blog: :beta)]
|
||||
|
||||
def all_tags, do: ["devops"]
|
||||
|
||||
def unfiltered_posts,
|
||||
|
||||
@ -10,15 +10,22 @@ defmodule Blogex.RouterTest do
|
||||
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: "future-post", title: "Future", tags: ["elixir"], date: ~D[2099-01-01], published: true)
|
||||
build(
|
||||
id: "future-post",
|
||||
title: "Future",
|
||||
tags: ["elixir"],
|
||||
date: ~D[2099-01-01],
|
||||
published: true
|
||||
)
|
||||
]
|
||||
|
||||
{:ok, _} = FakeBlog.start(posts,
|
||||
blog_id: :test,
|
||||
title: "Test Blog",
|
||||
description: "Test",
|
||||
base_path: "/blog/test"
|
||||
)
|
||||
{:ok, _} =
|
||||
FakeBlog.start(posts,
|
||||
blog_id: :test,
|
||||
title: "Test Blog",
|
||||
description: "Test",
|
||||
base_path: "/blog/test"
|
||||
)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
@ -35,7 +35,9 @@ defmodule Blogex.Test.FakeBlog do
|
||||
}
|
||||
|
||||
case Agent.start(fn -> state end, name: __MODULE__) do
|
||||
{:ok, pid} -> {:ok, pid}
|
||||
{:ok, pid} ->
|
||||
{:ok, pid}
|
||||
|
||||
{:error, {:already_started, pid}} ->
|
||||
Agent.update(__MODULE__, fn _ -> state end)
|
||||
{:ok, pid}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user